@wordpress/core-data 4.0.4 → 4.0.8
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/README.md +2 -4
- package/build/actions.js +321 -247
- package/build/actions.js.map +1 -1
- package/build/batch/create-batch.js +17 -9
- package/build/batch/create-batch.js.map +1 -1
- package/build/entities.js +67 -14
- package/build/entities.js.map +1 -1
- package/build/entity-provider.js +18 -13
- package/build/entity-provider.js.map +1 -1
- package/build/fetch/__experimental-fetch-link-suggestions.js +3 -1
- package/build/fetch/__experimental-fetch-link-suggestions.js.map +1 -1
- package/build/fetch/__experimental-fetch-url-data.js +3 -2
- package/build/fetch/__experimental-fetch-url-data.js.map +1 -1
- package/build/index.js +25 -5
- package/build/index.js.map +1 -1
- package/build/locks/actions.js +4 -3
- package/build/locks/actions.js.map +1 -1
- package/build/locks/reducer.js +4 -1
- package/build/locks/reducer.js.map +1 -1
- package/build/locks/selectors.js +4 -3
- package/build/locks/selectors.js.map +1 -1
- package/build/locks/utils.js +7 -5
- package/build/locks/utils.js.map +1 -1
- package/build/queried-data/actions.js +6 -3
- package/build/queried-data/actions.js.map +1 -1
- package/build/queried-data/get-query-parts.js +1 -1
- package/build/queried-data/reducer.js +17 -6
- package/build/queried-data/reducer.js.map +1 -1
- package/build/queried-data/selectors.js +2 -1
- package/build/queried-data/selectors.js.map +1 -1
- package/build/reducer.js +90 -43
- package/build/reducer.js.map +1 -1
- package/build/resolvers.js +216 -163
- package/build/resolvers.js.map +1 -1
- package/build/selectors.js +75 -22
- package/build/selectors.js.map +1 -1
- package/build/utils/forward-resolver.js +30 -0
- package/build/utils/forward-resolver.js.map +1 -0
- package/build/utils/index.js +9 -9
- package/build/utils/index.js.map +1 -1
- package/build/utils/on-sub-key.js +4 -2
- package/build/utils/on-sub-key.js.map +1 -1
- package/build-module/actions.js +306 -240
- package/build-module/actions.js.map +1 -1
- package/build-module/batch/create-batch.js +17 -9
- package/build-module/batch/create-batch.js.map +1 -1
- package/build-module/entities.js +66 -13
- package/build-module/entities.js.map +1 -1
- package/build-module/entity-provider.js +17 -12
- package/build-module/entity-provider.js.map +1 -1
- package/build-module/fetch/__experimental-fetch-link-suggestions.js +3 -1
- package/build-module/fetch/__experimental-fetch-link-suggestions.js.map +1 -1
- package/build-module/fetch/__experimental-fetch-url-data.js +3 -2
- package/build-module/fetch/__experimental-fetch-url-data.js.map +1 -1
- package/build-module/index.js +21 -3
- package/build-module/index.js.map +1 -1
- package/build-module/locks/actions.js +4 -3
- package/build-module/locks/actions.js.map +1 -1
- package/build-module/locks/reducer.js +4 -1
- package/build-module/locks/reducer.js.map +1 -1
- package/build-module/locks/selectors.js +4 -3
- package/build-module/locks/selectors.js.map +1 -1
- package/build-module/locks/utils.js +5 -3
- package/build-module/locks/utils.js.map +1 -1
- package/build-module/queried-data/actions.js +5 -2
- package/build-module/queried-data/actions.js.map +1 -1
- package/build-module/queried-data/reducer.js +15 -4
- package/build-module/queried-data/reducer.js.map +1 -1
- package/build-module/queried-data/selectors.js +2 -1
- package/build-module/queried-data/selectors.js.map +1 -1
- package/build-module/reducer.js +80 -34
- package/build-module/reducer.js.map +1 -1
- package/build-module/resolvers.js +211 -161
- package/build-module/resolvers.js.map +1 -1
- package/build-module/selectors.js +44 -3
- package/build-module/selectors.js.map +1 -1
- package/build-module/utils/forward-resolver.js +22 -0
- package/build-module/utils/forward-resolver.js.map +1 -0
- package/build-module/utils/index.js +1 -1
- package/build-module/utils/index.js.map +1 -1
- package/build-module/utils/on-sub-key.js +3 -1
- package/build-module/utils/on-sub-key.js.map +1 -1
- package/package.json +12 -12
- package/src/actions.js +51 -5
- package/src/entities.js +43 -6
- package/src/fetch/__experimental-fetch-url-data.js +1 -1
- package/src/reducer.js +14 -17
- package/src/resolvers.js +56 -19
- package/src/selectors.js +43 -4
- package/src/test/actions.js +89 -0
- package/src/test/selectors.js +56 -1
- package/src/utils/forward-resolver.js +14 -0
- package/src/utils/index.js +1 -1
- package/build/utils/if-not-resolved.js +0 -31
- package/build/utils/if-not-resolved.js.map +0 -1
- package/build-module/utils/if-not-resolved.js +0 -23
- package/build-module/utils/if-not-resolved.js.map +0 -1
- package/src/utils/if-not-resolved.js +0 -22
- package/src/utils/test/if-not-resolved.js +0 -76
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-data/src/entity-provider.js"],"names":["EMPTY_ARRAY","entities","defaultEntities","reduce","acc","entity","kind","name","context","kinds","getEntity","type","Error","EntityProvider","id","children","Provider","useEntityId","useEntityProp","prop","_id","providerId","value","fullValue","select","getEntityRecord","getEditedEntityRecord","STORE_NAME","editedEntity","editEntityRecord","setValue","newValue","useEntityBlockEditor","content","blocks","__unstableCreateUndoLevel","parsedContent","undoIgnore","onChange","newBlocks","options","selection","edits","noChange","blocksForSerialization","onInput"],"mappings":";;;;;;;;;;AAGA;;AAMA;;AACA;;AAKA;;AAOA;;AAtBA;AACA;AACA;;AAUA;AACA;AACA;AAGA,MAAMA,WAAW,GAAG,EAApB;AAEA;AACA;AACA;;AAGA,MAAMC,QAAQ,GAAG,EAChB,GAAGC,0BAAgBC,MAAhB,CAAwB,CAAEC,GAAF,EAAOC,MAAP,KAAmB;AAC7C,QAAK,CAAED,GAAG,CAAEC,MAAM,CAACC,IAAT,CAAV,EAA4B;AAC3BF,MAAAA,GAAG,CAAEC,MAAM,CAACC,IAAT,CAAH,GAAqB,EAArB;AACA;;AACDF,IAAAA,GAAG,CAAEC,MAAM,CAACC,IAAT,CAAH,CAAoBD,MAAM,CAACE,IAA3B,IAAoC;AAAEC,MAAAA,OAAO,EAAE;AAAX,KAApC;AACA,WAAOJ,GAAP;AACA,GANE,EAMA,EANA,CADa;AAQhB,KAAGK,gBAAMN,MAAN,CAAc,CAAEC,GAAF,EAAOE,IAAP,KAAiB;AACjCF,IAAAA,GAAG,CAAEE,IAAI,CAACC,IAAP,CAAH,GAAmB,EAAnB;AACA,WAAOH,GAAP;AACA,GAHE,EAGA,EAHA;AAR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AME,QAAQ,GAAGT,MAAM,KAAKQ,KAAK,CAACR,MAAlC;;AACA,QAAKS,QAAL,EAAgB;AACf,aAAOR,yBAAyB,CAAE7B,IAAF,EAAQK,IAAR,EAAcG,EAAd,CAAhC;AACA,KAPwB,CASzB;AACA;AACA;;;AACA4B,IAAAA,KAAK,CAACT,OAAN,GAAgB,CAAE;AAAEC,MAAAA,MAAM,EAAEU,sBAAsB,GAAG;AAAnC,KAAF,KACf,yCAA6BA,sBAA7B,CADD;;AAGAf,IAAAA,gBAAgB,CAAEvB,IAAF,EAAQK,IAAR,EAAcG,EAAd,EAAkB4B,KAAlB,CAAhB;AACA,GAjBe,EAkBhB,CAAEpC,IAAF,EAAQK,IAAR,EAAcG,EAAd,EAAkBoB,MAAlB,CAlBgB,CAAjB;AAqBA,QAAMW,OAAO,GAAG,0BACf,CAAEN,SAAF,EAAaC,OAAb,KAA0B;AACzB,UAAM;AAAEC,MAAAA;AAAF,QAAgBD,OAAtB;AACA,UAAME,KAAK,GAAG;AAAER,MAAAA,MAAM,EAAEK,SAAV;AAAqBE,MAAAA;AAArB,KAAd;AACAZ,IAAAA,gBAAgB,CAAEvB,IAAF,EAAQK,IAAR,EAAcG,EAAd,EAAkB4B,KAAlB,CAAhB;AACA,GALc,EAMf,CAAEpC,IAAF,EAAQK,IAAR,EAAcG,EAAd,CANe,CAAhB;AASA,SAAO,CAAEoB,MAAF,aAAEA,MAAF,cAAEA,MAAF,GAAYlC,WAAZ,EAAyB6C,OAAzB,EAAkCP,QAAlC,CAAP;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tcreateContext,\n\tuseContext,\n\tuseCallback,\n\tuseEffect,\n} from '@wordpress/element';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { parse, __unstableSerializeAndClean } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport { STORE_NAME } from './name';\n\nconst EMPTY_ARRAY = [];\n\n/**\n * Internal dependencies\n */\nimport { defaultEntities, kinds } from './entities';\n\nconst entities = {\n\t...defaultEntities.reduce( ( acc, entity ) => {\n\t\tif ( ! acc[ entity.kind ] ) {\n\t\t\tacc[ entity.kind ] = {};\n\t\t}\n\t\tacc[ entity.kind ][ entity.name ] = { context: createContext() };\n\t\treturn acc;\n\t}, {} ),\n\t...kinds.reduce( ( acc, kind ) => {\n\t\tacc[ kind.name ] = {};\n\t\treturn acc;\n\t}, {} ),\n};\nconst getEntity = ( kind, type ) => {\n\tif ( ! entities[ kind ] ) {\n\t\tthrow new Error( `Missing entity config for kind: ${ kind }.` );\n\t}\n\n\tif ( ! entities[ kind ][ type ] ) {\n\t\tentities[ kind ][ type ] = { context: createContext() };\n\t}\n\n\treturn entities[ kind ][ type ];\n};\n\n/**\n * Context provider component for providing\n * an entity for a specific entity type.\n *\n * @param {Object} props The component's props.\n * @param {string} props.kind The entity kind.\n * @param {string} props.type The entity type.\n * @param {number} props.id The entity ID.\n * @param {*} props.children The children to wrap.\n *\n * @return {Object} The provided children, wrapped with\n * the entity's context provider.\n */\nexport default function EntityProvider( { kind, type, id, children } ) {\n\tconst Provider = getEntity( kind, type ).context.Provider;\n\treturn <Provider value={ id }>{ children }</Provider>;\n}\n\n/**\n * Hook that returns the ID for the nearest\n * provided entity of the specified type.\n *\n * @param {string} kind The entity kind.\n * @param {string} type The entity type.\n */\nexport function useEntityId( kind, type ) {\n\treturn useContext( getEntity( kind, type ).context );\n}\n\n/**\n * Hook that returns the value and a setter for the\n * specified property of the nearest provided\n * entity of the specified type.\n *\n * @param {string} kind The entity kind.\n * @param {string} type The entity type.\n * @param {string} prop The property name.\n * @param {string} [_id] An entity ID to use instead of the context-provided one.\n *\n * @return {[*, Function, *]} An array where the first item is the\n * property value, the second is the\n * setter and the third is the full value\n * \t\t\t\t\t\t\t object from REST API containing more\n * \t\t\t\t\t\t\t information like `raw`, `rendered` and\n * \t\t\t\t\t\t\t `protected` props.\n */\nexport function useEntityProp( kind, type, prop, _id ) {\n\tconst providerId = useEntityId( kind, type );\n\tconst id = _id ?? providerId;\n\n\tconst { value, fullValue } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getEntityRecord, getEditedEntityRecord } = select(\n\t\t\t\tSTORE_NAME\n\t\t\t);\n\t\t\tconst entity = getEntityRecord( kind, type, id ); // Trigger resolver.\n\t\t\tconst editedEntity = getEditedEntityRecord( kind, type, id );\n\t\t\treturn entity && editedEntity\n\t\t\t\t? {\n\t\t\t\t\t\tvalue: editedEntity[ prop ],\n\t\t\t\t\t\tfullValue: entity[ prop ],\n\t\t\t\t }\n\t\t\t\t: {};\n\t\t},\n\t\t[ kind, type, id, prop ]\n\t);\n\tconst { editEntityRecord } = useDispatch( STORE_NAME );\n\tconst setValue = useCallback(\n\t\t( newValue ) => {\n\t\t\teditEntityRecord( kind, type, id, {\n\t\t\t\t[ prop ]: newValue,\n\t\t\t} );\n\t\t},\n\t\t[ kind, type, id, prop ]\n\t);\n\n\treturn [ value, setValue, fullValue ];\n}\n\n/**\n * Hook that returns block content getters and setters for\n * the nearest provided entity of the specified type.\n *\n * The return value has the shape `[ blocks, onInput, onChange ]`.\n * `onInput` is for block changes that don't create undo levels\n * or dirty the post, non-persistent changes, and `onChange` is for\n * peristent changes. They map directly to the props of a\n * `BlockEditorProvider` and are intended to be used with it,\n * or similar components or hooks.\n *\n * @param {string} kind The entity kind.\n * @param {string} type The entity type.\n * @param {Object} options\n * @param {string} [options.id] An entity ID to use instead of the context-provided one.\n *\n * @return {[WPBlock[], Function, Function]} The block array and setters.\n */\nexport function useEntityBlockEditor( kind, type, { id: _id } = {} ) {\n\tconst providerId = useEntityId( kind, type );\n\tconst id = _id ?? providerId;\n\tconst { content, blocks } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getEditedEntityRecord } = select( STORE_NAME );\n\t\t\tconst editedEntity = getEditedEntityRecord( kind, type, id );\n\t\t\treturn {\n\t\t\t\tblocks: editedEntity.blocks,\n\t\t\t\tcontent: editedEntity.content,\n\t\t\t};\n\t\t},\n\t\t[ kind, type, id ]\n\t);\n\tconst { __unstableCreateUndoLevel, editEntityRecord } = useDispatch(\n\t\tSTORE_NAME\n\t);\n\n\tuseEffect( () => {\n\t\t// Load the blocks from the content if not already in state\n\t\t// Guard against other instances that might have\n\t\t// set content to a function already or the blocks are already in state.\n\t\tif ( content && typeof content !== 'function' && ! blocks ) {\n\t\t\tconst parsedContent = parse( content );\n\t\t\teditEntityRecord(\n\t\t\t\tkind,\n\t\t\t\ttype,\n\t\t\t\tid,\n\t\t\t\t{\n\t\t\t\t\tblocks: parsedContent,\n\t\t\t\t},\n\t\t\t\t{ undoIgnore: true }\n\t\t\t);\n\t\t}\n\t}, [ content ] );\n\n\tconst onChange = useCallback(\n\t\t( newBlocks, options ) => {\n\t\t\tconst { selection } = options;\n\t\t\tconst edits = { blocks: newBlocks, selection };\n\n\t\t\tconst noChange = blocks === edits.blocks;\n\t\t\tif ( noChange ) {\n\t\t\t\treturn __unstableCreateUndoLevel( kind, type, id );\n\t\t\t}\n\n\t\t\t// We create a new function here on every persistent edit\n\t\t\t// to make sure the edit makes the post dirty and creates\n\t\t\t// a new undo level.\n\t\t\tedits.content = ( { blocks: blocksForSerialization = [] } ) =>\n\t\t\t\t__unstableSerializeAndClean( blocksForSerialization );\n\n\t\t\teditEntityRecord( kind, type, id, edits );\n\t\t},\n\t\t[ kind, type, id, blocks ]\n\t);\n\n\tconst onInput = useCallback(\n\t\t( newBlocks, options ) => {\n\t\t\tconst { selection } = options;\n\t\t\tconst edits = { blocks: newBlocks, selection };\n\t\t\teditEntityRecord( kind, type, id, edits );\n\t\t},\n\t\t[ kind, type, id ]\n\t);\n\n\treturn [ blocks ?? EMPTY_ARRAY, onInput, onChange ];\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-data/src/entity-provider.js"],"names":["EMPTY_ARRAY","entities","defaultEntities","reduce","acc","entity","kind","name","context","kinds","getEntity","type","Error","EntityProvider","id","children","Provider","useEntityId","useEntityProp","prop","_id","providerId","value","fullValue","select","getEntityRecord","getEditedEntityRecord","STORE_NAME","editedEntity","editEntityRecord","setValue","newValue","useEntityBlockEditor","content","blocks","__unstableCreateUndoLevel","parsedContent","undoIgnore","onChange","newBlocks","options","selection","edits","noChange","blocksForSerialization","onInput"],"mappings":";;;;;;;;;;AAGA;;AAMA;;AACA;;AAKA;;AAOA;;AAtBA;AACA;AACA;;AAUA;AACA;AACA;AAGA,MAAMA,WAAW,GAAG,EAApB;AAEA;AACA;AACA;;AAGA,MAAMC,QAAQ,GAAG,EAChB,GAAGC,0BAAgBC,MAAhB,CAAwB,CAAEC,GAAF,EAAOC,MAAP,KAAmB;AAC7C,QAAK,CAAED,GAAG,CAAEC,MAAM,CAACC,IAAT,CAAV,EAA4B;AAC3BF,MAAAA,GAAG,CAAEC,MAAM,CAACC,IAAT,CAAH,GAAqB,EAArB;AACA;;AACDF,IAAAA,GAAG,CAAEC,MAAM,CAACC,IAAT,CAAH,CAAoBD,MAAM,CAACE,IAA3B,IAAoC;AAAEC,MAAAA,OAAO,EAAE;AAAX,KAApC;AACA,WAAOJ,GAAP;AACA,GANE,EAMA,EANA,CADa;AAQhB,KAAGK,gBAAMN,MAAN,CAAc,CAAEC,GAAF,EAAOE,IAAP,KAAiB;AACjCF,IAAAA,GAAG,CAAEE,IAAI,CAACC,IAAP,CAAH,GAAmB,EAAnB;AACA,WAAOH,GAAP;AACA,GAHE,EAGA,EAHA;AARa,CAAjB;;AAaA,MAAMM,SAAS,GAAG,CAAEJ,IAAF,EAAQK,IAAR,KAAkB;AACnC,MAAK,CAAEV,QAAQ,CAAEK,IAAF,CAAf,EAA0B;AACzB,UAAM,IAAIM,KAAJ,CAAY,mCAAmCN,IAAM,GAArD,CAAN;AACA;;AAED,MAAK,CAAEL,QAAQ,CAAEK,IAAF,CAAR,CAAkBK,IAAlB,CAAP,EAAkC;AACjCV,IAAAA,QAAQ,CAAEK,IAAF,CAAR,CAAkBK,IAAlB,IAA2B;AAAEH,MAAAA,OAAO,EAAE;AAAX,KA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AA,gBAAgB,CAAEvB,IAAF,EAAQK,IAAR,EAAcG,EAAd,EAAkB4B,KAAlB,CAAhB;AACA,GAjBe,EAkBhB,CAAEpC,IAAF,EAAQK,IAAR,EAAcG,EAAd,EAAkBoB,MAAlB,CAlBgB,CAAjB;AAqBA,QAAMW,OAAO,GAAG,0BACf,CAAEN,SAAF,EAAaC,OAAb,KAA0B;AACzB,UAAM;AAAEC,MAAAA;AAAF,QAAgBD,OAAtB;AACA,UAAME,KAAK,GAAG;AAAER,MAAAA,MAAM,EAAEK,SAAV;AAAqBE,MAAAA;AAArB,KAAd;AACAZ,IAAAA,gBAAgB,CAAEvB,IAAF,EAAQK,IAAR,EAAcG,EAAd,EAAkB4B,KAAlB,CAAhB;AACA,GALc,EAMf,CAAEpC,IAAF,EAAQK,IAAR,EAAcG,EAAd,CANe,CAAhB;AASA,SAAO,CAAEoB,MAAF,aAAEA,MAAF,cAAEA,MAAF,GAAYlC,WAAZ,EAAyB6C,OAAzB,EAAkCP,QAAlC,CAAP;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tcreateContext,\n\tuseContext,\n\tuseCallback,\n\tuseEffect,\n} from '@wordpress/element';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { parse, __unstableSerializeAndClean } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport { STORE_NAME } from './name';\n\nconst EMPTY_ARRAY = [];\n\n/**\n * Internal dependencies\n */\nimport { defaultEntities, kinds } from './entities';\n\nconst entities = {\n\t...defaultEntities.reduce( ( acc, entity ) => {\n\t\tif ( ! acc[ entity.kind ] ) {\n\t\t\tacc[ entity.kind ] = {};\n\t\t}\n\t\tacc[ entity.kind ][ entity.name ] = { context: createContext() };\n\t\treturn acc;\n\t}, {} ),\n\t...kinds.reduce( ( acc, kind ) => {\n\t\tacc[ kind.name ] = {};\n\t\treturn acc;\n\t}, {} ),\n};\nconst getEntity = ( kind, type ) => {\n\tif ( ! entities[ kind ] ) {\n\t\tthrow new Error( `Missing entity config for kind: ${ kind }.` );\n\t}\n\n\tif ( ! entities[ kind ][ type ] ) {\n\t\tentities[ kind ][ type ] = { context: createContext() };\n\t}\n\n\treturn entities[ kind ][ type ];\n};\n\n/**\n * Context provider component for providing\n * an entity for a specific entity type.\n *\n * @param {Object} props The component's props.\n * @param {string} props.kind The entity kind.\n * @param {string} props.type The entity type.\n * @param {number} props.id The entity ID.\n * @param {*} props.children The children to wrap.\n *\n * @return {Object} The provided children, wrapped with\n * the entity's context provider.\n */\nexport default function EntityProvider( { kind, type, id, children } ) {\n\tconst Provider = getEntity( kind, type ).context.Provider;\n\treturn <Provider value={ id }>{ children }</Provider>;\n}\n\n/**\n * Hook that returns the ID for the nearest\n * provided entity of the specified type.\n *\n * @param {string} kind The entity kind.\n * @param {string} type The entity type.\n */\nexport function useEntityId( kind, type ) {\n\treturn useContext( getEntity( kind, type ).context );\n}\n\n/**\n * Hook that returns the value and a setter for the\n * specified property of the nearest provided\n * entity of the specified type.\n *\n * @param {string} kind The entity kind.\n * @param {string} type The entity type.\n * @param {string} prop The property name.\n * @param {string} [_id] An entity ID to use instead of the context-provided one.\n *\n * @return {[*, Function, *]} An array where the first item is the\n * property value, the second is the\n * setter and the third is the full value\n * \t\t\t\t\t\t\t object from REST API containing more\n * \t\t\t\t\t\t\t information like `raw`, `rendered` and\n * \t\t\t\t\t\t\t `protected` props.\n */\nexport function useEntityProp( kind, type, prop, _id ) {\n\tconst providerId = useEntityId( kind, type );\n\tconst id = _id ?? providerId;\n\n\tconst { value, fullValue } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getEntityRecord, getEditedEntityRecord } = select(\n\t\t\t\tSTORE_NAME\n\t\t\t);\n\t\t\tconst entity = getEntityRecord( kind, type, id ); // Trigger resolver.\n\t\t\tconst editedEntity = getEditedEntityRecord( kind, type, id );\n\t\t\treturn entity && editedEntity\n\t\t\t\t? {\n\t\t\t\t\t\tvalue: editedEntity[ prop ],\n\t\t\t\t\t\tfullValue: entity[ prop ],\n\t\t\t\t }\n\t\t\t\t: {};\n\t\t},\n\t\t[ kind, type, id, prop ]\n\t);\n\tconst { editEntityRecord } = useDispatch( STORE_NAME );\n\tconst setValue = useCallback(\n\t\t( newValue ) => {\n\t\t\teditEntityRecord( kind, type, id, {\n\t\t\t\t[ prop ]: newValue,\n\t\t\t} );\n\t\t},\n\t\t[ kind, type, id, prop ]\n\t);\n\n\treturn [ value, setValue, fullValue ];\n}\n\n/**\n * Hook that returns block content getters and setters for\n * the nearest provided entity of the specified type.\n *\n * The return value has the shape `[ blocks, onInput, onChange ]`.\n * `onInput` is for block changes that don't create undo levels\n * or dirty the post, non-persistent changes, and `onChange` is for\n * peristent changes. They map directly to the props of a\n * `BlockEditorProvider` and are intended to be used with it,\n * or similar components or hooks.\n *\n * @param {string} kind The entity kind.\n * @param {string} type The entity type.\n * @param {Object} options\n * @param {string} [options.id] An entity ID to use instead of the context-provided one.\n *\n * @return {[WPBlock[], Function, Function]} The block array and setters.\n */\nexport function useEntityBlockEditor( kind, type, { id: _id } = {} ) {\n\tconst providerId = useEntityId( kind, type );\n\tconst id = _id ?? providerId;\n\tconst { content, blocks } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getEditedEntityRecord } = select( STORE_NAME );\n\t\t\tconst editedEntity = getEditedEntityRecord( kind, type, id );\n\t\t\treturn {\n\t\t\t\tblocks: editedEntity.blocks,\n\t\t\t\tcontent: editedEntity.content,\n\t\t\t};\n\t\t},\n\t\t[ kind, type, id ]\n\t);\n\tconst { __unstableCreateUndoLevel, editEntityRecord } = useDispatch(\n\t\tSTORE_NAME\n\t);\n\n\tuseEffect( () => {\n\t\t// Load the blocks from the content if not already in state\n\t\t// Guard against other instances that might have\n\t\t// set content to a function already or the blocks are already in state.\n\t\tif ( content && typeof content !== 'function' && ! blocks ) {\n\t\t\tconst parsedContent = parse( content );\n\t\t\teditEntityRecord(\n\t\t\t\tkind,\n\t\t\t\ttype,\n\t\t\t\tid,\n\t\t\t\t{\n\t\t\t\t\tblocks: parsedContent,\n\t\t\t\t},\n\t\t\t\t{ undoIgnore: true }\n\t\t\t);\n\t\t}\n\t}, [ content ] );\n\n\tconst onChange = useCallback(\n\t\t( newBlocks, options ) => {\n\t\t\tconst { selection } = options;\n\t\t\tconst edits = { blocks: newBlocks, selection };\n\n\t\t\tconst noChange = blocks === edits.blocks;\n\t\t\tif ( noChange ) {\n\t\t\t\treturn __unstableCreateUndoLevel( kind, type, id );\n\t\t\t}\n\n\t\t\t// We create a new function here on every persistent edit\n\t\t\t// to make sure the edit makes the post dirty and creates\n\t\t\t// a new undo level.\n\t\t\tedits.content = ( { blocks: blocksForSerialization = [] } ) =>\n\t\t\t\t__unstableSerializeAndClean( blocksForSerialization );\n\n\t\t\teditEntityRecord( kind, type, id, edits );\n\t\t},\n\t\t[ kind, type, id, blocks ]\n\t);\n\n\tconst onInput = useCallback(\n\t\t( newBlocks, options ) => {\n\t\t\tconst { selection } = options;\n\t\t\tconst edits = { blocks: newBlocks, selection };\n\t\t\teditEntityRecord( kind, type, id, edits );\n\t\t},\n\t\t[ kind, type, id ]\n\t);\n\n\treturn [ blocks ?? EMPTY_ARRAY, onInput, onChange ];\n}\n"]}
|
|
@@ -80,7 +80,9 @@ var _i18n = require("@wordpress/i18n");
|
|
|
80
80
|
* ```
|
|
81
81
|
* @return {Promise< WPLinkSearchResult[] >} List of search suggestions
|
|
82
82
|
*/
|
|
83
|
-
const fetchLinkSuggestions = async (search
|
|
83
|
+
const fetchLinkSuggestions = async function (search) {
|
|
84
|
+
let searchOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
85
|
+
let settings = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
84
86
|
const {
|
|
85
87
|
isInitialSuggestions = false,
|
|
86
88
|
type = undefined,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-data/src/fetch/__experimental-fetch-link-suggestions.js"],"names":["fetchLinkSuggestions","search","searchOptions","settings","isInitialSuggestions","type","undefined","subtype","page","perPage","disablePostFormats","queries","push","path","per_page","then","results","map","result","meta","kind","catch","Promise","all","reduce","accumulator","current","concat","filter","id","slice","url","title"],"mappings":";;;;;;;;;AAGA;;AACA;;AACA;;AACA;;AANA;AACA;AACA;;AAMA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMA,oBAAoB,GAAG,
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-data/src/fetch/__experimental-fetch-link-suggestions.js"],"names":["fetchLinkSuggestions","search","searchOptions","settings","isInitialSuggestions","type","undefined","subtype","page","perPage","disablePostFormats","queries","push","path","per_page","then","results","map","result","meta","kind","catch","Promise","all","reduce","accumulator","current","concat","filter","id","slice","url","title"],"mappings":";;;;;;;;;AAGA;;AACA;;AACA;;AACA;;AANA;AACA;AACA;;AAMA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMA,oBAAoB,GAAG,gBAC5BC,MAD4B,EAIxB;AAAA,MAFJC,aAEI,uEAFY,EAEZ;AAAA,MADJC,QACI,uEADO,EACP;AACJ,QAAM;AACLC,IAAAA,oBAAoB,GAAG,KADlB;AAELC,IAAAA,IAAI,GAAGC,SAF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Ac;AAAA;;AACb,aAAO;AACNW,QAAAA,EAAE,EAAEX,MAAM,CAACW,EADL;AAENE,QAAAA,GAAG,EAAEb,MAAM,CAACa,GAFN;AAGNC,QAAAA,KAAK,EACJ,kCAAgBd,MAAM,CAACc,KAAP,IAAgB,EAAhC,KACA,cAAI,YAAJ,CALK;AAMN3B,QAAAA,IAAI,EAAEa,MAAM,CAACX,OAAP,IAAkBW,MAAM,CAACb,IANzB;AAONe,QAAAA,IAAI,EAAEF,MAAF,aAAEA,MAAF,uCAAEA,MAAM,CAAEC,IAAV,iDAAE,aAAcC;AAPd,OAAP;AASA,KA5BI,CAAP;AA8BA,GA/BM,CAAP;AAgCA,CAtHD;;eAwHepB,oB","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\n/**\n * Filters the search by type\n *\n * @typedef { 'post' | 'term' | 'post-format' } WPLinkSearchType\n */\n\n/**\n * A link with an id may be of kind post-type or taxonomy\n *\n * @typedef { 'post-type' | 'taxonomy' } WPKind\n */\n\n/**\n * @typedef WPLinkSearchOptions\n *\n * @property {boolean} [isInitialSuggestions] Displays initial search suggestions, when true.\n * @property {WPLinkSearchType} [type] Filters by search type.\n * @property {string} [subtype] Slug of the post-type or taxonomy.\n * @property {number} [page] Which page of results to return.\n * @property {number} [perPage] Search results per page.\n */\n\n/**\n * @typedef WPLinkSearchResult\n *\n * @property {number} id Post or term id.\n * @property {string} url Link url.\n * @property {string} title Title of the link.\n * @property {string} type The taxonomy or post type slug or type URL.\n * @property {WPKind} [kind] Link kind of post-type or taxonomy\n */\n\n/**\n * @typedef WPEditorSettings\n *\n * @property {boolean} [ disablePostFormats ] Disables post formats, when true.\n */\n\n/**\n * Fetches link suggestions from the API.\n *\n * @async\n * @param {string} search\n * @param {WPLinkSearchOptions} [searchOptions]\n * @param {WPEditorSettings} [settings]\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 * @return {Promise< WPLinkSearchResult[] >} List of search suggestions\n */\nconst fetchLinkSuggestions = async (\n\tsearch,\n\tsearchOptions = {},\n\tsettings = {}\n) => {\n\tconst {\n\t\tisInitialSuggestions = false,\n\t\ttype = undefined,\n\t\tsubtype = undefined,\n\t\tpage = undefined,\n\t\tperPage = isInitialSuggestions ? 3 : 20,\n\t} = searchOptions;\n\n\tconst { disablePostFormats = false } = settings;\n\n\tconst queries = [];\n\n\tif ( ! type || type === 'post' ) {\n\t\tqueries.push(\n\t\t\tapiFetch( {\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\t...result,\n\t\t\t\t\t\t\tmeta: { kind: 'post-type', subtype },\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( {\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\t...result,\n\t\t\t\t\t\t\tmeta: { kind: 'taxonomy', subtype },\n\t\t\t\t\t\t};\n\t\t\t\t\t} );\n\t\t\t\t} )\n\t\t\t\t.catch( () => [] )\n\t\t);\n\t}\n\n\tif ( ! disablePostFormats && ( ! type || type === 'post-format' ) ) {\n\t\tqueries.push(\n\t\t\tapiFetch( {\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\t...result,\n\t\t\t\t\t\t\tmeta: { kind: 'taxonomy', subtype },\n\t\t\t\t\t\t};\n\t\t\t\t\t} );\n\t\t\t\t} )\n\t\t\t\t.catch( () => [] )\n\t\t);\n\t}\n\n\treturn Promise.all( queries ).then( ( results ) => {\n\t\treturn results\n\t\t\t.reduce(\n\t\t\t\t( accumulator, current ) => accumulator.concat( current ), //flatten list\n\t\t\t\t[]\n\t\t\t)\n\t\t\t.filter(\n\t\t\t\t/**\n\t\t\t\t * @param {{ id: number }} result\n\t\t\t\t */\n\t\t\t\t( result ) => {\n\t\t\t\t\treturn !! result.id;\n\t\t\t\t}\n\t\t\t)\n\t\t\t.slice( 0, perPage )\n\t\t\t.map(\n\t\t\t\t/**\n\t\t\t\t * @param {{ id: number, url:string, title?:string, subtype?: string, type?: string }} result\n\t\t\t\t */\n\t\t\t\t( result ) => {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tid: result.id,\n\t\t\t\t\t\turl: result.url,\n\t\t\t\t\t\ttitle:\n\t\t\t\t\t\t\tdecodeEntities( result.title || '' ) ||\n\t\t\t\t\t\t\t__( '(no title)' ),\n\t\t\t\t\t\ttype: result.subtype || result.type,\n\t\t\t\t\t\tkind: result?.meta?.kind,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t);\n\t} );\n};\n\nexport default fetchLinkSuggestions;\n"]}
|
|
@@ -49,8 +49,9 @@ const CACHE = new Map();
|
|
|
49
49
|
* @return {Promise< WPRemoteUrlData[] >} Remote URL data.
|
|
50
50
|
*/
|
|
51
51
|
|
|
52
|
-
const fetchUrlData = async (url
|
|
53
|
-
|
|
52
|
+
const fetchUrlData = async function (url) {
|
|
53
|
+
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
54
|
+
const endpoint = '/wp-block-editor/v1/url-details';
|
|
54
55
|
const args = {
|
|
55
56
|
url: (0, _url.prependHTTP)(url)
|
|
56
57
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-data/src/fetch/__experimental-fetch-url-data.js"],"names":["CACHE","Map","fetchUrlData","url","options","endpoint","args","Promise","reject","protocol","startsWith","test","has","get","path","then","res","set"],"mappings":";;;;;;;;;AAGA;;AACA;;AAJA;AACA;AACA;;AAUA;AACA;AACA;AACA;AACA;AACA,MAAMA,KAAK,GAAG,IAAIC,GAAJ,EAAd;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,MAAMC,YAAY,GAAG,
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-data/src/fetch/__experimental-fetch-url-data.js"],"names":["CACHE","Map","fetchUrlData","url","options","endpoint","args","Promise","reject","protocol","startsWith","test","has","get","path","then","res","set"],"mappings":";;;;;;;;;AAGA;;AACA;;AAJA;AACA;AACA;;AAUA;AACA;AACA;AACA;AACA;AACA,MAAMA,KAAK,GAAG,IAAIC,GAAJ,EAAd;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,MAAMC,YAAY,GAAG,gBAAQC,GAAR,EAA+B;AAAA,MAAlBC,OAAkB,uEAAR,EAAQ;AACnD,QAAMC,QAAQ,GAAG,iCAAjB;AAEA,QAAMC,IAAI,GAAG;AACZH,IAAAA,GAAG,EAAE,sBAAaA,GAAb;AADO,GAAb;;AAIA,MAAK,CAAE,gBAAOA,GAAP,CAAP,EAAsB;AACrB,WAAOI,OAAO,CAACC,MAAR,CAAiB,GAAGL,GAAK,sBAAzB,CAAP;AACA,GATkD,CAWnD;AACA;;;AACA,QAAMM,QAAQ,GAAG,sBAAaN,GAAb,CAAjB;;AAEA,MACC,CAAE,0BAAiBM,QAAjB,CAAF,IACA,CAAEA,QAAQ,CAACC,UAAT,CAAqB,MAArB,CADF,IAEA,CAAE,uBAAuBC,IAAvB,CAA6BR,GAA7B,CAHH,EAIE;AACD,WAAOI,OAAO,CAACC,MAAR,CACL,GAAGL,GAAK,4DADH,CAAP;AAGA;;AAED,MAAKH,KAAK,CAACY,GAAN,CAAWT,GAAX,CAAL,EAAwB;AACvB,WAAOH,KAAK,CAACa,GAAN,CAAWV,GAAX,CAAP;AACA;;AAED,SAAO,uBAAU;AAChBW,IAAAA,IAAI,EAAE,uBAAcT,QAAd,EAAwBC,IAAxB,CADU;AAEhB,OAAGF;AAFa,GAAV,EAGHW,IAHG,CAGKC,GAAF,IAAW;AACpBhB,IAAAA,KAAK,CAACiB,GAAN,CAAWd,GAAX,EAAgBa,GAAhB;AACA,WAAOA,GAAP;AACA,GANM,CAAP;AAOA,CApCD;;eAsCed,Y","sourcesContent":["/**\n * WordPress dependencies\n */\nimport apiFetch from '@wordpress/api-fetch';\nimport {\n\taddQueryArgs,\n\tprependHTTP,\n\tisURL,\n\tgetProtocol,\n\tisValidProtocol,\n} from '@wordpress/url';\n\n/**\n * A simple in-memory cache for requests.\n * This avoids repeat HTTP requests which may be beneficial\n * for those wishing to preserve low-bandwidth.\n */\nconst CACHE = new Map();\n\n/**\n * @typedef WPRemoteUrlData\n *\n * @property {string} title contents of the remote URL's `<title>` tag.\n */\n\n/**\n * Fetches data about a remote URL.\n * eg: <title> tag, favicon...etc.\n *\n * @async\n * @param {string} url the URL to request details from.\n * @param {Object?} options any options to pass to the underlying fetch.\n * @example\n * ```js\n * import { __experimentalFetchUrlData as fetchUrlData } from '@wordpress/core-data';\n *\n * //...\n *\n * export function initialize( id, settings ) {\n *\n * settings.__experimentalFetchUrlData = (\n * url\n * ) => fetchUrlData( url );\n * ```\n * @return {Promise< WPRemoteUrlData[] >} Remote URL data.\n */\nconst fetchUrlData = async ( url, options = {} ) => {\n\tconst endpoint = '/wp-block-editor/v1/url-details';\n\n\tconst args = {\n\t\turl: prependHTTP( url ),\n\t};\n\n\tif ( ! isURL( url ) ) {\n\t\treturn Promise.reject( `${ url } is not a valid URL.` );\n\t}\n\n\t// Test for \"http\" based URL as it is possible for valid\n\t// yet unusable URLs such as `tel:123456` to be passed.\n\tconst protocol = getProtocol( url );\n\n\tif (\n\t\t! isValidProtocol( protocol ) ||\n\t\t! protocol.startsWith( 'http' ) ||\n\t\t! /^https?:\\/\\/[^\\/\\s]/i.test( url )\n\t) {\n\t\treturn Promise.reject(\n\t\t\t`${ url } does not have a valid protocol. URLs must be \"http\" based`\n\t\t);\n\t}\n\n\tif ( CACHE.has( url ) ) {\n\t\treturn CACHE.get( url );\n\t}\n\n\treturn apiFetch( {\n\t\tpath: addQueryArgs( endpoint, args ),\n\t\t...options,\n\t} ).then( ( res ) => {\n\t\tCACHE.set( url, res );\n\t\treturn res;\n\t} );\n};\n\nexport default fetchUrlData;\n"]}
|
package/build/index.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
|
|
4
|
-
|
|
5
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
6
4
|
|
|
7
5
|
Object.defineProperty(exports, "__esModule", {
|
|
@@ -63,6 +61,10 @@ Object.keys(_fetch).forEach(function (key) {
|
|
|
63
61
|
});
|
|
64
62
|
});
|
|
65
63
|
|
|
64
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
65
|
+
|
|
66
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
67
|
+
|
|
66
68
|
/**
|
|
67
69
|
* WordPress dependencies
|
|
68
70
|
*/
|
|
@@ -82,7 +84,13 @@ const entitySelectors = _entities.defaultEntities.reduce((result, entity) => {
|
|
|
82
84
|
|
|
83
85
|
result[(0, _entities.getMethodName)(kind, name)] = (state, key, query) => selectors.getEntityRecord(state, kind, name, key, query);
|
|
84
86
|
|
|
85
|
-
result[(0, _entities.getMethodName)(kind, name, 'get', true)] = (state
|
|
87
|
+
result[(0, _entities.getMethodName)(kind, name, 'get', true)] = function (state) {
|
|
88
|
+
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
89
|
+
args[_key - 1] = arguments[_key];
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return selectors.getEntityRecords(state, kind, name, ...args);
|
|
93
|
+
};
|
|
86
94
|
|
|
87
95
|
return result;
|
|
88
96
|
}, {});
|
|
@@ -97,9 +105,21 @@ const entityResolvers = _entities.defaultEntities.reduce((result, entity) => {
|
|
|
97
105
|
|
|
98
106
|
const pluralMethodName = (0, _entities.getMethodName)(kind, name, 'get', true);
|
|
99
107
|
|
|
100
|
-
result[pluralMethodName] = (
|
|
108
|
+
result[pluralMethodName] = function () {
|
|
109
|
+
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
110
|
+
args[_key2] = arguments[_key2];
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return resolvers.getEntityRecords(kind, name, ...args);
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
result[pluralMethodName].shouldInvalidate = function (action) {
|
|
117
|
+
for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
|
|
118
|
+
args[_key3 - 1] = arguments[_key3];
|
|
119
|
+
}
|
|
101
120
|
|
|
102
|
-
|
|
121
|
+
return resolvers.getEntityRecords.shouldInvalidate(action, kind, name, ...args);
|
|
122
|
+
};
|
|
103
123
|
|
|
104
124
|
return result;
|
|
105
125
|
}, {});
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-data/src/index.js"],"names":["entitySelectors","defaultEntities","reduce","result","entity","kind","name","state","key","query","selectors","getEntityRecord","args","getEntityRecords","entityResolvers","resolvers","pluralMethodName","shouldInvalidate","action","entityActions","actions","saveEntityRecord","deleteEntityRecord","storeConfig","reducer","__experimentalUseThunks","store","STORE_NAME"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-data/src/index.js"],"names":["entitySelectors","defaultEntities","reduce","result","entity","kind","name","state","key","query","selectors","getEntityRecord","args","getEntityRecords","entityResolvers","resolvers","pluralMethodName","shouldInvalidate","action","entityActions","actions","saveEntityRecord","deleteEntityRecord","storeConfig","reducer","__experimentalUseThunks","store","STORE_NAME"],"mappings":";;;;;;;;;;;;;;;;;;;AAGA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AA6DA;;AACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;;;;AA7EA;AACA;AACA;;AAGA;AACA;AACA;AASA;AACA;AACA;AACA;AAEA,MAAMA,eAAe,GAAGC,0BAAgBC,MAAhB,CAAwB,CAAEC,MAAF,EAAUC,MAAV,KAAsB;AACrE,QAAM;AAAEC,IAAAA,IAAF;AAAQC,IAAAA;AAAR,MAAiBF,MAAvB;;AACAD,EAAAA,MAAM,CAAE,6BAAeE,IAAf,EAAqBC,IAArB,CAAF,CAAN,GAAwC,CAAEC,KAAF,EAASC,GAAT,EAAcC,KAAd,KACvCC,SAAS,CAACC,eAAV,CAA2BJ,KAA3B,EAAkCF,IAAlC,EAAwCC,IAAxC,EAA8CE,GAA9C,EAAmDC,KAAnD,CADD;;AAEAN,EAAAA,MAAM,CAAE,6BAAeE,IAAf,EAAqBC,IAArB,EAA2B,KAA3B,EAAkC,IAAlC,CAAF,CAAN,GAAqD,UAAEC,KAAF;AAAA,sCAAYK,IAAZ;AAAYA,MAAAA,IAAZ;AAAA;;AAAA,WACpDF,SAAS,CAACG,gBAAV,CAA4BN,KAA5B,EAAmCF,IAAnC,EAAyCC,IAAzC,EAA+C,GAAGM,IAAlD,CADoD;AAAA,GAArD;;AAEA,SAAOT,MAAP;AACA,CAPuB,EAOrB,EAPqB,CAAxB;;AASA,MAAMW,eAAe,GAAGb,0BAAgBC,MAAhB,CAAwB,CAAEC,MAAF,EAAUC,MAAV,KAAsB;AACrE,QAAM;AAAEC,IAAAA,IAAF;AAAQC,I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B,CAAF,CAAN,GAAkD,CAAEE,GAAF,EAAOC,KAAP,KACjDW,OAAO,CAACE,kBAAR,CAA4BjB,IAA5B,EAAkCC,IAAlC,EAAwCE,GAAxC,EAA6CC,KAA7C,CADD;;AAEA,SAAON,MAAP;AACA,CAPqB,EAOnB,EAPmB,CAAtB;;AASA,MAAMoB,WAAW,GAAG,OAAQ;AAC3BC,EAAAA,OAAO,EAAPA,gBAD2B;AAE3BJ,EAAAA,OAAO,EAAE,EAAE,GAAGA,OAAL;AAAc,OAAGD,aAAjB;AAAgC,OAAG;AAAnC,GAFkB;AAG3BT,EAAAA,SAAS,EAAE,EAAE,GAAGA,SAAL;AAAgB,OAAGV;AAAnB,GAHgB;AAI3Be,EAAAA,SAAS,EAAE,EAAE,GAAGA,SAAL;AAAgB,OAAGD;AAAnB,GAJgB;AAK3BW,EAAAA,uBAAuB,EAAE;AALE,CAAR,CAApB;AAQA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,MAAMC,KAAK,GAAG,4BAAkBC,gBAAlB,EAA8BJ,WAAW,EAAzC,CAAd;;AAEP,oBAAUG,KAAV","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 actions from './actions';\nimport * as resolvers from './resolvers';\nimport createLocksActions from './locks/actions';\nimport { defaultEntities, getMethodName } from './entities';\nimport { STORE_NAME } from './name';\n\n// The entity selectors/resolvers and actions are shortcuts to their generic equivalents\n// (getEntityRecord, getEntityRecords, updateEntityRecord, updateEntityRecordss)\n// Instead of getEntityRecord, the consumer could use more user-frieldly named selector: getPostType, getTaxonomy...\n// The \"kind\" and the \"name\" of the entity are combined to generate these shortcuts.\n\nconst entitySelectors = defaultEntities.reduce( ( result, entity ) => {\n\tconst { kind, name } = entity;\n\tresult[ getMethodName( kind, name ) ] = ( state, key, query ) =>\n\t\tselectors.getEntityRecord( state, kind, name, key, query );\n\tresult[ getMethodName( kind, name, 'get', true ) ] = ( state, ...args ) =>\n\t\tselectors.getEntityRecords( state, kind, name, ...args );\n\treturn result;\n}, {} );\n\nconst entityResolvers = defaultEntities.reduce( ( result, entity ) => {\n\tconst { kind, name } = entity;\n\tresult[ getMethodName( kind, name ) ] = ( key, query ) =>\n\t\tresolvers.getEntityRecord( kind, name, key, query );\n\tconst pluralMethodName = getMethodName( kind, name, 'get', true );\n\tresult[ pluralMethodName ] = ( ...args ) =>\n\t\tresolvers.getEntityRecords( kind, name, ...args );\n\tresult[ pluralMethodName ].shouldInvalidate = ( action, ...args ) =>\n\t\tresolvers.getEntityRecords.shouldInvalidate(\n\t\t\taction,\n\t\t\tkind,\n\t\t\tname,\n\t\t\t...args\n\t\t);\n\treturn result;\n}, {} );\n\nconst entityActions = defaultEntities.reduce( ( result, entity ) => {\n\tconst { kind, name } = entity;\n\tresult[ getMethodName( kind, name, 'save' ) ] = ( key ) =>\n\t\tactions.saveEntityRecord( kind, name, key );\n\tresult[ getMethodName( kind, name, 'delete' ) ] = ( key, query ) =>\n\t\tactions.deleteEntityRecord( kind, name, key, query );\n\treturn result;\n}, {} );\n\nconst storeConfig = () => ( {\n\treducer,\n\tactions: { ...actions, ...entityActions, ...createLocksActions() },\n\tselectors: { ...selectors, ...entitySelectors },\n\tresolvers: { ...resolvers, ...entityResolvers },\n\t__experimentalUseThunks: true,\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 *\n * @type {Object}\n */\nexport const store = createReduxStore( STORE_NAME, storeConfig() );\n\nregister( store );\n\nexport { default as EntityProvider } from './entity-provider';\nexport * from './entity-provider';\nexport * from './fetch';\n"]}
|
package/build/locks/actions.js
CHANGED
|
@@ -15,9 +15,10 @@ var _engine = _interopRequireDefault(require("./engine"));
|
|
|
15
15
|
function createLocksActions() {
|
|
16
16
|
const locks = (0, _engine.default)();
|
|
17
17
|
|
|
18
|
-
function __unstableAcquireStoreLock(store, path, {
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
function __unstableAcquireStoreLock(store, path, _ref) {
|
|
19
|
+
let {
|
|
20
|
+
exclusive
|
|
21
|
+
} = _ref;
|
|
21
22
|
return () => locks.acquire(store, path, exclusive);
|
|
22
23
|
}
|
|
23
24
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-data/src/locks/actions.js"],"names":["createLocksActions","locks","__unstableAcquireStoreLock","store","path","exclusive","acquire","__unstableReleaseStoreLock","lock","release"],"mappings":";;;;;;;;;AAGA;;AAHA;AACA;AACA;AAGe,SAASA,kBAAT,GAA8B;AAC5C,QAAMC,KAAK,GAAG,sBAAd;;AAEA,WAASC,0BAAT,CAAqCC,KAArC,EAA4CC,IAA5C,
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-data/src/locks/actions.js"],"names":["createLocksActions","locks","__unstableAcquireStoreLock","store","path","exclusive","acquire","__unstableReleaseStoreLock","lock","release"],"mappings":";;;;;;;;;AAGA;;AAHA;AACA;AACA;AAGe,SAASA,kBAAT,GAA8B;AAC5C,QAAMC,KAAK,GAAG,sBAAd;;AAEA,WAASC,0BAAT,CAAqCC,KAArC,EAA4CC,IAA5C,QAAkE;AAAA,QAAhB;AAAEC,MAAAA;AAAF,KAAgB;AACjE,WAAO,MAAMJ,KAAK,CAACK,OAAN,CAAeH,KAAf,EAAsBC,IAAtB,EAA4BC,SAA5B,CAAb;AACA;;AAED,WAASE,0BAAT,CAAqCC,IAArC,EAA4C;AAC3C,WAAO,MAAMP,KAAK,CAACQ,OAAN,CAAeD,IAAf,CAAb;AACA;;AAED,SAAO;AAAEN,IAAAA,0BAAF;AAA8BK,IAAAA;AAA9B,GAAP;AACA","sourcesContent":["/**\n * Internal dependencies\n */\nimport createLocks from './engine';\n\nexport default function createLocksActions() {\n\tconst locks = createLocks();\n\n\tfunction __unstableAcquireStoreLock( store, path, { exclusive } ) {\n\t\treturn () => locks.acquire( store, path, exclusive );\n\t}\n\n\tfunction __unstableReleaseStoreLock( lock ) {\n\t\treturn () => locks.release( lock );\n\t}\n\n\treturn { __unstableAcquireStoreLock, __unstableReleaseStoreLock };\n}\n"]}
|
package/build/locks/reducer.js
CHANGED
|
@@ -26,7 +26,10 @@ const DEFAULT_STATE = {
|
|
|
26
26
|
* @return {Object} Updated state.
|
|
27
27
|
*/
|
|
28
28
|
|
|
29
|
-
function locks(
|
|
29
|
+
function locks() {
|
|
30
|
+
let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : DEFAULT_STATE;
|
|
31
|
+
let action = arguments.length > 1 ? arguments[1] : undefined;
|
|
32
|
+
|
|
30
33
|
switch (action.type) {
|
|
31
34
|
case 'ENQUEUE_LOCK_REQUEST':
|
|
32
35
|
{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-data/src/locks/reducer.js"],"names":["DEFAULT_STATE","requests","tree","locks","children","state","action","type","request","lock","store","path","storePath","newTree","node","filter","r","l"],"mappings":";;;;;;;AAGA;;AAHA;AACA;AACA;AAGA,MAAMA,aAAa,GAAG;AACrBC,EAAAA,QAAQ,EAAE,EADW;AAErBC,EAAAA,IAAI,EAAE;AACLC,IAAAA,KAAK,EAAE,EADF;AAELC,IAAAA,QAAQ,EAAE;AAFL;AAFe,CAAtB;AAQA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACe,SAASD,KAAT,
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-data/src/locks/reducer.js"],"names":["DEFAULT_STATE","requests","tree","locks","children","state","action","type","request","lock","store","path","storePath","newTree","node","filter","r","l"],"mappings":";;;;;;;AAGA;;AAHA;AACA;AACA;AAGA,MAAMA,aAAa,GAAG;AACrBC,EAAAA,QAAQ,EAAE,EADW;AAErBC,EAAAA,IAAI,EAAE;AACLC,IAAAA,KAAK,EAAE,EADF;AAELC,IAAAA,QAAQ,EAAE;AAFL;AAFe,CAAtB;AAQA;AACA;AACA;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AASD,OAAT,EAAkBD,SAAlB,CAAb;AACAE,QAAAA,IAAI,CAACX,KAAL,GAAaW,IAAI,CAACX,KAAL,CAAWY,MAAX,CAAqBE,CAAF,IAASA,CAAC,KAAKR,IAAlC,CAAb;AAEA,eAAO,EACN,GAAGJ,KADG;AAENH,UAAAA,IAAI,EAAEW;AAFA,SAAP;AAIA;AAnCF;;AAsCA,SAAOR,KAAP;AACA","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"]}
|
package/build/locks/selectors.js
CHANGED
|
@@ -15,9 +15,10 @@ function getPendingLockRequests(state) {
|
|
|
15
15
|
return state.requests;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
function isLockAvailable(state, store, path, {
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
function isLockAvailable(state, store, path, _ref) {
|
|
19
|
+
let {
|
|
20
|
+
exclusive
|
|
21
|
+
} = _ref;
|
|
21
22
|
const storePath = [store, ...path];
|
|
22
23
|
const locks = state.tree; // Validate all parents and the node itself
|
|
23
24
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-data/src/locks/selectors.js"],"names":["getPendingLockRequests","state","requests","isLockAvailable","store","path","exclusive","storePath","locks","tree","node","descendant"],"mappings":";;;;;;;;AAGA;;AAHA;AACA;AACA;AAQO,SAASA,sBAAT,CAAiCC,KAAjC,EAAyC;AAC/C,SAAOA,KAAK,CAACC,QAAb;AACA;;AAEM,SAASC,eAAT,CAA0BF,KAA1B,EAAiCG,KAAjC,EAAwCC,IAAxC,
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-data/src/locks/selectors.js"],"names":["getPendingLockRequests","state","requests","isLockAvailable","store","path","exclusive","storePath","locks","tree","node","descendant"],"mappings":";;;;;;;;AAGA;;AAHA;AACA;AACA;AAQO,SAASA,sBAAT,CAAiCC,KAAjC,EAAyC;AAC/C,SAAOA,KAAK,CAACC,QAAb;AACA;;AAEM,SAASC,eAAT,CAA0BF,KAA1B,EAAiCG,KAAjC,EAAwCC,IAAxC,QAA8D;AAAA,MAAhB;AAAEC,IAAAA;AAAF,GAAgB;AACpE,QAAMC,SAAS,GAAG,CAAEH,KAAF,EAAS,GAAGC,IAAZ,CAAlB;AACA,QAAMG,KAAK,GAAGP,KAAK,CAACQ,IAApB,CAFoE,CAIpE;;AACA,OAAM,MAAMC,IAAZ,IAAoB,wBAAaF,KAAb,EAAoBD,SAApB,CAApB,EAAsD;AACrD,QAAK,+BAAoB;AAAED,MAAAA;AAAF,KAApB,EAAmCI,IAAI,CAACF,KAAxC,CAAL,EAAuD;AACtD,aAAO,KAAP;AACA;AACD,GATmE,CAWpE;AACA;;;AACA,QAAME,IAAI,GAAG,oBAASF,KAAT,EAAgBD,SAAhB,CAAb;;AACA,MAAK,CAAEG,IAAP,EAAc;AACb,WAAO,IAAP;AACA,GAhBmE,CAkBpE;;;AACA,OAAM,MAAMC,UAAZ,IAA0B,+BAAoBD,IAApB,CAA1B,EAAuD;AACtD,QAAK,+BAAoB;AAAEJ,MAAAA;AAAF,KAApB,EAAmCK,UAAU,CAACH,KAA9C,CAAL,EAA6D;AAC5D,aAAO,KAAP;AACA;AACD;;AAED,SAAO,IAAP;AACA","sourcesContent":["/**\n * Internal dependencies\n */\nimport {\n\titerateDescendants,\n\titeratePath,\n\thasConflictingLock,\n\tgetNode,\n} from './utils';\n\nexport function getPendingLockRequests( state ) {\n\treturn state.requests;\n}\n\nexport function isLockAvailable( state, store, path, { exclusive } ) {\n\tconst storePath = [ store, ...path ];\n\tconst locks = state.tree;\n\n\t// Validate all parents and the node itself\n\tfor ( const node of iteratePath( locks, storePath ) ) {\n\t\tif ( hasConflictingLock( { exclusive }, node.locks ) ) {\n\t\t\treturn false;\n\t\t}\n\t}\n\n\t// iteratePath terminates early if path is unreachable, let's\n\t// re-fetch the node and check it exists in the tree.\n\tconst node = getNode( locks, storePath );\n\tif ( ! node ) {\n\t\treturn true;\n\t}\n\n\t// Validate all nested nodes\n\tfor ( const descendant of iterateDescendants( node ) ) {\n\t\tif ( hasConflictingLock( { exclusive }, descendant.locks ) ) {\n\t\t\treturn false;\n\t\t}\n\t}\n\n\treturn true;\n}\n"]}
|
package/build/locks/utils.js
CHANGED
|
@@ -5,9 +5,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.deepCopyLocksTreePath = deepCopyLocksTreePath;
|
|
7
7
|
exports.getNode = getNode;
|
|
8
|
-
exports.iteratePath = iteratePath;
|
|
9
|
-
exports.iterateDescendants = iterateDescendants;
|
|
10
8
|
exports.hasConflictingLock = hasConflictingLock;
|
|
9
|
+
exports.iterateDescendants = iterateDescendants;
|
|
10
|
+
exports.iteratePath = iteratePath;
|
|
11
11
|
|
|
12
12
|
function deepCopyLocksTreePath(tree, path) {
|
|
13
13
|
const newTree = { ...tree
|
|
@@ -70,9 +70,11 @@ function* iterateDescendants(node) {
|
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
function hasConflictingLock({
|
|
74
|
-
|
|
75
|
-
|
|
73
|
+
function hasConflictingLock(_ref, locks) {
|
|
74
|
+
let {
|
|
75
|
+
exclusive
|
|
76
|
+
} = _ref;
|
|
77
|
+
|
|
76
78
|
if (exclusive && locks.length) {
|
|
77
79
|
return true;
|
|
78
80
|
}
|
package/build/locks/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-data/src/locks/utils.js"],"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"],"mappings":";;;;;;;;;;;AAAO,SAASA,qBAAT,CAAgCC,IAAhC,EAAsCC,IAAtC,EAA6C;AACnD,QAAMC,OAAO,GAAG,EAAE,GAAGF;AAAL,GAAhB;AACA,MAAIG,WAAW,GAAGD,OAAlB;;AACA,OAAM,MAAME,UAAZ,IAA0BH,IAA1B,EAAiC;AAChCE,IAAAA,WAAW,CAACE,QAAZ,GAAuB,EACtB,GAAGF,WAAW,CAACE,QADO;AAEtB,OAAED,UAAF,GAAgB;AACfE,QAAAA,KAAK,EAAE,EADQ;AAEfD,QAAAA,QAAQ,EAAE,EAFK;AAGf,WAAGF,WAAW,CAACE,QAAZ,CAAsBD,UAAtB;AAHY;AAFM,KAAvB;AAQAD,IAAAA,WAAW,GAAGA,WAAW,CAACE,QAAZ,CAAsBD,UAAtB,CAAd;AACA;;AACD,SAAOF,OAAP;AACA;;AAEM,SAASK,OAAT,CAAkBP,IAAlB,EAAwBC,IAAxB,EAA+B;AACrC,MAAIE,WAAW,GAAGH,IAAlB;;AACA,OAAM,MAAMI,UAAZ,IAA0BH,IAA1B,EAAiC;AAChC,UAAMO,QAAQ,GAAGL,WAAW,CAACE,QAAZ,CAAsBD,UAAtB,CAAjB;;AACA,QAAK,CAAEI,QAAP,EAAkB;AACjB,aAAO,IAAP;AACA;;AACDL,IAAAA,WAAW,GAAGK,QAAd;AACA;;AACD,SAAOL,WAAP;AACA;;AAEM,UAAUM,WAAV,CAAuBT,IAAvB,EAA6BC,IAA7B,EAAoC;AAC1C,MAAIE,WAAW,GAAGH,IAAlB;AACA,QAAMG,WAAN;;AACA,OAAM,MAAMC,UAAZ,IAA0BH,IAA1B,EAAiC;AAChC,UAAMO,QAAQ,GAAGL,WAAW,CAACE,QAAZ,CAAsBD,UAAtB,CAAjB;;AACA,QAAK,CAAEI,QAAP,EAAkB;AACjB;AACA;;AACD,UAAMA,QAAN;AACAL,IAAAA,WAAW,GAAGK,QAAd;AACA;AACD;;AAEM,UAAUE,kBAAV,CAA8BC,IAA9B,EAAqC;AAC3C,QAAMC,KAAK,GAAGC,MAAM,CAACC,MAAP,CAAeH,IAAI,CAACN,QAApB,CAAd;;AACA,SAAQO,KAAK,CAACG,MAAd,EAAuB;AACtB,UAAMC,SAAS,GAAGJ,KAAK,CAACK,GAAN,EAAlB;AACA,UAAMD,SAAN;AACAJ,IAAAA,KAAK,CAACM,IAAN,CAAY,GAAGL,MAAM,CAACC,MAAP,CAAeE,SAAS,CAACX,QAAzB,CAAf;AACA;AACD;;AAEM,SAASc,kBAAT,
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-data/src/locks/utils.js"],"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"],"mappings":";;;;;;;;;;;AAAO,SAASA,qBAAT,CAAgCC,IAAhC,EAAsCC,IAAtC,EAA6C;AACnD,QAAMC,OAAO,GAAG,EAAE,GAAGF;AAAL,GAAhB;AACA,MAAIG,WAAW,GAAGD,OAAlB;;AACA,OAAM,MAAME,UAAZ,IAA0BH,IAA1B,EAAiC;AAChCE,IAAAA,WAAW,CAACE,QAAZ,GAAuB,EACtB,GAAGF,WAAW,CAACE,QADO;AAEtB,OAAED,UAAF,GAAgB;AACfE,QAAAA,KAAK,EAAE,EADQ;AAEfD,QAAAA,QAAQ,EAAE,EAFK;AAGf,WAAGF,WAAW,CAACE,QAAZ,CAAsBD,UAAtB;AAHY;AAFM,KAAvB;AAQAD,IAAAA,WAAW,GAAGA,WAAW,CAACE,QAAZ,CAAsBD,UAAtB,CAAd;AACA;;AACD,SAAOF,OAAP;AACA;;AAEM,SAASK,OAAT,CAAkBP,IAAlB,EAAwBC,IAAxB,EAA+B;AACrC,MAAIE,WAAW,GAAGH,IAAlB;;AACA,OAAM,MAAMI,UAAZ,IAA0BH,IAA1B,EAAiC;AAChC,UAAMO,QAAQ,GAAGL,WAAW,CAACE,QAAZ,CAAsBD,UAAtB,CAAjB;;AACA,QAAK,CAAEI,QAAP,EAAkB;AACjB,aAAO,IAAP;AACA;;AACDL,IAAAA,WAAW,GAAGK,QAAd;AACA;;AACD,SAAOL,WAAP;AACA;;AAEM,UAAUM,WAAV,CAAuBT,IAAvB,EAA6BC,IAA7B,EAAoC;AAC1C,MAAIE,WAAW,GAAGH,IAAlB;AACA,QAAMG,WAAN;;AACA,OAAM,MAAMC,UAAZ,IAA0BH,IAA1B,EAAiC;AAChC,UAAMO,QAAQ,GAAGL,WAAW,CAACE,QAAZ,CAAsBD,UAAtB,CAAjB;;AACA,QAAK,CAAEI,QAAP,EAAkB;AACjB;AACA;;AACD,UAAMA,QAAN;AACAL,IAAAA,WAAW,GAAGK,QAAd;AACA;AACD;;AAEM,UAAUE,kBAAV,CAA8BC,IAA9B,EAAqC;AAC3C,QAAMC,KAAK,GAAGC,MAAM,CAACC,MAAP,CAAeH,IAAI,CAACN,QAApB,CAAd;;AACA,SAAQO,KAAK,CAACG,MAAd,EAAuB;AACtB,UAAMC,SAAS,GAAGJ,KAAK,CAACK,GAAN,EAAlB;AACA,UAAMD,SAAN;AACAJ,IAAAA,KAAK,CAACM,IAAN,CAAY,GAAGL,MAAM,CAACC,MAAP,CAAeE,SAAS,CAACX,QAAzB,CAAf;AACA;AACD;;AAEM,SAASc,kBAAT,OAA4Cb,KAA5C,EAAoD;AAAA,MAAvB;AAAEc,IAAAA;AAAF,GAAuB;;AAC1D,MAAKA,SAAS,IAAId,KAAK,CAACS,MAAxB,EAAiC;AAChC,WAAO,IAAP;AACA;;AAED,MAAK,CAAEK,SAAF,IAAed,KAAK,CAACe,MAAN,CAAgBC,IAAF,IAAYA,IAAI,CAACF,SAA/B,EAA2CL,MAA/D,EAAwE;AACvE,WAAO,IAAP;AACA;;AAED,SAAO,KAAP;AACA","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"]}
|
|
@@ -4,8 +4,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.receiveItems = receiveItems;
|
|
7
|
-
exports.removeItems = removeItems;
|
|
8
7
|
exports.receiveQueriedItems = receiveQueriedItems;
|
|
8
|
+
exports.removeItems = removeItems;
|
|
9
9
|
|
|
10
10
|
var _lodash = require("lodash");
|
|
11
11
|
|
|
@@ -40,7 +40,8 @@ function receiveItems(items, edits) {
|
|
|
40
40
|
*/
|
|
41
41
|
|
|
42
42
|
|
|
43
|
-
function removeItems(kind, name, records
|
|
43
|
+
function removeItems(kind, name, records) {
|
|
44
|
+
let invalidateCache = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
44
45
|
return {
|
|
45
46
|
type: 'REMOVE_ITEMS',
|
|
46
47
|
itemIds: (0, _lodash.castArray)(records),
|
|
@@ -61,7 +62,9 @@ function removeItems(kind, name, records, invalidateCache = false) {
|
|
|
61
62
|
*/
|
|
62
63
|
|
|
63
64
|
|
|
64
|
-
function receiveQueriedItems(items
|
|
65
|
+
function receiveQueriedItems(items) {
|
|
66
|
+
let query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
67
|
+
let edits = arguments.length > 2 ? arguments[2] : undefined;
|
|
65
68
|
return { ...receiveItems(items, edits),
|
|
66
69
|
query
|
|
67
70
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-data/src/queried-data/actions.js"],"names":["receiveItems","items","edits","type","persistedEdits","removeItems","kind","name","records","invalidateCache","itemIds","receiveQueriedItems","query"],"mappings":";;;;;;;;;AAGA;;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,YAAT,CAAuBC,KAAvB,EAA8BC,KAA9B,EAAsC;AAC5C,SAAO;AACNC,IAAAA,IAAI,EAAE,eADA;AAENF,IAAAA,KAAK,EAAE,uBAAWA,KAAX,CAFD;AAGNG,IAAAA,cAAc,EAAEF;AAHV,GAAP;AAKA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASG,WAAT,CAAsBC,IAAtB,EAA4BC,IAA5B,EAAkCC,OAAlC,
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-data/src/queried-data/actions.js"],"names":["receiveItems","items","edits","type","persistedEdits","removeItems","kind","name","records","invalidateCache","itemIds","receiveQueriedItems","query"],"mappings":";;;;;;;;;AAGA;;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,YAAT,CAAuBC,KAAvB,EAA8BC,KAA9B,EAAsC;AAC5C,SAAO;AACNC,IAAAA,IAAI,EAAE,eADA;AAENF,IAAAA,KAAK,EAAE,uBAAWA,KAAX,CAFD;AAGNG,IAAAA,cAAc,EAAEF;AAHV,GAAP;AAKA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASG,WAAT,CAAsBC,IAAtB,EAA4BC,IAA5B,EAAkCC,OAAlC,EAAqE;AAAA,MAA1BC,eAA0B,uEAAR,KAAQ;AAC3E,SAAO;AACNN,IAAAA,IAAI,EAAE,cADA;AAENO,IAAAA,OAAO,EAAE,uBAAWF,OAAX,CAFH;AAGNF,IAAAA,IAHM;AAINC,IAAAA,IAJM;AAKNE,IAAAA;AALM,GAAP;AAOA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASE,mBAAT,CAA8BV,KAA9B,EAAyD;AAAA,MAApBW,KAAoB,uEAAZ,EAAY;AAAA,MAARV,KAAQ;AAC/D,SAAO,EACN,GAAGF,YAAY,CAAEC,KAAF,EAASC,KAAT,CADT;AAENU,IAAAA;AAFM,GAAP;AAIA","sourcesContent":["/**\n * External dependencies\n */\nimport { castArray } from 'lodash';\n\n/**\n * Returns an action object used in signalling that items have been received.\n *\n * @param {Array} items Items received.\n * @param {?Object} edits Optional edits to reset.\n *\n * @return {Object} Action object.\n */\nexport function receiveItems( items, edits ) {\n\treturn {\n\t\ttype: 'RECEIVE_ITEMS',\n\t\titems: castArray( items ),\n\t\tpersistedEdits: edits,\n\t};\n}\n\n/**\n * Returns an action object used in signalling that entity records have been\n * deleted and they need to be removed from entities state.\n *\n * @param {string} kind Kind of the removed entities.\n * @param {string} name Name of the removed entities.\n * @param {Array|number} records Record IDs of the removed entities.\n * @param {boolean} invalidateCache Controls whether we want to invalidate the cache.\n * @return {Object} Action object.\n */\nexport function removeItems( kind, name, records, invalidateCache = false ) {\n\treturn {\n\t\ttype: 'REMOVE_ITEMS',\n\t\titemIds: castArray( records ),\n\t\tkind,\n\t\tname,\n\t\tinvalidateCache,\n\t};\n}\n\n/**\n * Returns an action object used in signalling that queried data has been\n * received.\n *\n * @param {Array} items Queried items received.\n * @param {?Object} query Optional query object.\n * @param {?Object} edits Optional edits to reset.\n *\n * @return {Object} Action object.\n */\nexport function receiveQueriedItems( items, query = {}, edits ) {\n\treturn {\n\t\t...receiveItems( items, edits ),\n\t\tquery,\n\t};\n}\n"]}
|
|
@@ -5,10 +5,10 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
+
exports.default = void 0;
|
|
8
9
|
exports.getMergedItemIds = getMergedItemIds;
|
|
9
|
-
exports.items = items;
|
|
10
10
|
exports.itemIsComplete = itemIsComplete;
|
|
11
|
-
exports.
|
|
11
|
+
exports.items = items;
|
|
12
12
|
|
|
13
13
|
var _lodash = require("lodash");
|
|
14
14
|
|
|
@@ -89,7 +89,10 @@ function getMergedItemIds(itemIds, nextItemIds, page, perPage) {
|
|
|
89
89
|
*/
|
|
90
90
|
|
|
91
91
|
|
|
92
|
-
function items(
|
|
92
|
+
function items() {
|
|
93
|
+
let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
94
|
+
let action = arguments.length > 1 ? arguments[1] : undefined;
|
|
95
|
+
|
|
93
96
|
switch (action.type) {
|
|
94
97
|
case 'RECEIVE_ITEMS':
|
|
95
98
|
{
|
|
@@ -128,7 +131,10 @@ function items(state = {}, action) {
|
|
|
128
131
|
*/
|
|
129
132
|
|
|
130
133
|
|
|
131
|
-
function itemIsComplete(
|
|
134
|
+
function itemIsComplete() {
|
|
135
|
+
let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
136
|
+
let action = arguments.length > 1 ? arguments[1] : undefined;
|
|
137
|
+
|
|
132
138
|
switch (action.type) {
|
|
133
139
|
case 'RECEIVE_ITEMS':
|
|
134
140
|
{
|
|
@@ -193,7 +199,9 @@ const receiveQueries = (0, _lodash.flowRight)([// Limit to matching action type
|
|
|
193
199
|
return action;
|
|
194
200
|
}), (0, _utils.onSubKey)('context'), // Queries shape is shared, but keyed by query `stableKey` part. Original
|
|
195
201
|
// reducer tracks only a single query object.
|
|
196
|
-
(0, _utils.onSubKey)('stableKey')])((
|
|
202
|
+
(0, _utils.onSubKey)('stableKey')])(function () {
|
|
203
|
+
let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
204
|
+
let action = arguments.length > 1 ? arguments[1] : undefined;
|
|
197
205
|
const {
|
|
198
206
|
type,
|
|
199
207
|
page,
|
|
@@ -216,7 +224,10 @@ const receiveQueries = (0, _lodash.flowRight)([// Limit to matching action type
|
|
|
216
224
|
* @return {Object} Next state.
|
|
217
225
|
*/
|
|
218
226
|
|
|
219
|
-
const queries = (
|
|
227
|
+
const queries = function () {
|
|
228
|
+
let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
229
|
+
let action = arguments.length > 1 ? arguments[1] : undefined;
|
|
230
|
+
|
|
220
231
|
switch (action.type) {
|
|
221
232
|
case 'RECEIVE_ITEMS':
|
|
222
233
|
return receiveQueries(state, action);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-data/src/queried-data/reducer.js"],"names":["getContextFromAction","action","query","queryParts","context","getMergedItemIds","itemIds","nextItemIds","page","perPage","receivedAllIds","nextItemIdsStartIndex","size","Math","max","length","mergedItemIds","Array","i","isInNextItemsRange","items","state","type","key","DEFAULT_ENTITY_KEY","reduce","accumulator","value","itemId","contextState","itemIsComplete","isCompleteQuery","isArray","fields","result","item","receiveQueries","queries","removedItems","contextQueries","queryItems","queryId"],"mappings":";;;;;;;;;;;;AAGA;;AAKA;;AAKA;;AAMA;;AACA;;AApBA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;AAUA,SAASA,oBAAT,CAA+BC,MAA/B,EAAwC;AACvC,QAAM;AAAEC,IAAAA;AAAF,MAAYD,MAAlB;;AACA,MAAK,CAAEC,KAAP,EAAe;AACd,WAAO,SAAP;AACA;;AAED,QAAMC,UAAU,GAAG,4BAAeD,KAAf,CAAnB;AACA,SAAOC,UAAU,CAACC,OAAlB;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASC,gBAAT,CAA2BC,OAA3B,EAAoCC,WAApC,EAAiDC,IAAjD,EAAuDC,OAAvD,EAAiE;AACvE,QAAMC,cAAc,GAAGF,IAAI,KAAK,CAAT,IA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AACA;AACA;;AACA,MAAM4B,OAAO,GAAG,CAAEhB,KAAK,GAAG,EAAV,EAAcpB,MAAd,KAA0B;AACzC,UAASA,MAAM,CAACqB,IAAhB;AACC,SAAK,eAAL;AACC,aAAOc,cAAc,CAAEf,KAAF,EAASpB,MAAT,CAArB;;AACD,SAAK,cAAL;AACC,YAAMqC,YAAY,GAAGrC,MAAM,CAACK,OAAP,CAAemB,MAAf,CAAuB,CAAES,MAAF,EAAUN,MAAV,KAAsB;AACjEM,QAAAA,MAAM,CAAEN,MAAF,CAAN,GAAmB,IAAnB;AACA,eAAOM,MAAP;AACA,OAHoB,EAGlB,EAHkB,CAArB;AAKA,aAAO,uBAAWb,KAAX,EAAoBkB,cAAF,IAAsB;AAC9C,eAAO,uBAAWA,cAAX,EAA6BC,UAAF,IAAkB;AACnD,iBAAO,oBAAQA,UAAR,EAAsBC,OAAF,IAAe;AACzC,mBAAO,CAAEH,YAAY,CAAEG,OAAF,CAArB;AACA,WAFM,CAAP;AAGA,SAJM,CAAP;AAKA,OANM,CAAP;;AAOD;AACC,aAAOpB,KAAP;AAjBF;AAmBA,CApBD;;eAsBe,2BAAiB;AAC/BD,EAAAA,KAD+B;AAE/BU,EAAAA,cAF+B;AAG/BO,EAAAA;AAH+B,CAAjB,C","sourcesContent":["/**\n * External dependencies\n */\nimport { map, flowRight, omit, filter, mapValues } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { combineReducers } from '@wordpress/data';\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,\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\tconst isInNextItemsRange =\n\t\t\ti >= nextItemIdsStartIndex &&\n\t\t\ti < nextItemIdsStartIndex + nextItemIds.length;\n\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 * 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\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 mapValues( state, ( contextState ) =>\n\t\t\t\tomit( contextState, action.itemIds )\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,boolean>} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {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 entity types, 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 mapValues( state, ( contextState ) =>\n\t\t\t\tomit( contextState, action.itemIds )\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 = flowRight( [\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 = null, 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 getMergedItemIds(\n\t\tstate || [],\n\t\tmap( action.items, key ),\n\t\tpage,\n\t\tperPage\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 mapValues( state, ( contextQueries ) => {\n\t\t\t\treturn mapValues( contextQueries, ( queryItems ) => {\n\t\t\t\t\treturn filter( queryItems, ( queryId ) => {\n\t\t\t\t\t\treturn ! removedItems[ queryId ];\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"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-data/src/queried-data/reducer.js"],"names":["getContextFromAction","action","query","queryParts","context","getMergedItemIds","itemIds","nextItemIds","page","perPage","receivedAllIds","nextItemIdsStartIndex","size","Math","max","length","mergedItemIds","Array","i","isInNextItemsRange","items","state","type","key","DEFAULT_ENTITY_KEY","reduce","accumulator","value","itemId","contextState","itemIsComplete","isCompleteQuery","isArray","fields","result","item","receiveQueries","queries","removedItems","contextQueries","queryItems","queryId"],"mappings":";;;;;;;;;;;;AAGA;;AAKA;;AAKA;;AAMA;;AACA;;AApBA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;AAUA,SAASA,oBAAT,CAA+BC,MAA/B,EAAwC;AACvC,QAAM;AAAEC,IAAAA;AAAF,MAAYD,MAAlB;;AACA,MAAK,CAAEC,KAAP,EAAe;AACd,WAAO,SAAP;AACA;;AAED,QAAMC,UAAU,GAAG,4BAAeD,KAAf,CAAnB;AACA,SAAOC,UAAU,CAACC,OAAlB;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASC,gBAAT,CAA2BC,OAA3B,EAAoCC,WAApC,EAAiDC,IAAjD,EAAuDC,OAAvD,EAAiE;AACvE,QAAMC,cAAc,GAAGF,IAAI,KAAK,CAAT,IAAcC,OAAO,KAAK,CAAC,CAAlD;;AACA,MAAKC,cAAL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ACA,MAAM4B,OAAO,GAAG,YAA0B;AAAA,MAAxBhB,KAAwB,uEAAhB,EAAgB;AAAA,MAAZpB,MAAY;;AACzC,UAASA,MAAM,CAACqB,IAAhB;AACC,SAAK,eAAL;AACC,aAAOc,cAAc,CAAEf,KAAF,EAASpB,MAAT,CAArB;;AACD,SAAK,cAAL;AACC,YAAMqC,YAAY,GAAGrC,MAAM,CAACK,OAAP,CAAemB,MAAf,CAAuB,CAAES,MAAF,EAAUN,MAAV,KAAsB;AACjEM,QAAAA,MAAM,CAAEN,MAAF,CAAN,GAAmB,IAAnB;AACA,eAAOM,MAAP;AACA,OAHoB,EAGlB,EAHkB,CAArB;AAKA,aAAO,uBAAWb,KAAX,EAAoBkB,cAAF,IAAsB;AAC9C,eAAO,uBAAWA,cAAX,EAA6BC,UAAF,IAAkB;AACnD,iBAAO,oBAAQA,UAAR,EAAsBC,OAAF,IAAe;AACzC,mBAAO,CAAEH,YAAY,CAAEG,OAAF,CAArB;AACA,WAFM,CAAP;AAGA,SAJM,CAAP;AAKA,OANM,CAAP;;AAOD;AACC,aAAOpB,KAAP;AAjBF;AAmBA,CApBD;;eAsBe,2BAAiB;AAC/BD,EAAAA,KAD+B;AAE/BU,EAAAA,cAF+B;AAG/BO,EAAAA;AAH+B,CAAjB,C","sourcesContent":["/**\n * External dependencies\n */\nimport { map, flowRight, omit, filter, mapValues } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { combineReducers } from '@wordpress/data';\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,\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\tconst isInNextItemsRange =\n\t\t\ti >= nextItemIdsStartIndex &&\n\t\t\ti < nextItemIdsStartIndex + nextItemIds.length;\n\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 * 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\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 mapValues( state, ( contextState ) =>\n\t\t\t\tomit( contextState, action.itemIds )\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,boolean>} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {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 entity types, 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 mapValues( state, ( contextState ) =>\n\t\t\t\tomit( contextState, action.itemIds )\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 = flowRight( [\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 = null, 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 getMergedItemIds(\n\t\tstate || [],\n\t\tmap( action.items, key ),\n\t\tpage,\n\t\tperPage\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 mapValues( state, ( contextQueries ) => {\n\t\t\t\treturn mapValues( contextQueries, ( queryItems ) => {\n\t\t\t\t\treturn filter( queryItems, ( queryId ) => {\n\t\t\t\t\t\treturn ! removedItems[ queryId ];\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"]}
|
|
@@ -122,7 +122,8 @@ function getQueriedItemsUncached(state, query) {
|
|
|
122
122
|
*/
|
|
123
123
|
|
|
124
124
|
|
|
125
|
-
const getQueriedItems = (0, _rememo.default)((state
|
|
125
|
+
const getQueriedItems = (0, _rememo.default)(function (state) {
|
|
126
|
+
let query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
126
127
|
let queriedItemsCache = queriedItemsCacheByState.get(state);
|
|
127
128
|
|
|
128
129
|
if (queriedItemsCache) {
|