@wordpress/data 10.32.0 → 10.32.1-next.ff1cebbba.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 (157) hide show
  1. package/build/components/async-mode-provider/context.js +35 -54
  2. package/build/components/async-mode-provider/context.js.map +7 -1
  3. package/build/components/async-mode-provider/index.js +40 -25
  4. package/build/components/async-mode-provider/index.js.map +7 -1
  5. package/build/components/async-mode-provider/use-async-mode.js +25 -16
  6. package/build/components/async-mode-provider/use-async-mode.js.map +7 -1
  7. package/build/components/registry-provider/context.js +46 -64
  8. package/build/components/registry-provider/context.js.map +7 -1
  9. package/build/components/registry-provider/index.js +40 -25
  10. package/build/components/registry-provider/index.js.map +7 -1
  11. package/build/components/registry-provider/use-registry.js +25 -55
  12. package/build/components/registry-provider/use-registry.js.map +7 -1
  13. package/build/components/use-dispatch/index.js +38 -17
  14. package/build/components/use-dispatch/index.js.map +7 -1
  15. package/build/components/use-dispatch/use-dispatch-with-map.js +59 -44
  16. package/build/components/use-dispatch/use-dispatch-with-map.js.map +7 -1
  17. package/build/components/use-dispatch/use-dispatch.js +36 -71
  18. package/build/components/use-dispatch/use-dispatch.js.map +7 -1
  19. package/build/components/use-select/index.js +79 -208
  20. package/build/components/use-select/index.js.map +7 -1
  21. package/build/components/with-dispatch/index.js +34 -107
  22. package/build/components/with-dispatch/index.js.map +7 -1
  23. package/build/components/with-registry/index.js +30 -30
  24. package/build/components/with-registry/index.js.map +7 -1
  25. package/build/components/with-select/index.js +44 -67
  26. package/build/components/with-select/index.js.map +7 -1
  27. package/build/controls.js +49 -110
  28. package/build/controls.js.map +7 -1
  29. package/build/create-selector.js +36 -11
  30. package/build/create-selector.js.map +7 -1
  31. package/build/default-registry.js +24 -10
  32. package/build/default-registry.js.map +7 -1
  33. package/build/dispatch.js +38 -31
  34. package/build/dispatch.js.map +7 -1
  35. package/build/factory.js +29 -85
  36. package/build/factory.js.map +7 -1
  37. package/build/index.js +114 -301
  38. package/build/index.js.map +7 -1
  39. package/build/lock-unlock.js +31 -14
  40. package/build/lock-unlock.js.map +7 -1
  41. package/build/plugins/index.js +36 -11
  42. package/build/plugins/index.js.map +7 -1
  43. package/build/plugins/persistence/index.js +74 -139
  44. package/build/plugins/persistence/index.js.map +7 -1
  45. package/build/plugins/persistence/storage/default.js +37 -18
  46. package/build/plugins/persistence/storage/default.js.map +7 -1
  47. package/build/plugins/persistence/storage/object.js +24 -7
  48. package/build/plugins/persistence/storage/object.js.map +7 -1
  49. package/build/promise-middleware.js +37 -20
  50. package/build/promise-middleware.js.map +7 -1
  51. package/build/redux-store/combine-reducers.js +26 -5
  52. package/build/redux-store/combine-reducers.js.map +7 -1
  53. package/build/redux-store/index.js +221 -331
  54. package/build/redux-store/index.js.map +7 -1
  55. package/build/redux-store/metadata/actions.js +51 -112
  56. package/build/redux-store/metadata/actions.js.map +7 -1
  57. package/build/redux-store/metadata/equivalent-key-map.d.js +1 -1
  58. package/build/redux-store/metadata/equivalent-key-map.d.js.map +7 -1
  59. package/build/redux-store/metadata/reducer.js +111 -115
  60. package/build/redux-store/metadata/reducer.js.map +7 -1
  61. package/build/redux-store/metadata/selectors.js +109 -181
  62. package/build/redux-store/metadata/selectors.js.map +7 -1
  63. package/build/redux-store/metadata/utils.js +32 -35
  64. package/build/redux-store/metadata/utils.js.map +7 -1
  65. package/build/redux-store/thunk-middleware.js +24 -7
  66. package/build/redux-store/thunk-middleware.js.map +7 -1
  67. package/build/registry.js +94 -198
  68. package/build/registry.js.map +7 -1
  69. package/build/resolvers-cache-middleware.js +26 -27
  70. package/build/resolvers-cache-middleware.js.map +7 -1
  71. package/build/select.js +38 -31
  72. package/build/select.js.map +7 -1
  73. package/build/store/index.js +52 -16
  74. package/build/store/index.js.map +7 -1
  75. package/build/types.js +16 -5
  76. package/build/types.js.map +7 -1
  77. package/build/utils/emitter.js +33 -16
  78. package/build/utils/emitter.js.map +7 -1
  79. package/build-module/components/async-mode-provider/context.js +12 -49
  80. package/build-module/components/async-mode-provider/context.js.map +7 -1
  81. package/build-module/components/async-mode-provider/index.js +8 -3
  82. package/build-module/components/async-mode-provider/index.js.map +7 -1
  83. package/build-module/components/async-mode-provider/use-async-mode.js +7 -11
  84. package/build-module/components/async-mode-provider/use-async-mode.js.map +7 -1
  85. package/build-module/components/registry-provider/context.js +13 -58
  86. package/build-module/components/registry-provider/context.js.map +7 -1
  87. package/build-module/components/registry-provider/index.js +8 -3
  88. package/build-module/components/registry-provider/index.js.map +7 -1
  89. package/build-module/components/registry-provider/use-registry.js +7 -51
  90. package/build-module/components/registry-provider/use-registry.js.map +7 -1
  91. package/build-module/components/use-dispatch/index.js +7 -3
  92. package/build-module/components/use-dispatch/index.js.map +7 -1
  93. package/build-module/components/use-dispatch/use-dispatch-with-map.js +27 -35
  94. package/build-module/components/use-dispatch/use-dispatch-with-map.js.map +7 -1
  95. package/build-module/components/use-dispatch/use-dispatch.js +8 -66
  96. package/build-module/components/use-dispatch/use-dispatch.js.map +7 -1
  97. package/build-module/components/use-select/index.js +45 -193
  98. package/build-module/components/use-select/index.js.map +7 -1
  99. package/build-module/components/with-dispatch/index.js +16 -104
  100. package/build-module/components/with-dispatch/index.js.map +7 -1
  101. package/build-module/components/with-registry/index.js +12 -27
  102. package/build-module/components/with-registry/index.js.map +7 -1
  103. package/build-module/components/with-select/index.js +16 -63
  104. package/build-module/components/with-select/index.js.map +7 -1
  105. package/build-module/controls.js +25 -105
  106. package/build-module/controls.js.map +7 -1
  107. package/build-module/create-selector.js +5 -8
  108. package/build-module/create-selector.js.map +7 -1
  109. package/build-module/default-registry.js +6 -6
  110. package/build-module/default-registry.js.map +7 -1
  111. package/build-module/dispatch.js +6 -27
  112. package/build-module/dispatch.js.map +7 -1
  113. package/build-module/factory.js +8 -82
  114. package/build-module/factory.js.map +7 -1
  115. package/build-module/index.js +62 -185
  116. package/build-module/index.js.map +7 -1
  117. package/build-module/lock-unlock.js +8 -7
  118. package/build-module/lock-unlock.js.map +7 -1
  119. package/build-module/plugins/index.js +5 -2
  120. package/build-module/plugins/index.js.map +7 -1
  121. package/build-module/plugins/persistence/index.js +38 -129
  122. package/build-module/plugins/persistence/index.js.map +7 -1
  123. package/build-module/plugins/persistence/storage/default.js +8 -11
  124. package/build-module/plugins/persistence/storage/default.js.map +7 -1
  125. package/build-module/plugins/persistence/storage/object.js +6 -3
  126. package/build-module/plugins/persistence/storage/object.js.map +7 -1
  127. package/build-module/promise-middleware.js +8 -14
  128. package/build-module/promise-middleware.js.map +7 -1
  129. package/build-module/redux-store/combine-reducers.js +5 -2
  130. package/build-module/redux-store/combine-reducers.js.map +7 -1
  131. package/build-module/redux-store/index.js +180 -310
  132. package/build-module/redux-store/index.js.map +7 -1
  133. package/build-module/redux-store/metadata/actions.js +30 -109
  134. package/build-module/redux-store/metadata/actions.js.map +7 -1
  135. package/build-module/redux-store/metadata/equivalent-key-map.d.js +1 -2
  136. package/build-module/redux-store/metadata/equivalent-key-map.d.js.map +7 -1
  137. package/build-module/redux-store/metadata/reducer.js +83 -108
  138. package/build-module/redux-store/metadata/reducer.js.map +7 -1
  139. package/build-module/redux-store/metadata/selectors.js +76 -175
  140. package/build-module/redux-store/metadata/selectors.js.map +7 -1
  141. package/build-module/redux-store/metadata/utils.js +10 -30
  142. package/build-module/redux-store/metadata/utils.js.map +7 -1
  143. package/build-module/redux-store/thunk-middleware.js +7 -4
  144. package/build-module/redux-store/thunk-middleware.js.map +7 -1
  145. package/build-module/registry.js +56 -187
  146. package/build-module/registry.js.map +7 -1
  147. package/build-module/resolvers-cache-middleware.js +8 -23
  148. package/build-module/resolvers-cache-middleware.js.map +7 -1
  149. package/build-module/select.js +6 -27
  150. package/build-module/select.js.map +7 -1
  151. package/build-module/store/index.js +34 -12
  152. package/build-module/store/index.js.map +7 -1
  153. package/build-module/types.js +1 -2
  154. package/build-module/types.js.map +7 -1
  155. package/build-module/utils/emitter.js +12 -13
  156. package/build-module/utils/emitter.js.map +7 -1
  157. package/package.json +17 -10
@@ -1 +1,7 @@
1
- {"version":3,"names":["_priorityQueue","require","_element","_isShallowEqual","_interopRequireDefault","_useRegistry","_useAsyncMode","renderQueue","createQueue","warnOnUnstableReference","a","b","keys","Object","filter","k","console","warn","join","Store","registry","suspense","select","suspendSelect","queueContext","lastMapSelect","lastMapResult","lastMapResultValid","lastIsAsync","subscriber","didWarnUnstableReference","storeStatesOnMount","Map","getStoreState","name","_registry$stores$name","stores","store","getState","createSubscriber","activeStores","activeSubscriptions","Set","subscribe","listener","get","clear","onStoreChange","onChange","add","unsubs","subscribeStore","storeName","push","delete","unsub","values","cancel","updateStores","newStores","newStore","includes","subscription","mapSelect","isAsync","updateValue","listeningStores","current","mapResult","__unstableMarkListeningStores","globalThis","SCRIPT_DEBUG","secondMapResult","isShallowEqual","set","getValue","_useStaticSelect","useRegistry","_useMappingSelect","deps","useAsyncMode","useMemo","selector","useCallback","result","useSyncExternalStore","useDebugValue","useSelect","staticSelectMode","staticSelectModeRef","useRef","prevMode","nextMode","Error","useSuspenseSelect"],"sources":["@wordpress/data/src/components/use-select/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createQueue } from '@wordpress/priority-queue';\nimport {\n\tuseRef,\n\tuseCallback,\n\tuseMemo,\n\tuseSyncExternalStore,\n\tuseDebugValue,\n} from '@wordpress/element';\nimport isShallowEqual from '@wordpress/is-shallow-equal';\n\n/**\n * Internal dependencies\n */\nimport useRegistry from '../registry-provider/use-registry';\nimport useAsyncMode from '../async-mode-provider/use-async-mode';\n\nconst renderQueue = createQueue();\n\nfunction warnOnUnstableReference( a, b ) {\n\tif ( ! a || ! b ) {\n\t\treturn;\n\t}\n\n\tconst keys =\n\t\ttypeof a === 'object' && typeof b === 'object'\n\t\t\t? Object.keys( a ).filter( ( k ) => a[ k ] !== b[ k ] )\n\t\t\t: [];\n\n\t// eslint-disable-next-line no-console\n\tconsole.warn(\n\t\t'The `useSelect` hook returns different values when called with the same state and parameters.\\n' +\n\t\t\t'This can lead to unnecessary re-renders and performance issues if not fixed.\\n\\n' +\n\t\t\t'Non-equal value keys: %s\\n\\n',\n\t\tkeys.join( ', ' )\n\t);\n}\n\n/**\n * @typedef {import('../../types').StoreDescriptor<C>} StoreDescriptor\n * @template {import('../../types').AnyConfig} C\n */\n/**\n * @typedef {import('../../types').ReduxStoreConfig<State,Actions,Selectors>} ReduxStoreConfig\n * @template State\n * @template {Record<string,import('../../types').ActionCreator>} Actions\n * @template Selectors\n */\n/** @typedef {import('../../types').MapSelect} MapSelect */\n/**\n * @typedef {import('../../types').UseSelectReturn<T>} UseSelectReturn\n * @template {MapSelect|StoreDescriptor<any>} T\n */\n\nfunction Store( registry, suspense ) {\n\tconst select = suspense ? registry.suspendSelect : registry.select;\n\tconst queueContext = {};\n\tlet lastMapSelect;\n\tlet lastMapResult;\n\tlet lastMapResultValid = false;\n\tlet lastIsAsync;\n\tlet subscriber;\n\tlet didWarnUnstableReference;\n\tconst storeStatesOnMount = new Map();\n\n\tfunction getStoreState( name ) {\n\t\t// If there's no store property (custom generic store), return an empty\n\t\t// object. When comparing the state, the empty objects will cause the\n\t\t// equality check to fail, setting `lastMapResultValid` to false.\n\t\treturn registry.stores[ name ]?.store?.getState?.() ?? {};\n\t}\n\n\tconst createSubscriber = ( stores ) => {\n\t\t// The set of stores the `subscribe` function is supposed to subscribe to. Here it is\n\t\t// initialized, and then the `updateStores` function can add new stores to it.\n\t\tconst activeStores = [ ...stores ];\n\n\t\t// The `subscribe` function, which is passed to the `useSyncExternalStore` hook, could\n\t\t// be called multiple times to establish multiple subscriptions. That's why we need to\n\t\t// keep a set of active subscriptions;\n\t\tconst activeSubscriptions = new Set();\n\n\t\tfunction subscribe( listener ) {\n\t\t\t// Maybe invalidate the value right after subscription was created.\n\t\t\t// React will call `getValue` after subscribing, to detect store\n\t\t\t// updates that happened in the interval between the `getValue` call\n\t\t\t// during render and creating the subscription, which is slightly\n\t\t\t// delayed. We need to ensure that this second `getValue` call will\n\t\t\t// compute a fresh value only if any of the store states have\n\t\t\t// changed in the meantime.\n\t\t\tif ( lastMapResultValid ) {\n\t\t\t\tfor ( const name of activeStores ) {\n\t\t\t\t\tif (\n\t\t\t\t\t\tstoreStatesOnMount.get( name ) !== getStoreState( name )\n\t\t\t\t\t) {\n\t\t\t\t\t\tlastMapResultValid = false;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tstoreStatesOnMount.clear();\n\n\t\t\tconst onStoreChange = () => {\n\t\t\t\t// Invalidate the value on store update, so that a fresh value is computed.\n\t\t\t\tlastMapResultValid = false;\n\t\t\t\tlistener();\n\t\t\t};\n\n\t\t\tconst onChange = () => {\n\t\t\t\tif ( lastIsAsync ) {\n\t\t\t\t\trenderQueue.add( queueContext, onStoreChange );\n\t\t\t\t} else {\n\t\t\t\t\tonStoreChange();\n\t\t\t\t}\n\t\t\t};\n\n\t\t\tconst unsubs = [];\n\t\t\tfunction subscribeStore( storeName ) {\n\t\t\t\tunsubs.push( registry.subscribe( onChange, storeName ) );\n\t\t\t}\n\n\t\t\tfor ( const storeName of activeStores ) {\n\t\t\t\tsubscribeStore( storeName );\n\t\t\t}\n\n\t\t\tactiveSubscriptions.add( subscribeStore );\n\n\t\t\treturn () => {\n\t\t\t\tactiveSubscriptions.delete( subscribeStore );\n\n\t\t\t\tfor ( const unsub of unsubs.values() ) {\n\t\t\t\t\t// The return value of the subscribe function could be undefined if the store is a custom generic store.\n\t\t\t\t\tunsub?.();\n\t\t\t\t}\n\t\t\t\t// Cancel existing store updates that were already scheduled.\n\t\t\t\trenderQueue.cancel( queueContext );\n\t\t\t};\n\t\t}\n\n\t\t// Check if `newStores` contains some stores we're not subscribed to yet, and add them.\n\t\tfunction updateStores( newStores ) {\n\t\t\tfor ( const newStore of newStores ) {\n\t\t\t\tif ( activeStores.includes( newStore ) ) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\t// New `subscribe` calls will subscribe to `newStore`, too.\n\t\t\t\tactiveStores.push( newStore );\n\n\t\t\t\t// Add `newStore` to existing subscriptions.\n\t\t\t\tfor ( const subscription of activeSubscriptions ) {\n\t\t\t\t\tsubscription( newStore );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn { subscribe, updateStores };\n\t};\n\n\treturn ( mapSelect, isAsync ) => {\n\t\tfunction updateValue() {\n\t\t\t// If the last value is valid, and the `mapSelect` callback hasn't changed,\n\t\t\t// then we can safely return the cached value. The value can change only on\n\t\t\t// store update, and in that case value will be invalidated by the listener.\n\t\t\tif ( lastMapResultValid && mapSelect === lastMapSelect ) {\n\t\t\t\treturn lastMapResult;\n\t\t\t}\n\n\t\t\tconst listeningStores = { current: null };\n\t\t\tconst mapResult = registry.__unstableMarkListeningStores(\n\t\t\t\t() => mapSelect( select, registry ),\n\t\t\t\tlisteningStores\n\t\t\t);\n\n\t\t\tif ( globalThis.SCRIPT_DEBUG ) {\n\t\t\t\tif ( ! didWarnUnstableReference ) {\n\t\t\t\t\tconst secondMapResult = mapSelect( select, registry );\n\t\t\t\t\tif ( ! isShallowEqual( mapResult, secondMapResult ) ) {\n\t\t\t\t\t\twarnOnUnstableReference( mapResult, secondMapResult );\n\t\t\t\t\t\tdidWarnUnstableReference = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif ( ! subscriber ) {\n\t\t\t\tfor ( const name of listeningStores.current ) {\n\t\t\t\t\tstoreStatesOnMount.set( name, getStoreState( name ) );\n\t\t\t\t}\n\t\t\t\tsubscriber = createSubscriber( listeningStores.current );\n\t\t\t} else {\n\t\t\t\tsubscriber.updateStores( listeningStores.current );\n\t\t\t}\n\n\t\t\t// If the new value is shallow-equal to the old one, keep the old one so\n\t\t\t// that we don't trigger unwanted updates that do a `===` check.\n\t\t\tif ( ! isShallowEqual( lastMapResult, mapResult ) ) {\n\t\t\t\tlastMapResult = mapResult;\n\t\t\t}\n\t\t\tlastMapSelect = mapSelect;\n\t\t\tlastMapResultValid = true;\n\t\t}\n\n\t\tfunction getValue() {\n\t\t\t// Update the value in case it's been invalidated or `mapSelect` has changed.\n\t\t\tupdateValue();\n\t\t\treturn lastMapResult;\n\t\t}\n\n\t\t// When transitioning from async to sync mode, cancel existing store updates\n\t\t// that have been scheduled, and invalidate the value so that it's freshly\n\t\t// computed. It might have been changed by the update we just cancelled.\n\t\tif ( lastIsAsync && ! isAsync ) {\n\t\t\tlastMapResultValid = false;\n\t\t\trenderQueue.cancel( queueContext );\n\t\t}\n\n\t\tupdateValue();\n\n\t\tlastIsAsync = isAsync;\n\n\t\t// Return a pair of functions that can be passed to `useSyncExternalStore`.\n\t\treturn { subscribe: subscriber.subscribe, getValue };\n\t};\n}\n\nfunction _useStaticSelect( storeName ) {\n\treturn useRegistry().select( storeName );\n}\n\nfunction _useMappingSelect( suspense, mapSelect, deps ) {\n\tconst registry = useRegistry();\n\tconst isAsync = useAsyncMode();\n\tconst store = useMemo(\n\t\t() => Store( registry, suspense ),\n\t\t[ registry, suspense ]\n\t);\n\n\t// These are \"pass-through\" dependencies from the parent hook,\n\t// and the parent should catch any hook rule violations.\n\tconst selector = useCallback( mapSelect, deps );\n\tconst { subscribe, getValue } = store( selector, isAsync );\n\tconst result = useSyncExternalStore( subscribe, getValue, getValue );\n\tuseDebugValue( result );\n\treturn result;\n}\n\n/**\n * Custom react hook for retrieving props from registered selectors.\n *\n * In general, this custom React hook follows the\n * [rules of hooks](https://react.dev/reference/rules/rules-of-hooks).\n *\n * @template {MapSelect | StoreDescriptor<any>} T\n * @param {T} mapSelect Function called on every state change. The returned value is\n * exposed to the component implementing this hook. The function\n * receives the `registry.select` method on the first argument\n * and the `registry` on the second argument.\n * When a store key is passed, all selectors for the store will be\n * returned. This is only meant for usage of these selectors in event\n * callbacks, not for data needed to create the element tree.\n * @param {unknown[]} deps If provided, this memoizes the mapSelect so the same `mapSelect` is\n * invoked on every state change unless the dependencies change.\n *\n * @example\n * ```js\n * import { useSelect } from '@wordpress/data';\n * import { store as myCustomStore } from 'my-custom-store';\n *\n * function HammerPriceDisplay( { currency } ) {\n * const price = useSelect( ( select ) => {\n * return select( myCustomStore ).getPrice( 'hammer', currency );\n * }, [ currency ] );\n * return new Intl.NumberFormat( 'en-US', {\n * style: 'currency',\n * currency,\n * } ).format( price );\n * }\n *\n * // Rendered in the application:\n * // <HammerPriceDisplay currency=\"USD\" />\n * ```\n *\n * In the above example, when `HammerPriceDisplay` is rendered into an\n * application, the price will be retrieved from the store state using the\n * `mapSelect` callback on `useSelect`. If the currency prop changes then\n * any price in the state for that currency is retrieved. If the currency prop\n * doesn't change and other props are passed in that do change, the price will\n * not change because the dependency is just the currency.\n *\n * When data is only used in an event callback, the data should not be retrieved\n * on render, so it may be useful to get the selectors function instead.\n *\n * **Don't use `useSelect` this way when calling the selectors in the render\n * function because your component won't re-render on a data change.**\n *\n * ```js\n * import { useSelect } from '@wordpress/data';\n * import { store as myCustomStore } from 'my-custom-store';\n *\n * function Paste( { children } ) {\n * const { getSettings } = useSelect( myCustomStore );\n * function onPaste() {\n * // Do something with the settings.\n * const settings = getSettings();\n * }\n * return <div onPaste={ onPaste }>{ children }</div>;\n * }\n * ```\n * @return {UseSelectReturn<T>} A custom react hook.\n */\nexport default function useSelect( mapSelect, deps ) {\n\t// On initial call, on mount, determine the mode of this `useSelect` call\n\t// and then never allow it to change on subsequent updates.\n\tconst staticSelectMode = typeof mapSelect !== 'function';\n\tconst staticSelectModeRef = useRef( staticSelectMode );\n\n\tif ( staticSelectMode !== staticSelectModeRef.current ) {\n\t\tconst prevMode = staticSelectModeRef.current ? 'static' : 'mapping';\n\t\tconst nextMode = staticSelectMode ? 'static' : 'mapping';\n\t\tthrow new Error(\n\t\t\t`Switching useSelect from ${ prevMode } to ${ nextMode } is not allowed`\n\t\t);\n\t}\n\n\t// `staticSelectMode` is not allowed to change during the hook instance's,\n\t// lifetime, so the rules of hooks are not really violated.\n\treturn staticSelectMode\n\t\t? _useStaticSelect( mapSelect )\n\t\t: _useMappingSelect( false, mapSelect, deps );\n}\n\n/**\n * A variant of the `useSelect` hook that has the same API, but is a compatible\n * Suspense-enabled data source.\n *\n * @template {MapSelect} T\n * @param {T} mapSelect Function called on every state change. The\n * returned value is exposed to the component\n * using this hook. The function receives the\n * `registry.suspendSelect` method as the first\n * argument and the `registry` as the second one.\n * @param {Array} deps A dependency array used to memoize the `mapSelect`\n * so that the same `mapSelect` is invoked on every\n * state change unless the dependencies change.\n *\n * @throws {Promise} A suspense Promise that is thrown if any of the called\n * selectors is in an unresolved state.\n *\n * @return {ReturnType<T>} Data object returned by the `mapSelect` function.\n */\nexport function useSuspenseSelect( mapSelect, deps ) {\n\treturn _useMappingSelect( true, mapSelect, deps );\n}\n"],"mappings":";;;;;;;;AAGA,IAAAA,cAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AAOA,IAAAE,eAAA,GAAAC,sBAAA,CAAAH,OAAA;AAKA,IAAAI,YAAA,GAAAD,sBAAA,CAAAH,OAAA;AACA,IAAAK,aAAA,GAAAF,sBAAA,CAAAH,OAAA;AAjBA;AACA;AACA;;AAWA;AACA;AACA;;AAIA,MAAMM,WAAW,GAAG,IAAAC,0BAAW,EAAC,CAAC;AAEjC,SAASC,uBAAuBA,CAAEC,CAAC,EAAEC,CAAC,EAAG;EACxC,IAAK,CAAED,CAAC,IAAI,CAAEC,CAAC,EAAG;IACjB;EACD;EAEA,MAAMC,IAAI,GACT,OAAOF,CAAC,KAAK,QAAQ,IAAI,OAAOC,CAAC,KAAK,QAAQ,GAC3CE,MAAM,CAACD,IAAI,CAAEF,CAAE,CAAC,CAACI,MAAM,CAAIC,CAAC,IAAML,CAAC,CAAEK,CAAC,CAAE,KAAKJ,CAAC,CAAEI,CAAC,CAAG,CAAC,GACrD,EAAE;;EAEN;EACAC,OAAO,CAACC,IAAI,CACX,iGAAiG,GAChG,kFAAkF,GAClF,8BAA8B,EAC/BL,IAAI,CAACM,IAAI,CAAE,IAAK,CACjB,CAAC;AACF;;AAEA;AACA;AACA;AACA;AACA;A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AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASG,SAASA,CAAExB,SAAS,EAAEgB,IAAI,EAAG;EACpD;EACA;EACA,MAAMS,gBAAgB,GAAG,OAAOzB,SAAS,KAAK,UAAU;EACxD,MAAM0B,mBAAmB,GAAG,IAAAC,eAAM,EAAEF,gBAAiB,CAAC;EAEtD,IAAKA,gBAAgB,KAAKC,mBAAmB,CAACtB,OAAO,EAAG;IACvD,MAAMwB,QAAQ,GAAGF,mBAAmB,CAACtB,OAAO,GAAG,QAAQ,GAAG,SAAS;IACnE,MAAMyB,QAAQ,GAAGJ,gBAAgB,GAAG,QAAQ,GAAG,SAAS;IACxD,MAAM,IAAIK,KAAK,CACd,4BAA6BF,QAAQ,OAASC,QAAQ,iBACvD,CAAC;EACF;;EAEA;EACA;EACA,OAAOJ,gBAAgB,GACpBZ,gBAAgB,CAAEb,SAAU,CAAC,GAC7Be,iBAAiB,CAAE,KAAK,EAAEf,SAAS,EAAEgB,IAAK,CAAC;AAC/C;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASe,iBAAiBA,CAAE/B,SAAS,EAAEgB,IAAI,EAAG;EACpD,OAAOD,iBAAiB,CAAE,IAAI,EAAEf,SAAS,EAAEgB,IAAK,CAAC;AAClD","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/components/use-select/index.js"],
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { createQueue } from '@wordpress/priority-queue';\nimport {\n\tuseRef,\n\tuseCallback,\n\tuseMemo,\n\tuseSyncExternalStore,\n\tuseDebugValue,\n} from '@wordpress/element';\nimport isShallowEqual from '@wordpress/is-shallow-equal';\n\n/**\n * Internal dependencies\n */\nimport useRegistry from '../registry-provider/use-registry';\nimport useAsyncMode from '../async-mode-provider/use-async-mode';\n\nconst renderQueue = createQueue();\n\nfunction warnOnUnstableReference( a, b ) {\n\tif ( ! a || ! b ) {\n\t\treturn;\n\t}\n\n\tconst keys =\n\t\ttypeof a === 'object' && typeof b === 'object'\n\t\t\t? Object.keys( a ).filter( ( k ) => a[ k ] !== b[ k ] )\n\t\t\t: [];\n\n\t// eslint-disable-next-line no-console\n\tconsole.warn(\n\t\t'The `useSelect` hook returns different values when called with the same state and parameters.\\n' +\n\t\t\t'This can lead to unnecessary re-renders and performance issues if not fixed.\\n\\n' +\n\t\t\t'Non-equal value keys: %s\\n\\n',\n\t\tkeys.join( ', ' )\n\t);\n}\n\n/**\n * @typedef {import('../../types').StoreDescriptor<C>} StoreDescriptor\n * @template {import('../../types').AnyConfig} C\n */\n/**\n * @typedef {import('../../types').ReduxStoreConfig<State,Actions,Selectors>} ReduxStoreConfig\n * @template State\n * @template {Record<string,import('../../types').ActionCreator>} Actions\n * @template Selectors\n */\n/** @typedef {import('../../types').MapSelect} MapSelect */\n/**\n * @typedef {import('../../types').UseSelectReturn<T>} UseSelectReturn\n * @template {MapSelect|StoreDescriptor<any>} T\n */\n\nfunction Store( registry, suspense ) {\n\tconst select = suspense ? registry.suspendSelect : registry.select;\n\tconst queueContext = {};\n\tlet lastMapSelect;\n\tlet lastMapResult;\n\tlet lastMapResultValid = false;\n\tlet lastIsAsync;\n\tlet subscriber;\n\tlet didWarnUnstableReference;\n\tconst storeStatesOnMount = new Map();\n\n\tfunction getStoreState( name ) {\n\t\t// If there's no store property (custom generic store), return an empty\n\t\t// object. When comparing the state, the empty objects will cause the\n\t\t// equality check to fail, setting `lastMapResultValid` to false.\n\t\treturn registry.stores[ name ]?.store?.getState?.() ?? {};\n\t}\n\n\tconst createSubscriber = ( stores ) => {\n\t\t// The set of stores the `subscribe` function is supposed to subscribe to. Here it is\n\t\t// initialized, and then the `updateStores` function can add new stores to it.\n\t\tconst activeStores = [ ...stores ];\n\n\t\t// The `subscribe` function, which is passed to the `useSyncExternalStore` hook, could\n\t\t// be called multiple times to establish multiple subscriptions. That's why we need to\n\t\t// keep a set of active subscriptions;\n\t\tconst activeSubscriptions = new Set();\n\n\t\tfunction subscribe( listener ) {\n\t\t\t// Maybe invalidate the value right after subscription was created.\n\t\t\t// React will call `getValue` after subscribing, to detect store\n\t\t\t// updates that happened in the interval between the `getValue` call\n\t\t\t// during render and creating the subscription, which is slightly\n\t\t\t// delayed. We need to ensure that this second `getValue` call will\n\t\t\t// compute a fresh value only if any of the store states have\n\t\t\t// changed in the meantime.\n\t\t\tif ( lastMapResultValid ) {\n\t\t\t\tfor ( const name of activeStores ) {\n\t\t\t\t\tif (\n\t\t\t\t\t\tstoreStatesOnMount.get( name ) !== getStoreState( name )\n\t\t\t\t\t) {\n\t\t\t\t\t\tlastMapResultValid = false;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tstoreStatesOnMount.clear();\n\n\t\t\tconst onStoreChange = () => {\n\t\t\t\t// Invalidate the value on store update, so that a fresh value is computed.\n\t\t\t\tlastMapResultValid = false;\n\t\t\t\tlistener();\n\t\t\t};\n\n\t\t\tconst onChange = () => {\n\t\t\t\tif ( lastIsAsync ) {\n\t\t\t\t\trenderQueue.add( queueContext, onStoreChange );\n\t\t\t\t} else {\n\t\t\t\t\tonStoreChange();\n\t\t\t\t}\n\t\t\t};\n\n\t\t\tconst unsubs = [];\n\t\t\tfunction subscribeStore( storeName ) {\n\t\t\t\tunsubs.push( registry.subscribe( onChange, storeName ) );\n\t\t\t}\n\n\t\t\tfor ( const storeName of activeStores ) {\n\t\t\t\tsubscribeStore( storeName );\n\t\t\t}\n\n\t\t\tactiveSubscriptions.add( subscribeStore );\n\n\t\t\treturn () => {\n\t\t\t\tactiveSubscriptions.delete( subscribeStore );\n\n\t\t\t\tfor ( const unsub of unsubs.values() ) {\n\t\t\t\t\t// The return value of the subscribe function could be undefined if the store is a custom generic store.\n\t\t\t\t\tunsub?.();\n\t\t\t\t}\n\t\t\t\t// Cancel existing store updates that were already scheduled.\n\t\t\t\trenderQueue.cancel( queueContext );\n\t\t\t};\n\t\t}\n\n\t\t// Check if `newStores` contains some stores we're not subscribed to yet, and add them.\n\t\tfunction updateStores( newStores ) {\n\t\t\tfor ( const newStore of newStores ) {\n\t\t\t\tif ( activeStores.includes( newStore ) ) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\t// New `subscribe` calls will subscribe to `newStore`, too.\n\t\t\t\tactiveStores.push( newStore );\n\n\t\t\t\t// Add `newStore` to existing subscriptions.\n\t\t\t\tfor ( const subscription of activeSubscriptions ) {\n\t\t\t\t\tsubscription( newStore );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn { subscribe, updateStores };\n\t};\n\n\treturn ( mapSelect, isAsync ) => {\n\t\tfunction updateValue() {\n\t\t\t// If the last value is valid, and the `mapSelect` callback hasn't changed,\n\t\t\t// then we can safely return the cached value. The value can change only on\n\t\t\t// store update, and in that case value will be invalidated by the listener.\n\t\t\tif ( lastMapResultValid && mapSelect === lastMapSelect ) {\n\t\t\t\treturn lastMapResult;\n\t\t\t}\n\n\t\t\tconst listeningStores = { current: null };\n\t\t\tconst mapResult = registry.__unstableMarkListeningStores(\n\t\t\t\t() => mapSelect( select, registry ),\n\t\t\t\tlisteningStores\n\t\t\t);\n\n\t\t\tif ( globalThis.SCRIPT_DEBUG ) {\n\t\t\t\tif ( ! didWarnUnstableReference ) {\n\t\t\t\t\tconst secondMapResult = mapSelect( select, registry );\n\t\t\t\t\tif ( ! isShallowEqual( mapResult, secondMapResult ) ) {\n\t\t\t\t\t\twarnOnUnstableReference( mapResult, secondMapResult );\n\t\t\t\t\t\tdidWarnUnstableReference = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif ( ! subscriber ) {\n\t\t\t\tfor ( const name of listeningStores.current ) {\n\t\t\t\t\tstoreStatesOnMount.set( name, getStoreState( name ) );\n\t\t\t\t}\n\t\t\t\tsubscriber = createSubscriber( listeningStores.current );\n\t\t\t} else {\n\t\t\t\tsubscriber.updateStores( listeningStores.current );\n\t\t\t}\n\n\t\t\t// If the new value is shallow-equal to the old one, keep the old one so\n\t\t\t// that we don't trigger unwanted updates that do a `===` check.\n\t\t\tif ( ! isShallowEqual( lastMapResult, mapResult ) ) {\n\t\t\t\tlastMapResult = mapResult;\n\t\t\t}\n\t\t\tlastMapSelect = mapSelect;\n\t\t\tlastMapResultValid = true;\n\t\t}\n\n\t\tfunction getValue() {\n\t\t\t// Update the value in case it's been invalidated or `mapSelect` has changed.\n\t\t\tupdateValue();\n\t\t\treturn lastMapResult;\n\t\t}\n\n\t\t// When transitioning from async to sync mode, cancel existing store updates\n\t\t// that have been scheduled, and invalidate the value so that it's freshly\n\t\t// computed. It might have been changed by the update we just cancelled.\n\t\tif ( lastIsAsync && ! isAsync ) {\n\t\t\tlastMapResultValid = false;\n\t\t\trenderQueue.cancel( queueContext );\n\t\t}\n\n\t\tupdateValue();\n\n\t\tlastIsAsync = isAsync;\n\n\t\t// Return a pair of functions that can be passed to `useSyncExternalStore`.\n\t\treturn { subscribe: subscriber.subscribe, getValue };\n\t};\n}\n\nfunction _useStaticSelect( storeName ) {\n\treturn useRegistry().select( storeName );\n}\n\nfunction _useMappingSelect( suspense, mapSelect, deps ) {\n\tconst registry = useRegistry();\n\tconst isAsync = useAsyncMode();\n\tconst store = useMemo(\n\t\t() => Store( registry, suspense ),\n\t\t[ registry, suspense ]\n\t);\n\n\t// These are \"pass-through\" dependencies from the parent hook,\n\t// and the parent should catch any hook rule violations.\n\tconst selector = useCallback( mapSelect, deps );\n\tconst { subscribe, getValue } = store( selector, isAsync );\n\tconst result = useSyncExternalStore( subscribe, getValue, getValue );\n\tuseDebugValue( result );\n\treturn result;\n}\n\n/**\n * Custom react hook for retrieving props from registered selectors.\n *\n * In general, this custom React hook follows the\n * [rules of hooks](https://react.dev/reference/rules/rules-of-hooks).\n *\n * @template {MapSelect | StoreDescriptor<any>} T\n * @param {T} mapSelect Function called on every state change. The returned value is\n * exposed to the component implementing this hook. The function\n * receives the `registry.select` method on the first argument\n * and the `registry` on the second argument.\n * When a store key is passed, all selectors for the store will be\n * returned. This is only meant for usage of these selectors in event\n * callbacks, not for data needed to create the element tree.\n * @param {unknown[]} deps If provided, this memoizes the mapSelect so the same `mapSelect` is\n * invoked on every state change unless the dependencies change.\n *\n * @example\n * ```js\n * import { useSelect } from '@wordpress/data';\n * import { store as myCustomStore } from 'my-custom-store';\n *\n * function HammerPriceDisplay( { currency } ) {\n * const price = useSelect( ( select ) => {\n * return select( myCustomStore ).getPrice( 'hammer', currency );\n * }, [ currency ] );\n * return new Intl.NumberFormat( 'en-US', {\n * style: 'currency',\n * currency,\n * } ).format( price );\n * }\n *\n * // Rendered in the application:\n * // <HammerPriceDisplay currency=\"USD\" />\n * ```\n *\n * In the above example, when `HammerPriceDisplay` is rendered into an\n * application, the price will be retrieved from the store state using the\n * `mapSelect` callback on `useSelect`. If the currency prop changes then\n * any price in the state for that currency is retrieved. If the currency prop\n * doesn't change and other props are passed in that do change, the price will\n * not change because the dependency is just the currency.\n *\n * When data is only used in an event callback, the data should not be retrieved\n * on render, so it may be useful to get the selectors function instead.\n *\n * **Don't use `useSelect` this way when calling the selectors in the render\n * function because your component won't re-render on a data change.**\n *\n * ```js\n * import { useSelect } from '@wordpress/data';\n * import { store as myCustomStore } from 'my-custom-store';\n *\n * function Paste( { children } ) {\n * const { getSettings } = useSelect( myCustomStore );\n * function onPaste() {\n * // Do something with the settings.\n * const settings = getSettings();\n * }\n * return <div onPaste={ onPaste }>{ children }</div>;\n * }\n * ```\n * @return {UseSelectReturn<T>} A custom react hook.\n */\nexport default function useSelect( mapSelect, deps ) {\n\t// On initial call, on mount, determine the mode of this `useSelect` call\n\t// and then never allow it to change on subsequent updates.\n\tconst staticSelectMode = typeof mapSelect !== 'function';\n\tconst staticSelectModeRef = useRef( staticSelectMode );\n\n\tif ( staticSelectMode !== staticSelectModeRef.current ) {\n\t\tconst prevMode = staticSelectModeRef.current ? 'static' : 'mapping';\n\t\tconst nextMode = staticSelectMode ? 'static' : 'mapping';\n\t\tthrow new Error(\n\t\t\t`Switching useSelect from ${ prevMode } to ${ nextMode } is not allowed`\n\t\t);\n\t}\n\n\t// `staticSelectMode` is not allowed to change during the hook instance's,\n\t// lifetime, so the rules of hooks are not really violated.\n\treturn staticSelectMode\n\t\t? _useStaticSelect( mapSelect )\n\t\t: _useMappingSelect( false, mapSelect, deps );\n}\n\n/**\n * A variant of the `useSelect` hook that has the same API, but is a compatible\n * Suspense-enabled data source.\n *\n * @template {MapSelect} T\n * @param {T} mapSelect Function called on every state change. The\n * returned value is exposed to the component\n * using this hook. The function receives the\n * `registry.suspendSelect` method as the first\n * argument and the `registry` as the second one.\n * @param {Array} deps A dependency array used to memoize the `mapSelect`\n * so that the same `mapSelect` is invoked on every\n * state change unless the dependencies change.\n *\n * @throws {Promise} A suspense Promise that is thrown if any of the called\n * selectors is in an unresolved state.\n *\n * @return {ReturnType<T>} Data object returned by the `mapSelect` function.\n */\nexport function useSuspenseSelect( mapSelect, deps ) {\n\treturn _useMappingSelect( true, mapSelect, deps );\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,4BAA4B;AAC5B,qBAMO;AACP,8BAA2B;AAK3B,0BAAwB;AACxB,4BAAyB;AAEzB,MAAM,kBAAc,mCAAY;AAEhC,SAAS,wBAAyB,GAAG,GAAI;AACxC,MAAK,CAAE,KAAK,CAAE,GAAI;AACjB;AAAA,EACD;AAEA,QAAM,OACL,OAAO,MAAM,YAAY,OAAO,MAAM,WACnC,OAAO,KAAM,CAAE,EAAE,OAAQ,CAAE,MAAO,EAAG,CAAE,MAAM,EAAG,CAAE,CAAE,IACpD,CAAC;AAGL,UAAQ;AAAA,IACP;AAAA,IAGA,KAAK,KAAM,IAAK;AAAA,EACjB;AACD;AAkBA,SAAS,MAAO,UAAU,UAAW;AAC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SAAU;AACxC;AAEA,SAAS,kBAAmB,UAAU,WAAW,MAAO;AACvD,QAAM,eAAW,oBAAAA,SAAY;AAC7B,QAAM,cAAU,sBAAAC,SAAa;AAC7B,QAAM,YAAQ;AAAA,IACb,MAAM,MAAO,UAAU,QAAS;AAAA,IAChC,CAAE,UAAU,QAAS;AAAA,EACtB;AAIA,QAAM,eAAW,4BAAa,WAAW,IAAK;AAC9C,QAAM,EAAE,WAAW,SAAS,IAAI,MAAO,UAAU,OAAQ;AACzD,QAAM,aAAS,qCAAsB,WAAW,UAAU,QAAS;AACnE,oCAAe,MAAO;AACtB,SAAO;AACR;AAkEe,SAAR,UAA4B,WAAW,MAAO;AAGpD,QAAM,mBAAmB,OAAO,cAAc;AAC9C,QAAM,0BAAsB,uBAAQ,gBAAiB;AAErD,MAAK,qBAAqB,oBAAoB,SAAU;AACvD,UAAM,WAAW,oBAAoB,UAAU,WAAW;AAC1D,UAAM,WAAW,mBAAmB,WAAW;AAC/C,UAAM,IAAI;AAAA,MACT,4BAA6B,QAAS,OAAQ,QAAS;AAAA,IACxD;AAAA,EACD;AAIA,SAAO,mBACJ,iBAAkB,SAAU,IAC5B,kBAAmB,OAAO,WAAW,IAAK;AAC9C;AAqBO,SAAS,kBAAmB,WAAW,MAAO;AACpD,SAAO,kBAAmB,MAAM,WAAW,IAAK;AACjD;",
6
+ "names": ["isShallowEqual", "useRegistry", "useAsyncMode"]
7
+ }
@@ -1,109 +1,36 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var with_dispatch_exports = {};
20
+ __export(with_dispatch_exports, {
21
+ default: () => with_dispatch_default
5
22
  });
6
- exports.default = void 0;
7
- var _compose = require("@wordpress/compose");
8
- var _useDispatch = require("../use-dispatch");
9
- var _jsxRuntime = require("react/jsx-runtime");
10
- /**
11
- * WordPress dependencies
12
- */
13
-
14
- /**
15
- * Internal dependencies
16
- */
17
-
18
- /** @typedef {import('react').ComponentType} ComponentType */
19
-
20
- /**
21
- * Higher-order component used to add dispatch props using registered action
22
- * creators.
23
- *
24
- * @param {Function} mapDispatchToProps A function of returning an object of
25
- * prop names where value is a
26
- * dispatch-bound action creator, or a
27
- * function to be called with the
28
- * component's props and returning an
29
- * action creator.
30
- *
31
- * @example
32
- * ```jsx
33
- * function Button( { onClick, children } ) {
34
- * return <button type="button" onClick={ onClick }>{ children }</button>;
35
- * }
36
- *
37
- * import { withDispatch } from '@wordpress/data';
38
- * import { store as myCustomStore } from 'my-custom-store';
39
- *
40
- * const SaleButton = withDispatch( ( dispatch, ownProps ) => {
41
- * const { startSale } = dispatch( myCustomStore );
42
- * const { discountPercent } = ownProps;
43
- *
44
- * return {
45
- * onClick() {
46
- * startSale( discountPercent );
47
- * },
48
- * };
49
- * } )( Button );
50
- *
51
- * // Rendered in the application:
52
- * //
53
- * // <SaleButton discountPercent="20">Start Sale!</SaleButton>
54
- * ```
55
- *
56
- * @example
57
- * In the majority of cases, it will be sufficient to use only two first params
58
- * passed to `mapDispatchToProps` as illustrated in the previous example.
59
- * However, there might be some very advanced use cases where using the
60
- * `registry` object might be used as a tool to optimize the performance of
61
- * your component. Using `select` function from the registry might be useful
62
- * when you need to fetch some dynamic data from the store at the time when the
63
- * event is fired, but at the same time, you never use it to render your
64
- * component. In such scenario, you can avoid using the `withSelect` higher
65
- * order component to compute such prop, which might lead to unnecessary
66
- * re-renders of your component caused by its frequent value change.
67
- * Keep in mind, that `mapDispatchToProps` must return an object with functions
68
- * only.
69
- *
70
- * ```jsx
71
- * function Button( { onClick, children } ) {
72
- * return <button type="button" onClick={ onClick }>{ children }</button>;
73
- * }
74
- *
75
- * import { withDispatch } from '@wordpress/data';
76
- * import { store as myCustomStore } from 'my-custom-store';
77
- *
78
- * const SaleButton = withDispatch( ( dispatch, ownProps, { select } ) => {
79
- * // Stock number changes frequently.
80
- * const { getStockNumber } = select( myCustomStore );
81
- * const { startSale } = dispatch( myCustomStore );
82
- * return {
83
- * onClick() {
84
- * const discountPercent = getStockNumber() > 50 ? 10 : 20;
85
- * startSale( discountPercent );
86
- * },
87
- * };
88
- * } )( Button );
89
- *
90
- * // Rendered in the application:
91
- * //
92
- * // <SaleButton>Start Sale!</SaleButton>
93
- * ```
94
- *
95
- * _Note:_ It is important that the `mapDispatchToProps` function always
96
- * returns an object with the same keys. For example, it should not contain
97
- * conditions under which a different value would be returned.
98
- *
99
- * @return {ComponentType} Enhanced component with merged dispatcher props.
100
- */const withDispatch = mapDispatchToProps => (0, _compose.createHigherOrderComponent)(WrappedComponent => ownProps => {
101
- const mapDispatch = (dispatch, registry) => mapDispatchToProps(dispatch, ownProps, registry);
102
- const dispatchProps = (0, _useDispatch.useDispatchWithMap)(mapDispatch, []);
103
- return /*#__PURE__*/(0, _jsxRuntime.jsx)(WrappedComponent, {
104
- ...ownProps,
105
- ...dispatchProps
106
- });
107
- }, 'withDispatch');
108
- var _default = exports.default = withDispatch;
109
- //# sourceMappingURL=index.js.map
23
+ module.exports = __toCommonJS(with_dispatch_exports);
24
+ var import_jsx_runtime = require("react/jsx-runtime");
25
+ var import_compose = require("@wordpress/compose");
26
+ var import_use_dispatch = require("../use-dispatch");
27
+ const withDispatch = (mapDispatchToProps) => (0, import_compose.createHigherOrderComponent)(
28
+ (WrappedComponent) => (ownProps) => {
29
+ const mapDispatch = (dispatch, registry) => mapDispatchToProps(dispatch, ownProps, registry);
30
+ const dispatchProps = (0, import_use_dispatch.useDispatchWithMap)(mapDispatch, []);
31
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(WrappedComponent, { ...ownProps, ...dispatchProps });
32
+ },
33
+ "withDispatch"
34
+ );
35
+ var with_dispatch_default = withDispatch;
36
+ //# sourceMappingURL=index.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["_compose","require","_useDispatch","_jsxRuntime","withDispatch","mapDispatchToProps","createHigherOrderComponent","WrappedComponent","ownProps","mapDispatch","dispatch","registry","dispatchProps","useDispatchWithMap","jsx","_default","exports","default"],"sources":["@wordpress/data/src/components/with-dispatch/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createHigherOrderComponent } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { useDispatchWithMap } from '../use-dispatch';\n\n/** @typedef {import('react').ComponentType} ComponentType */\n\n/**\n * Higher-order component used to add dispatch props using registered action\n * creators.\n *\n * @param {Function} mapDispatchToProps A function of returning an object of\n * prop names where value is a\n * dispatch-bound action creator, or a\n * function to be called with the\n * component's props and returning an\n * action creator.\n *\n * @example\n * ```jsx\n * function Button( { onClick, children } ) {\n * return <button type=\"button\" onClick={ onClick }>{ children }</button>;\n * }\n *\n * import { withDispatch } from '@wordpress/data';\n * import { store as myCustomStore } from 'my-custom-store';\n *\n * const SaleButton = withDispatch( ( dispatch, ownProps ) => {\n * const { startSale } = dispatch( myCustomStore );\n * const { discountPercent } = ownProps;\n *\n * return {\n * onClick() {\n * startSale( discountPercent );\n * },\n * };\n * } )( Button );\n *\n * // Rendered in the application:\n * //\n * // <SaleButton discountPercent=\"20\">Start Sale!</SaleButton>\n * ```\n *\n * @example\n * In the majority of cases, it will be sufficient to use only two first params\n * passed to `mapDispatchToProps` as illustrated in the previous example.\n * However, there might be some very advanced use cases where using the\n * `registry` object might be used as a tool to optimize the performance of\n * your component. Using `select` function from the registry might be useful\n * when you need to fetch some dynamic data from the store at the time when the\n * event is fired, but at the same time, you never use it to render your\n * component. In such scenario, you can avoid using the `withSelect` higher\n * order component to compute such prop, which might lead to unnecessary\n * re-renders of your component caused by its frequent value change.\n * Keep in mind, that `mapDispatchToProps` must return an object with functions\n * only.\n *\n * ```jsx\n * function Button( { onClick, children } ) {\n * return <button type=\"button\" onClick={ onClick }>{ children }</button>;\n * }\n *\n * import { withDispatch } from '@wordpress/data';\n * import { store as myCustomStore } from 'my-custom-store';\n *\n * const SaleButton = withDispatch( ( dispatch, ownProps, { select } ) => {\n * // Stock number changes frequently.\n * const { getStockNumber } = select( myCustomStore );\n * const { startSale } = dispatch( myCustomStore );\n * return {\n * onClick() {\n * const discountPercent = getStockNumber() > 50 ? 10 : 20;\n * startSale( discountPercent );\n * },\n * };\n * } )( Button );\n *\n * // Rendered in the application:\n * //\n * // <SaleButton>Start Sale!</SaleButton>\n * ```\n *\n * _Note:_ It is important that the `mapDispatchToProps` function always\n * returns an object with the same keys. For example, it should not contain\n * conditions under which a different value would be returned.\n *\n * @return {ComponentType} Enhanced component with merged dispatcher props.\n */\nconst withDispatch = ( mapDispatchToProps ) =>\n\tcreateHigherOrderComponent(\n\t\t( WrappedComponent ) => ( ownProps ) => {\n\t\t\tconst mapDispatch = ( dispatch, registry ) =>\n\t\t\t\tmapDispatchToProps( dispatch, ownProps, registry );\n\t\t\tconst dispatchProps = useDispatchWithMap( mapDispatch, [] );\n\t\t\treturn <WrappedComponent { ...ownProps } { ...dispatchProps } />;\n\t\t},\n\t\t'withDispatch'\n\t);\n\nexport default withDispatch;\n"],"mappings":";;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AAKA,IAAAC,YAAA,GAAAD,OAAA;AAAqD,IAAAE,WAAA,GAAAF,OAAA;AARrD;AACA;AACA;;AAGA;AACA;AACA;;AAGA;;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;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,GACA,MAAMG,YAAY,GAAKC,kBAAkB,IACxC,IAAAC,mCAA0B,EACvBC,gBAAgB,IAAQC,QAAQ,IAAM;EACvC,MAAMC,WAAW,GAAGA,CAAEC,QAAQ,EAAEC,QAAQ,KACvCN,kBAAkB,CAAEK,QAAQ,EAAEF,QAAQ,EAAEG,QAAS,CAAC;EACnD,MAAMC,aAAa,GAAG,IAAAC,+BAAkB,EAAEJ,WAAW,EAAE,EAAG,CAAC;EAC3D,oBAAO,IAAAN,WAAA,CAAAW,GAAA,EAACP,gBAAgB;IAAA,GAAMC,QAAQ;IAAA,GAAQI;EAAa,CAAI,CAAC;AACjE,CAAC,EACD,cACD,CAAC;AAAC,IAAAG,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEYb,YAAY","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/components/with-dispatch/index.js"],
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { createHigherOrderComponent } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { useDispatchWithMap } from '../use-dispatch';\n\n/** @typedef {import('react').ComponentType} ComponentType */\n\n/**\n * Higher-order component used to add dispatch props using registered action\n * creators.\n *\n * @param {Function} mapDispatchToProps A function of returning an object of\n * prop names where value is a\n * dispatch-bound action creator, or a\n * function to be called with the\n * component's props and returning an\n * action creator.\n *\n * @example\n * ```jsx\n * function Button( { onClick, children } ) {\n * return <button type=\"button\" onClick={ onClick }>{ children }</button>;\n * }\n *\n * import { withDispatch } from '@wordpress/data';\n * import { store as myCustomStore } from 'my-custom-store';\n *\n * const SaleButton = withDispatch( ( dispatch, ownProps ) => {\n * const { startSale } = dispatch( myCustomStore );\n * const { discountPercent } = ownProps;\n *\n * return {\n * onClick() {\n * startSale( discountPercent );\n * },\n * };\n * } )( Button );\n *\n * // Rendered in the application:\n * //\n * // <SaleButton discountPercent=\"20\">Start Sale!</SaleButton>\n * ```\n *\n * @example\n * In the majority of cases, it will be sufficient to use only two first params\n * passed to `mapDispatchToProps` as illustrated in the previous example.\n * However, there might be some very advanced use cases where using the\n * `registry` object might be used as a tool to optimize the performance of\n * your component. Using `select` function from the registry might be useful\n * when you need to fetch some dynamic data from the store at the time when the\n * event is fired, but at the same time, you never use it to render your\n * component. In such scenario, you can avoid using the `withSelect` higher\n * order component to compute such prop, which might lead to unnecessary\n * re-renders of your component caused by its frequent value change.\n * Keep in mind, that `mapDispatchToProps` must return an object with functions\n * only.\n *\n * ```jsx\n * function Button( { onClick, children } ) {\n * return <button type=\"button\" onClick={ onClick }>{ children }</button>;\n * }\n *\n * import { withDispatch } from '@wordpress/data';\n * import { store as myCustomStore } from 'my-custom-store';\n *\n * const SaleButton = withDispatch( ( dispatch, ownProps, { select } ) => {\n * // Stock number changes frequently.\n * const { getStockNumber } = select( myCustomStore );\n * const { startSale } = dispatch( myCustomStore );\n * return {\n * onClick() {\n * const discountPercent = getStockNumber() > 50 ? 10 : 20;\n * startSale( discountPercent );\n * },\n * };\n * } )( Button );\n *\n * // Rendered in the application:\n * //\n * // <SaleButton>Start Sale!</SaleButton>\n * ```\n *\n * _Note:_ It is important that the `mapDispatchToProps` function always\n * returns an object with the same keys. For example, it should not contain\n * conditions under which a different value would be returned.\n *\n * @return {ComponentType} Enhanced component with merged dispatcher props.\n */\nconst withDispatch = ( mapDispatchToProps ) =>\n\tcreateHigherOrderComponent(\n\t\t( WrappedComponent ) => ( ownProps ) => {\n\t\t\tconst mapDispatch = ( dispatch, registry ) =>\n\t\t\t\tmapDispatchToProps( dispatch, ownProps, registry );\n\t\t\tconst dispatchProps = useDispatchWithMap( mapDispatch, [] );\n\t\t\treturn <WrappedComponent { ...ownProps } { ...dispatchProps } />;\n\t\t},\n\t\t'withDispatch'\n\t);\n\nexport default withDispatch;\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAmGU;AAhGV,qBAA2C;AAK3C,0BAAmC;AAqFnC,MAAM,eAAe,CAAE,2BACtB;AAAA,EACC,CAAE,qBAAsB,CAAE,aAAc;AACvC,UAAM,cAAc,CAAE,UAAU,aAC/B,mBAAoB,UAAU,UAAU,QAAS;AAClD,UAAM,oBAAgB,wCAAoB,aAAa,CAAC,CAAE;AAC1D,WAAO,4CAAC,oBAAmB,GAAG,UAAa,GAAG,eAAgB;AAAA,EAC/D;AAAA,EACA;AACD;AAED,IAAO,wBAAQ;",
6
+ "names": []
7
+ }
@@ -1,32 +1,32 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var with_registry_exports = {};
20
+ __export(with_registry_exports, {
21
+ default: () => with_registry_default
5
22
  });
6
- exports.default = void 0;
7
- var _compose = require("@wordpress/compose");
8
- var _registryProvider = require("../registry-provider");
9
- var _jsxRuntime = require("react/jsx-runtime");
10
- /**
11
- * WordPress dependencies
12
- */
13
-
14
- /**
15
- * Internal dependencies
16
- */
17
-
18
- /**
19
- * Higher-order component which renders the original component with the current
20
- * registry context passed as its `registry` prop.
21
- *
22
- * @param {Component} OriginalComponent Original component.
23
- *
24
- * @return {Component} Enhanced component.
25
- */const withRegistry = (0, _compose.createHigherOrderComponent)(OriginalComponent => props => /*#__PURE__*/(0, _jsxRuntime.jsx)(_registryProvider.RegistryConsumer, {
26
- children: registry => /*#__PURE__*/(0, _jsxRuntime.jsx)(OriginalComponent, {
27
- ...props,
28
- registry: registry
29
- })
30
- }), 'withRegistry');
31
- var _default = exports.default = withRegistry;
32
- //# sourceMappingURL=index.js.map
23
+ module.exports = __toCommonJS(with_registry_exports);
24
+ var import_jsx_runtime = require("react/jsx-runtime");
25
+ var import_compose = require("@wordpress/compose");
26
+ var import_registry_provider = require("../registry-provider");
27
+ const withRegistry = (0, import_compose.createHigherOrderComponent)(
28
+ (OriginalComponent) => (props) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_registry_provider.RegistryConsumer, { children: (registry) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(OriginalComponent, { ...props, registry }) }),
29
+ "withRegistry"
30
+ );
31
+ var with_registry_default = withRegistry;
32
+ //# sourceMappingURL=index.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["_compose","require","_registryProvider","_jsxRuntime","withRegistry","createHigherOrderComponent","OriginalComponent","props","jsx","RegistryConsumer","children","registry","_default","exports","default"],"sources":["@wordpress/data/src/components/with-registry/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createHigherOrderComponent } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { RegistryConsumer } from '../registry-provider';\n\n/**\n * Higher-order component which renders the original component with the current\n * registry context passed as its `registry` prop.\n *\n * @param {Component} OriginalComponent Original component.\n *\n * @return {Component} Enhanced component.\n */\nconst withRegistry = createHigherOrderComponent(\n\t( OriginalComponent ) => ( props ) => (\n\t\t<RegistryConsumer>\n\t\t\t{ ( registry ) => (\n\t\t\t\t<OriginalComponent { ...props } registry={ registry } />\n\t\t\t) }\n\t\t</RegistryConsumer>\n\t),\n\t'withRegistry'\n);\n\nexport default withRegistry;\n"],"mappings":";;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AAKA,IAAAC,iBAAA,GAAAD,OAAA;AAAwD,IAAAE,WAAA,GAAAF,OAAA;AARxD;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GACA,MAAMG,YAAY,GAAG,IAAAC,mCAA0B,EAC5CC,iBAAiB,IAAQC,KAAK,iBAC/B,IAAAJ,WAAA,CAAAK,GAAA,EAACN,iBAAA,CAAAO,gBAAgB;EAAAC,QAAA,EACZC,QAAQ,iBACX,IAAAR,WAAA,CAAAK,GAAA,EAACF,iBAAiB;IAAA,GAAMC,KAAK;IAAGI,QAAQ,EAAGA;EAAU,CAAE;AACvD,CACgB,CAClB,EACD,cACD,CAAC;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEaV,YAAY","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/components/with-registry/index.js"],
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { createHigherOrderComponent } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { RegistryConsumer } from '../registry-provider';\n\n/**\n * Higher-order component which renders the original component with the current\n * registry context passed as its `registry` prop.\n *\n * @param {Component} OriginalComponent Original component.\n *\n * @return {Component} Enhanced component.\n */\nconst withRegistry = createHigherOrderComponent(\n\t( OriginalComponent ) => ( props ) => (\n\t\t<RegistryConsumer>\n\t\t\t{ ( registry ) => (\n\t\t\t\t<OriginalComponent { ...props } registry={ registry } />\n\t\t\t) }\n\t\t</RegistryConsumer>\n\t),\n\t'withRegistry'\n);\n\nexport default withRegistry;\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAsBI;AAnBJ,qBAA2C;AAK3C,+BAAiC;AAUjC,MAAM,mBAAe;AAAA,EACpB,CAAE,sBAAuB,CAAE,UAC1B,4CAAC,6CACE,WAAE,aACH,4CAAC,qBAAoB,GAAG,OAAQ,UAAsB,GAExD;AAAA,EAED;AACD;AAEA,IAAO,wBAAQ;",
6
+ "names": []
7
+ }
@@ -1,69 +1,46 @@
1
1
  "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var with_select_exports = {};
30
+ __export(with_select_exports, {
31
+ default: () => with_select_default
6
32
  });
7
- exports.default = void 0;
8
- var _compose = require("@wordpress/compose");
9
- var _useSelect = _interopRequireDefault(require("../use-select"));
10
- var _jsxRuntime = require("react/jsx-runtime");
11
- /**
12
- * WordPress dependencies
13
- */
14
-
15
- /**
16
- * Internal dependencies
17
- */
18
-
19
- /** @typedef {import('react').ComponentType} ComponentType */
20
-
21
- /**
22
- * Higher-order component used to inject state-derived props using registered
23
- * selectors.
24
- *
25
- * @param {Function} mapSelectToProps Function called on every state change,
26
- * expected to return object of props to
27
- * merge with the component's own props.
28
- *
29
- * @example
30
- * ```js
31
- * import { withSelect } from '@wordpress/data';
32
- * import { store as myCustomStore } from 'my-custom-store';
33
- *
34
- * function PriceDisplay( { price, currency } ) {
35
- * return new Intl.NumberFormat( 'en-US', {
36
- * style: 'currency',
37
- * currency,
38
- * } ).format( price );
39
- * }
40
- *
41
- * const HammerPriceDisplay = withSelect( ( select, ownProps ) => {
42
- * const { getPrice } = select( myCustomStore );
43
- * const { currency } = ownProps;
44
- *
45
- * return {
46
- * price: getPrice( 'hammer', currency ),
47
- * };
48
- * } )( PriceDisplay );
49
- *
50
- * // Rendered in the application:
51
- * //
52
- * // <HammerPriceDisplay currency="USD" />
53
- * ```
54
- * In the above example, when `HammerPriceDisplay` is rendered into an
55
- * application, it will pass the price into the underlying `PriceDisplay`
56
- * component and update automatically if the price of a hammer ever changes in
57
- * the store.
58
- *
59
- * @return {ComponentType} Enhanced component with merged state data props.
60
- */const withSelect = mapSelectToProps => (0, _compose.createHigherOrderComponent)(WrappedComponent => (0, _compose.pure)(ownProps => {
61
- const mapSelect = (select, registry) => mapSelectToProps(select, ownProps, registry);
62
- const mergeProps = (0, _useSelect.default)(mapSelect);
63
- return /*#__PURE__*/(0, _jsxRuntime.jsx)(WrappedComponent, {
64
- ...ownProps,
65
- ...mergeProps
66
- });
67
- }), 'withSelect');
68
- var _default = exports.default = withSelect;
69
- //# sourceMappingURL=index.js.map
33
+ module.exports = __toCommonJS(with_select_exports);
34
+ var import_jsx_runtime = require("react/jsx-runtime");
35
+ var import_compose = require("@wordpress/compose");
36
+ var import_use_select = __toESM(require("../use-select"));
37
+ const withSelect = (mapSelectToProps) => (0, import_compose.createHigherOrderComponent)(
38
+ (WrappedComponent) => (0, import_compose.pure)((ownProps) => {
39
+ const mapSelect = (select, registry) => mapSelectToProps(select, ownProps, registry);
40
+ const mergeProps = (0, import_use_select.default)(mapSelect);
41
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(WrappedComponent, { ...ownProps, ...mergeProps });
42
+ }),
43
+ "withSelect"
44
+ );
45
+ var with_select_default = withSelect;
46
+ //# sourceMappingURL=index.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["_compose","require","_useSelect","_interopRequireDefault","_jsxRuntime","withSelect","mapSelectToProps","createHigherOrderComponent","WrappedComponent","pure","ownProps","mapSelect","select","registry","mergeProps","useSelect","jsx","_default","exports","default"],"sources":["@wordpress/data/src/components/with-select/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createHigherOrderComponent, pure } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport useSelect from '../use-select';\n\n/** @typedef {import('react').ComponentType} ComponentType */\n\n/**\n * Higher-order component used to inject state-derived props using registered\n * selectors.\n *\n * @param {Function} mapSelectToProps Function called on every state change,\n * expected to return object of props to\n * merge with the component's own props.\n *\n * @example\n * ```js\n * import { withSelect } from '@wordpress/data';\n * import { store as myCustomStore } from 'my-custom-store';\n *\n * function PriceDisplay( { price, currency } ) {\n * \treturn new Intl.NumberFormat( 'en-US', {\n * \t\tstyle: 'currency',\n * \t\tcurrency,\n * \t} ).format( price );\n * }\n *\n * const HammerPriceDisplay = withSelect( ( select, ownProps ) => {\n * \tconst { getPrice } = select( myCustomStore );\n * \tconst { currency } = ownProps;\n *\n * \treturn {\n * \t\tprice: getPrice( 'hammer', currency ),\n * \t};\n * } )( PriceDisplay );\n *\n * // Rendered in the application:\n * //\n * // <HammerPriceDisplay currency=\"USD\" />\n * ```\n * In the above example, when `HammerPriceDisplay` is rendered into an\n * application, it will pass the price into the underlying `PriceDisplay`\n * component and update automatically if the price of a hammer ever changes in\n * the store.\n *\n * @return {ComponentType} Enhanced component with merged state data props.\n */\nconst withSelect = ( mapSelectToProps ) =>\n\tcreateHigherOrderComponent(\n\t\t( WrappedComponent ) =>\n\t\t\tpure( ( ownProps ) => {\n\t\t\t\tconst mapSelect = ( select, registry ) =>\n\t\t\t\t\tmapSelectToProps( select, ownProps, registry );\n\t\t\t\tconst mergeProps = useSelect( mapSelect );\n\t\t\t\treturn <WrappedComponent { ...ownProps } { ...mergeProps } />;\n\t\t\t} ),\n\t\t'withSelect'\n\t);\n\nexport default withSelect;\n"],"mappings":";;;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AAKA,IAAAC,UAAA,GAAAC,sBAAA,CAAAF,OAAA;AAAsC,IAAAG,WAAA,GAAAH,OAAA;AARtC;AACA;AACA;;AAGA;AACA;AACA;;AAGA;;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,GACA,MAAMI,UAAU,GAAKC,gBAAgB,IACpC,IAAAC,mCAA0B,EACvBC,gBAAgB,IACjB,IAAAC,aAAI,EAAIC,QAAQ,IAAM;EACrB,MAAMC,SAAS,GAAGA,CAAEC,MAAM,EAAEC,QAAQ,KACnCP,gBAAgB,CAAEM,MAAM,EAAEF,QAAQ,EAAEG,QAAS,CAAC;EAC/C,MAAMC,UAAU,GAAG,IAAAC,kBAAS,EAAEJ,SAAU,CAAC;EACzC,oBAAO,IAAAP,WAAA,CAAAY,GAAA,EAACR,gBAAgB;IAAA,GAAME,QAAQ;IAAA,GAAQI;EAAU,CAAI,CAAC;AAC9D,CAAE,CAAC,EACJ,YACD,CAAC;AAAC,IAAAG,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEYd,UAAU","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/components/with-select/index.js"],
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { createHigherOrderComponent, pure } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport useSelect from '../use-select';\n\n/** @typedef {import('react').ComponentType} ComponentType */\n\n/**\n * Higher-order component used to inject state-derived props using registered\n * selectors.\n *\n * @param {Function} mapSelectToProps Function called on every state change,\n * expected to return object of props to\n * merge with the component's own props.\n *\n * @example\n * ```js\n * import { withSelect } from '@wordpress/data';\n * import { store as myCustomStore } from 'my-custom-store';\n *\n * function PriceDisplay( { price, currency } ) {\n * \treturn new Intl.NumberFormat( 'en-US', {\n * \t\tstyle: 'currency',\n * \t\tcurrency,\n * \t} ).format( price );\n * }\n *\n * const HammerPriceDisplay = withSelect( ( select, ownProps ) => {\n * \tconst { getPrice } = select( myCustomStore );\n * \tconst { currency } = ownProps;\n *\n * \treturn {\n * \t\tprice: getPrice( 'hammer', currency ),\n * \t};\n * } )( PriceDisplay );\n *\n * // Rendered in the application:\n * //\n * // <HammerPriceDisplay currency=\"USD\" />\n * ```\n * In the above example, when `HammerPriceDisplay` is rendered into an\n * application, it will pass the price into the underlying `PriceDisplay`\n * component and update automatically if the price of a hammer ever changes in\n * the store.\n *\n * @return {ComponentType} Enhanced component with merged state data props.\n */\nconst withSelect = ( mapSelectToProps ) =>\n\tcreateHigherOrderComponent(\n\t\t( WrappedComponent ) =>\n\t\t\tpure( ( ownProps ) => {\n\t\t\t\tconst mapSelect = ( select, registry ) =>\n\t\t\t\t\tmapSelectToProps( select, ownProps, registry );\n\t\t\t\tconst mergeProps = useSelect( mapSelect );\n\t\t\t\treturn <WrappedComponent { ...ownProps } { ...mergeProps } />;\n\t\t\t} ),\n\t\t'withSelect'\n\t);\n\nexport default withSelect;\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA2DW;AAxDX,qBAAiD;AAKjD,wBAAsB;AA4CtB,MAAM,aAAa,CAAE,yBACpB;AAAA,EACC,CAAE,yBACD,qBAAM,CAAE,aAAc;AACrB,UAAM,YAAY,CAAE,QAAQ,aAC3B,iBAAkB,QAAQ,UAAU,QAAS;AAC9C,UAAM,iBAAa,kBAAAA,SAAW,SAAU;AACxC,WAAO,4CAAC,oBAAmB,GAAG,UAAa,GAAG,YAAa;AAAA,EAC5D,CAAE;AAAA,EACH;AACD;AAED,IAAO,sBAAQ;",
6
+ "names": ["useSelect"]
7
+ }