@wordpress/core-data 6.10.0 → 6.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/README.md +4 -0
- package/build/actions.js +252 -276
- package/build/actions.js.map +1 -1
- package/build/batch/create-batch.js +8 -16
- package/build/batch/create-batch.js.map +1 -1
- package/build/batch/default-processor.js +1 -1
- package/build/batch/default-processor.js.map +1 -1
- package/build/entities.js +16 -25
- package/build/entities.js.map +1 -1
- package/build/entity-provider.js +12 -17
- package/build/entity-provider.js.map +1 -1
- package/build/fetch/__experimental-fetch-link-suggestions.js +2 -6
- package/build/fetch/__experimental-fetch-link-suggestions.js.map +1 -1
- package/build/fetch/__experimental-fetch-url-data.js +1 -2
- package/build/fetch/__experimental-fetch-url-data.js.map +1 -1
- package/build/hooks/use-entity-record.js +7 -11
- package/build/hooks/use-entity-record.js.map +1 -1
- package/build/hooks/use-entity-records.js +3 -5
- package/build/hooks/use-entity-records.js.map +1 -1
- package/build/hooks/use-query-select.js +1 -6
- package/build/hooks/use-query-select.js.map +1 -1
- package/build/index.js +1 -7
- package/build/index.js.map +1 -1
- package/build/locks/actions.js +3 -4
- package/build/locks/actions.js.map +1 -1
- package/build/locks/reducer.js +1 -4
- package/build/locks/reducer.js.map +1 -1
- package/build/locks/selectors.js +3 -4
- package/build/locks/selectors.js.map +1 -1
- package/build/locks/utils.js +3 -5
- package/build/locks/utils.js.map +1 -1
- package/build/private-selectors.js +37 -0
- package/build/private-selectors.js.map +1 -0
- package/build/queried-data/actions.js +2 -5
- package/build/queried-data/actions.js.map +1 -1
- package/build/queried-data/reducer.js +17 -47
- package/build/queried-data/reducer.js.map +1 -1
- package/build/queried-data/selectors.js +4 -11
- package/build/queried-data/selectors.js.map +1 -1
- package/build/reducer.js +167 -194
- package/build/reducer.js.map +1 -1
- package/build/resolvers.js +175 -220
- package/build/resolvers.js.map +1 -1
- package/build/selectors.js +53 -61
- package/build/selectors.js.map +1 -1
- package/build/utils/forward-resolver.js +4 -11
- package/build/utils/forward-resolver.js.map +1 -1
- package/build/utils/on-sub-key.js +1 -3
- package/build/utils/on-sub-key.js.map +1 -1
- package/build-module/actions.js +251 -276
- package/build-module/actions.js.map +1 -1
- package/build-module/batch/create-batch.js +8 -16
- package/build-module/batch/create-batch.js.map +1 -1
- package/build-module/batch/default-processor.js +1 -1
- package/build-module/batch/default-processor.js.map +1 -1
- package/build-module/entities.js +16 -25
- package/build-module/entities.js.map +1 -1
- package/build-module/entity-provider.js +12 -17
- package/build-module/entity-provider.js.map +1 -1
- package/build-module/fetch/__experimental-fetch-link-suggestions.js +2 -6
- package/build-module/fetch/__experimental-fetch-link-suggestions.js.map +1 -1
- package/build-module/fetch/__experimental-fetch-url-data.js +1 -2
- package/build-module/fetch/__experimental-fetch-url-data.js.map +1 -1
- package/build-module/hooks/use-entity-record.js +7 -11
- package/build-module/hooks/use-entity-record.js.map +1 -1
- package/build-module/hooks/use-entity-records.js +3 -5
- package/build-module/hooks/use-entity-records.js.map +1 -1
- package/build-module/hooks/use-query-select.js +1 -6
- package/build-module/hooks/use-query-select.js.map +1 -1
- package/build-module/index.js +1 -7
- package/build-module/index.js.map +1 -1
- package/build-module/locks/actions.js +3 -4
- package/build-module/locks/actions.js.map +1 -1
- package/build-module/locks/reducer.js +1 -4
- package/build-module/locks/reducer.js.map +1 -1
- package/build-module/locks/selectors.js +3 -4
- package/build-module/locks/selectors.js.map +1 -1
- package/build-module/locks/utils.js +3 -5
- package/build-module/locks/utils.js.map +1 -1
- package/build-module/private-selectors.js +28 -0
- package/build-module/private-selectors.js.map +1 -0
- package/build-module/queried-data/actions.js +2 -5
- package/build-module/queried-data/actions.js.map +1 -1
- package/build-module/queried-data/reducer.js +17 -47
- package/build-module/queried-data/reducer.js.map +1 -1
- package/build-module/queried-data/selectors.js +4 -11
- package/build-module/queried-data/selectors.js.map +1 -1
- package/build-module/reducer.js +168 -194
- package/build-module/reducer.js.map +1 -1
- package/build-module/resolvers.js +175 -220
- package/build-module/resolvers.js.map +1 -1
- package/build-module/selectors.js +55 -61
- package/build-module/selectors.js.map +1 -1
- package/build-module/utils/forward-resolver.js +4 -11
- package/build-module/utils/forward-resolver.js.map +1 -1
- package/build-module/utils/on-sub-key.js +1 -3
- package/build-module/utils/on-sub-key.js.map +1 -1
- package/build-types/actions.d.ts.map +1 -1
- package/build-types/private-selectors.d.ts +25 -0
- package/build-types/private-selectors.d.ts.map +1 -0
- package/build-types/reducer.d.ts +6 -2
- package/build-types/reducer.d.ts.map +1 -1
- package/build-types/selectors.d.ts +16 -4
- package/build-types/selectors.d.ts.map +1 -1
- package/package.json +13 -13
- package/src/actions.js +9 -8
- package/src/index.js +0 -1
- package/src/private-selectors.ts +30 -0
- package/src/reducer.js +130 -104
- package/src/selectors.ts +33 -13
- package/src/test/reducer.js +89 -54
- package/src/test/selectors.js +8 -8
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-data/src/entity-provider.js"],"names":["createContext","useContext","useCallback","useEffect","useSelect","useDispatch","parse","__unstableSerializeAndClean","STORE_NAME","EMPTY_ARRAY","rootEntitiesConfig","additionalEntityConfigLoaders","entityContexts","reduce","acc","loader","kind","name","context","undefined","getEntityContext","Error","EntityProvider","type","id","children","Provider","useEntityId","useEntityProp","prop","_id","providerId","value","fullValue","select","getEntityRecord","getEditedEntityRecord","record","editedRecord","editEntityRecord","setValue","newValue","useEntityBlockEditor","content","blocks","__unstableCreateUndoLevel","parsedContent","undoIgnore","onChange","newBlocks","options","selection","edits","noChange","blocksForSerialization","onInput"],"mappings":";;AAAA;AACA;AACA;AACA,SACCA,aADD,EAECC,UAFD,EAGCC,WAHD,EAICC,SAJD,QAKO,oBALP;AAMA,SAASC,SAAT,EAAoBC,WAApB,QAAuC,iBAAvC;AACA,SAASC,KAAT,EAAgBC,2BAAhB,QAAmD,mBAAnD;AAEA;AACA;AACA;;AACA,S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A,gBAAgB,CAAEvB,IAAF,EAAQC,IAAR,EAAcO,EAAd,EAAkB4B,KAAlB,CAAhB;AACA,GAjB0B,EAkB3B,CAAEpC,IAAF,EAAQC,IAAR,EAAcO,EAAd,EAAkBoB,MAAlB,CAlB2B,CAA5B;AAqBA,QAAMW,OAAO,GAAGrD,WAAW,CAC1B,CAAE+C,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,EAAQC,IAAR,EAAcO,EAAd,EAAkB4B,KAAlB,CAAhB;AACA,GALyB,EAM1B,CAAEpC,IAAF,EAAQC,IAAR,EAAcO,EAAd,CAN0B,CAA3B;AASA,SAAO,CAAEoB,MAAF,aAAEA,MAAF,cAAEA,MAAF,GAAYnC,WAAZ,EAAyB8C,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 } =\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"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-data/src/entity-provider.js"],"names":["createContext","useContext","useCallback","useEffect","useSelect","useDispatch","parse","__unstableSerializeAndClean","STORE_NAME","EMPTY_ARRAY","rootEntitiesConfig","additionalEntityConfigLoaders","entityContexts","reduce","acc","loader","kind","name","context","undefined","getEntityContext","Error","EntityProvider","type","id","children","Provider","useEntityId","useEntityProp","prop","_id","providerId","value","fullValue","select","getEntityRecord","getEditedEntityRecord","record","editedRecord","editEntityRecord","setValue","newValue","useEntityBlockEditor","content","blocks","__unstableCreateUndoLevel","parsedContent","undoIgnore","onChange","newBlocks","options","selection","edits","noChange","blocksForSerialization","onInput"],"mappings":";;AAAA;AACA;AACA;AACA,SACCA,aADD,EAECC,UAFD,EAGCC,WAHD,EAICC,SAJD,QAKO,oBALP;AAMA,SAASC,SAAT,EAAoBC,WAApB,QAAuC,iBAAvC;AACA,SAASC,KAAT,EAAgBC,2BAAhB,QAAmD,mBAAnD;AAEA;AACA;AACA;;AACA,SAASC,UAAT,QAA2B,QAA3B;AAEA;;AAEA,MAAMC,WAAW,GAAG,EAApB;AAEA;AACA;AACA;;AACA,SAASC,kBAAT,EAA6BC,6BAA7B,QAAkE,YAAlE;AAEA,MAAMC,cAAc,GAAG,EACtB,GAAGF,kBAAkB,CAACG,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,EAAElB,aAAa,CAAEmB,SAAF;AADa,KAApC;AAGA,WAAOL,GAAP;AACA,GARE,EAQA,EARA,CADmB;AAUtB,KAAGH,6BAA6B,CAACE,MAA9B,CAAsC,CAAEC,GAAF,EAAOC,MAAP,KAAmB;AAC3DD,IAAAA,GAAG,CAAEC,MAAM,CAACC,IAAT,CAAH,GAAqB,EAArB;AACA,WAAOF,GAAP;AACA,GAHE,EAGA,EAHA;AAVmB,CAAvB;;AAeA,MAAMM,gBAAgB,GAAG,CAAEJ,IAAF,EAAQC,IAAR,KAAkB;AAC1C,MAAK,CAAEL,cAAc,CAAEI,IAAF,CAArB,EAAgC;AAC/B,UAAM,IAAIK,KAAJ,CAAY,mCAAmCL,IAAM,GAArD,CAAN;AACA;;AAED,MAAK,CA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BAAyB,CAAE7B,IAAF,EAAQC,IAAR,EAAcO,EAAd,CAAhC;AACA,KAPwB,CASzB;AACA;AACA;;;AACA4B,IAAAA,KAAK,CAACT,OAAN,GAAgB,CAAE;AAAEC,MAAAA,MAAM,EAAEU,sBAAsB,GAAG;AAAnC,KAAF,KACf/C,2BAA2B,CAAE+C,sBAAF,CAD5B;;AAGAf,IAAAA,gBAAgB,CAAEvB,IAAF,EAAQC,IAAR,EAAcO,EAAd,EAAkB4B,KAAlB,CAAhB;AACA,GAjB0B,EAkB3B,CAAEpC,IAAF,EAAQC,IAAR,EAAcO,EAAd,EAAkBoB,MAAlB,CAlB2B,CAA5B;AAqBA,QAAMW,OAAO,GAAGrD,WAAW,CAC1B,CAAE+C,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,EAAQC,IAAR,EAAcO,EAAd,EAAkB4B,KAAlB,CAAhB;AACA,GALyB,EAM1B,CAAEpC,IAAF,EAAQC,IAAR,EAAcO,EAAd,CAN0B,CAA3B;AASA,SAAO,CAAEoB,MAAF,aAAEA,MAAF,cAAEA,MAAF,GAAYnC,WAAZ,EAAyB8C,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 } =\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"]}
|
|
@@ -78,9 +78,7 @@ import { __ } from '@wordpress/i18n';
|
|
|
78
78
|
* @return {Promise< WPLinkSearchResult[] >} List of search suggestions
|
|
79
79
|
*/
|
|
80
80
|
|
|
81
|
-
const fetchLinkSuggestions = async
|
|
82
|
-
let searchOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
83
|
-
let settings = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
81
|
+
const fetchLinkSuggestions = async (search, searchOptions = {}, settings = {}) => {
|
|
84
82
|
const {
|
|
85
83
|
isInitialSuggestions = false,
|
|
86
84
|
type = undefined,
|
|
@@ -193,8 +191,6 @@ const fetchLinkSuggestions = async function (search) {
|
|
|
193
191
|
}).slice(0, perPage).map((
|
|
194
192
|
/** @type {WPLinkSearchResultAugmented} */
|
|
195
193
|
result) => {
|
|
196
|
-
var _result$meta;
|
|
197
|
-
|
|
198
194
|
const isMedia = result.type === 'attachment';
|
|
199
195
|
return {
|
|
200
196
|
id: result.id,
|
|
@@ -203,7 +199,7 @@ const fetchLinkSuggestions = async function (search) {
|
|
|
203
199
|
title: decodeEntities(isMedia ? // @ts-ignore fix when we make this a TS file
|
|
204
200
|
result.title.rendered : result.title || '') || __('(no title)'),
|
|
205
201
|
type: result.subtype || result.type,
|
|
206
|
-
kind: result
|
|
202
|
+
kind: result?.meta?.kind
|
|
207
203
|
};
|
|
208
204
|
});
|
|
209
205
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-data/src/fetch/__experimental-fetch-link-suggestions.js"],"names":["apiFetch","addQueryArgs","decodeEntities","__","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","isMedia","url","source_url","title","rendered"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,QAAP,MAAqB,sBAArB;AACA,SAASC,YAAT,QAA6B,gBAA7B;AACA,SAASC,cAAT,QAA+B,0BAA/B;AACA,SAASC,EAAT,QAAmB,iBAAnB;AAEA;AACA;AACA;AAC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A,aAAO;AACNwB,QAAAA,EAAE,EAAEX,MAAM,CAACW,EADL;AAEN;AACAG,QAAAA,GAAG,EAAED,OAAO,GAAGb,MAAM,CAACe,UAAV,GAAuBf,MAAM,CAACc,GAHpC;AAINE,QAAAA,KAAK,EACJpC,cAAc,CACbiC,OAAO,GACJ;AACAb,QAAAA,MAAM,CAACgB,KAAP,CAAaC,QAFT,GAGJjB,MAAM,CAACgB,KAAP,IAAgB,EAJN,CAAd,IAKKnC,EAAE,CAAE,YAAF,CAVF;AAWNM,QAAAA,IAAI,EAAEa,MAAM,CAACX,OAAP,IAAkBW,MAAM,CAACb,IAXzB;AAYNe,QAAAA,IAAI,EAAEF,MAAF,aAAEA,MAAF,uCAAEA,MAAM,CAAEC,IAAV,iDAAE,aAAcC;AAZd,OAAP;AAcA,KAhCK,CAAP;AAiCA,GAlCM,CAAP;AAmCA,CA/ID;;AAiJA,eAAepB,oBAAf","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 { 'attachment' | '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 WPLinkSearchResultAugments\n *\n * @property {{kind: WPKind}} [meta] Contains kind information.\n * @property {WPKind} [subtype] Optional subtype if it exists.\n */\n\n/**\n * @typedef {WPLinkSearchResult & WPLinkSearchResultAugments} WPLinkSearchResultAugmented\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\t/** @type {Promise<WPLinkSearchResult>[]} */\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( () => [] ) // Fail by returning no results.\n\t\t);\n\t}\n\n\tif ( ! disablePostFormats && ( ! type || type === 'post-format' ) ) {\n\t\tqueries.push(\n\t\t\tapiFetch( {\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( () => [] ) // Fail by returning no results.\n\t\t);\n\t}\n\n\tif ( ! type || type === 'attachment' ) {\n\t\tqueries.push(\n\t\t\tapiFetch( {\n\t\t\t\tpath: addQueryArgs( '/wp/v2/media', {\n\t\t\t\t\tsearch,\n\t\t\t\t\tpage,\n\t\t\t\t\tper_page: perPage,\n\t\t\t\t} ),\n\t\t\t} )\n\t\t\t\t.then( ( results ) => {\n\t\t\t\t\treturn results.map( ( result ) => {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t...result,\n\t\t\t\t\t\t\tmeta: { kind: 'media' },\n\t\t\t\t\t\t};\n\t\t\t\t\t} );\n\t\t\t\t} )\n\t\t\t\t.catch( () => [] ) // Fail by returning no results.\n\t\t);\n\t}\n\n\treturn Promise.all( queries ).then( ( results ) => {\n\t\treturn results\n\t\t\t.reduce(\n\t\t\t\t( /** @type {WPLinkSearchResult[]} */ accumulator, current ) =>\n\t\t\t\t\taccumulator.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( ( /** @type {WPLinkSearchResultAugmented} */ result ) => {\n\t\t\t\tconst isMedia = result.type === 'attachment';\n\n\t\t\t\treturn {\n\t\t\t\t\tid: result.id,\n\t\t\t\t\t// @ts-ignore fix when we make this a TS file\n\t\t\t\t\turl: isMedia ? result.source_url : result.url,\n\t\t\t\t\ttitle:\n\t\t\t\t\t\tdecodeEntities(\n\t\t\t\t\t\t\tisMedia\n\t\t\t\t\t\t\t\t? // @ts-ignore fix when we make this a TS file\n\t\t\t\t\t\t\t\t result.title.rendered\n\t\t\t\t\t\t\t\t: result.title || ''\n\t\t\t\t\t\t) || __( '(no title)' ),\n\t\t\t\t\ttype: result.subtype || result.type,\n\t\t\t\t\tkind: result?.meta?.kind,\n\t\t\t\t};\n\t\t\t} );\n\t} );\n};\n\nexport default fetchLinkSuggestions;\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-data/src/fetch/__experimental-fetch-link-suggestions.js"],"names":["apiFetch","addQueryArgs","decodeEntities","__","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","isMedia","url","source_url","title","rendered"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,QAAP,MAAqB,sBAArB;AACA,SAASC,YAAT,QAA6B,gBAA7B;AACA,SAASC,cAAT,QAA+B,0BAA/B;AACA,SAASC,EAAT,QAAmB,iBAAnB;AAEA;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;AACA;;AAEA;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,MAAMC,oBAAoB,GAAG,OAC5BC,MAD4B,EAE5BC,aAAa,GAAG,EAFY,EAG5BC,QAAQ,GAAG,EAHiB,KAIxB;AACJ,QAAM;AACLC,IAAAA,oBAAoB,GAAG,KADlB;AAELC,IAAAA,IAAI,GAAGC,SAFF;AAGLC,IAAAA,OAAO,GAAGD,SAHL;AAILE,IAAAA,IAAI,GAAGF,SAJF;AAKLG,IAAAA,OAAO,GAAGL,oBAAoB,GAAG,CAAH,GAAO;AALhC,MAMFF,aANJ;AAQA,QAAM;AAAEQ,IAAAA,kBAAkB,GAAG;AAAvB,MAAiCP,QAAvC;AAEA;;AACA,QAAMQ,OAAO,GAAG,EAAhB;;AAEA,MAAK,CAAEN,IAAF,IAAUA,IAAI,KAAK,MAAxB,EAAiC;AAChCM,IAAAA,OAAO,CAACC,IAAR,CACChB,QAAQ,CAAE;AACTiB,MAAAA,IAAI,EAAEhB,YAAY,CAAE,eAAF,EAAmB;AACpCI,QAAAA,MADoC;AAEpCO,QAAAA,IAFoC;AAGpCM,QAAAA,QAAQ,EAAEL,O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V,IAAAA,MAAF,IAAc;AACb,aAAO,CAAC,CAAEA,MAAM,CAACW,EAAjB;AACA,KAZI,EAcLC,KAdK,CAcE,CAdF,EAcKrB,OAdL,EAeLQ,GAfK,CAeA;AAAE;AAA2CC,IAAAA,MAA7C,KAAyD;AAC9D,YAAMa,OAAO,GAAGb,MAAM,CAACb,IAAP,KAAgB,YAAhC;AAEA,aAAO;AACNwB,QAAAA,EAAE,EAAEX,MAAM,CAACW,EADL;AAEN;AACAG,QAAAA,GAAG,EAAED,OAAO,GAAGb,MAAM,CAACe,UAAV,GAAuBf,MAAM,CAACc,GAHpC;AAINE,QAAAA,KAAK,EACJpC,cAAc,CACbiC,OAAO,GACJ;AACAb,QAAAA,MAAM,CAACgB,KAAP,CAAaC,QAFT,GAGJjB,MAAM,CAACgB,KAAP,IAAgB,EAJN,CAAd,IAKKnC,EAAE,CAAE,YAAF,CAVF;AAWNM,QAAAA,IAAI,EAAEa,MAAM,CAACX,OAAP,IAAkBW,MAAM,CAACb,IAXzB;AAYNe,QAAAA,IAAI,EAAEF,MAAM,EAAEC,IAAR,EAAcC;AAZd,OAAP;AAcA,KAhCK,CAAP;AAiCA,GAlCM,CAAP;AAmCA,CA/ID;;AAiJA,eAAepB,oBAAf","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 { 'attachment' | '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 WPLinkSearchResultAugments\n *\n * @property {{kind: WPKind}} [meta] Contains kind information.\n * @property {WPKind} [subtype] Optional subtype if it exists.\n */\n\n/**\n * @typedef {WPLinkSearchResult & WPLinkSearchResultAugments} WPLinkSearchResultAugmented\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\t/** @type {Promise<WPLinkSearchResult>[]} */\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( () => [] ) // Fail by returning no results.\n\t\t);\n\t}\n\n\tif ( ! disablePostFormats && ( ! type || type === 'post-format' ) ) {\n\t\tqueries.push(\n\t\t\tapiFetch( {\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( () => [] ) // Fail by returning no results.\n\t\t);\n\t}\n\n\tif ( ! type || type === 'attachment' ) {\n\t\tqueries.push(\n\t\t\tapiFetch( {\n\t\t\t\tpath: addQueryArgs( '/wp/v2/media', {\n\t\t\t\t\tsearch,\n\t\t\t\t\tpage,\n\t\t\t\t\tper_page: perPage,\n\t\t\t\t} ),\n\t\t\t} )\n\t\t\t\t.then( ( results ) => {\n\t\t\t\t\treturn results.map( ( result ) => {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t...result,\n\t\t\t\t\t\t\tmeta: { kind: 'media' },\n\t\t\t\t\t\t};\n\t\t\t\t\t} );\n\t\t\t\t} )\n\t\t\t\t.catch( () => [] ) // Fail by returning no results.\n\t\t);\n\t}\n\n\treturn Promise.all( queries ).then( ( results ) => {\n\t\treturn results\n\t\t\t.reduce(\n\t\t\t\t( /** @type {WPLinkSearchResult[]} */ accumulator, current ) =>\n\t\t\t\t\taccumulator.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( ( /** @type {WPLinkSearchResultAugmented} */ result ) => {\n\t\t\t\tconst isMedia = result.type === 'attachment';\n\n\t\t\t\treturn {\n\t\t\t\t\tid: result.id,\n\t\t\t\t\t// @ts-ignore fix when we make this a TS file\n\t\t\t\t\turl: isMedia ? result.source_url : result.url,\n\t\t\t\t\ttitle:\n\t\t\t\t\t\tdecodeEntities(\n\t\t\t\t\t\t\tisMedia\n\t\t\t\t\t\t\t\t? // @ts-ignore fix when we make this a TS file\n\t\t\t\t\t\t\t\t result.title.rendered\n\t\t\t\t\t\t\t\t: result.title || ''\n\t\t\t\t\t\t) || __( '(no title)' ),\n\t\t\t\t\ttype: result.subtype || result.type,\n\t\t\t\t\tkind: result?.meta?.kind,\n\t\t\t\t};\n\t\t\t} );\n\t} );\n};\n\nexport default fetchLinkSuggestions;\n"]}
|
|
@@ -38,8 +38,7 @@ const CACHE = new Map();
|
|
|
38
38
|
* @return {Promise< WPRemoteUrlData[] >} Remote URL data.
|
|
39
39
|
*/
|
|
40
40
|
|
|
41
|
-
const fetchUrlData = async
|
|
42
|
-
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
41
|
+
const fetchUrlData = async (url, options = {}) => {
|
|
43
42
|
const endpoint = '/wp-block-editor/v1/url-details';
|
|
44
43
|
const args = {
|
|
45
44
|
url: prependHTTP(url)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-data/src/fetch/__experimental-fetch-url-data.js"],"names":["apiFetch","addQueryArgs","prependHTTP","isURL","getProtocol","isValidProtocol","CACHE","Map","fetchUrlData","url","options","endpoint","args","Promise","reject","protocol","startsWith","test","has","get","path","then","res","set"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,QAAP,MAAqB,sBAArB;AACA,SACCC,YADD,EAECC,WAFD,EAGCC,KAHD,EAICC,WAJD,EAKCC,eALD,QAMO,gBANP;AAQA;AACA;AACA;AACA;AACA;;AACA,MAAMC,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":["apiFetch","addQueryArgs","prependHTTP","isURL","getProtocol","isValidProtocol","CACHE","Map","fetchUrlData","url","options","endpoint","args","Promise","reject","protocol","startsWith","test","has","get","path","then","res","set"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,QAAP,MAAqB,sBAArB;AACA,SACCC,YADD,EAECC,WAFD,EAGCC,KAHD,EAICC,WAJD,EAKCC,eALD,QAMO,gBANP;AAQA;A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**\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! protocol ||\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"]}
|
|
@@ -99,23 +99,19 @@ import { store as coreStore } from '../';
|
|
|
99
99
|
* @return Entity record data.
|
|
100
100
|
* @template RecordType
|
|
101
101
|
*/
|
|
102
|
-
export default function useEntityRecord(kind, name, recordId
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
};
|
|
102
|
+
export default function useEntityRecord(kind, name, recordId, options = {
|
|
103
|
+
enabled: true
|
|
104
|
+
}) {
|
|
106
105
|
const {
|
|
107
106
|
editEntityRecord,
|
|
108
107
|
saveEditedEntityRecord
|
|
109
108
|
} = useDispatch(coreStore);
|
|
110
109
|
const mutations = useMemo(() => ({
|
|
111
110
|
edit: record => editEntityRecord(kind, name, recordId, record),
|
|
112
|
-
save:
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
...saveOptions
|
|
117
|
-
});
|
|
118
|
-
}
|
|
111
|
+
save: (saveOptions = {}) => saveEditedEntityRecord(kind, name, recordId, {
|
|
112
|
+
throwOnError: true,
|
|
113
|
+
...saveOptions
|
|
114
|
+
})
|
|
119
115
|
}), [recordId]);
|
|
120
116
|
const {
|
|
121
117
|
editedRecord,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-data/src/hooks/use-entity-record.ts"],"names":["useDispatch","useSelect","deprecated","useMemo","useQuerySelect","store","coreStore","useEntityRecord","kind","name","recordId","options","enabled","editEntityRecord","saveEditedEntityRecord","mutations","edit","record","save","saveOptions","throwOnError","editedRecord","hasEdits","select","getEditedEntityRecord","hasEditsForEntityRecord","data","querySelectRest","query","getEntityRecord","__experimentalUseEntityRecord","alternative","since"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,WAAT,EAAsBC,SAAtB,QAAuC,iBAAvC;AACA,OAAOC,UAAP,MAAuB,uBAAvB;AACA,SAASC,OAAT,QAAwB,oBAAxB;AAEA;AACA;AACA;;AACA,OAAOC,cAAP,MAA2B,oBAA3B;AACA,SAASC,KAAK,IAAIC,SAAlB,QAAmC,KAAnC;;AA4CA;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;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;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,eAAT,CACdC,IADc,EAEdC,IAFc,EAGdC,QAHc,
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-data/src/hooks/use-entity-record.ts"],"names":["useDispatch","useSelect","deprecated","useMemo","useQuerySelect","store","coreStore","useEntityRecord","kind","name","recordId","options","enabled","editEntityRecord","saveEditedEntityRecord","mutations","edit","record","save","saveOptions","throwOnError","editedRecord","hasEdits","select","getEditedEntityRecord","hasEditsForEntityRecord","data","querySelectRest","query","getEntityRecord","__experimentalUseEntityRecord","alternative","since"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,WAAT,EAAsBC,SAAtB,QAAuC,iBAAvC;AACA,OAAOC,UAAP,MAAuB,uBAAvB;AACA,SAASC,OAAT,QAAwB,oBAAxB;AAEA;AACA;AACA;;AACA,OAAOC,cAAP,MAA2B,oBAA3B;AACA,SAASC,KAAK,IAAIC,SAAlB,QAAmC,KAAnC;;AA4CA;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;AACA;AACA;AACA;A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,IAAAA,IAAI,EAAET,MAAR;AAAgB,OAAGU;AAAnB,MAAuCvB,cAAc,CACxDwB,KAAF,IAAa;AACZ,QAAK,CAAEjB,OAAO,CAACC,OAAf,EAAyB;AACxB,aAAO,IAAP;AACA;;AACD,WAAOgB,KAAK,CAAEtB,SAAF,CAAL,CAAmBuB,eAAnB,CAAoCrB,IAApC,EAA0CC,IAA1C,EAAgDC,QAAhD,CAAP;AACA,GANyD,EAO1D,CAAEF,IAAF,EAAQC,IAAR,EAAcC,QAAd,EAAwBC,OAAO,CAACC,OAAhC,CAP0D,CAA3D;AAUA,SAAO;AACNK,IAAAA,MADM;AAENI,IAAAA,YAFM;AAGNC,IAAAA,QAHM;AAIN,OAAGK,eAJG;AAKN,OAAGZ;AALG,GAAP;AAOA;AAED,OAAO,SAASe,6BAAT,CACNtB,IADM,EAENC,IAFM,EAGNC,QAHM,EAINC,OAJM,EAKL;AACDT,EAAAA,UAAU,CAAG,uCAAH,EAA2C;AACpD6B,IAAAA,WAAW,EAAE,yBADuC;AAEpDC,IAAAA,KAAK,EAAE;AAF6C,GAA3C,CAAV;AAIA,SAAOzB,eAAe,CAAEC,IAAF,EAAQC,IAAR,EAAcC,QAAd,EAAwBC,OAAxB,CAAtB;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport deprecated from '@wordpress/deprecated';\nimport { useMemo } from '@wordpress/element';\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/** The edited entity record */\n\teditedRecord: Partial< RecordType >;\n\n\t/** Apply local (in-browser) edits to the edited entity record */\n\tedit: ( diff: Partial< RecordType > ) => void;\n\n\t/** Persist the edits to the server */\n\tsave: () => Promise< void >;\n\n\t/**\n\t * Is the record still being resolved?\n\t */\n\tisResolving: boolean;\n\n\t/**\n\t * Does the record have any local edits?\n\t */\n\thasEdits: 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 * @since 6.1.0 Introduced in WordPress core.\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 * @example\n * ```js\n * import { useDispatch } from '@wordpress/data';\n * import { useCallback } from '@wordpress/element';\n * import { __ } from '@wordpress/i18n';\n * import { TextControl } from '@wordpress/components';\n * import { store as noticeStore } from '@wordpress/notices';\n * import { useEntityRecord } from '@wordpress/core-data';\n *\n * function PageRenameForm( { id } ) {\n * \tconst page = useEntityRecord( 'postType', 'page', id );\n * \tconst { createSuccessNotice, createErrorNotice } =\n * \t\tuseDispatch( noticeStore );\n *\n * \tconst setTitle = useCallback( ( title ) => {\n * \t\tpage.edit( { title } );\n * \t}, [ page.edit ] );\n *\n * \tif ( page.isResolving ) {\n * \t\treturn 'Loading...';\n * \t}\n *\n * \tasync function onRename( event ) {\n * \t\tevent.preventDefault();\n * \t\ttry {\n * \t\t\tawait page.save();\n * \t\t\tcreateSuccessNotice( __( 'Page renamed.' ), {\n * \t\t\t\ttype: 'snackbar',\n * \t\t\t} );\n * \t\t} catch ( error ) {\n * \t\t\tcreateErrorNotice( error.message, { type: 'snackbar' } );\n * \t\t}\n * \t}\n *\n * \treturn (\n * \t\t<form onSubmit={ onRename }>\n * \t\t\t<TextControl\n * \t\t\t\tlabel={ __( 'Name' ) }\n * \t\t\t\tvalue={ page.editedRecord.title }\n * \t\t\t\tonChange={ setTitle }\n * \t\t\t/>\n * \t\t\t<button type=\"submit\">{ __( 'Save' ) }</button>\n * \t\t</form>\n * \t);\n * }\n *\n * // Rendered in the application:\n * // <PageRenameForm id={ 1 } />\n * ```\n *\n * In the above example, updating and saving the page title is handled\n * via the `edit()` and `save()` mutation helpers provided by\n * `useEntityRecord()`;\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 { editEntityRecord, saveEditedEntityRecord } =\n\t\tuseDispatch( coreStore );\n\n\tconst mutations = useMemo(\n\t\t() => ( {\n\t\t\tedit: ( record ) =>\n\t\t\t\teditEntityRecord( kind, name, recordId, record ),\n\t\t\tsave: ( saveOptions: any = {} ) =>\n\t\t\t\tsaveEditedEntityRecord( kind, name, recordId, {\n\t\t\t\t\tthrowOnError: true,\n\t\t\t\t\t...saveOptions,\n\t\t\t\t} ),\n\t\t} ),\n\t\t[ recordId ]\n\t);\n\n\tconst { editedRecord, hasEdits } = useSelect(\n\t\t( select ) => ( {\n\t\t\teditedRecord: select( coreStore ).getEditedEntityRecord(\n\t\t\t\tkind,\n\t\t\t\tname,\n\t\t\t\trecordId\n\t\t\t),\n\t\t\thasEdits: select( coreStore ).hasEditsForEntityRecord(\n\t\t\t\tkind,\n\t\t\t\tname,\n\t\t\t\trecordId\n\t\t\t),\n\t\t} ),\n\t\t[ kind, name, recordId ]\n\t);\n\n\tconst { data: record, ...querySelectRest } = 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\teditedRecord,\n\t\thasEdits,\n\t\t...querySelectRest,\n\t\t...mutations,\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"]}
|
|
@@ -51,11 +51,9 @@ const EMPTY_ARRAY = [];
|
|
|
51
51
|
* @template RecordType
|
|
52
52
|
*/
|
|
53
53
|
|
|
54
|
-
export default function useEntityRecords(kind, name
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
enabled: true
|
|
58
|
-
};
|
|
54
|
+
export default function useEntityRecords(kind, name, queryArgs = {}, options = {
|
|
55
|
+
enabled: true
|
|
56
|
+
}) {
|
|
59
57
|
// Serialize queryArgs to a string that can be safely used as a React dep.
|
|
60
58
|
// We can't just pass queryArgs as one of the deps, because if it is passed
|
|
61
59
|
// as an object literal, then it will be a different object on each call even
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-data/src/hooks/use-entity-records.ts"],"names":["addQueryArgs","deprecated","useQuerySelect","store","coreStore","EMPTY_ARRAY","useEntityRecords","kind","name","queryArgs","options","enabled","queryAsString","data","records","rest","query","getEntityRecords","__experimentalUseEntityRecords","alternative","since"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,YAAT,QAA6B,gBAA7B;AACA,OAAOC,UAAP,MAAuB,uBAAvB;AAEA;AACA;AACA;;AACA,OAAOC,cAAP,MAA2B,oBAA3B;AACA,SAASC,KAAK,IAAIC,SAAlB,QAAmC,KAAnC;AAsBA,MAAMC,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;AACA;AACA;;AACA,eAAe,SAASC,gBAAT,CACdC,IADc,EAEdC,IAFc,
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-data/src/hooks/use-entity-records.ts"],"names":["addQueryArgs","deprecated","useQuerySelect","store","coreStore","EMPTY_ARRAY","useEntityRecords","kind","name","queryArgs","options","enabled","queryAsString","data","records","rest","query","getEntityRecords","__experimentalUseEntityRecords","alternative","since"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,YAAT,QAA6B,gBAA7B;AACA,OAAOC,UAAP,MAAuB,uBAAvB;AAEA;AACA;AACA;;AACA,OAAOC,cAAP,MAA2B,oBAA3B;AACA,SAASC,KAAK,IAAIC,SAAlB,QAAmC,KAAnC;AAsBA,MAAMC,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;AACA;AACA;;AACA,eAAe,SAASC,gBAAT,CACdC,IADc,EAEdC,IAFc,EAGdC,SAAoC,GAAG,EAHzB,EAIdC,OAAgB,GAAG;AAAEC,EAAAA,OAAO,EAAE;AAAX,CAJL,EAK0B;AACxC;AACA;AACA;AACA;AACA,QAAMC,aAAa,GAAGZ,YAAY,CAAE,EAAF,EAAMS,SAAN,CAAlC;AAEA,QAAM;AAAEI,IAAAA,IAAI,EAAEC,OAAR;AAAiB,OAAGC;AAApB,MAA6Bb,cAAc,CAC9Cc,KAAF,IAAa;AACZ,QAAK,CAAEN,OAAO,CAACC,OAAf,EAAyB;AACxB,aAAO;AACN;AACAE,QAAAA,IAAI,EAAER;AAFA,OAAP;AAIA;;AACD,WAAOW,KAAK,CAAEZ,SAAF,CAAL,CAAmBa,gBAAnB,CAAqCV,IAArC,EAA2CC,IAA3C,EAAiDC,SAAjD,CAAP;AACA,GAT+C,EAUhD,CAAEF,IAAF,EAAQC,IAAR,EAAcI,aAAd,EAA6BF,OAAO,CAACC,OAArC,CAVgD,CAAjD;AAaA,SAAO;AACNG,IAAAA,OADM;AAEN,OAAGC;AAFG,GAAP;AAIA;AAED,OAAO,SAASG,8BAAT,CACNX,IADM,EAENC,IAFM,EAGNC,SAHM,EAINC,OAJM,EAKL;AACDT,EAAAA,UAAU,CAAG,wCAAH,EAA4C;AACrDkB,IAAAA,WAAW,EAAE,0BADwC;AAErDC,IAAAA,KAAK,EAAE;AAF8C,GAA5C,CAAV;AAIA,SAAOd,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 } from './use-entity-record';\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\nconst EMPTY_ARRAY = [];\n\n/**\n * Resolves the specified entity records.\n *\n * @since 6.1.0 Introduced in WordPress core.\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"]}
|
|
@@ -77,16 +77,11 @@ const enrichSelectors = memoize(selectors => {
|
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
Object.defineProperty(resolvers, selectorName, {
|
|
80
|
-
get: () =>
|
|
80
|
+
get: () => (...args) => {
|
|
81
81
|
const {
|
|
82
82
|
getIsResolving,
|
|
83
83
|
hasFinishedResolution
|
|
84
84
|
} = selectors;
|
|
85
|
-
|
|
86
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
87
|
-
args[_key] = arguments[_key];
|
|
88
|
-
}
|
|
89
|
-
|
|
90
85
|
const isResolving = !!getIsResolving(selectorName, args);
|
|
91
86
|
const hasResolved = !isResolving && hasFinishedResolution(selectorName, args);
|
|
92
87
|
const data = selectors[selectorName](...args);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-data/src/hooks/use-query-select.ts"],"names":["useSelect","memoize","Status","META_SELECTORS","useQuerySelect","mapQuerySelect","deps","select","registry","resolve","store","enrichSelectors","selectors","resolvers","selectorName","includes","Object","defineProperty","get","
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-data/src/hooks/use-query-select.ts"],"names":["useSelect","memoize","Status","META_SELECTORS","useQuerySelect","mapQuerySelect","deps","select","registry","resolve","store","enrichSelectors","selectors","resolvers","selectorName","includes","Object","defineProperty","get","args","getIsResolving","hasFinishedResolution","isResolving","hasResolved","data","status","Resolving","Success","Error","Idle"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAT,QAA0B,iBAA1B;AAEA;AACA;AACA;;AACA,OAAOC,OAAP,MAAoB,WAApB;AACA,SAASC,MAAT,QAAuB,aAAvB;AAEA,OAAO,MAAMC,cAAc,GAAG,CAC7B,gBAD6B,EAE7B,sBAF6B,EAG7B,uBAH6B,EAI7B,aAJ6B,EAK7B,oBAL6B,CAAvB;;AAsBP;AACA;AACA;AACA;AACA;AACA;AACA;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,MAAM,CAACwB,SAAhB;AACA,SAFD,MAEO,IAAKH,WAAL,EAAmB;AACzB,cAAKC,IAAL,EAAY;AACXC,YAAAA,MAAM,GAAGvB,MAAM,CAACyB,OAAhB;AACA,WAFD,MAEO;AACNF,YAAAA,MAAM,GAAGvB,MAAM,CAAC0B,KAAhB;AACA;AACD,SANM,MAMA;AACNH,UAAAA,MAAM,GAAGvB,MAAM,CAAC2B,IAAhB;AACA;;AAED,eAAO;AACNL,UAAAA,IADM;AAENC,UAAAA,MAFM;AAGNH,UAAAA,WAHM;AAINC,UAAAA;AAJM,SAAP;AAMA;AA9B6C,KAAhD;AAgCA;;AACD,SAAOV,SAAP;AACA,CAxC8B,CAA/B","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 * @since 6.1.0 Introduced in WordPress core.\n * @private\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 useQuerySelect( 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-module/index.js
CHANGED
|
@@ -39,13 +39,7 @@ const entityResolvers = rootEntitiesConfig.reduce((result, entity) => {
|
|
|
39
39
|
|
|
40
40
|
const pluralMethodName = getMethodName(kind, name, 'get', true);
|
|
41
41
|
|
|
42
|
-
result[pluralMethodName] =
|
|
43
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
44
|
-
args[_key] = arguments[_key];
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return resolvers.getEntityRecords(kind, name, ...args);
|
|
48
|
-
};
|
|
42
|
+
result[pluralMethodName] = (...args) => resolvers.getEntityRecords(kind, name, ...args);
|
|
49
43
|
|
|
50
44
|
result[pluralMethodName].shouldInvalidate = action => resolvers.getEntityRecords.shouldInvalidate(action, kind, name);
|
|
51
45
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-data/src/index.js"],"names":["createReduxStore","register","reducer","selectors","actions","resolvers","createLocksActions","rootEntitiesConfig","getMethodName","STORE_NAME","entitySelectors","reduce","result","entity","kind","name","state","key","query","getEntityRecord","getEntityRecords","entityResolvers","pluralMethodName","args","shouldInvalidate","action","entityActions","saveEntityRecord","deleteEntityRecord","storeConfig","store","default","EntityProvider"],"mappings":"AA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M,IAAF,EAAQC,IAAR,CAAf,CAAN,GAAwC,CAAEE,GAAF,EAAOC,KAAP,KACvCb,SAAS,CAACc,eAAV,CAA2BL,IAA3B,EAAiCC,IAAjC,EAAuCE,GAAvC,EAA4CC,KAA5C,CADD;;AAEA,QAAMI,gBAAgB,GAAGd,aAAa,CAAEM,IAAF,EAAQC,IAAR,EAAc,KAAd,EAAqB,IAArB,CAAtC;;AACAH,EAAAA,MAAM,CAAEU,gBAAF,CAAN,GAA6B
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-data/src/index.js"],"names":["createReduxStore","register","reducer","selectors","actions","resolvers","createLocksActions","rootEntitiesConfig","getMethodName","STORE_NAME","entitySelectors","reduce","result","entity","kind","name","state","key","query","getEntityRecord","getEntityRecords","entityResolvers","pluralMethodName","args","shouldInvalidate","action","entityActions","saveEntityRecord","deleteEntityRecord","storeConfig","store","default","EntityProvider"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,gBAAT,EAA2BC,QAA3B,QAA2C,iBAA3C;AAEA;AACA;AACA;;AACA,OAAOC,OAAP,MAAoB,WAApB;AACA,OAAO,KAAKC,SAAZ,MAA2B,aAA3B;AACA,OAAO,KAAKC,OAAZ,MAAyB,WAAzB;AACA,OAAO,KAAKC,SAAZ,MAA2B,aAA3B;AACA,OAAOC,kBAAP,MAA+B,iBAA/B;AACA,SAASC,kBAAT,EAA6BC,aAA7B,QAAkD,YAAlD;AACA,SAASC,UAAT,QAA2B,QAA3B,C,CAEA;AACA;AACA;AACA;;AAEA,MAAMC,eAAe,GAAGH,kBAAkB,CAACI,MAAnB,CAA2B,CAAEC,MAAF,EAAUC,MAAV,KAAsB;AACxE,QAAM;AAAEC,IAAAA,IAAF;AAAQC,IAAAA;AAAR,MAAiBF,MAAvB;;AACAD,EAAAA,MAAM,CAAEJ,aAAa,CAAEM,IAAF,EAAQC,IAAR,CAAf,CAAN,GAAwC,CAAEC,KAAF,EAASC,GAAT,EAAcC,KAAd,KACvCf,SAAS,CAACgB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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 */\nexport const store = createReduxStore( STORE_NAME, storeConfig() );\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"]}
|
|
@@ -5,10 +5,9 @@ import createLocks from './engine';
|
|
|
5
5
|
export default function createLocksActions() {
|
|
6
6
|
const locks = createLocks();
|
|
7
7
|
|
|
8
|
-
function __unstableAcquireStoreLock(store, path,
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
} = _ref;
|
|
8
|
+
function __unstableAcquireStoreLock(store, path, {
|
|
9
|
+
exclusive
|
|
10
|
+
}) {
|
|
12
11
|
return () => locks.acquire(store, path, exclusive);
|
|
13
12
|
}
|
|
14
13
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-data/src/locks/actions.js"],"names":["createLocks","createLocksActions","locks","__unstableAcquireStoreLock","store","path","exclusive","acquire","__unstableReleaseStoreLock","lock","release"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,WAAP,MAAwB,UAAxB;AAEA,eAAe,SAASC,kBAAT,GAA8B;AAC5C,QAAMC,KAAK,GAAGF,WAAW,EAAzB;;AAEA,WAASG,0BAAT,CAAqCC,KAArC,EAA4CC,IAA5C,
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-data/src/locks/actions.js"],"names":["createLocks","createLocksActions","locks","__unstableAcquireStoreLock","store","path","exclusive","acquire","__unstableReleaseStoreLock","lock","release"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,WAAP,MAAwB,UAAxB;AAEA,eAAe,SAASC,kBAAT,GAA8B;AAC5C,QAAMC,KAAK,GAAGF,WAAW,EAAzB;;AAEA,WAASG,0BAAT,CAAqCC,KAArC,EAA4CC,IAA5C,EAAkD;AAAEC,IAAAA;AAAF,GAAlD,EAAkE;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"]}
|
|
@@ -18,10 +18,7 @@ const DEFAULT_STATE = {
|
|
|
18
18
|
* @return {Object} Updated state.
|
|
19
19
|
*/
|
|
20
20
|
|
|
21
|
-
export default function locks() {
|
|
22
|
-
let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : DEFAULT_STATE;
|
|
23
|
-
let action = arguments.length > 1 ? arguments[1] : undefined;
|
|
24
|
-
|
|
21
|
+
export default function locks(state = DEFAULT_STATE, action) {
|
|
25
22
|
switch (action.type) {
|
|
26
23
|
case 'ENQUEUE_LOCK_REQUEST':
|
|
27
24
|
{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-data/src/locks/reducer.js"],"names":["getNode","deepCopyLocksTreePath","DEFAULT_STATE","requests","tree","locks","children","state","action","type","request","lock","store","path","storePath","newTree","node","filter","r","l"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,OAAT,EAAkBC,qBAAlB,QAA+C,SAA/C;AAEA,MAAMC,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;;AACA,eAAe,SAASD,KAAT,
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-data/src/locks/reducer.js"],"names":["getNode","deepCopyLocksTreePath","DEFAULT_STATE","requests","tree","locks","children","state","action","type","request","lock","store","path","storePath","newTree","node","filter","r","l"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,OAAT,EAAkBC,qBAAlB,QAA+C,SAA/C;AAEA,MAAMC,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;;AACA,eAAe,SAASD,KAAT,CAAgBE,KAAK,GAAGL,aAAxB,EAAuCM,MAAvC,EAAgD;AAC9D,UAASA,MAAM,CAACC,IAAhB;AACC,SAAK,sBAAL;AAA6B;AAC5B,cAAM;AAAEC,UAAAA;AAAF,YAAcF,MAApB;AACA,eAAO,EACN,GAAGD,KADG;AAENJ,UAAAA,QAAQ,EAAE,CAAEO,OAAF,EAAW,GAAGH,KAAK,CAACJ,QAApB;AAFJ,SAAP;AAIA;;AACD,SAAK,oBAAL;AAA2B;AAC1B,cAAM;AAAEQ,UAAAA,IAAF;AAAQD,UAAAA;AAAR,YAAoBF,MAA1B;AACA,cAAM;AAAEI,UAAAA,KAAF;AAASC,UAAAA;AAAT,YAAkBH,OAAxB;AACA,cAAMI,SAAS,GAAG,CAAEF,KAAF,EAAS,GAAGC,IAAZ,CAAlB;AAEA,cAAME,OAAO,GAAGd,qBAAqB,CAAEM,KAAK,CAACH,IAAR,EAAcU,SAAd,CAArC;AACA,cAAME,IAAI,GAAGhB,OAAO,CAAEe,OAAF,EAAWD,SAAX,CAApB;AACAE,QAAAA,IAAI,CAACX,KAAL,GAAa,CAAE,GAAGW,IAAI,CAACX,KAAV,EAAiBM,IAAjB,CAAb;AAEA,eAAO,EACN,GAAGJ,KADG;AAENJ,UAAAA,QAAQ,EAAEI,KAAK,CAACJ,QAAN,CAAec,MAAf,CAAyBC,CAAF,IAASA,CAAC,KAAKR,OAAtC,CAFJ;AAGNN,UAAAA,IAAI,EAAEW;AAHA,SAAP;AAKA;;AACD,SAAK,cAAL;AAAqB;AACpB,cAAM;AAAEJ,UAAAA;AAAF,YAAWH,MAAjB;AACA,cAAMM,SAAS,GAAG,CAAEH,IAAI,CAACC,KAAP,EAAc,GAAGD,IAAI,CAACE,IAAtB,CAAlB;AAEA,cAAME,OAAO,GAAGd,qBAAqB,CAAEM,KAAK,CAACH,IAAR,EAAcU,SAAd,CAArC;AACA,cAAME,IAAI,GAAGhB,OAAO,CAAEe,OAAF,EAAWD,SAAX,CAApB;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"]}
|
|
@@ -5,10 +5,9 @@ import { iterateDescendants, iteratePath, hasConflictingLock, getNode } from './
|
|
|
5
5
|
export function getPendingLockRequests(state) {
|
|
6
6
|
return state.requests;
|
|
7
7
|
}
|
|
8
|
-
export function isLockAvailable(state, store, path,
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
} = _ref;
|
|
8
|
+
export function isLockAvailable(state, store, path, {
|
|
9
|
+
exclusive
|
|
10
|
+
}) {
|
|
12
11
|
const storePath = [store, ...path];
|
|
13
12
|
const locks = state.tree; // Validate all parents and the node itself
|
|
14
13
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-data/src/locks/selectors.js"],"names":["iterateDescendants","iteratePath","hasConflictingLock","getNode","getPendingLockRequests","state","requests","isLockAvailable","store","path","exclusive","storePath","locks","tree","node","descendant"],"mappings":"AAAA;AACA;AACA;AACA,SACCA,kBADD,EAECC,WAFD,EAGCC,kBAHD,EAICC,OAJD,QAKO,SALP;AAOA,OAAO,SAASC,sBAAT,CAAiCC,KAAjC,EAAyC;AAC/C,SAAOA,KAAK,CAACC,QAAb;AACA;AAED,OAAO,SAASC,eAAT,CAA0BF,KAA1B,EAAiCG,KAAjC,EAAwCC,IAAxC,
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-data/src/locks/selectors.js"],"names":["iterateDescendants","iteratePath","hasConflictingLock","getNode","getPendingLockRequests","state","requests","isLockAvailable","store","path","exclusive","storePath","locks","tree","node","descendant"],"mappings":"AAAA;AACA;AACA;AACA,SACCA,kBADD,EAECC,WAFD,EAGCC,kBAHD,EAICC,OAJD,QAKO,SALP;AAOA,OAAO,SAASC,sBAAT,CAAiCC,KAAjC,EAAyC;AAC/C,SAAOA,KAAK,CAACC,QAAb;AACA;AAED,OAAO,SAASC,eAAT,CAA0BF,KAA1B,EAAiCG,KAAjC,EAAwCC,IAAxC,EAA8C;AAAEC,EAAAA;AAAF,CAA9C,EAA8D;AACpE,QAAMC,SAAS,GAAG,CAAEH,KAAF,EAAS,GAAGC,IAAZ,CAAlB;AACA,QAAMG,KAAK,GAAGP,KAAK,CAACQ,IAApB,CAFoE,CAIpE;;AACA,OAAM,MAAMC,IAAZ,IAAoBb,WAAW,CAAEW,KAAF,EAASD,SAAT,CAA/B,EAAsD;AACrD,QAAKT,kBAAkB,CAAE;AAAEQ,MAAAA;AAAF,KAAF,EAAiBI,IAAI,CAACF,KAAtB,CAAvB,EAAuD;AACtD,aAAO,KAAP;AACA;AACD,GATmE,CAWpE;AACA;;;AACA,QAAME,IAAI,GAAGX,OAAO,CAAES,KAAF,EAASD,SAAT,CAApB;;AACA,MAAK,CAAEG,IAAP,EAAc;AACb,WAAO,IAAP;AACA,GAhBmE,CAkBpE;;;AACA,OAAM,MAAMC,UAAZ,IAA0Bf,kBAAkB,CAAEc,IAAF,CAA5C,EAAuD;AACtD,QAAKZ,kBAAkB,CAAE;AAAEQ,MAAAA;AAAF,KAAF,EAAiBK,UAAU,CAACH,KAA5B,CAAvB,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"]}
|
|
@@ -55,11 +55,9 @@ export function* iterateDescendants(node) {
|
|
|
55
55
|
stack.push(...Object.values(childNode.children));
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
|
-
export function hasConflictingLock(
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
} = _ref;
|
|
62
|
-
|
|
58
|
+
export function hasConflictingLock({
|
|
59
|
+
exclusive
|
|
60
|
+
}, locks) {
|
|
63
61
|
if (exclusive && locks.length) {
|
|
64
62
|
return true;
|
|
65
63
|
}
|
|
@@ -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":"AAAA,OAAO,SAASA,qBAAT,CAAgCC,IAAhC,E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M,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;AAED,OAAO,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":"AAAA,OAAO,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;AAED,OAAO,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;AAED,OAAO,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;AAED,OAAO,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;AAED,OAAO,SAASc,kBAAT,CAA6B;AAAEC,EAAAA;AAAF,CAA7B,EAA4Cd,KAA5C,EAAoD;AAC1D,MAAKc,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"]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal dependencies
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Returns the previous edit from the current undo offset
|
|
7
|
+
* for the entity records edits history, if any.
|
|
8
|
+
*
|
|
9
|
+
* @param state State tree.
|
|
10
|
+
*
|
|
11
|
+
* @return The edit.
|
|
12
|
+
*/
|
|
13
|
+
export function getUndoEdits(state) {
|
|
14
|
+
return state.undo.list[state.undo.list.length - 1 + state.undo.offset];
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Returns the next edit from the current undo offset
|
|
18
|
+
* for the entity records edits history, if any.
|
|
19
|
+
*
|
|
20
|
+
* @param state State tree.
|
|
21
|
+
*
|
|
22
|
+
* @return The edit.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
export function getRedoEdits(state) {
|
|
26
|
+
return state.undo.list[state.undo.list.length + state.undo.offset];
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=private-selectors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-data/src/private-selectors.ts"],"names":["getUndoEdits","state","undo","list","length","offset","getRedoEdits"],"mappings":"AAAA;AACA;AACA;;AAKA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASA,YAAT,CAAuBC,KAAvB,EAA8D;AACpE,SAAOA,KAAK,CAACC,IAAN,CAAWC,IAAX,CAAiBF,KAAK,CAACC,IAAN,CAAWC,IAAX,CAAgBC,MAAhB,GAAyB,CAAzB,GAA6BH,KAAK,CAACC,IAAN,CAAWG,MAAzD,CAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,YAAT,CAAuBL,KAAvB,EAA8D;AACpE,SAAOA,KAAK,CAACC,IAAN,CAAWC,IAAX,CAAiBF,KAAK,CAACC,IAAN,CAAWC,IAAX,CAAgBC,MAAhB,GAAyBH,KAAK,CAACC,IAAN,CAAWG,MAArD,CAAP;AACA","sourcesContent":["/**\n * Internal dependencies\n */\nimport type { State, UndoEdit } from './selectors';\n\ntype Optional< T > = T | undefined;\n\n/**\n * Returns the previous edit from the current undo offset\n * for the entity records edits history, if any.\n *\n * @param state State tree.\n *\n * @return The edit.\n */\nexport function getUndoEdits( state: State ): Optional< UndoEdit[] > {\n\treturn state.undo.list[ state.undo.list.length - 1 + state.undo.offset ];\n}\n\n/**\n * Returns the next edit from the current undo offset\n * for the entity records edits history, if any.\n *\n * @param state State tree.\n *\n * @return The edit.\n */\nexport function getRedoEdits( state: State ): Optional< UndoEdit[] > {\n\treturn state.undo.list[ state.undo.list.length + state.undo.offset ];\n}\n"]}
|
|
@@ -24,8 +24,7 @@ export function receiveItems(items, edits) {
|
|
|
24
24
|
* @return {Object} Action object.
|
|
25
25
|
*/
|
|
26
26
|
|
|
27
|
-
export function removeItems(kind, name, records) {
|
|
28
|
-
let invalidateCache = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
27
|
+
export function removeItems(kind, name, records, invalidateCache = false) {
|
|
29
28
|
return {
|
|
30
29
|
type: 'REMOVE_ITEMS',
|
|
31
30
|
itemIds: Array.isArray(records) ? records : [records],
|
|
@@ -45,9 +44,7 @@ export function removeItems(kind, name, records) {
|
|
|
45
44
|
* @return {Object} Action object.
|
|
46
45
|
*/
|
|
47
46
|
|
|
48
|
-
export function receiveQueriedItems(items) {
|
|
49
|
-
let query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
50
|
-
let edits = arguments.length > 2 ? arguments[2] : undefined;
|
|
47
|
+
export function receiveQueriedItems(items, query = {}, edits) {
|
|
51
48
|
return { ...receiveItems(items, edits),
|
|
52
49
|
query
|
|
53
50
|
};
|