@wordpress/core-data 4.6.0 → 4.9.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.
Files changed (98) hide show
  1. package/CHANGELOG.md +11 -1
  2. package/README.md +209 -119
  3. package/build/actions.js.map +1 -1
  4. package/build/batch/create-batch.js +1 -1
  5. package/build/batch/create-batch.js.map +1 -1
  6. package/build/entities.js +49 -35
  7. package/build/entities.js.map +1 -1
  8. package/build/entity-provider.js.map +1 -1
  9. package/build/entity-types/entities.js +6 -0
  10. package/build/entity-types/entities.js.map +1 -0
  11. package/build/hooks/constants.js +0 -2
  12. package/build/hooks/constants.js.map +1 -1
  13. package/build/hooks/index.js +38 -0
  14. package/build/hooks/index.js.map +1 -0
  15. package/build/hooks/use-entity-record.js +22 -8
  16. package/build/hooks/use-entity-record.js.map +1 -1
  17. package/build/hooks/use-entity-records.js +21 -8
  18. package/build/hooks/use-entity-records.js.map +1 -1
  19. package/build/hooks/use-query-select.js.map +1 -1
  20. package/build/index.js +17 -21
  21. package/build/index.js.map +1 -1
  22. package/build/queried-data/selectors.js.map +1 -1
  23. package/build/resolvers.js.map +1 -1
  24. package/build/selectors.js +206 -169
  25. package/build/selectors.js.map +1 -1
  26. package/build/utils/forward-resolver.js.map +1 -1
  27. package/build/utils/on-sub-key.js.map +1 -1
  28. package/build/utils/with-weak-map-cache.js +1 -7
  29. package/build/utils/with-weak-map-cache.js.map +1 -1
  30. package/build-module/actions.js.map +1 -1
  31. package/build-module/batch/create-batch.js +2 -2
  32. package/build-module/batch/create-batch.js.map +1 -1
  33. package/build-module/entities.js +49 -35
  34. package/build-module/entities.js.map +1 -1
  35. package/build-module/entity-provider.js.map +1 -1
  36. package/build-module/entity-types/entities.js +2 -0
  37. package/build-module/entity-types/entities.js.map +1 -0
  38. package/build-module/hooks/constants.js +0 -1
  39. package/build-module/hooks/constants.js.map +1 -1
  40. package/build-module/hooks/index.js +3 -0
  41. package/build-module/hooks/index.js.map +1 -0
  42. package/build-module/hooks/use-entity-record.js +18 -7
  43. package/build-module/hooks/use-entity-record.js.map +1 -1
  44. package/build-module/hooks/use-entity-records.js +17 -7
  45. package/build-module/hooks/use-entity-records.js.map +1 -1
  46. package/build-module/hooks/use-query-select.js.map +1 -1
  47. package/build-module/index.js +2 -3
  48. package/build-module/index.js.map +1 -1
  49. package/build-module/queried-data/selectors.js.map +1 -1
  50. package/build-module/resolvers.js.map +1 -1
  51. package/build-module/selectors.js +203 -166
  52. package/build-module/selectors.js.map +1 -1
  53. package/build-module/utils/forward-resolver.js.map +1 -1
  54. package/build-module/utils/on-sub-key.js.map +1 -1
  55. package/build-module/utils/with-weak-map-cache.js +1 -6
  56. package/build-module/utils/with-weak-map-cache.js.map +1 -1
  57. package/package.json +12 -12
  58. package/src/actions.js +389 -372
  59. package/src/batch/create-batch.js +2 -2
  60. package/src/entities.ts +357 -135
  61. package/src/entity-provider.js +4 -6
  62. package/src/entity-types/attachment.ts +4 -3
  63. package/src/entity-types/comment.ts +4 -3
  64. package/src/entity-types/entities.ts +130 -0
  65. package/src/entity-types/index.ts +115 -20
  66. package/src/entity-types/menu-location.ts +4 -3
  67. package/src/entity-types/nav-menu-item.ts +4 -3
  68. package/src/entity-types/nav-menu.ts +3 -3
  69. package/src/entity-types/page.ts +3 -3
  70. package/src/entity-types/plugin.ts +3 -3
  71. package/src/entity-types/post.ts +3 -3
  72. package/src/entity-types/settings.ts +3 -3
  73. package/src/entity-types/sidebar.ts +4 -3
  74. package/src/entity-types/taxonomy.ts +4 -3
  75. package/src/entity-types/theme.ts +3 -3
  76. package/src/entity-types/type.ts +3 -3
  77. package/src/entity-types/user.ts +3 -3
  78. package/src/entity-types/widget-type.ts +4 -3
  79. package/src/entity-types/widget.ts +3 -3
  80. package/src/entity-types/wp-template-part.ts +4 -3
  81. package/src/entity-types/wp-template.ts +4 -3
  82. package/src/fetch/test/__experimental-fetch-link-suggestions.js +2 -4
  83. package/src/hooks/constants.ts +1 -2
  84. package/src/hooks/index.ts +8 -0
  85. package/src/hooks/test/use-query-select.js +4 -2
  86. package/src/hooks/use-entity-record.ts +31 -9
  87. package/src/hooks/use-entity-records.ts +28 -30
  88. package/src/hooks/use-query-select.ts +26 -24
  89. package/src/index.js +2 -3
  90. package/src/locks/test/selectors.js +2 -1
  91. package/src/queried-data/selectors.js +2 -8
  92. package/src/resolvers.js +344 -325
  93. package/src/selectors.ts +639 -296
  94. package/src/test/resolvers.js +1 -3
  95. package/src/test/selectors.js +1 -2
  96. package/src/utils/forward-resolver.js +6 -5
  97. package/src/utils/on-sub-key.js +20 -20
  98. package/src/utils/with-weak-map-cache.js +1 -6
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/core-data/src/entity-provider.js"],"names":["EMPTY_ARRAY","entityContexts","rootEntitiesConfig","reduce","acc","loader","kind","name","context","undefined","additionalEntityConfigLoaders","getEntityContext","Error","EntityProvider","type","id","children","Provider","useEntityId","useEntityProp","prop","_id","providerId","value","fullValue","select","getEntityRecord","getEditedEntityRecord","STORE_NAME","record","editedRecord","editEntityRecord","setValue","newValue","useEntityBlockEditor","content","blocks","__unstableCreateUndoLevel","parsedContent","undoIgnore","onChange","newBlocks","options","selection","edits","noChange","blocksForSerialization","onInput"],"mappings":";;;;;;;;;;AAGA;;AAMA;;AACA;;AAKA;;AASA;;AAxBA;AACA;AACA;;AAUA;AACA;AACA;;AAGA;AAEA,MAAMA,WAAW,GAAG,EAApB;AAEA;AACA;AACA;;AAGA,MAAMC,cAAc,GAAG,EACtB,GAAGC,6BAAmBC,MAAnB,CAA2B,CAAEC,GAAF,EAAOC,MAAP,KAAmB;AAChD,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;AACnC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AAEA,MAAF,GAAYpC,WAAZ,EAAyB+C,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\n/** @typedef {import('@wordpress/blocks').WPBlock} WPBlock */\n\nconst EMPTY_ARRAY = [];\n\n/**\n * Internal dependencies\n */\nimport { rootEntitiesConfig, additionalEntityConfigLoaders } from './entities';\n\nconst entityContexts = {\n\t...rootEntitiesConfig.reduce( ( acc, loader ) => {\n\t\tif ( ! acc[ loader.kind ] ) {\n\t\t\tacc[ loader.kind ] = {};\n\t\t}\n\t\tacc[ loader.kind ][ loader.name ] = {\n\t\t\tcontext: createContext( undefined ),\n\t\t};\n\t\treturn acc;\n\t}, {} ),\n\t...additionalEntityConfigLoaders.reduce( ( acc, loader ) => {\n\t\tacc[ loader.kind ] = {};\n\t\treturn acc;\n\t}, {} ),\n};\nconst getEntityContext = ( kind, name ) => {\n\tif ( ! entityContexts[ kind ] ) {\n\t\tthrow new Error( `Missing entity config for kind: ${ kind }.` );\n\t}\n\n\tif ( ! entityContexts[ kind ][ name ] ) {\n\t\tentityContexts[ kind ][ name ] = {\n\t\t\tcontext: createContext( undefined ),\n\t\t};\n\t}\n\n\treturn entityContexts[ kind ][ name ].context;\n};\n\n/**\n * Context provider component for providing\n * an entity for a specific entity.\n *\n * @param {Object} props The component's props.\n * @param {string} props.kind The entity kind.\n * @param {string} props.type The entity name.\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: name, id, children } ) {\n\tconst Provider = getEntityContext( kind, name ).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} name The entity name.\n */\nexport function useEntityId( kind, name ) {\n\treturn useContext( getEntityContext( kind, name ) );\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} name The entity name.\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, name, prop, _id ) {\n\tconst providerId = useEntityId( kind, name );\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 record = getEntityRecord( kind, name, id ); // Trigger resolver.\n\t\t\tconst editedRecord = getEditedEntityRecord( kind, name, id );\n\t\t\treturn record && editedRecord\n\t\t\t\t? {\n\t\t\t\t\t\tvalue: editedRecord[ prop ],\n\t\t\t\t\t\tfullValue: record[ prop ],\n\t\t\t\t }\n\t\t\t\t: {};\n\t\t},\n\t\t[ kind, name, id, prop ]\n\t);\n\tconst { editEntityRecord } = useDispatch( STORE_NAME );\n\tconst setValue = useCallback(\n\t\t( newValue ) => {\n\t\t\teditEntityRecord( kind, name, id, {\n\t\t\t\t[ prop ]: newValue,\n\t\t\t} );\n\t\t},\n\t\t[ kind, name, 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} name The entity name.\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, name, { id: _id } = {} ) {\n\tconst providerId = useEntityId( kind, name );\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 editedRecord = getEditedEntityRecord( kind, name, id );\n\t\t\treturn {\n\t\t\t\tblocks: editedRecord.blocks,\n\t\t\t\tcontent: editedRecord.content,\n\t\t\t};\n\t\t},\n\t\t[ kind, name, 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\tname,\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, name, 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, name, id, edits );\n\t\t},\n\t\t[ kind, name, 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, name, id, edits );\n\t\t},\n\t\t[ kind, name, 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","entityContexts","rootEntitiesConfig","reduce","acc","loader","kind","name","context","undefined","additionalEntityConfigLoaders","getEntityContext","Error","EntityProvider","type","id","children","Provider","useEntityId","useEntityProp","prop","_id","providerId","value","fullValue","select","getEntityRecord","getEditedEntityRecord","STORE_NAME","record","editedRecord","editEntityRecord","setValue","newValue","useEntityBlockEditor","content","blocks","__unstableCreateUndoLevel","parsedContent","undoIgnore","onChange","newBlocks","options","selection","edits","noChange","blocksForSerialization","onInput"],"mappings":";;;;;;;;;;AAGA;;AAMA;;AACA;;AAKA;;AASA;;AAxBA;AACA;AACA;;AAUA;AACA;AACA;;AAGA;AAEA,MAAMA,WAAW,GAAG,EAApB;AAEA;AACA;AACA;;AAGA,MAAMC,cAAc,GAAG,EACtB,GAAGC,6BAAmBC,MAAnB,CAA2B,CAAEC,GAAF,EAAOC,MAAP,KAAmB;AAChD,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;AACnCC,MAAAA,OAAO,EAAE,4BAAeC,SAAf;AAD0B,KAApC;AAGA,WAAOL,GAAP;AACA,GARE,EAQA,EARA,CADmB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port {\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\n/** @typedef {import('@wordpress/blocks').WPBlock} WPBlock */\n\nconst EMPTY_ARRAY = [];\n\n/**\n * Internal dependencies\n */\nimport { rootEntitiesConfig, additionalEntityConfigLoaders } from './entities';\n\nconst entityContexts = {\n\t...rootEntitiesConfig.reduce( ( acc, loader ) => {\n\t\tif ( ! acc[ loader.kind ] ) {\n\t\t\tacc[ loader.kind ] = {};\n\t\t}\n\t\tacc[ loader.kind ][ loader.name ] = {\n\t\t\tcontext: createContext( undefined ),\n\t\t};\n\t\treturn acc;\n\t}, {} ),\n\t...additionalEntityConfigLoaders.reduce( ( acc, loader ) => {\n\t\tacc[ loader.kind ] = {};\n\t\treturn acc;\n\t}, {} ),\n};\nconst getEntityContext = ( kind, name ) => {\n\tif ( ! entityContexts[ kind ] ) {\n\t\tthrow new Error( `Missing entity config for kind: ${ kind }.` );\n\t}\n\n\tif ( ! entityContexts[ kind ][ name ] ) {\n\t\tentityContexts[ kind ][ name ] = {\n\t\t\tcontext: createContext( undefined ),\n\t\t};\n\t}\n\n\treturn entityContexts[ kind ][ name ].context;\n};\n\n/**\n * Context provider component for providing\n * an entity for a specific entity.\n *\n * @param {Object} props The component's props.\n * @param {string} props.kind The entity kind.\n * @param {string} props.type The entity name.\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: name, id, children } ) {\n\tconst Provider = getEntityContext( kind, name ).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} name The entity name.\n */\nexport function useEntityId( kind, name ) {\n\treturn useContext( getEntityContext( kind, name ) );\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} name The entity name.\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, name, prop, _id ) {\n\tconst providerId = useEntityId( kind, name );\n\tconst id = _id ?? providerId;\n\n\tconst { value, fullValue } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getEntityRecord, getEditedEntityRecord } =\n\t\t\t\tselect( STORE_NAME );\n\t\t\tconst record = getEntityRecord( kind, name, id ); // Trigger resolver.\n\t\t\tconst editedRecord = getEditedEntityRecord( kind, name, id );\n\t\t\treturn record && editedRecord\n\t\t\t\t? {\n\t\t\t\t\t\tvalue: editedRecord[ prop ],\n\t\t\t\t\t\tfullValue: record[ prop ],\n\t\t\t\t }\n\t\t\t\t: {};\n\t\t},\n\t\t[ kind, name, id, prop ]\n\t);\n\tconst { editEntityRecord } = useDispatch( STORE_NAME );\n\tconst setValue = useCallback(\n\t\t( newValue ) => {\n\t\t\teditEntityRecord( kind, name, id, {\n\t\t\t\t[ prop ]: newValue,\n\t\t\t} );\n\t\t},\n\t\t[ kind, name, 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} name The entity name.\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, name, { id: _id } = {} ) {\n\tconst providerId = useEntityId( kind, name );\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 editedRecord = getEditedEntityRecord( kind, name, id );\n\t\t\treturn {\n\t\t\t\tblocks: editedRecord.blocks,\n\t\t\t\tcontent: editedRecord.content,\n\t\t\t};\n\t\t},\n\t\t[ kind, name, id ]\n\t);\n\tconst { __unstableCreateUndoLevel, editEntityRecord } =\n\t\tuseDispatch( STORE_NAME );\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\tname,\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, name, 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, name, id, edits );\n\t\t},\n\t\t[ kind, name, 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, name, id, edits );\n\t\t},\n\t\t[ kind, name, id ]\n\t);\n\n\treturn [ blocks ?? EMPTY_ARRAY, onInput, onChange ];\n}\n"]}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ //# sourceMappingURL=entities.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[]}
@@ -4,8 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.Status = void 0;
7
-
8
- /* eslint-disable-next-line no-shadow */
9
7
  let Status;
10
8
  exports.Status = Status;
11
9
 
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/core-data/src/hooks/constants.ts"],"names":["Status"],"mappings":";;;;;;;AAAA;IACYA,M;;;WAAAA,M;AAAAA,EAAAA,M;AAAAA,EAAAA,M;AAAAA,EAAAA,M;AAAAA,EAAAA,M;GAAAA,M,sBAAAA,M","sourcesContent":["/* eslint-disable-next-line no-shadow */\nexport enum Status {\n\tIdle = 'IDLE',\n\tResolving = 'RESOLVING',\n\tError = 'ERROR',\n\tSuccess = 'SUCCESS',\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/core-data/src/hooks/constants.ts"],"names":["Status"],"mappings":";;;;;;IAAkBA,M;;;WAAAA,M;AAAAA,EAAAA,M;AAAAA,EAAAA,M;AAAAA,EAAAA,M;AAAAA,EAAAA,M;GAAAA,M,sBAAAA,M","sourcesContent":["export const enum Status {\n\tIdle = 'IDLE',\n\tResolving = 'RESOLVING',\n\tError = 'ERROR',\n\tSuccess = 'SUCCESS',\n}\n"]}
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "__experimentalUseEntityRecord", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _useEntityRecord.__experimentalUseEntityRecord;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "__experimentalUseEntityRecords", {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _useEntityRecords.__experimentalUseEntityRecords;
16
+ }
17
+ });
18
+ Object.defineProperty(exports, "useEntityRecord", {
19
+ enumerable: true,
20
+ get: function () {
21
+ return _useEntityRecord.default;
22
+ }
23
+ });
24
+ Object.defineProperty(exports, "useEntityRecords", {
25
+ enumerable: true,
26
+ get: function () {
27
+ return _useEntityRecords.default;
28
+ }
29
+ });
30
+
31
+ var _useEntityRecord = _interopRequireWildcard(require("./use-entity-record"));
32
+
33
+ var _useEntityRecords = _interopRequireWildcard(require("./use-entity-records"));
34
+
35
+ 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); }
36
+
37
+ 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; }
38
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["@wordpress/core-data/src/hooks/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AAIA","sourcesContent":["export {\n\tdefault as useEntityRecord,\n\t__experimentalUseEntityRecord,\n} from './use-entity-record';\nexport {\n\tdefault as useEntityRecords,\n\t__experimentalUseEntityRecords,\n} from './use-entity-records';\n"]}
@@ -5,12 +5,19 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
- exports.default = __experimentalUseEntityRecord;
8
+ exports.__experimentalUseEntityRecord = __experimentalUseEntityRecord;
9
+ exports.default = useEntityRecord;
10
+
11
+ var _deprecated = _interopRequireDefault(require("@wordpress/deprecated"));
9
12
 
10
13
  var _useQuerySelect = _interopRequireDefault(require("./use-query-select"));
11
14
 
12
15
  var _ = require("../");
13
16
 
17
+ /**
18
+ * WordPress dependencies
19
+ */
20
+
14
21
  /**
15
22
  * Internal dependencies
16
23
  */
@@ -18,11 +25,10 @@ var _ = require("../");
18
25
  /**
19
26
  * Resolves the specified entity record.
20
27
  *
21
- * @param kind Kind of the requested entity.
22
- * @param name Name of the requested entity.
23
- * @param recordId Record ID of the requested entity.
24
- * @param options Hook options.
25
- * @param [options.enabled=true] Whether to run the query or short-circuit and return null. Defaults to true.
28
+ * @param kind Kind of the entity, e.g. `root` or a `postType`. See rootEntitiesConfig in ../entities.ts for a list of available kinds.
29
+ * @param name Name of the entity, e.g. `plugin` or a `post`. See rootEntitiesConfig in ../entities.ts for a list of available names.
30
+ * @param recordId ID of the requested entity record.
31
+ * @param options Optional hook options.
26
32
  * @example
27
33
  * ```js
28
34
  * import { useEntityRecord } from '@wordpress/core-data';
@@ -45,10 +51,10 @@ var _ = require("../");
45
51
  * application, the page and the resolution details will be retrieved from
46
52
  * the store state using `getEntityRecord()`, or resolved if missing.
47
53
  *
48
- * @return {EntityRecordResolution<RecordType>} Entity record data.
54
+ * @return Entity record data.
49
55
  * @template RecordType
50
56
  */
51
- function __experimentalUseEntityRecord(kind, name, recordId) {
57
+ function useEntityRecord(kind, name, recordId) {
52
58
  let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {
53
59
  enabled: true
54
60
  };
@@ -67,4 +73,12 @@ function __experimentalUseEntityRecord(kind, name, recordId) {
67
73
  ...rest
68
74
  };
69
75
  }
76
+
77
+ function __experimentalUseEntityRecord(kind, name, recordId, options) {
78
+ (0, _deprecated.default)(`wp.data.__experimentalUseEntityRecord`, {
79
+ alternative: 'wp.data.useEntityRecord',
80
+ since: '6.1'
81
+ });
82
+ return useEntityRecord(kind, name, recordId, options);
83
+ }
70
84
  //# sourceMappingURL=use-entity-record.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/core-data/src/hooks/use-entity-record.ts"],"names":["__experimentalUseEntityRecord","kind","name","recordId","options","enabled","data","record","rest","query","coreStore","getEntityRecord"],"mappings":";;;;;;;;;AAGA;;AACA;;AAJA;AACA;AACA;;AA2BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,6BAAT,CACdC,IADc,EAEdC,IAFc,EAGdC,QAHc,EAKyB;AAAA,MADvCC,OACuC,uEADpB;AAAEC,IAAAA,OAAO,EAAE;AAAX,GACoB;AACvC,QAAM;AAAEC,IAAAA,IAAI,EAAEC,MAAR;AAAgB,OAAGC;AAAnB,MAA4B,6BAC/BC,KAAF,IAAa;AACZ,QAAK,CAAEL,OAAO,CAACC,OAAf,EAAyB;AACxB,aAAO,IAAP;AACA;;AACD,WAAOI,KAAK,CAAEC,OAAF,CAAL,CAAmBC,eAAnB,CAAoCV,IAApC,EAA0CC,IAA1C,EAAgDC,QAAhD,CAAP;AACA,GANgC,EAOjC,CAAEF,IAAF,EAAQC,IAAR,EAAcC,QAAd,EAAwBC,OAAO,CAACC,OAAhC,CAPiC,CAAlC;AAUA,SAAO;AACNE,IAAAA,MADM;AAEN,OAAGC;AAFG,GAAP;AAIA","sourcesContent":["/**\n * Internal dependencies\n */\nimport useQuerySelect from './use-query-select';\nimport { store as coreStore } from '../';\nimport type { Status } from './constants';\n\ninterface EntityRecordResolution< RecordType > {\n\t/** The requested entity record */\n\trecord: RecordType | null;\n\n\t/**\n\t * Is the record still being resolved?\n\t */\n\tisResolving: boolean;\n\n\t/**\n\t * Is the record resolved by now?\n\t */\n\thasResolved: boolean;\n\n\t/** Resolution status */\n\tstatus: Status;\n}\n\ninterface Options {\n\tenabled: boolean;\n}\n\n/**\n * Resolves the specified entity record.\n *\n * @param kind Kind of the requested entity.\n * @param name Name of the requested entity.\n * @param recordId Record ID of the requested entity.\n * @param options Hook options.\n * @param [options.enabled=true] Whether to run the query or short-circuit and return null. Defaults to true.\n * @example\n * ```js\n * import { useEntityRecord } from '@wordpress/core-data';\n *\n * function PageTitleDisplay( { id } ) {\n * const { record, isResolving } = useEntityRecord( 'postType', 'page', id );\n *\n * if ( isResolving ) {\n * return 'Loading...';\n * }\n *\n * return record.title;\n * }\n *\n * // Rendered in the application:\n * // <PageTitleDisplay id={ 1 } />\n * ```\n *\n * In the above example, when `PageTitleDisplay` is rendered into an\n * application, the page and the resolution details will be retrieved from\n * the store state using `getEntityRecord()`, or resolved if missing.\n *\n * @return {EntityRecordResolution<RecordType>} Entity record data.\n * @template RecordType\n */\nexport default function __experimentalUseEntityRecord< RecordType >(\n\tkind: string,\n\tname: string,\n\trecordId: string | number,\n\toptions: Options = { enabled: true }\n): EntityRecordResolution< RecordType > {\n\tconst { data: record, ...rest } = useQuerySelect(\n\t\t( query ) => {\n\t\t\tif ( ! options.enabled ) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\treturn query( coreStore ).getEntityRecord( kind, name, recordId );\n\t\t},\n\t\t[ kind, name, recordId, options.enabled ]\n\t);\n\n\treturn {\n\t\trecord,\n\t\t...rest,\n\t};\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/core-data/src/hooks/use-entity-record.ts"],"names":["useEntityRecord","kind","name","recordId","options","enabled","data","record","rest","query","coreStore","getEntityRecord","__experimentalUseEntityRecord","alternative","since"],"mappings":";;;;;;;;;;AAGA;;AAKA;;AACA;;AATA;AACA;AACA;;AAGA;AACA;AACA;;AAgCA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,eAAT,CACdC,IADc,EAEdC,IAFc,EAGdC,QAHc,EAKyB;AAAA,MADvCC,OACuC,uEADpB;AAAEC,IAAAA,OAAO,EAAE;AAAX,GACoB;AACvC,QAAM;AAAEC,IAAAA,IAAI,EAAEC,MAAR;AAAgB,OAAGC;AAAnB,MAA4B,6BAC/BC,KAAF,IAAa;AACZ,QAAK,CAAEL,OAAO,CAACC,OAAf,EAAyB;AACxB,aAAO,IAAP;AACA;;AACD,WAAOI,KAAK,CAAEC,OAAF,CAAL,CAAmBC,eAAnB,CAAoCV,IAApC,EAA0CC,IAA1C,EAAgDC,QAAhD,CAAP;AACA,GANgC,EAOjC,CAAEF,IAAF,EAAQC,IAAR,EAAcC,QAAd,EAAwBC,OAAO,CAACC,OAAhC,CAPiC,CAAlC;AAUA,SAAO;AACNE,IAAAA,MADM;AAEN,OAAGC;AAFG,GAAP;AAIA;;AAEM,SAASI,6BAAT,CACNX,IADM,EAENC,IAFM,EAGNC,QAHM,EAINC,OAJM,EAKL;AACD,2BAAa,uCAAb,EAAqD;AACpDS,IAAAA,WAAW,EAAE,yBADuC;AAEpDC,IAAAA,KAAK,EAAE;AAF6C,GAArD;AAIA,SAAOd,eAAe,CAAEC,IAAF,EAAQC,IAAR,EAAcC,QAAd,EAAwBC,OAAxB,CAAtB;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport deprecated from '@wordpress/deprecated';\n\n/**\n * Internal dependencies\n */\nimport useQuerySelect from './use-query-select';\nimport { store as coreStore } from '../';\nimport type { Status } from './constants';\n\nexport interface EntityRecordResolution< RecordType > {\n\t/** The requested entity record */\n\trecord: RecordType | null;\n\n\t/**\n\t * Is the record still being resolved?\n\t */\n\tisResolving: boolean;\n\n\t/**\n\t * Is the record resolved by now?\n\t */\n\thasResolved: boolean;\n\n\t/** Resolution status */\n\tstatus: Status;\n}\n\nexport interface Options {\n\t/**\n\t * Whether to run the query or short-circuit and return null.\n\t *\n\t * @default true\n\t */\n\tenabled: boolean;\n}\n\n/**\n * Resolves the specified entity record.\n *\n * @param kind Kind of the entity, e.g. `root` or a `postType`. See rootEntitiesConfig in ../entities.ts for a list of available kinds.\n * @param name Name of the entity, e.g. `plugin` or a `post`. See rootEntitiesConfig in ../entities.ts for a list of available names.\n * @param recordId ID of the requested entity record.\n * @param options Optional hook options.\n * @example\n * ```js\n * import { useEntityRecord } from '@wordpress/core-data';\n *\n * function PageTitleDisplay( { id } ) {\n * const { record, isResolving } = useEntityRecord( 'postType', 'page', id );\n *\n * if ( isResolving ) {\n * return 'Loading...';\n * }\n *\n * return record.title;\n * }\n *\n * // Rendered in the application:\n * // <PageTitleDisplay id={ 1 } />\n * ```\n *\n * In the above example, when `PageTitleDisplay` is rendered into an\n * application, the page and the resolution details will be retrieved from\n * the store state using `getEntityRecord()`, or resolved if missing.\n *\n * @return Entity record data.\n * @template RecordType\n */\nexport default function useEntityRecord< RecordType >(\n\tkind: string,\n\tname: string,\n\trecordId: string | number,\n\toptions: Options = { enabled: true }\n): EntityRecordResolution< RecordType > {\n\tconst { data: record, ...rest } = useQuerySelect(\n\t\t( query ) => {\n\t\t\tif ( ! options.enabled ) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\treturn query( coreStore ).getEntityRecord( kind, name, recordId );\n\t\t},\n\t\t[ kind, name, recordId, options.enabled ]\n\t);\n\n\treturn {\n\t\trecord,\n\t\t...rest,\n\t};\n}\n\nexport function __experimentalUseEntityRecord(\n\tkind: string,\n\tname: string,\n\trecordId: any,\n\toptions: any\n) {\n\tdeprecated( `wp.data.__experimentalUseEntityRecord`, {\n\t\talternative: 'wp.data.useEntityRecord',\n\t\tsince: '6.1',\n\t} );\n\treturn useEntityRecord( kind, name, recordId, options );\n}\n"]}
@@ -5,10 +5,13 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
- exports.default = __experimentalUseEntityRecords;
8
+ exports.__experimentalUseEntityRecords = __experimentalUseEntityRecords;
9
+ exports.default = useEntityRecords;
9
10
 
10
11
  var _url = require("@wordpress/url");
11
12
 
13
+ var _deprecated = _interopRequireDefault(require("@wordpress/deprecated"));
14
+
12
15
  var _useQuerySelect = _interopRequireDefault(require("./use-query-select"));
13
16
 
14
17
  var _ = require("../");
@@ -20,14 +23,14 @@ var _ = require("../");
20
23
  /**
21
24
  * Internal dependencies
22
25
  */
23
-
26
+ const EMPTY_ARRAY = [];
24
27
  /**
25
28
  * Resolves the specified entity records.
26
29
  *
27
- * @param kind Kind of the requested entities.
28
- * @param name Name of the requested entities.
29
- * @param queryArgs HTTP query for the requested entities.
30
- * @param options Hook options.
30
+ * @param kind Kind of the entity, e.g. `root` or a `postType`. See rootEntitiesConfig in ../entities.ts for a list of available kinds.
31
+ * @param name Name of the entity, e.g. `plugin` or a `post`. See rootEntitiesConfig in ../entities.ts for a list of available names.
32
+ * @param queryArgs Optional HTTP query description for how to fetch the data, passed to the requested API endpoint.
33
+ * @param options Optional hook options.
31
34
  * @example
32
35
  * ```js
33
36
  * import { useEntityRecord } from '@wordpress/core-data';
@@ -59,7 +62,8 @@ var _ = require("../");
59
62
  * @return Entity records data.
60
63
  * @template RecordType
61
64
  */
62
- function __experimentalUseEntityRecords(kind, name) {
65
+
66
+ function useEntityRecords(kind, name) {
63
67
  let queryArgs = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
64
68
  let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {
65
69
  enabled: true
@@ -75,7 +79,8 @@ function __experimentalUseEntityRecords(kind, name) {
75
79
  } = (0, _useQuerySelect.default)(query => {
76
80
  if (!options.enabled) {
77
81
  return {
78
- data: []
82
+ // Avoiding returning a new reference on every execution.
83
+ data: EMPTY_ARRAY
79
84
  };
80
85
  }
81
86
 
@@ -86,4 +91,12 @@ function __experimentalUseEntityRecords(kind, name) {
86
91
  ...rest
87
92
  };
88
93
  }
94
+
95
+ function __experimentalUseEntityRecords(kind, name, queryArgs, options) {
96
+ (0, _deprecated.default)(`wp.data.__experimentalUseEntityRecords`, {
97
+ alternative: 'wp.data.useEntityRecords',
98
+ since: '6.1'
99
+ });
100
+ return useEntityRecords(kind, name, queryArgs, options);
101
+ }
89
102
  //# sourceMappingURL=use-entity-records.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/core-data/src/hooks/use-entity-records.ts"],"names":["__experimentalUseEntityRecords","kind","name","queryArgs","options","enabled","queryAsString","data","records","rest","query","coreStore","getEntityRecords"],"mappings":";;;;;;;;;AAGA;;AAKA;;AACA;;AATA;AACA;AACA;;AAGA;AACA;AACA;;AAgCA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,8BAAT,CACdC,IADc,EAEdC,IAFc,EAK0B;AAAA,MAFxCC,SAEwC,uEAFD,EAEC;AAAA,MADxCC,OACwC,uEADrB;AAAEC,IAAAA,OAAO,EAAE;AAAX,GACqB;AACxC;AACA;AACA;AACA;AACA,QAAMC,aAAa,GAAG,uBAAc,EAAd,EAAkBH,SAAlB,CAAtB;AAEA,QAAM;AAAEI,IAAAA,IAAI,EAAEC,OAAR;AAAiB,OAAGC;AAApB,MAA6B,6BAChCC,KAAF,IAAa;AACZ,QAAK,CAAEN,OAAO,CAACC,OAAf,EAAyB;AACxB,aAAO;AACNE,QAAAA,IAAI,EAAE;AADA,OAAP;AAGA;;AACD,WAAOG,KAAK,CAAEC,OAAF,CAAL,CAAmBC,gBAAnB,CAAqCX,IAArC,EAA2CC,IAA3C,EAAiDC,SAAjD,CAAP;AACA,GARiC,EASlC,CAAEF,IAAF,EAAQC,IAAR,EAAcI,aAAd,EAA6BF,OAAO,CAACC,OAArC,CATkC,CAAnC;AAYA,SAAO;AACNG,IAAAA,OADM;AAEN,OAAGC;AAFG,GAAP;AAIA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { addQueryArgs } from '@wordpress/url';\n\n/**\n * Internal dependencies\n */\nimport useQuerySelect from './use-query-select';\nimport { store as coreStore } from '../';\nimport type { Status } from './constants';\n\ninterface EntityRecordsResolution< RecordType > {\n\t/** The requested entity record */\n\trecords: RecordType[] | null;\n\n\t/**\n\t * Is the record still being resolved?\n\t */\n\tisResolving: boolean;\n\n\t/**\n\t * Is the record resolved by now?\n\t */\n\thasResolved: boolean;\n\n\t/** Resolution status */\n\tstatus: Status;\n}\n\ninterface Options {\n\t/**\n\t * Whether to run the query or short-circuit and return null.\n\t *\n\t * @default true\n\t */\n\tenabled: boolean;\n}\n\n/**\n * Resolves the specified entity records.\n *\n * @param kind Kind of the requested entities.\n * @param name Name of the requested entities.\n * @param queryArgs HTTP query for the requested entities.\n * @param options Hook options.\n * @example\n * ```js\n * import { useEntityRecord } from '@wordpress/core-data';\n *\n * function PageTitlesList() {\n * const { records, isResolving } = useEntityRecords( 'postType', 'page' );\n *\n * if ( isResolving ) {\n * return 'Loading...';\n * }\n *\n * return (\n * <ul>\n * {records.map(( page ) => (\n * <li>{ page.title }</li>\n * ))}\n * </ul>\n * );\n * }\n *\n * // Rendered in the application:\n * // <PageTitlesList />\n * ```\n *\n * In the above example, when `PageTitlesList` is rendered into an\n * application, the list of records and the resolution details will be retrieved from\n * the store state using `getEntityRecords()`, or resolved if missing.\n *\n * @return Entity records data.\n * @template RecordType\n */\nexport default function __experimentalUseEntityRecords< RecordType >(\n\tkind: string,\n\tname: string,\n\tqueryArgs: Record< string, unknown > = {},\n\toptions: Options = { enabled: true }\n): EntityRecordsResolution< RecordType > {\n\t// Serialize queryArgs to a string that can be safely used as a React dep.\n\t// We can't just pass queryArgs as one of the deps, because if it is passed\n\t// as an object literal, then it will be a different object on each call even\n\t// if the values remain the same.\n\tconst queryAsString = addQueryArgs( '', queryArgs );\n\n\tconst { data: records, ...rest } = useQuerySelect(\n\t\t( query ) => {\n\t\t\tif ( ! options.enabled ) {\n\t\t\t\treturn {\n\t\t\t\t\tdata: [],\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn query( coreStore ).getEntityRecords( kind, name, queryArgs );\n\t\t},\n\t\t[ kind, name, queryAsString, options.enabled ]\n\t);\n\n\treturn {\n\t\trecords,\n\t\t...rest,\n\t};\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/core-data/src/hooks/use-entity-records.ts"],"names":["EMPTY_ARRAY","useEntityRecords","kind","name","queryArgs","options","enabled","queryAsString","data","records","rest","query","coreStore","getEntityRecords","__experimentalUseEntityRecords","alternative","since"],"mappings":";;;;;;;;;;AAGA;;AACA;;AAKA;;AACA;;AAVA;AACA;AACA;;AAIA;AACA;AACA;AAaA,MAAMA,WAAW,GAAG,EAApB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACe,SAASC,gBAAT,CACdC,IADc,EAEdC,IAFc,EAK0B;AAAA,MAFxCC,SAEwC,uEAFD,EAEC;AAAA,MADxCC,OACwC,uEADrB;AAAEC,IAAAA,OAAO,EAAE;AAAX,GACqB;AACxC;AACA;AACA;AACA;AACA,QAAMC,aAAa,GAAG,uBAAc,EAAd,EAAkBH,SAAlB,CAAtB;AAEA,QAAM;AAAEI,IAAAA,IAAI,EAAEC,OAAR;AAAiB,OAAGC;AAApB,MAA6B,6BAChCC,KAAF,IAAa;AACZ,QAAK,CAAEN,OAAO,CAACC,OAAf,EAAyB;AACxB,aAAO;AACN;AACAE,QAAAA,IAAI,EAAER;AAFA,OAAP;AAIA;;AACD,WAAOW,KAAK,CAAEC,OAAF,CAAL,CAAmBC,gBAAnB,CAAqCX,IAArC,EAA2CC,IAA3C,EAAiDC,SAAjD,CAAP;AACA,GATiC,EAUlC,CAAEF,IAAF,EAAQC,IAAR,EAAcI,aAAd,EAA6BF,OAAO,CAACC,OAArC,CAVkC,CAAnC;AAaA,SAAO;AACNG,IAAAA,OADM;AAEN,OAAGC;AAFG,GAAP;AAIA;;AAEM,SAASI,8BAAT,CACNZ,IADM,EAENC,IAFM,EAGNC,SAHM,EAINC,OAJM,EAKL;AACD,2BAAa,wCAAb,EAAsD;AACrDU,IAAAA,WAAW,EAAE,0BADwC;AAErDC,IAAAA,KAAK,EAAE;AAF8C,GAAtD;AAIA,SAAOf,gBAAgB,CAAEC,IAAF,EAAQC,IAAR,EAAcC,SAAd,EAAyBC,OAAzB,CAAvB;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { addQueryArgs } from '@wordpress/url';\nimport deprecated from '@wordpress/deprecated';\n\n/**\n * Internal dependencies\n */\nimport useQuerySelect from './use-query-select';\nimport { store as coreStore } from '../';\nimport type { Options, EntityRecordResolution } from './use-entity-record';\n\ntype EntityRecordsResolution< RecordType > = Omit<\n\tEntityRecordResolution< RecordType >,\n\t'record'\n> & {\n\t/** The requested entity record */\n\trecords: RecordType[] | null;\n};\n\nconst EMPTY_ARRAY = [];\n\n/**\n * Resolves the specified entity records.\n *\n * @param kind Kind of the entity, e.g. `root` or a `postType`. See rootEntitiesConfig in ../entities.ts for a list of available kinds.\n * @param name Name of the entity, e.g. `plugin` or a `post`. See rootEntitiesConfig in ../entities.ts for a list of available names.\n * @param queryArgs Optional HTTP query description for how to fetch the data, passed to the requested API endpoint.\n * @param options Optional hook options.\n * @example\n * ```js\n * import { useEntityRecord } from '@wordpress/core-data';\n *\n * function PageTitlesList() {\n * const { records, isResolving } = useEntityRecords( 'postType', 'page' );\n *\n * if ( isResolving ) {\n * return 'Loading...';\n * }\n *\n * return (\n * <ul>\n * {records.map(( page ) => (\n * <li>{ page.title }</li>\n * ))}\n * </ul>\n * );\n * }\n *\n * // Rendered in the application:\n * // <PageTitlesList />\n * ```\n *\n * In the above example, when `PageTitlesList` is rendered into an\n * application, the list of records and the resolution details will be retrieved from\n * the store state using `getEntityRecords()`, or resolved if missing.\n *\n * @return Entity records data.\n * @template RecordType\n */\nexport default function useEntityRecords< RecordType >(\n\tkind: string,\n\tname: string,\n\tqueryArgs: Record< string, unknown > = {},\n\toptions: Options = { enabled: true }\n): EntityRecordsResolution< RecordType > {\n\t// Serialize queryArgs to a string that can be safely used as a React dep.\n\t// We can't just pass queryArgs as one of the deps, because if it is passed\n\t// as an object literal, then it will be a different object on each call even\n\t// if the values remain the same.\n\tconst queryAsString = addQueryArgs( '', queryArgs );\n\n\tconst { data: records, ...rest } = useQuerySelect(\n\t\t( query ) => {\n\t\t\tif ( ! options.enabled ) {\n\t\t\t\treturn {\n\t\t\t\t\t// Avoiding returning a new reference on every execution.\n\t\t\t\t\tdata: EMPTY_ARRAY,\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn query( coreStore ).getEntityRecords( kind, name, queryArgs );\n\t\t},\n\t\t[ kind, name, queryAsString, options.enabled ]\n\t);\n\n\treturn {\n\t\trecords,\n\t\t...rest,\n\t};\n}\n\nexport function __experimentalUseEntityRecords(\n\tkind: string,\n\tname: string,\n\tqueryArgs: any,\n\toptions: any\n) {\n\tdeprecated( `wp.data.__experimentalUseEntityRecords`, {\n\t\talternative: 'wp.data.useEntityRecords',\n\t\tsince: '6.1',\n\t} );\n\treturn useEntityRecords( kind, name, queryArgs, options );\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/core-data/src/hooks/use-query-select.ts"],"names":["META_SELECTORS","__experimentalUseQuerySelect","mapQuerySelect","deps","select","registry","resolve","store","enrichSelectors","selectors","resolvers","selectorName","includes","Object","defineProperty","get","getIsResolving","hasFinishedResolution","args","isResolving","hasResolved","data","status","Status","Resolving","Success","Error","Idle"],"mappings":";;;;;;;;;;AAGA;;AAKA;;AACA;;AATA;AACA;AACA;;AAGA;AACA;AACA;AAIO,MAAMA,cAAc,GAAG,CAC7B,gBAD6B,EAE7B,sBAF6B,EAG7B,uBAH6B,EAI7B,aAJ6B,EAK7B,oBAL6B,CAAvB;;;AAsBP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASC,4BAAT,CAAuCC,cAAvC,EAAuDC,IAAvD,EAA8D;AAC5E,SAAO,qBAAW,CAAEC,MAAF,EAAUC,QAAV,KAAwB;AACzC,UAAMC,OAAO,GAAKC,KAAF,IAAaC,eAAe,CAAEJ,MAAM,CAAEG,KAAF,CAAR,CAA5C;;AACA,WAAOL,cAAc,CAAEI,OAAF,EAAWD,QAAX,CAArB;AACA,GAHM,EAGJF,IAHI,CAAP;AAIA;;AAYD;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMK,eAAe,GAAG,sBAAaC,SAAF,IAAiB;AACnD,QAAMC,SAAS,GAAG,EAAlB;;AACA,OAAM,MAAMC,YAAZ,IAA4BF,SAA5B,EAAwC;AACvC,QAAKT,cAAc,CAACY,QAAf,CAAyBD,YAAzB,CAAL,EAA+C;AAC9C;AACA;;AACDE,IAAAA,MAAM,CAACC,cAAP,CAAuBJ,SAAvB,EAAkCC,YAAlC,EAAgD;AAC/CI,MAAAA,GAAG,EAAE,MAAM,YAA0B;AACpC,cAAM;AAAEC,UAAAA,cAAF;AAAkBC,UAAAA;AAAlB,YAA4CR,SAAlD;;AADoC,0CAArBS,IAAqB;AAArBA,UAAAA,IAAqB;AAAA;;AAEpC,cAAMC,WAAW,GAAG,CAAC,CAAEH,cAAc,CAAEL,YAAF,EAAgBO,IAAhB,CAArC;AACA,cAAME,WAAW,GAChB,CAAED,WAAF,IACAF,qBAAqB,CAAEN,YAAF,EAAgBO,IAAhB,CAFtB;AAGA,cAAMG,IAAI,GAAGZ,SAAS,CAAEE,YAAF,CAAT,CAA2B,GAAGO,IAA9B,CAAb;AAEA,YAAII,MAAJ;;AACA,YAAKH,WAAL,EAAmB;AAClBG,UAAAA,MAAM,GAAGC,kBAAOC,SAAhB;AACA,SAFD,MAEO,IAAKJ,WAAL,EAAmB;AACzB,cAAKC,IAAL,EAAY;AACXC,YAAAA,MAAM,GAAGC,kBAAOE,OAAhB;AACA,WAFD,MAEO;AACNH,YAAAA,MAAM,GAAGC,kBAAOG,KAAhB;AACA;AACD,SANM,MAMA;AACNJ,UAAAA,MAAM,GAAGC,kBAAOI,IAAhB;AACA;;AAED,eAAO;AACNN,UAAAA,IADM;AAENC,UAAAA,MAFM;AAGNH,UAAAA,WAHM;AAINC,UAAAA;AAJM,SAAP;AAMA;AA5B8C,KAAhD;AA8BA;;AACD,SAAOV,SAAP;AACA,CAtCuB,CAAxB","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport memoize from './memoize';\nimport { Status } from './constants';\n\nexport const META_SELECTORS = [\n\t'getIsResolving',\n\t'hasStartedResolution',\n\t'hasFinishedResolution',\n\t'isResolving',\n\t'getCachedResolvers',\n];\n\ninterface QuerySelectResponse< Data > {\n\t/** the requested selector return value */\n\tdata: Data;\n\n\t/** is the record still being resolved? Via the `getIsResolving` meta-selector */\n\tisResolving: boolean;\n\n\t/** was the resolution started? Via the `hasStartedResolution` meta-selector */\n\thasStarted: boolean;\n\n\t/** has the resolution finished? Via the `hasFinishedResolution` meta-selector. */\n\thasResolved: boolean;\n}\n\n/**\n * Like useSelect, but the selectors return objects containing\n * both the original data AND the resolution info.\n *\n * @param {Function} mapQuerySelect see useSelect\n * @param {Array} deps see useSelect\n *\n * @example\n * ```js\n * import { useQuerySelect } from '@wordpress/data';\n * import { store as coreDataStore } from '@wordpress/core-data';\n *\n * function PageTitleDisplay( { id } ) {\n * const { data: page, isResolving } = useQuerySelect( ( query ) => {\n * return query( coreDataStore ).getEntityRecord( 'postType', 'page', id )\n * }, [ id ] );\n *\n * if ( isResolving ) {\n * return 'Loading...';\n * }\n *\n * return page.title;\n * }\n *\n * // Rendered in the application:\n * // <PageTitleDisplay id={ 10 } />\n * ```\n *\n * In the above example, when `PageTitleDisplay` is rendered into an\n * application, the page and the resolution details will be retrieved from\n * the store state using the `mapSelect` callback on `useQuerySelect`.\n *\n * If the id prop changes then any page in the state for that id is\n * retrieved. If the id prop doesn't change and other props are passed in\n * that do change, the title will not change because the dependency is just\n * the id.\n * @see useSelect\n *\n * @return {QuerySelectResponse} Queried data.\n */\nexport default function __experimentalUseQuerySelect( mapQuerySelect, deps ) {\n\treturn useSelect( ( select, registry ) => {\n\t\tconst resolve = ( store ) => enrichSelectors( select( store ) );\n\t\treturn mapQuerySelect( resolve, registry );\n\t}, deps );\n}\n\ninterface EnrichedSelectors {\n\t< Selectors extends Record< string, ( ...args: any[] ) => any > >(\n\t\tselectors: Selectors\n\t): {\n\t\t[ Selector in keyof Selectors ]: (\n\t\t\t...args: Parameters< Selectors[ Selector ] >\n\t\t) => QuerySelectResponse< ReturnType< Selectors[ Selector ] > >;\n\t};\n}\n\n/**\n * Transform simple selectors into ones that return an object with the\n * original return value AND the resolution info.\n *\n * @param {Object} selectors Selectors to enrich\n * @return {EnrichedSelectors} Enriched selectors\n */\nconst enrichSelectors = memoize( ( ( selectors ) => {\n\tconst resolvers = {};\n\tfor ( const selectorName in selectors ) {\n\t\tif ( META_SELECTORS.includes( selectorName ) ) {\n\t\t\tcontinue;\n\t\t}\n\t\tObject.defineProperty( resolvers, selectorName, {\n\t\t\tget: () => ( ...args: unknown[] ) => {\n\t\t\t\tconst { getIsResolving, hasFinishedResolution } = selectors;\n\t\t\t\tconst isResolving = !! getIsResolving( selectorName, args );\n\t\t\t\tconst hasResolved =\n\t\t\t\t\t! isResolving &&\n\t\t\t\t\thasFinishedResolution( selectorName, args );\n\t\t\t\tconst data = selectors[ selectorName ]( ...args );\n\n\t\t\t\tlet status;\n\t\t\t\tif ( isResolving ) {\n\t\t\t\t\tstatus = Status.Resolving;\n\t\t\t\t} else if ( hasResolved ) {\n\t\t\t\t\tif ( data ) {\n\t\t\t\t\t\tstatus = Status.Success;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tstatus = Status.Error;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tstatus = Status.Idle;\n\t\t\t\t}\n\n\t\t\t\treturn {\n\t\t\t\t\tdata,\n\t\t\t\t\tstatus,\n\t\t\t\t\tisResolving,\n\t\t\t\t\thasResolved,\n\t\t\t\t};\n\t\t\t},\n\t\t} );\n\t}\n\treturn resolvers;\n} ) as EnrichedSelectors );\n"]}
1
+ {"version":3,"sources":["@wordpress/core-data/src/hooks/use-query-select.ts"],"names":["META_SELECTORS","__experimentalUseQuerySelect","mapQuerySelect","deps","select","registry","resolve","store","enrichSelectors","selectors","resolvers","selectorName","includes","Object","defineProperty","get","getIsResolving","hasFinishedResolution","args","isResolving","hasResolved","data","status","Status","Resolving","Success","Error","Idle"],"mappings":";;;;;;;;;;AAGA;;AAKA;;AACA;;AATA;AACA;AACA;;AAGA;AACA;AACA;AAIO,MAAMA,cAAc,GAAG,CAC7B,gBAD6B,EAE7B,sBAF6B,EAG7B,uBAH6B,EAI7B,aAJ6B,EAK7B,oBAL6B,CAAvB;;;AAsBP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;A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EO,IAAKJ,WAAL,EAAmB;AACzB,cAAKC,IAAL,EAAY;AACXC,YAAAA,MAAM,GAAGC,kBAAOE,OAAhB;AACA,WAFD,MAEO;AACNH,YAAAA,MAAM,GAAGC,kBAAOG,KAAhB;AACA;AACD,SANM,MAMA;AACNJ,UAAAA,MAAM,GAAGC,kBAAOI,IAAhB;AACA;;AAED,eAAO;AACNN,UAAAA,IADM;AAENC,UAAAA,MAFM;AAGNH,UAAAA,WAHM;AAINC,UAAAA;AAJM,SAAP;AAMA;AA9B6C,KAAhD;AAgCA;;AACD,SAAOV,SAAP;AACA,CAxCuB,CAAxB","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport memoize from './memoize';\nimport { Status } from './constants';\n\nexport const META_SELECTORS = [\n\t'getIsResolving',\n\t'hasStartedResolution',\n\t'hasFinishedResolution',\n\t'isResolving',\n\t'getCachedResolvers',\n];\n\ninterface QuerySelectResponse< Data > {\n\t/** the requested selector return value */\n\tdata: Data;\n\n\t/** is the record still being resolved? Via the `getIsResolving` meta-selector */\n\tisResolving: boolean;\n\n\t/** was the resolution started? Via the `hasStartedResolution` meta-selector */\n\thasStarted: boolean;\n\n\t/** has the resolution finished? Via the `hasFinishedResolution` meta-selector. */\n\thasResolved: boolean;\n}\n\n/**\n * Like useSelect, but the selectors return objects containing\n * both the original data AND the resolution info.\n *\n * @param {Function} mapQuerySelect see useSelect\n * @param {Array} deps see useSelect\n *\n * @example\n * ```js\n * import { useQuerySelect } from '@wordpress/data';\n * import { store as coreDataStore } from '@wordpress/core-data';\n *\n * function PageTitleDisplay( { id } ) {\n * const { data: page, isResolving } = useQuerySelect( ( query ) => {\n * return query( coreDataStore ).getEntityRecord( 'postType', 'page', id )\n * }, [ id ] );\n *\n * if ( isResolving ) {\n * return 'Loading...';\n * }\n *\n * return page.title;\n * }\n *\n * // Rendered in the application:\n * // <PageTitleDisplay id={ 10 } />\n * ```\n *\n * In the above example, when `PageTitleDisplay` is rendered into an\n * application, the page and the resolution details will be retrieved from\n * the store state using the `mapSelect` callback on `useQuerySelect`.\n *\n * If the id prop changes then any page in the state for that id is\n * retrieved. If the id prop doesn't change and other props are passed in\n * that do change, the title will not change because the dependency is just\n * the id.\n * @see useSelect\n *\n * @return {QuerySelectResponse} Queried data.\n */\nexport default function __experimentalUseQuerySelect( mapQuerySelect, deps ) {\n\treturn useSelect( ( select, registry ) => {\n\t\tconst resolve = ( store ) => enrichSelectors( select( store ) );\n\t\treturn mapQuerySelect( resolve, registry );\n\t}, deps );\n}\n\ninterface EnrichedSelectors {\n\t< Selectors extends Record< string, ( ...args: any[] ) => any > >(\n\t\tselectors: Selectors\n\t): {\n\t\t[ Selector in keyof Selectors ]: (\n\t\t\t...args: Parameters< Selectors[ Selector ] >\n\t\t) => QuerySelectResponse< ReturnType< Selectors[ Selector ] > >;\n\t};\n}\n\n/**\n * Transform simple selectors into ones that return an object with the\n * original return value AND the resolution info.\n *\n * @param {Object} selectors Selectors to enrich\n * @return {EnrichedSelectors} Enriched selectors\n */\nconst enrichSelectors = memoize( ( ( selectors ) => {\n\tconst resolvers = {};\n\tfor ( const selectorName in selectors ) {\n\t\tif ( META_SELECTORS.includes( selectorName ) ) {\n\t\t\tcontinue;\n\t\t}\n\t\tObject.defineProperty( resolvers, selectorName, {\n\t\t\tget:\n\t\t\t\t() =>\n\t\t\t\t( ...args: unknown[] ) => {\n\t\t\t\t\tconst { getIsResolving, hasFinishedResolution } = selectors;\n\t\t\t\t\tconst isResolving = !! getIsResolving( selectorName, args );\n\t\t\t\t\tconst hasResolved =\n\t\t\t\t\t\t! isResolving &&\n\t\t\t\t\t\thasFinishedResolution( selectorName, args );\n\t\t\t\t\tconst data = selectors[ selectorName ]( ...args );\n\n\t\t\t\t\tlet status;\n\t\t\t\t\tif ( isResolving ) {\n\t\t\t\t\t\tstatus = Status.Resolving;\n\t\t\t\t\t} else if ( hasResolved ) {\n\t\t\t\t\t\tif ( data ) {\n\t\t\t\t\t\t\tstatus = Status.Success;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tstatus = Status.Error;\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tstatus = Status.Idle;\n\t\t\t\t\t}\n\n\t\t\t\t\treturn {\n\t\t\t\t\t\tdata,\n\t\t\t\t\t\tstatus,\n\t\t\t\t\t\tisResolving,\n\t\t\t\t\t\thasResolved,\n\t\t\t\t\t};\n\t\t\t\t},\n\t\t} );\n\t}\n\treturn resolvers;\n} ) as EnrichedSelectors );\n"]}
package/build/index.js CHANGED
@@ -7,9 +7,7 @@ Object.defineProperty(exports, "__esModule", {
7
7
  });
8
8
  var _exportNames = {
9
9
  store: true,
10
- EntityProvider: true,
11
- __experimentalUseEntityRecord: true,
12
- __experimentalUseEntityRecords: true
10
+ EntityProvider: true
13
11
  };
14
12
  Object.defineProperty(exports, "EntityProvider", {
15
13
  enumerable: true,
@@ -17,18 +15,6 @@ Object.defineProperty(exports, "EntityProvider", {
17
15
  return _entityProvider.default;
18
16
  }
19
17
  });
20
- Object.defineProperty(exports, "__experimentalUseEntityRecord", {
21
- enumerable: true,
22
- get: function () {
23
- return _useEntityRecord.default;
24
- }
25
- });
26
- Object.defineProperty(exports, "__experimentalUseEntityRecords", {
27
- enumerable: true,
28
- get: function () {
29
- return _useEntityRecords.default;
30
- }
31
- });
32
18
  exports.store = void 0;
33
19
 
34
20
  var _data = require("@wordpress/data");
@@ -61,9 +47,19 @@ Object.keys(_entityProvider).forEach(function (key) {
61
47
  });
62
48
  });
63
49
 
64
- var _useEntityRecord = _interopRequireDefault(require("./hooks/use-entity-record"));
50
+ var _entityTypes = require("./entity-types");
65
51
 
66
- var _useEntityRecords = _interopRequireDefault(require("./hooks/use-entity-records"));
52
+ Object.keys(_entityTypes).forEach(function (key) {
53
+ if (key === "default" || key === "__esModule") return;
54
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
55
+ if (key in exports && exports[key] === _entityTypes[key]) return;
56
+ Object.defineProperty(exports, key, {
57
+ enumerable: true,
58
+ get: function () {
59
+ return _entityTypes[key];
60
+ }
61
+ });
62
+ });
67
63
 
68
64
  var _fetch = require("./fetch");
69
65
 
@@ -79,16 +75,16 @@ Object.keys(_fetch).forEach(function (key) {
79
75
  });
80
76
  });
81
77
 
82
- var _entityTypes = require("./entity-types");
78
+ var _hooks = require("./hooks");
83
79
 
84
- Object.keys(_entityTypes).forEach(function (key) {
80
+ Object.keys(_hooks).forEach(function (key) {
85
81
  if (key === "default" || key === "__esModule") return;
86
82
  if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
87
- if (key in exports && exports[key] === _entityTypes[key]) return;
83
+ if (key in exports && exports[key] === _hooks[key]) return;
88
84
  Object.defineProperty(exports, key, {
89
85
  enumerable: true,
90
86
  get: function () {
91
- return _entityTypes[key];
87
+ return _hooks[key];
92
88
  }
93
89
  });
94
90
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/core-data/src/index.js"],"names":["entitySelectors","rootEntitiesConfig","reduce","result","entity","kind","name","state","key","query","selectors","getEntityRecord","getEntityRecords","entityResolvers","resolvers","pluralMethodName","args","shouldInvalidate","action","entityActions","actions","saveEntityRecord","deleteEntityRecord","storeConfig","reducer","store","STORE_NAME"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAuDA;;AAGA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAFA;;AACA;;AAEA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;;;;AA1EA;AACA;AACA;;AAGA;AACA;AACA;AASA;AACA;AACA;AACA;AAEA,MAAMA,eAAe,GAAGC,6BAAmBC,MAA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K,GAAG,4BAAkBC,gBAAlB,EAA8BH,WAAW,EAAzC,CAAd;;AAEP,oBAAUE,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 { rootEntitiesConfig, 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, 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.\n\nconst entitySelectors = rootEntitiesConfig.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, query ) =>\n\t\tselectors.getEntityRecords( state, kind, name, query );\n\treturn result;\n}, {} );\n\nconst entityResolvers = rootEntitiesConfig.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 ) =>\n\t\tresolvers.getEntityRecords.shouldInvalidate( action, kind, name );\n\treturn result;\n}, {} );\n\nconst entityActions = rootEntitiesConfig.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} );\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 { default as __experimentalUseEntityRecord } from './hooks/use-entity-record';\nexport { default as __experimentalUseEntityRecords } from './hooks/use-entity-records';\nexport * from './entity-provider';\nexport * from './fetch';\nexport * from './entity-types';\n"]}
1
+ {"version":3,"sources":["@wordpress/core-data/src/index.js"],"names":["entitySelectors","rootEntitiesConfig","reduce","result","entity","kind","name","state","key","query","selectors","getEntityRecord","getEntityRecords","entityResolvers","resolvers","pluralMethodName","args","shouldInvalidate","action","entityActions","actions","saveEntityRecord","deleteEntityRecord","storeConfig","reducer","store","STORE_NAME"],"mappings":";;;;;;;;;;;;;;;;;;;AAGA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAuDA;;AACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;;;;AAzEA;AACA;AACA;;AAGA;AACA;AACA;AASA;AACA;AACA;AACA;AAEA,MAAMA,eAAe,GAAGC,6BAAmBC,MAAnB,CAA2B,CAAEC,MAAF,EAAUC,MAAV,KAAsB;AACxE,QAA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;AAEP,oBAAUE,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 { rootEntitiesConfig, 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, 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.\n\nconst entitySelectors = rootEntitiesConfig.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, query ) =>\n\t\tselectors.getEntityRecords( state, kind, name, query );\n\treturn result;\n}, {} );\n\nconst entityResolvers = rootEntitiesConfig.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 ) =>\n\t\tresolvers.getEntityRecords.shouldInvalidate( action, kind, name );\n\treturn result;\n}, {} );\n\nconst entityActions = rootEntitiesConfig.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} );\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 './entity-types';\nexport * from './fetch';\nexport * from './hooks';\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/core-data/src/queried-data/selectors.js"],"names":["queriedItemsCacheByState","WeakMap","getQueriedItemsUncached","state","query","stableKey","page","perPage","include","fields","context","itemIds","queries","startOffset","endOffset","length","Math","min","items","i","itemId","Array","isArray","includes","hasOwnProperty","item","filteredItem","f","field","split","value","itemIsComplete","push","getQueriedItems","queriedItemsCache","get","queriedItems","undefined","EquivalentKeyMap","set"],"mappings":";;;;;;;;;AAGA;;AACA;;AACA;;AAKA;;AAVA;AACA;AACA;;AAKA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMA,wBAAwB,GAAG,IAAIC,OAAJ,EAAjC;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,SAASC,uBAAT,CAAkCC,KAAlC,EAAyCC,KAAzC,EAAiD;AAAA;;AAChD,QAAM;AACLC,IAAAA,SADK;AAELC,IAAAA,IAFK;AAGLC,IAAAA,OAHK;AAILC,IAAAA,OAJK;AAKLC,IAAAA,MALK;AAMLC,IAAAA;AANK,MAOF,4BAAeN,KAAf,CAPJ;AAQA,MAAIO,OAAJ;;AAEA,wBAAKR,KAAK,CAACS,OAAX,oEAAK,eAAiBF,OAAjB,CAAL,kDAAK,sBAA8BL,SAA9B,CAAL,EAAiD;AAChDM,IAAAA,OAAO,GAAGR,KAAK,CAACS,OAAN,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C,KAAK,GAAG,iBAAKL,IAAL,EAAWG,KAAX,CAAd;AACA,yBAAKF,YAAL,EAAmBE,KAAnB,EAA0BE,KAA1B;AACA;AACD,KARD,MAQO;AAAA;;AACN;AACA;AACA,UAAK,2BAAE3B,KAAK,CAAC4B,cAAN,CAAsBrB,OAAtB,CAAF,kDAAE,sBAAmCU,MAAnC,CAAF,CAAL,EAAqD;AACpD,eAAO,IAAP;AACA;;AAEDM,MAAAA,YAAY,GAAGD,IAAf;AACA;;AAEDP,IAAAA,KAAK,CAACc,IAAN,CAAYN,YAAZ;AACA;;AAED,SAAOR,KAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,MAAMe,eAAe,GAAG,qBAAgB,UAAE9B,KAAF,EAAyB;AAAA,MAAhBC,KAAgB,uEAAR,EAAQ;AACvE,MAAI8B,iBAAiB,GAAGlC,wBAAwB,CAACmC,GAAzB,CAA8BhC,KAA9B,CAAxB;;AACA,MAAK+B,iBAAL,EAAyB;AACxB,UAAME,YAAY,GAAGF,iBAAiB,CAACC,GAAlB,CAAuB/B,KAAvB,CAArB;;AACA,QAAKgC,YAAY,KAAKC,SAAtB,EAAkC;AACjC,aAAOD,YAAP;AACA;AACD,GALD,MAKO;AACNF,IAAAA,iBAAiB,GAAG,IAAII,yBAAJ,EAApB;AACAtC,IAAAA,wBAAwB,CAACuC,GAAzB,CAA8BpC,KAA9B,EAAqC+B,iBAArC;AACA;;AAED,QAAMhB,KAAK,GAAGhB,uBAAuB,CAAEC,KAAF,EAASC,KAAT,CAArC;AACA8B,EAAAA,iBAAiB,CAACK,GAAlB,CAAuBnC,KAAvB,EAA8Bc,KAA9B;AACA,SAAOA,KAAP;AACA,CAf8B,CAAxB","sourcesContent":["/**\n * External dependencies\n */\nimport createSelector from 'rememo';\nimport EquivalentKeyMap from 'equivalent-key-map';\nimport { get, set } from 'lodash';\n\n/**\n * Internal dependencies\n */\nimport getQueryParts from './get-query-parts';\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 {\n\t\tstableKey,\n\t\tpage,\n\t\tperPage,\n\t\tinclude,\n\t\tfields,\n\t\tcontext,\n\t} = getQueryParts( query );\n\tlet itemIds;\n\n\tif ( state.queries?.[ context ]?.[ stableKey ] ) {\n\t\titemIds = state.queries[ context ][ stableKey ];\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\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\tconst value = get( item, field );\n\t\t\t\tset( 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"]}
1
+ {"version":3,"sources":["@wordpress/core-data/src/queried-data/selectors.js"],"names":["queriedItemsCacheByState","WeakMap","getQueriedItemsUncached","state","query","stableKey","page","perPage","include","fields","context","itemIds","queries","startOffset","endOffset","length","Math","min","items","i","itemId","Array","isArray","includes","hasOwnProperty","item","filteredItem","f","field","split","value","itemIsComplete","push","getQueriedItems","queriedItemsCache","get","queriedItems","undefined","EquivalentKeyMap","set"],"mappings":";;;;;;;;;AAGA;;AACA;;AACA;;AAKA;;AAVA;AACA;AACA;;AAKA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMA,wBAAwB,GAAG,IAAIC,OAAJ,EAAjC;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,SAASC,uBAAT,CAAkCC,KAAlC,EAAyCC,KAAzC,EAAiD;AAAA;;AAChD,QAAM;AAAEC,IAAAA,SAAF;AAAaC,IAAAA,IAA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uBAAuB,CAAEC,KAAF,EAASC,KAAT,CAArC;AACA8B,EAAAA,iBAAiB,CAACK,GAAlB,CAAuBnC,KAAvB,EAA8Bc,KAA9B;AACA,SAAOA,KAAP;AACA,CAf8B,CAAxB","sourcesContent":["/**\n * External dependencies\n */\nimport createSelector from 'rememo';\nimport EquivalentKeyMap from 'equivalent-key-map';\nimport { get, set } from 'lodash';\n\n/**\n * Internal dependencies\n */\nimport getQueryParts from './get-query-parts';\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 ];\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\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\tconst value = get( item, field );\n\t\t\t\tset( 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"]}