@wordpress/compose 6.33.0 → 6.35.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 (55) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +21 -0
  3. package/build/hooks/use-focusable-iframe/index.js +6 -2
  4. package/build/hooks/use-focusable-iframe/index.js.map +1 -1
  5. package/build/hooks/use-instance-id/index.js +3 -1
  6. package/build/hooks/use-instance-id/index.js.map +1 -1
  7. package/build/hooks/use-media-query/index.js +13 -2
  8. package/build/hooks/use-media-query/index.js.map +1 -1
  9. package/build/hooks/use-observable-value/index.js +32 -0
  10. package/build/hooks/use-observable-value/index.js.map +1 -0
  11. package/build/index.js +21 -1
  12. package/build/index.js.map +1 -1
  13. package/build/index.native.js +21 -1
  14. package/build/index.native.js.map +1 -1
  15. package/build/utils/observable-map/index.js +58 -0
  16. package/build/utils/observable-map/index.js.map +1 -0
  17. package/build-module/hooks/use-focusable-iframe/index.js +6 -2
  18. package/build-module/hooks/use-focusable-iframe/index.js.map +1 -1
  19. package/build-module/hooks/use-instance-id/index.js +3 -1
  20. package/build-module/hooks/use-instance-id/index.js.map +1 -1
  21. package/build-module/hooks/use-media-query/index.js +12 -2
  22. package/build-module/hooks/use-media-query/index.js.map +1 -1
  23. package/build-module/hooks/use-observable-value/index.js +26 -0
  24. package/build-module/hooks/use-observable-value/index.js.map +1 -0
  25. package/build-module/index.js +3 -0
  26. package/build-module/index.js.map +1 -1
  27. package/build-module/index.native.js +3 -0
  28. package/build-module/index.native.js.map +1 -1
  29. package/build-module/utils/observable-map/index.js +52 -0
  30. package/build-module/utils/observable-map/index.js.map +1 -0
  31. package/build-types/higher-order/if-condition/index.d.ts +1 -1
  32. package/build-types/higher-order/if-condition/index.d.ts.map +1 -1
  33. package/build-types/higher-order/with-instance-id/index.d.ts +1 -1
  34. package/build-types/higher-order/with-instance-id/index.d.ts.map +1 -1
  35. package/build-types/higher-order/with-safe-timeout/index.d.ts +1 -1
  36. package/build-types/hooks/use-focusable-iframe/index.d.ts.map +1 -1
  37. package/build-types/hooks/use-instance-id/index.d.ts.map +1 -1
  38. package/build-types/hooks/use-media-query/index.d.ts.map +1 -1
  39. package/build-types/hooks/use-observable-value/index.d.ts +18 -0
  40. package/build-types/hooks/use-observable-value/index.d.ts.map +1 -0
  41. package/build-types/index.d.ts +2 -0
  42. package/build-types/utils/observable-map/index.d.ts +19 -0
  43. package/build-types/utils/observable-map/index.d.ts.map +1 -0
  44. package/package.json +9 -9
  45. package/src/hooks/use-focusable-iframe/index.ts +6 -2
  46. package/src/hooks/use-instance-id/index.ts +3 -1
  47. package/src/hooks/use-media-query/index.js +15 -2
  48. package/src/hooks/use-media-query/test/index.js +5 -4
  49. package/src/hooks/use-observable-value/index.ts +35 -0
  50. package/src/hooks/use-observable-value/test/index.js +42 -0
  51. package/src/index.js +3 -0
  52. package/src/index.native.js +3 -0
  53. package/src/utils/observable-map/index.ts +61 -0
  54. package/src/utils/observable-map/test/index.js +43 -0
  55. package/tsconfig.tsbuildinfo +1 -1
package/CHANGELOG.md CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 6.35.0 (2024-05-16)
6
+
7
+ ## 6.34.0 (2024-05-02)
8
+
9
+ - Added new `observableMap` data structure and `useObservableValue` React hook ([#60945](https://github.com/WordPress/gutenberg/pull/60945)).
10
+
5
11
  ## 6.33.0 (2024-04-19)
6
12
 
7
13
  ## 6.32.0 (2024-04-03)
package/README.md CHANGED
@@ -129,6 +129,14 @@ _Returns_
129
129
 
130
130
  - Higher-order component.
131
131
 
132
+ ### observableMap
133
+
134
+ A constructor (factory) for `ObservableMap`, a map-like key/value data structure where the individual entries are observable: using the `subscribe` method, you can subscribe to updates for a particular keys. Each subscriber always observes one specific key and is not notified about any unrelated changes (for different keys) in the `ObservableMap`.
135
+
136
+ _Returns_
137
+
138
+ - `ObservableMap< K, V >`: A new instance of the `ObservableMap` type.
139
+
132
140
  ### pipe
133
141
 
134
142
  Composes multiple higher-order components into a single higher-order component. Performs left-to-right function composition, where each successive invocation is supplied the return value of the previous.
@@ -442,6 +450,19 @@ _Returns_
442
450
 
443
451
  - `import('react').RefCallback<TypeFromRef<TRef>>`: The merged ref callback.
444
452
 
453
+ ### useObservableValue
454
+
455
+ React hook that lets you observe an entry in an `ObservableMap`. The hook returns the current value corresponding to the key, or `undefined` when there is no value stored. It also observes changes to the value and triggers an update of the calling component in case the value changes.
456
+
457
+ _Parameters_
458
+
459
+ - _map_ `ObservableMap< K, V >`: The `ObservableMap` to observe.
460
+ - _name_ `K`: The map key to observe.
461
+
462
+ _Returns_
463
+
464
+ - `V | undefined`: The value corresponding to the map key requested.
465
+
445
466
  ### usePrevious
446
467
 
447
468
  Use something's value from the previous render. Based on <https://usehooks.com/usePrevious/>.
@@ -25,11 +25,15 @@ function useFocusableIframe() {
25
25
  const {
26
26
  ownerDocument
27
27
  } = element;
28
- if (!ownerDocument) return;
28
+ if (!ownerDocument) {
29
+ return;
30
+ }
29
31
  const {
30
32
  defaultView
31
33
  } = ownerDocument;
32
- if (!defaultView) return;
34
+ if (!defaultView) {
35
+ return;
36
+ }
33
37
 
34
38
  /**
35
39
  * Checks whether the iframe is the activeElement, inferring that it has
@@ -1 +1 @@
1
- {"version":3,"names":["_useRefEffect","_interopRequireDefault","require","useFocusableIframe","useRefEffect","element","ownerDocument","defaultView","checkFocus","activeElement","focus","addEventListener","removeEventListener"],"sources":["@wordpress/compose/src/hooks/use-focusable-iframe/index.ts"],"sourcesContent":["/**\n * External dependencies\n */\nimport type { RefCallback } from 'react';\n\n/**\n * Internal dependencies\n */\nimport useRefEffect from '../use-ref-effect';\n\n/**\n * Dispatches a bubbling focus event when the iframe receives focus. Use\n * `onFocus` as usual on the iframe or a parent element.\n *\n * @return Ref to pass to the iframe.\n */\nexport default function useFocusableIframe(): RefCallback< HTMLIFrameElement > {\n\treturn useRefEffect( ( element ) => {\n\t\tconst { ownerDocument } = element;\n\t\tif ( ! ownerDocument ) return;\n\t\tconst { defaultView } = ownerDocument;\n\t\tif ( ! defaultView ) return;\n\n\t\t/**\n\t\t * Checks whether the iframe is the activeElement, inferring that it has\n\t\t * then received focus, and dispatches a focus event.\n\t\t */\n\t\tfunction checkFocus() {\n\t\t\tif ( ownerDocument && ownerDocument.activeElement === element ) {\n\t\t\t\t( element as HTMLElement ).focus();\n\t\t\t}\n\t\t}\n\n\t\tdefaultView.addEventListener( 'blur', checkFocus );\n\t\treturn () => {\n\t\t\tdefaultView.removeEventListener( 'blur', checkFocus );\n\t\t};\n\t}, [] );\n}\n"],"mappings":";;;;;;;AAQA,IAAAA,aAAA,GAAAC,sBAAA,CAAAC,OAAA;AARA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACe,SAASC,kBAAkBA,CAAA,EAAqC;EAC9E,OAAO,IAAAC,qBAAY,EAAIC,OAAO,IAAM;IACnC,MAAM;MAAEC;IAAc,CAAC,GAAGD,OAAO;IACjC,IAAK,CAAEC,aAAa,EAAG;IACvB,MAAM;MAAEC;IAAY,CAAC,GAAGD,aAAa;IACrC,IAAK,CAAEC,WAAW,EAAG;;IAErB;AACF;AACA;AACA;IACE,SAASC,UAAUA,CAAA,EAAG;MACrB,IAAKF,aAAa,IAAIA,aAAa,CAACG,aAAa,KAAKJ,OAAO,EAAG;QAC7DA,OAAO,CAAkBK,KAAK,CAAC,CAAC;MACnC;IACD;IAEAH,WAAW,CAACI,gBAAgB,CAAE,MAAM,EAAEH,UAAW,CAAC;IAClD,OAAO,MAAM;MACZD,WAAW,CAACK,mBAAmB,CAAE,MAAM,EAAEJ,UAAW,CAAC;IACtD,CAAC;EACF,CAAC,EAAE,EAAG,CAAC;AACR","ignoreList":[]}
1
+ {"version":3,"names":["_useRefEffect","_interopRequireDefault","require","useFocusableIframe","useRefEffect","element","ownerDocument","defaultView","checkFocus","activeElement","focus","addEventListener","removeEventListener"],"sources":["@wordpress/compose/src/hooks/use-focusable-iframe/index.ts"],"sourcesContent":["/**\n * External dependencies\n */\nimport type { RefCallback } from 'react';\n\n/**\n * Internal dependencies\n */\nimport useRefEffect from '../use-ref-effect';\n\n/**\n * Dispatches a bubbling focus event when the iframe receives focus. Use\n * `onFocus` as usual on the iframe or a parent element.\n *\n * @return Ref to pass to the iframe.\n */\nexport default function useFocusableIframe(): RefCallback< HTMLIFrameElement > {\n\treturn useRefEffect( ( element ) => {\n\t\tconst { ownerDocument } = element;\n\t\tif ( ! ownerDocument ) {\n\t\t\treturn;\n\t\t}\n\t\tconst { defaultView } = ownerDocument;\n\t\tif ( ! defaultView ) {\n\t\t\treturn;\n\t\t}\n\n\t\t/**\n\t\t * Checks whether the iframe is the activeElement, inferring that it has\n\t\t * then received focus, and dispatches a focus event.\n\t\t */\n\t\tfunction checkFocus() {\n\t\t\tif ( ownerDocument && ownerDocument.activeElement === element ) {\n\t\t\t\t( element as HTMLElement ).focus();\n\t\t\t}\n\t\t}\n\n\t\tdefaultView.addEventListener( 'blur', checkFocus );\n\t\treturn () => {\n\t\t\tdefaultView.removeEventListener( 'blur', checkFocus );\n\t\t};\n\t}, [] );\n}\n"],"mappings":";;;;;;;AAQA,IAAAA,aAAA,GAAAC,sBAAA,CAAAC,OAAA;AARA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACe,SAASC,kBAAkBA,CAAA,EAAqC;EAC9E,OAAO,IAAAC,qBAAY,EAAIC,OAAO,IAAM;IACnC,MAAM;MAAEC;IAAc,CAAC,GAAGD,OAAO;IACjC,IAAK,CAAEC,aAAa,EAAG;MACtB;IACD;IACA,MAAM;MAAEC;IAAY,CAAC,GAAGD,aAAa;IACrC,IAAK,CAAEC,WAAW,EAAG;MACpB;IACD;;IAEA;AACF;AACA;AACA;IACE,SAASC,UAAUA,CAAA,EAAG;MACrB,IAAKF,aAAa,IAAIA,aAAa,CAACG,aAAa,KAAKJ,OAAO,EAAG;QAC7DA,OAAO,CAAkBK,KAAK,CAAC,CAAC;MACnC;IACD;IAEAH,WAAW,CAACI,gBAAgB,CAAE,MAAM,EAAEH,UAAW,CAAC;IAClD,OAAO,MAAM;MACZD,WAAW,CAACK,mBAAmB,CAAE,MAAM,EAAEJ,UAAW,CAAC;IACtD,CAAC;EACF,CAAC,EAAE,EAAG,CAAC;AACR","ignoreList":[]}
@@ -46,7 +46,9 @@ function createId(object) {
46
46
  */
47
47
  function useInstanceId(object, prefix, preferredId) {
48
48
  return (0, _element.useMemo)(() => {
49
- if (preferredId) return preferredId;
49
+ if (preferredId) {
50
+ return preferredId;
51
+ }
50
52
  const id = createId(object);
51
53
  return prefix ? `${prefix}-${id}` : id;
52
54
  }, [object, preferredId, prefix]);
@@ -1 +1 @@
1
- {"version":3,"names":["_element","require","instanceMap","WeakMap","createId","object","instances","get","set","useInstanceId","prefix","preferredId","useMemo","id","_default","exports","default"],"sources":["@wordpress/compose/src/hooks/use-instance-id/index.ts"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useMemo } from '@wordpress/element';\n\nconst instanceMap = new WeakMap< object, number >();\n\n/**\n * Creates a new id for a given object.\n *\n * @param object Object reference to create an id for.\n * @return The instance id (index).\n */\nfunction createId( object: object ): number {\n\tconst instances = instanceMap.get( object ) || 0;\n\tinstanceMap.set( object, instances + 1 );\n\treturn instances;\n}\n\n/**\n * Specify the useInstanceId *function* signatures.\n *\n * More accurately, useInstanceId distinguishes between three different\n * signatures:\n *\n * 1. When only object is given, the returned value is a number\n * 2. When object and prefix is given, the returned value is a string\n * 3. When preferredId is given, the returned value is the type of preferredId\n *\n * @param object Object reference to create an id for.\n */\nfunction useInstanceId( object: object ): number;\nfunction useInstanceId( object: object, prefix: string ): string;\nfunction useInstanceId< T extends string | number >(\n\tobject: object,\n\tprefix: string,\n\tpreferredId?: T\n): T;\n\n/**\n * Provides a unique instance ID.\n *\n * @param object Object reference to create an id for.\n * @param [prefix] Prefix for the unique id.\n * @param [preferredId] Default ID to use.\n * @return The unique instance id.\n */\nfunction useInstanceId(\n\tobject: object,\n\tprefix?: string,\n\tpreferredId?: string | number\n): string | number {\n\treturn useMemo( () => {\n\t\tif ( preferredId ) return preferredId;\n\t\tconst id = createId( object );\n\n\t\treturn prefix ? `${ prefix }-${ id }` : id;\n\t}, [ object, preferredId, prefix ] );\n}\n\nexport default useInstanceId;\n"],"mappings":";;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AAHA;AACA;AACA;;AAGA,MAAMC,WAAW,GAAG,IAAIC,OAAO,CAAmB,CAAC;;AAEnD;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,QAAQA,CAAEC,MAAc,EAAW;EAC3C,MAAMC,SAAS,GAAGJ,WAAW,CAACK,GAAG,CAAEF,MAAO,CAAC,IAAI,CAAC;EAChDH,WAAW,CAACM,GAAG,CAAEH,MAAM,EAAEC,SAAS,GAAG,CAAE,CAAC;EACxC,OAAOA,SAAS;AACjB;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AASA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASG,aAAaA,CACrBJ,MAAc,EACdK,MAAe,EACfC,WAA6B,EACX;EAClB,OAAO,IAAAC,gBAAO,EAAE,MAAM;IACrB,IAAKD,WAAW,EAAG,OAAOA,WAAW;IACrC,MAAME,EAAE,GAAGT,QAAQ,CAAEC,MAAO,CAAC;IAE7B,OAAOK,MAAM,GAAI,GAAGA,MAAQ,IAAIG,EAAI,EAAC,GAAGA,EAAE;EAC3C,CAAC,EAAE,CAAER,MAAM,EAAEM,WAAW,EAAED,MAAM,CAAG,CAAC;AACrC;AAAC,IAAAI,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEcP,aAAa","ignoreList":[]}
1
+ {"version":3,"names":["_element","require","instanceMap","WeakMap","createId","object","instances","get","set","useInstanceId","prefix","preferredId","useMemo","id","_default","exports","default"],"sources":["@wordpress/compose/src/hooks/use-instance-id/index.ts"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useMemo } from '@wordpress/element';\n\nconst instanceMap = new WeakMap< object, number >();\n\n/**\n * Creates a new id for a given object.\n *\n * @param object Object reference to create an id for.\n * @return The instance id (index).\n */\nfunction createId( object: object ): number {\n\tconst instances = instanceMap.get( object ) || 0;\n\tinstanceMap.set( object, instances + 1 );\n\treturn instances;\n}\n\n/**\n * Specify the useInstanceId *function* signatures.\n *\n * More accurately, useInstanceId distinguishes between three different\n * signatures:\n *\n * 1. When only object is given, the returned value is a number\n * 2. When object and prefix is given, the returned value is a string\n * 3. When preferredId is given, the returned value is the type of preferredId\n *\n * @param object Object reference to create an id for.\n */\nfunction useInstanceId( object: object ): number;\nfunction useInstanceId( object: object, prefix: string ): string;\nfunction useInstanceId< T extends string | number >(\n\tobject: object,\n\tprefix: string,\n\tpreferredId?: T\n): T;\n\n/**\n * Provides a unique instance ID.\n *\n * @param object Object reference to create an id for.\n * @param [prefix] Prefix for the unique id.\n * @param [preferredId] Default ID to use.\n * @return The unique instance id.\n */\nfunction useInstanceId(\n\tobject: object,\n\tprefix?: string,\n\tpreferredId?: string | number\n): string | number {\n\treturn useMemo( () => {\n\t\tif ( preferredId ) {\n\t\t\treturn preferredId;\n\t\t}\n\t\tconst id = createId( object );\n\n\t\treturn prefix ? `${ prefix }-${ id }` : id;\n\t}, [ object, preferredId, prefix ] );\n}\n\nexport default useInstanceId;\n"],"mappings":";;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AAHA;AACA;AACA;;AAGA,MAAMC,WAAW,GAAG,IAAIC,OAAO,CAAmB,CAAC;;AAEnD;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,QAAQA,CAAEC,MAAc,EAAW;EAC3C,MAAMC,SAAS,GAAGJ,WAAW,CAACK,GAAG,CAAEF,MAAO,CAAC,IAAI,CAAC;EAChDH,WAAW,CAACM,GAAG,CAAEH,MAAM,EAAEC,SAAS,GAAG,CAAE,CAAC;EACxC,OAAOA,SAAS;AACjB;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AASA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASG,aAAaA,CACrBJ,MAAc,EACdK,MAAe,EACfC,WAA6B,EACX;EAClB,OAAO,IAAAC,gBAAO,EAAE,MAAM;IACrB,IAAKD,WAAW,EAAG;MAClB,OAAOA,WAAW;IACnB;IACA,MAAME,EAAE,GAAGT,QAAQ,CAAEC,MAAO,CAAC;IAE7B,OAAOK,MAAM,GAAI,GAAGA,MAAQ,IAAIG,EAAI,EAAC,GAAGA,EAAE;EAC3C,CAAC,EAAE,CAAER,MAAM,EAAEM,WAAW,EAAED,MAAM,CAAG,CAAC;AACrC;AAAC,IAAAI,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEcP,aAAa","ignoreList":[]}
@@ -9,6 +9,8 @@ var _element = require("@wordpress/element");
9
9
  * WordPress dependencies
10
10
  */
11
11
 
12
+ const matchMediaCache = new Map();
13
+
12
14
  /**
13
15
  * A new MediaQueryList object for the media query
14
16
  *
@@ -16,8 +18,17 @@ var _element = require("@wordpress/element");
16
18
  * @return {MediaQueryList|null} A new object for the media query
17
19
  */
18
20
  function getMediaQueryList(query) {
19
- if (query && typeof window !== 'undefined' && typeof window.matchMedia === 'function') {
20
- return window.matchMedia(query);
21
+ if (!query) {
22
+ return null;
23
+ }
24
+ let match = matchMediaCache.get(query);
25
+ if (match) {
26
+ return match;
27
+ }
28
+ if (typeof window !== 'undefined' && typeof window.matchMedia === 'function') {
29
+ match = window.matchMedia(query);
30
+ matchMediaCache.set(query, match);
31
+ return match;
21
32
  }
22
33
  return null;
23
34
  }
@@ -1 +1 @@
1
- {"version":3,"names":["_element","require","getMediaQueryList","query","window","matchMedia","useMediaQuery","source","useMemo","mediaQueryList","subscribe","onStoreChange","addEventListener","removeEventListener","getValue","_mediaQueryList$match","matches","useSyncExternalStore"],"sources":["@wordpress/compose/src/hooks/use-media-query/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useMemo, useSyncExternalStore } from '@wordpress/element';\n\n/**\n * A new MediaQueryList object for the media query\n *\n * @param {string} [query] Media Query.\n * @return {MediaQueryList|null} A new object for the media query\n */\nfunction getMediaQueryList( query ) {\n\tif (\n\t\tquery &&\n\t\ttypeof window !== 'undefined' &&\n\t\ttypeof window.matchMedia === 'function'\n\t) {\n\t\treturn window.matchMedia( query );\n\t}\n\n\treturn null;\n}\n\n/**\n * Runs a media query and returns its value when it changes.\n *\n * @param {string} [query] Media Query.\n * @return {boolean} return value of the media query.\n */\nexport default function useMediaQuery( query ) {\n\tconst source = useMemo( () => {\n\t\tconst mediaQueryList = getMediaQueryList( query );\n\n\t\treturn {\n\t\t\t/** @type {(onStoreChange: () => void) => () => void} */\n\t\t\tsubscribe( onStoreChange ) {\n\t\t\t\tif ( ! mediaQueryList ) {\n\t\t\t\t\treturn () => {};\n\t\t\t\t}\n\n\t\t\t\t// Avoid a fatal error when browsers don't support `addEventListener` on MediaQueryList.\n\t\t\t\tmediaQueryList.addEventListener?.( 'change', onStoreChange );\n\t\t\t\treturn () => {\n\t\t\t\t\tmediaQueryList.removeEventListener?.(\n\t\t\t\t\t\t'change',\n\t\t\t\t\t\tonStoreChange\n\t\t\t\t\t);\n\t\t\t\t};\n\t\t\t},\n\t\t\tgetValue() {\n\t\t\t\treturn mediaQueryList?.matches ?? false;\n\t\t\t},\n\t\t};\n\t}, [ query ] );\n\n\treturn useSyncExternalStore(\n\t\tsource.subscribe,\n\t\tsource.getValue,\n\t\t() => false\n\t);\n}\n"],"mappings":";;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,iBAAiBA,CAAEC,KAAK,EAAG;EACnC,IACCA,KAAK,IACL,OAAOC,MAAM,KAAK,WAAW,IAC7B,OAAOA,MAAM,CAACC,UAAU,KAAK,UAAU,EACtC;IACD,OAAOD,MAAM,CAACC,UAAU,CAAEF,KAAM,CAAC;EAClC;EAEA,OAAO,IAAI;AACZ;;AAEA;AACA;AACA;AACA;AACA;AACA;AACe,SAASG,aAAaA,CAAEH,KAAK,EAAG;EAC9C,MAAMI,MAAM,GAAG,IAAAC,gBAAO,EAAE,MAAM;IAC7B,MAAMC,cAAc,GAAGP,iBAAiB,CAAEC,KAAM,CAAC;IAEjD,OAAO;MACN;MACAO,SAASA,CAAEC,aAAa,EAAG;QAC1B,IAAK,CAAEF,cAAc,EAAG;UACvB,OAAO,MAAM,CAAC,CAAC;QAChB;;QAEA;QACAA,cAAc,CAACG,gBAAgB,GAAI,QAAQ,EAAED,aAAc,CAAC;QAC5D,OAAO,MAAM;UACZF,cAAc,CAACI,mBAAmB,GACjC,QAAQ,EACRF,aACD,CAAC;QACF,CAAC;MACF,CAAC;MACDG,QAAQA,CAAA,EAAG;QAAA,IAAAC,qBAAA;QACV,QAAAA,qBAAA,GAAON,cAAc,EAAEO,OAAO,cAAAD,qBAAA,cAAAA,qBAAA,GAAI,KAAK;MACxC;IACD,CAAC;EACF,CAAC,EAAE,CAAEZ,KAAK,CAAG,CAAC;EAEd,OAAO,IAAAc,6BAAoB,EAC1BV,MAAM,CAACG,SAAS,EAChBH,MAAM,CAACO,QAAQ,EACf,MAAM,KACP,CAAC;AACF","ignoreList":[]}
1
+ {"version":3,"names":["_element","require","matchMediaCache","Map","getMediaQueryList","query","match","get","window","matchMedia","set","useMediaQuery","source","useMemo","mediaQueryList","subscribe","onStoreChange","addEventListener","removeEventListener","getValue","_mediaQueryList$match","matches","useSyncExternalStore"],"sources":["@wordpress/compose/src/hooks/use-media-query/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useMemo, useSyncExternalStore } from '@wordpress/element';\n\nconst matchMediaCache = new Map();\n\n/**\n * A new MediaQueryList object for the media query\n *\n * @param {string} [query] Media Query.\n * @return {MediaQueryList|null} A new object for the media query\n */\nfunction getMediaQueryList( query ) {\n\tif ( ! query ) {\n\t\treturn null;\n\t}\n\n\tlet match = matchMediaCache.get( query );\n\n\tif ( match ) {\n\t\treturn match;\n\t}\n\n\tif (\n\t\ttypeof window !== 'undefined' &&\n\t\ttypeof window.matchMedia === 'function'\n\t) {\n\t\tmatch = window.matchMedia( query );\n\t\tmatchMediaCache.set( query, match );\n\t\treturn match;\n\t}\n\n\treturn null;\n}\n\n/**\n * Runs a media query and returns its value when it changes.\n *\n * @param {string} [query] Media Query.\n * @return {boolean} return value of the media query.\n */\nexport default function useMediaQuery( query ) {\n\tconst source = useMemo( () => {\n\t\tconst mediaQueryList = getMediaQueryList( query );\n\n\t\treturn {\n\t\t\t/** @type {(onStoreChange: () => void) => () => void} */\n\t\t\tsubscribe( onStoreChange ) {\n\t\t\t\tif ( ! mediaQueryList ) {\n\t\t\t\t\treturn () => {};\n\t\t\t\t}\n\n\t\t\t\t// Avoid a fatal error when browsers don't support `addEventListener` on MediaQueryList.\n\t\t\t\tmediaQueryList.addEventListener?.( 'change', onStoreChange );\n\t\t\t\treturn () => {\n\t\t\t\t\tmediaQueryList.removeEventListener?.(\n\t\t\t\t\t\t'change',\n\t\t\t\t\t\tonStoreChange\n\t\t\t\t\t);\n\t\t\t\t};\n\t\t\t},\n\t\t\tgetValue() {\n\t\t\t\treturn mediaQueryList?.matches ?? false;\n\t\t\t},\n\t\t};\n\t}, [ query ] );\n\n\treturn useSyncExternalStore(\n\t\tsource.subscribe,\n\t\tsource.getValue,\n\t\t() => false\n\t);\n}\n"],"mappings":";;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AAHA;AACA;AACA;;AAGA,MAAMC,eAAe,GAAG,IAAIC,GAAG,CAAC,CAAC;;AAEjC;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,iBAAiBA,CAAEC,KAAK,EAAG;EACnC,IAAK,CAAEA,KAAK,EAAG;IACd,OAAO,IAAI;EACZ;EAEA,IAAIC,KAAK,GAAGJ,eAAe,CAACK,GAAG,CAAEF,KAAM,CAAC;EAExC,IAAKC,KAAK,EAAG;IACZ,OAAOA,KAAK;EACb;EAEA,IACC,OAAOE,MAAM,KAAK,WAAW,IAC7B,OAAOA,MAAM,CAACC,UAAU,KAAK,UAAU,EACtC;IACDH,KAAK,GAAGE,MAAM,CAACC,UAAU,CAAEJ,KAAM,CAAC;IAClCH,eAAe,CAACQ,GAAG,CAAEL,KAAK,EAAEC,KAAM,CAAC;IACnC,OAAOA,KAAK;EACb;EAEA,OAAO,IAAI;AACZ;;AAEA;AACA;AACA;AACA;AACA;AACA;AACe,SAASK,aAAaA,CAAEN,KAAK,EAAG;EAC9C,MAAMO,MAAM,GAAG,IAAAC,gBAAO,EAAE,MAAM;IAC7B,MAAMC,cAAc,GAAGV,iBAAiB,CAAEC,KAAM,CAAC;IAEjD,OAAO;MACN;MACAU,SAASA,CAAEC,aAAa,EAAG;QAC1B,IAAK,CAAEF,cAAc,EAAG;UACvB,OAAO,MAAM,CAAC,CAAC;QAChB;;QAEA;QACAA,cAAc,CAACG,gBAAgB,GAAI,QAAQ,EAAED,aAAc,CAAC;QAC5D,OAAO,MAAM;UACZF,cAAc,CAACI,mBAAmB,GACjC,QAAQ,EACRF,aACD,CAAC;QACF,CAAC;MACF,CAAC;MACDG,QAAQA,CAAA,EAAG;QAAA,IAAAC,qBAAA;QACV,QAAAA,qBAAA,GAAON,cAAc,EAAEO,OAAO,cAAAD,qBAAA,cAAAA,qBAAA,GAAI,KAAK;MACxC;IACD,CAAC;EACF,CAAC,EAAE,CAAEf,KAAK,CAAG,CAAC;EAEd,OAAO,IAAAiB,6BAAoB,EAC1BV,MAAM,CAACG,SAAS,EAChBH,MAAM,CAACO,QAAQ,EACf,MAAM,KACP,CAAC;AACF","ignoreList":[]}
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = useObservableValue;
7
+ var _element = require("@wordpress/element");
8
+ /**
9
+ * WordPress dependencies
10
+ */
11
+
12
+ /**
13
+ * Internal dependencies
14
+ */
15
+
16
+ /**
17
+ * React hook that lets you observe an entry in an `ObservableMap`. The hook returns the
18
+ * current value corresponding to the key, or `undefined` when there is no value stored.
19
+ * It also observes changes to the value and triggers an update of the calling component
20
+ * in case the value changes.
21
+ *
22
+ * @template K The type of the keys in the map.
23
+ * @template V The type of the values in the map.
24
+ * @param map The `ObservableMap` to observe.
25
+ * @param name The map key to observe.
26
+ * @return The value corresponding to the map key requested.
27
+ */
28
+ function useObservableValue(map, name) {
29
+ const [subscribe, getValue] = (0, _element.useMemo)(() => [listener => map.subscribe(name, listener), () => map.get(name)], [map, name]);
30
+ return (0, _element.useSyncExternalStore)(subscribe, getValue, getValue);
31
+ }
32
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_element","require","useObservableValue","map","name","subscribe","getValue","useMemo","listener","get","useSyncExternalStore"],"sources":["@wordpress/compose/src/hooks/use-observable-value/index.ts"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useMemo, useSyncExternalStore } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport type { ObservableMap } from '../../utils/observable-map';\n\n/**\n * React hook that lets you observe an entry in an `ObservableMap`. The hook returns the\n * current value corresponding to the key, or `undefined` when there is no value stored.\n * It also observes changes to the value and triggers an update of the calling component\n * in case the value changes.\n *\n * @template K The type of the keys in the map.\n * @template V The type of the values in the map.\n * @param map The `ObservableMap` to observe.\n * @param name The map key to observe.\n * @return The value corresponding to the map key requested.\n */\nexport default function useObservableValue< K, V >(\n\tmap: ObservableMap< K, V >,\n\tname: K\n): V | undefined {\n\tconst [ subscribe, getValue ] = useMemo(\n\t\t() => [\n\t\t\t( listener: () => void ) => map.subscribe( name, listener ),\n\t\t\t() => map.get( name ),\n\t\t],\n\t\t[ map, name ]\n\t);\n\treturn useSyncExternalStore( subscribe, getValue, getValue );\n}\n"],"mappings":";;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AAHA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASC,kBAAkBA,CACzCC,GAA0B,EAC1BC,IAAO,EACS;EAChB,MAAM,CAAEC,SAAS,EAAEC,QAAQ,CAAE,GAAG,IAAAC,gBAAO,EACtC,MAAM,CACHC,QAAoB,IAAML,GAAG,CAACE,SAAS,CAAED,IAAI,EAAEI,QAAS,CAAC,EAC3D,MAAML,GAAG,CAACM,GAAG,CAAEL,IAAK,CAAC,CACrB,EACD,CAAED,GAAG,EAAEC,IAAI,CACZ,CAAC;EACD,OAAO,IAAAM,6BAAoB,EAAEL,SAAS,EAAEC,QAAQ,EAAEA,QAAS,CAAC;AAC7D","ignoreList":[]}
package/build/index.js CHANGED
@@ -40,7 +40,8 @@ var _exportNames = {
40
40
  useRefEffect: true,
41
41
  __experimentalUseDropZone: true,
42
42
  useFocusableIframe: true,
43
- __experimentalUseFixedWindowList: true
43
+ __experimentalUseFixedWindowList: true,
44
+ useObservableValue: true
44
45
  };
45
46
  Object.defineProperty(exports, "__experimentalUseDialog", {
46
47
  enumerable: true,
@@ -186,6 +187,12 @@ Object.defineProperty(exports, "useMergeRefs", {
186
187
  return _useMergeRefs.default;
187
188
  }
188
189
  });
190
+ Object.defineProperty(exports, "useObservableValue", {
191
+ enumerable: true,
192
+ get: function () {
193
+ return _useObservableValue.default;
194
+ }
195
+ });
189
196
  Object.defineProperty(exports, "usePrevious", {
190
197
  enumerable: true,
191
198
  get: function () {
@@ -294,6 +301,18 @@ Object.keys(_throttle).forEach(function (key) {
294
301
  }
295
302
  });
296
303
  });
304
+ var _observableMap = require("./utils/observable-map");
305
+ Object.keys(_observableMap).forEach(function (key) {
306
+ if (key === "default" || key === "__esModule") return;
307
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
308
+ if (key in exports && exports[key] === _observableMap[key]) return;
309
+ Object.defineProperty(exports, key, {
310
+ enumerable: true,
311
+ get: function () {
312
+ return _observableMap[key];
313
+ }
314
+ });
315
+ });
297
316
  var _compose = _interopRequireDefault(require("./higher-order/compose"));
298
317
  var _pipe = _interopRequireDefault(require("./higher-order/pipe"));
299
318
  var _ifCondition = _interopRequireDefault(require("./higher-order/if-condition"));
@@ -330,4 +349,5 @@ var _useRefEffect = _interopRequireDefault(require("./hooks/use-ref-effect"));
330
349
  var _useDropZone = _interopRequireDefault(require("./hooks/use-drop-zone"));
331
350
  var _useFocusableIframe = _interopRequireDefault(require("./hooks/use-focusable-iframe"));
332
351
  var _useFixedWindowList = _interopRequireDefault(require("./hooks/use-fixed-window-list"));
352
+ var _useObservableValue = _interopRequireDefault(require("./hooks/use-observable-value"));
333
353
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_createHigherOrderComponent","require","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_debounce","_throttle","_compose","_interopRequireDefault","_pipe","_ifCondition","_pure","_withGlobalEvents","_withInstanceId","_withSafeTimeout","_withState","_useConstrainedTabbing","_useCopyOnClick","_useCopyToClipboard","_useDialog","_useDisabled","_useDragging","_useFocusOnMount","_useFocusOutside","_useFocusReturn","_useInstanceId","_useIsomorphicLayoutEffect","_useKeyboardShortcut","_useMediaQuery","_usePrevious","_useReducedMotion","_useStateWithHistory","_useViewportMatch","_useResizeObserver","_useAsyncList","_useWarnOnChange","_useDebounce","_useDebouncedInput","_useThrottle","_useMergeRefs","_useRefEffect","_useDropZone","_useFocusableIframe","_useFixedWindowList"],"sources":["@wordpress/compose/src/index.js"],"sourcesContent":["// The `createHigherOrderComponent` helper and helper types.\nexport * from './utils/create-higher-order-component';\n// The `debounce` helper and its types.\nexport * from './utils/debounce';\n// The `throttle` helper and its types.\nexport * from './utils/throttle';\n\n// The `compose` and `pipe` helpers (inspired by `flowRight` and `flow` from Lodash).\nexport { default as compose } from './higher-order/compose';\nexport { default as pipe } from './higher-order/pipe';\n\n// Higher-order components.\nexport { default as ifCondition } from './higher-order/if-condition';\nexport { default as pure } from './higher-order/pure';\nexport { default as withGlobalEvents } from './higher-order/with-global-events';\nexport { default as withInstanceId } from './higher-order/with-instance-id';\nexport { default as withSafeTimeout } from './higher-order/with-safe-timeout';\nexport { default as withState } from './higher-order/with-state';\n\n// Hooks.\nexport { default as useConstrainedTabbing } from './hooks/use-constrained-tabbing';\nexport { default as useCopyOnClick } from './hooks/use-copy-on-click';\nexport { default as useCopyToClipboard } from './hooks/use-copy-to-clipboard';\nexport { default as __experimentalUseDialog } from './hooks/use-dialog';\nexport { default as useDisabled } from './hooks/use-disabled';\nexport { default as __experimentalUseDragging } from './hooks/use-dragging';\nexport { default as useFocusOnMount } from './hooks/use-focus-on-mount';\nexport { default as __experimentalUseFocusOutside } from './hooks/use-focus-outside';\nexport { default as useFocusReturn } from './hooks/use-focus-return';\nexport { default as useInstanceId } from './hooks/use-instance-id';\nexport { default as useIsomorphicLayoutEffect } from './hooks/use-isomorphic-layout-effect';\nexport { default as useKeyboardShortcut } from './hooks/use-keyboard-shortcut';\nexport { default as useMediaQuery } from './hooks/use-media-query';\nexport { default as usePrevious } from './hooks/use-previous';\nexport { default as useReducedMotion } from './hooks/use-reduced-motion';\nexport { default as useStateWithHistory } from './hooks/use-state-with-history';\nexport { default as useViewportMatch } from './hooks/use-viewport-match';\nexport { default as useResizeObserver } from './hooks/use-resize-observer';\nexport { default as useAsyncList } from './hooks/use-async-list';\nexport { default as useWarnOnChange } from './hooks/use-warn-on-change';\nexport { default as useDebounce } from './hooks/use-debounce';\nexport { default as useDebouncedInput } from './hooks/use-debounced-input';\nexport { default as useThrottle } from './hooks/use-throttle';\nexport { default as useMergeRefs } from './hooks/use-merge-refs';\nexport { default as useRefEffect } from './hooks/use-ref-effect';\nexport { default as __experimentalUseDropZone } from './hooks/use-drop-zone';\nexport { default as useFocusableIframe } from './hooks/use-focusable-iframe';\nexport { default as __experimentalUseFixedWindowList } from './hooks/use-fixed-window-list';\n"],"mappings":";;;;;;;;;;;;;;;;;;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AAA;AACA,IAAAiC,cAAA,GAAAjB,sBAAA,CAAAhB,OAAA;AACA,IAAAkC,0BAAA,GAAAlB,sBAAA,CAAAhB,OAAA;AACA,IAAAmC,oBAAA,GAAAnB,sBAAA,CAAAhB,OAAA;AACA,IAAAoC,cAAA,GAAApB,sBAAA,CAAAhB,OAAA;AACA,IAAAqC,YAAA,GAAArB,sBAAA,CAAAhB,OAAA;AACA,IAAAsC,iBAAA,GAAAtB,sBAAA,CAAAhB,OAAA;AACA,IAAAuC,oBAAA,GAAAvB,sBAAA,CAAAhB,OAAA;AACA,IAAAwC,iBAAA,GAAAxB,sBAAA,CAAAhB,OAAA;AACA,IAAAyC,kBAAA,GAAAzB,sBAAA,CAAAhB,OAAA;AACA,IAAA0C,aAAA,GAAA1B,sBAAA,CAAAhB,OAAA;AACA,IAAA2C,gBAAA,GAAA3B,sBAAA,CAAAhB,OAAA;AACA,IAAA4C,YAAA,GAAA5B,sBAAA,CAAAhB,OAAA;AACA,IAAA6C,kBAAA,GAAA7B,sBAAA,CAAAhB,OAAA;AACA,IAAA8C,YAAA,GAAA9B,sBAAA,CAAAhB,OAAA;AACA,IAAA+C,aAAA,GAAA/B,sBAAA,CAAAhB,OAAA;AACA,IAAAgD,aAAA,GAAAhC,sBAAA,CAAAhB,OAAA;AACA,IAAAiD,YAAA,GAAAjC,sBAAA,CAAAhB,OAAA;AACA,IAAAkD,mBAAA,GAAAlC,sBAAA,CAAAhB,OAAA;AACA,IAAAmD,mBAAA,GAAAnC,sBAAA,CAAAhB,OAAA","ignoreList":[]}
1
+ {"version":3,"names":["_createHigherOrderComponent","require","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_debounce","_throttle","_observableMap","_compose","_interopRequireDefault","_pipe","_ifCondition","_pure","_withGlobalEvents","_withInstanceId","_withSafeTimeout","_withState","_useConstrainedTabbing","_useCopyOnClick","_useCopyToClipboard","_useDialog","_useDisabled","_useDragging","_useFocusOnMount","_useFocusOutside","_useFocusReturn","_useInstanceId","_useIsomorphicLayoutEffect","_useKeyboardShortcut","_useMediaQuery","_usePrevious","_useReducedMotion","_useStateWithHistory","_useViewportMatch","_useResizeObserver","_useAsyncList","_useWarnOnChange","_useDebounce","_useDebouncedInput","_useThrottle","_useMergeRefs","_useRefEffect","_useDropZone","_useFocusableIframe","_useFixedWindowList","_useObservableValue"],"sources":["@wordpress/compose/src/index.js"],"sourcesContent":["// The `createHigherOrderComponent` helper and helper types.\nexport * from './utils/create-higher-order-component';\n// The `debounce` helper and its types.\nexport * from './utils/debounce';\n// The `throttle` helper and its types.\nexport * from './utils/throttle';\n// The `ObservableMap` data structure\nexport * from './utils/observable-map';\n\n// The `compose` and `pipe` helpers (inspired by `flowRight` and `flow` from Lodash).\nexport { default as compose } from './higher-order/compose';\nexport { default as pipe } from './higher-order/pipe';\n\n// Higher-order components.\nexport { default as ifCondition } from './higher-order/if-condition';\nexport { default as pure } from './higher-order/pure';\nexport { default as withGlobalEvents } from './higher-order/with-global-events';\nexport { default as withInstanceId } from './higher-order/with-instance-id';\nexport { default as withSafeTimeout } from './higher-order/with-safe-timeout';\nexport { default as withState } from './higher-order/with-state';\n\n// Hooks.\nexport { default as useConstrainedTabbing } from './hooks/use-constrained-tabbing';\nexport { default as useCopyOnClick } from './hooks/use-copy-on-click';\nexport { default as useCopyToClipboard } from './hooks/use-copy-to-clipboard';\nexport { default as __experimentalUseDialog } from './hooks/use-dialog';\nexport { default as useDisabled } from './hooks/use-disabled';\nexport { default as __experimentalUseDragging } from './hooks/use-dragging';\nexport { default as useFocusOnMount } from './hooks/use-focus-on-mount';\nexport { default as __experimentalUseFocusOutside } from './hooks/use-focus-outside';\nexport { default as useFocusReturn } from './hooks/use-focus-return';\nexport { default as useInstanceId } from './hooks/use-instance-id';\nexport { default as useIsomorphicLayoutEffect } from './hooks/use-isomorphic-layout-effect';\nexport { default as useKeyboardShortcut } from './hooks/use-keyboard-shortcut';\nexport { default as useMediaQuery } from './hooks/use-media-query';\nexport { default as usePrevious } from './hooks/use-previous';\nexport { default as useReducedMotion } from './hooks/use-reduced-motion';\nexport { default as useStateWithHistory } from './hooks/use-state-with-history';\nexport { default as useViewportMatch } from './hooks/use-viewport-match';\nexport { default as useResizeObserver } from './hooks/use-resize-observer';\nexport { default as useAsyncList } from './hooks/use-async-list';\nexport { default as useWarnOnChange } from './hooks/use-warn-on-change';\nexport { default as useDebounce } from './hooks/use-debounce';\nexport { default as useDebouncedInput } from './hooks/use-debounced-input';\nexport { default as useThrottle } from './hooks/use-throttle';\nexport { default as useMergeRefs } from './hooks/use-merge-refs';\nexport { default as useRefEffect } from './hooks/use-ref-effect';\nexport { default as __experimentalUseDropZone } from './hooks/use-drop-zone';\nexport { default as useFocusableIframe } from './hooks/use-focusable-iframe';\nexport { default as __experimentalUseFixedWindowList } from './hooks/use-fixed-window-list';\nexport { default as useObservableValue } from './hooks/use-observable-value';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,IAAAA,2BAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,2BAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAL,2BAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAS,cAAA,CA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ApB,sBAAA,CAAAjB,OAAA;AACA,IAAAsC,YAAA,GAAArB,sBAAA,CAAAjB,OAAA;AACA,IAAAuC,iBAAA,GAAAtB,sBAAA,CAAAjB,OAAA;AACA,IAAAwC,oBAAA,GAAAvB,sBAAA,CAAAjB,OAAA;AACA,IAAAyC,iBAAA,GAAAxB,sBAAA,CAAAjB,OAAA;AACA,IAAA0C,kBAAA,GAAAzB,sBAAA,CAAAjB,OAAA;AACA,IAAA2C,aAAA,GAAA1B,sBAAA,CAAAjB,OAAA;AACA,IAAA4C,gBAAA,GAAA3B,sBAAA,CAAAjB,OAAA;AACA,IAAA6C,YAAA,GAAA5B,sBAAA,CAAAjB,OAAA;AACA,IAAA8C,kBAAA,GAAA7B,sBAAA,CAAAjB,OAAA;AACA,IAAA+C,YAAA,GAAA9B,sBAAA,CAAAjB,OAAA;AACA,IAAAgD,aAAA,GAAA/B,sBAAA,CAAAjB,OAAA;AACA,IAAAiD,aAAA,GAAAhC,sBAAA,CAAAjB,OAAA;AACA,IAAAkD,YAAA,GAAAjC,sBAAA,CAAAjB,OAAA;AACA,IAAAmD,mBAAA,GAAAlC,sBAAA,CAAAjB,OAAA;AACA,IAAAoD,mBAAA,GAAAnC,sBAAA,CAAAjB,OAAA;AACA,IAAAqD,mBAAA,GAAApC,sBAAA,CAAAjB,OAAA","ignoreList":[]}
@@ -33,7 +33,8 @@ var _exportNames = {
33
33
  useThrottle: true,
34
34
  useMergeRefs: true,
35
35
  useRefEffect: true,
36
- useNetworkConnectivity: true
36
+ useNetworkConnectivity: true,
37
+ useObservableValue: true
37
38
  };
38
39
  Object.defineProperty(exports, "__experimentalUseDragging", {
39
40
  enumerable: true,
@@ -125,6 +126,12 @@ Object.defineProperty(exports, "useNetworkConnectivity", {
125
126
  return _useNetworkConnectivity.default;
126
127
  }
127
128
  });
129
+ Object.defineProperty(exports, "useObservableValue", {
130
+ enumerable: true,
131
+ get: function () {
132
+ return _useObservableValue.default;
133
+ }
134
+ });
128
135
  Object.defineProperty(exports, "usePreferredColorScheme", {
129
136
  enumerable: true,
130
137
  get: function () {
@@ -245,6 +252,18 @@ Object.keys(_throttle).forEach(function (key) {
245
252
  }
246
253
  });
247
254
  });
255
+ var _observableMap = require("./utils/observable-map");
256
+ Object.keys(_observableMap).forEach(function (key) {
257
+ if (key === "default" || key === "__esModule") return;
258
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
259
+ if (key in exports && exports[key] === _observableMap[key]) return;
260
+ Object.defineProperty(exports, key, {
261
+ enumerable: true,
262
+ get: function () {
263
+ return _observableMap[key];
264
+ }
265
+ });
266
+ });
248
267
  var _compose = _interopRequireDefault(require("./higher-order/compose"));
249
268
  var _pipe = _interopRequireDefault(require("./higher-order/pipe"));
250
269
  var _ifCondition = _interopRequireDefault(require("./higher-order/if-condition"));
@@ -274,4 +293,5 @@ var _useThrottle = _interopRequireDefault(require("./hooks/use-throttle"));
274
293
  var _useMergeRefs = _interopRequireDefault(require("./hooks/use-merge-refs"));
275
294
  var _useRefEffect = _interopRequireDefault(require("./hooks/use-ref-effect"));
276
295
  var _useNetworkConnectivity = _interopRequireDefault(require("./hooks/use-network-connectivity"));
296
+ var _useObservableValue = _interopRequireDefault(require("./hooks/use-observable-value"));
277
297
  //# sourceMappingURL=index.native.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_createHigherOrderComponent","require","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_debounce","_throttle","_compose","_interopRequireDefault","_pipe","_ifCondition","_pure","_withGlobalEvents","_withInstanceId","_withSafeTimeout","_withState","_withPreferredColorScheme","_withNetworkConnectivity","_useConstrainedTabbing","_useDragging","_useFocusOutside","_useInstanceId","_useIsomorphicLayoutEffect","_useKeyboardShortcut","_useMediaQuery","_usePrevious","_useReducedMotion","_useViewportMatch","_usePreferredColorScheme","_usePreferredColorSchemeStyle","_useResizeObserver","_useDebounce","_useDebouncedInput","_useThrottle","_useMergeRefs","_useRefEffect","_useNetworkConnectivity"],"sources":["@wordpress/compose/src/index.native.js"],"sourcesContent":["// The `createHigherOrderComponent` helper and helper types.\nexport * from './utils/create-higher-order-component';\n// The `debounce` helper and its types.\nexport * from './utils/debounce';\n// The `throttle` helper and its types.\nexport * from './utils/throttle';\n\n// The `compose` and `pipe` helpers (inspired by `flowRight` and `flow` from Lodash).\nexport { default as compose } from './higher-order/compose';\nexport { default as pipe } from './higher-order/pipe';\n\n// Higher-order components.\nexport { default as ifCondition } from './higher-order/if-condition';\nexport { default as pure } from './higher-order/pure';\nexport { default as withGlobalEvents } from './higher-order/with-global-events';\nexport { default as withInstanceId } from './higher-order/with-instance-id';\nexport { default as withSafeTimeout } from './higher-order/with-safe-timeout';\nexport { default as withState } from './higher-order/with-state';\nexport { default as withPreferredColorScheme } from './higher-order/with-preferred-color-scheme';\nexport { default as withNetworkConnectivity } from './higher-order/with-network-connectivity';\n\n// Hooks.\nexport { default as useConstrainedTabbing } from './hooks/use-constrained-tabbing';\nexport { default as __experimentalUseDragging } from './hooks/use-dragging';\nexport { default as __experimentalUseFocusOutside } from './hooks/use-focus-outside';\nexport { default as useInstanceId } from './hooks/use-instance-id';\nexport { default as useIsomorphicLayoutEffect } from './hooks/use-isomorphic-layout-effect';\nexport { default as useKeyboardShortcut } from './hooks/use-keyboard-shortcut';\nexport { default as useMediaQuery } from './hooks/use-media-query';\nexport { default as usePrevious } from './hooks/use-previous';\nexport { default as useReducedMotion } from './hooks/use-reduced-motion';\nexport { default as useViewportMatch } from './hooks/use-viewport-match';\nexport { default as usePreferredColorScheme } from './hooks/use-preferred-color-scheme';\nexport { default as usePreferredColorSchemeStyle } from './hooks/use-preferred-color-scheme-style';\nexport { default as useResizeObserver } from './hooks/use-resize-observer';\nexport { default as useDebounce } from './hooks/use-debounce';\nexport { default as useDebouncedInput } from './hooks/use-debounced-input';\nexport { default as useThrottle } from './hooks/use-throttle';\nexport { default as useMergeRefs } from './hooks/use-merge-refs';\nexport { default as useRefEffect } from './hooks/use-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AAhB,sBAAA,CAAAhB,OAAA;AACA,IAAAiC,YAAA,GAAAjB,sBAAA,CAAAhB,OAAA;AACA,IAAAkC,iBAAA,GAAAlB,sBAAA,CAAAhB,OAAA;AACA,IAAAmC,iBAAA,GAAAnB,sBAAA,CAAAhB,OAAA;AACA,IAAAoC,wBAAA,GAAApB,sBAAA,CAAAhB,OAAA;AACA,IAAAqC,6BAAA,GAAArB,sBAAA,CAAAhB,OAAA;AACA,IAAAsC,kBAAA,GAAAtB,sBAAA,CAAAhB,OAAA;AACA,IAAAuC,YAAA,GAAAvB,sBAAA,CAAAhB,OAAA;AACA,IAAAwC,kBAAA,GAAAxB,sBAAA,CAAAhB,OAAA;AACA,IAAAyC,YAAA,GAAAzB,sBAAA,CAAAhB,OAAA;AACA,IAAA0C,aAAA,GAAA1B,sBAAA,CAAAhB,OAAA;AACA,IAAA2C,aAAA,GAAA3B,sBAAA,CAAAhB,OAAA;AACA,IAAA4C,uBAAA,GAAA5B,sBAAA,CAAAhB,OAAA","ignoreList":[]}
1
+ {"version":3,"names":["_createHigherOrderComponent","require","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_debounce","_throttle","_observableMap","_compose","_interopRequireDefault","_pipe","_ifCondition","_pure","_withGlobalEvents","_withInstanceId","_withSafeTimeout","_withState","_withPreferredColorScheme","_withNetworkConnectivity","_useConstrainedTabbing","_useDragging","_useFocusOutside","_useInstanceId","_useIsomorphicLayoutEffect","_useKeyboardShortcut","_useMediaQuery","_usePrevious","_useReducedMotion","_useViewportMatch","_usePreferredColorScheme","_usePreferredColorSchemeStyle","_useResizeObserver","_useDebounce","_useDebouncedInput","_useThrottle","_useMergeRefs","_useRefEffect","_useNetworkConnectivity","_useObservableValue"],"sources":["@wordpress/compose/src/index.native.js"],"sourcesContent":["// The `createHigherOrderComponent` helper and helper types.\nexport * from './utils/create-higher-order-component';\n// The `debounce` helper and its types.\nexport * from './utils/debounce';\n// The `throttle` helper and its types.\nexport * from './utils/throttle';\n// The `ObservableMap` data structure\nexport * from './utils/observable-map';\n\n// The `compose` and `pipe` helpers (inspired by `flowRight` and `flow` from Lodash).\nexport { default as compose } from './higher-order/compose';\nexport { default as pipe } from './higher-order/pipe';\n\n// Higher-order components.\nexport { default as ifCondition } from './higher-order/if-condition';\nexport { default as pure } from './higher-order/pure';\nexport { default as withGlobalEvents } from './higher-order/with-global-events';\nexport { default as withInstanceId } from './higher-order/with-instance-id';\nexport { default as withSafeTimeout } from './higher-order/with-safe-timeout';\nexport { default as withState } from './higher-order/with-state';\nexport { default as withPreferredColorScheme } from './higher-order/with-preferred-color-scheme';\nexport { default as withNetworkConnectivity } from './higher-order/with-network-connectivity';\n\n// Hooks.\nexport { default as useConstrainedTabbing } from './hooks/use-constrained-tabbing';\nexport { default as __experimentalUseDragging } from './hooks/use-dragging';\nexport { default as __experimentalUseFocusOutside } from './hooks/use-focus-outside';\nexport { default as useInstanceId } from './hooks/use-instance-id';\nexport { default as useIsomorphicLayoutEffect } from './hooks/use-isomorphic-layout-effect';\nexport { default as useKeyboardShortcut } from './hooks/use-keyboard-shortcut';\nexport { default as useMediaQuery } from './hooks/use-media-query';\nexport { default as usePrevious } from './hooks/use-previous';\nexport { default as useReducedMotion } from './hooks/use-reduced-motion';\nexport { default as useViewportMatch } from './hooks/use-viewport-match';\nexport { default as usePreferredColorScheme } from './hooks/use-preferred-color-scheme';\nexport { default as usePreferredColorSchemeStyle } from './hooks/use-preferred-color-scheme-style';\nexport { default as useResizeObserver } from './hooks/use-resize-observer';\nexport { default as useDebounce } from './hooks/use-debounce';\nexport { default as useDebouncedInput } from './hooks/use-debounced-input';\nexport { default as useThrottle } from './hooks/use-throttle';\nexport { default as useMergeRefs } from './hooks/use-merge-refs';\nexport { default as useRefEffect } from './hooks/use-ref-effect';\nexport { default as useNetworkConnectivity } from './hooks/use-network-connectivity';\nexport { default as useObservableValue } from './hooks/use-observable-value';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;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AA;AACA,IAAA0B,wBAAA,GAAAT,sBAAA,CAAAjB,OAAA;AAGA,IAAA2B,sBAAA,GAAAV,sBAAA,CAAAjB,OAAA;AACA,IAAA4B,YAAA,GAAAX,sBAAA,CAAAjB,OAAA;AACA,IAAA6B,gBAAA,GAAAZ,sBAAA,CAAAjB,OAAA;AACA,IAAA8B,cAAA,GAAAb,sBAAA,CAAAjB,OAAA;AACA,IAAA+B,0BAAA,GAAAd,sBAAA,CAAAjB,OAAA;AACA,IAAAgC,oBAAA,GAAAf,sBAAA,CAAAjB,OAAA;AACA,IAAAiC,cAAA,GAAAhB,sBAAA,CAAAjB,OAAA;AACA,IAAAkC,YAAA,GAAAjB,sBAAA,CAAAjB,OAAA;AACA,IAAAmC,iBAAA,GAAAlB,sBAAA,CAAAjB,OAAA;AACA,IAAAoC,iBAAA,GAAAnB,sBAAA,CAAAjB,OAAA;AACA,IAAAqC,wBAAA,GAAApB,sBAAA,CAAAjB,OAAA;AACA,IAAAsC,6BAAA,GAAArB,sBAAA,CAAAjB,OAAA;AACA,IAAAuC,kBAAA,GAAAtB,sBAAA,CAAAjB,OAAA;AACA,IAAAwC,YAAA,GAAAvB,sBAAA,CAAAjB,OAAA;AACA,IAAAyC,kBAAA,GAAAxB,sBAAA,CAAAjB,OAAA;AACA,IAAA0C,YAAA,GAAAzB,sBAAA,CAAAjB,OAAA;AACA,IAAA2C,aAAA,GAAA1B,sBAAA,CAAAjB,OAAA;AACA,IAAA4C,aAAA,GAAA3B,sBAAA,CAAAjB,OAAA;AACA,IAAA6C,uBAAA,GAAA5B,sBAAA,CAAAjB,OAAA;AACA,IAAA8C,mBAAA,GAAA7B,sBAAA,CAAAjB,OAAA","ignoreList":[]}
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.observableMap = observableMap;
7
+ /**
8
+ * A constructor (factory) for `ObservableMap`, a map-like key/value data structure
9
+ * where the individual entries are observable: using the `subscribe` method, you can
10
+ * subscribe to updates for a particular keys. Each subscriber always observes one
11
+ * specific key and is not notified about any unrelated changes (for different keys)
12
+ * in the `ObservableMap`.
13
+ *
14
+ * @template K The type of the keys in the map.
15
+ * @template V The type of the values in the map.
16
+ * @return A new instance of the `ObservableMap` type.
17
+ */
18
+ function observableMap() {
19
+ const map = new Map();
20
+ const listeners = new Map();
21
+ function callListeners(name) {
22
+ const list = listeners.get(name);
23
+ if (!list) {
24
+ return;
25
+ }
26
+ for (const listener of list) {
27
+ listener();
28
+ }
29
+ }
30
+ return {
31
+ get(name) {
32
+ return map.get(name);
33
+ },
34
+ set(name, value) {
35
+ map.set(name, value);
36
+ callListeners(name);
37
+ },
38
+ delete(name) {
39
+ map.delete(name);
40
+ callListeners(name);
41
+ },
42
+ subscribe(name, listener) {
43
+ let list = listeners.get(name);
44
+ if (!list) {
45
+ list = new Set();
46
+ listeners.set(name, list);
47
+ }
48
+ list.add(listener);
49
+ return () => {
50
+ list.delete(listener);
51
+ if (list.size === 0) {
52
+ listeners.delete(name);
53
+ }
54
+ };
55
+ }
56
+ };
57
+ }
58
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["observableMap","map","Map","listeners","callListeners","name","list","get","listener","set","value","delete","subscribe","Set","add","size"],"sources":["@wordpress/compose/src/utils/observable-map/index.ts"],"sourcesContent":["export type ObservableMap< K, V > = {\n\tget( name: K ): V | undefined;\n\tset( name: K, value: V ): void;\n\tdelete( name: K ): void;\n\tsubscribe( name: K, listener: () => void ): () => void;\n};\n\n/**\n * A constructor (factory) for `ObservableMap`, a map-like key/value data structure\n * where the individual entries are observable: using the `subscribe` method, you can\n * subscribe to updates for a particular keys. Each subscriber always observes one\n * specific key and is not notified about any unrelated changes (for different keys)\n * in the `ObservableMap`.\n *\n * @template K The type of the keys in the map.\n * @template V The type of the values in the map.\n * @return A new instance of the `ObservableMap` type.\n */\nexport function observableMap< K, V >(): ObservableMap< K, V > {\n\tconst map = new Map< K, V >();\n\tconst listeners = new Map< K, Set< () => void > >();\n\n\tfunction callListeners( name: K ) {\n\t\tconst list = listeners.get( name );\n\t\tif ( ! list ) {\n\t\t\treturn;\n\t\t}\n\t\tfor ( const listener of list ) {\n\t\t\tlistener();\n\t\t}\n\t}\n\n\treturn {\n\t\tget( name ) {\n\t\t\treturn map.get( name );\n\t\t},\n\t\tset( name, value ) {\n\t\t\tmap.set( name, value );\n\t\t\tcallListeners( name );\n\t\t},\n\t\tdelete( name ) {\n\t\t\tmap.delete( name );\n\t\t\tcallListeners( name );\n\t\t},\n\t\tsubscribe( name, listener ) {\n\t\t\tlet list = listeners.get( name );\n\t\t\tif ( ! list ) {\n\t\t\t\tlist = new Set();\n\t\t\t\tlisteners.set( name, list );\n\t\t\t}\n\t\t\tlist.add( listener );\n\n\t\t\treturn () => {\n\t\t\t\tlist.delete( listener );\n\t\t\t\tif ( list.size === 0 ) {\n\t\t\t\t\tlisteners.delete( name );\n\t\t\t\t}\n\t\t\t};\n\t\t},\n\t};\n}\n"],"mappings":";;;;;;AAOA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,aAAaA,CAAA,EAAkC;EAC9D,MAAMC,GAAG,GAAG,IAAIC,GAAG,CAAS,CAAC;EAC7B,MAAMC,SAAS,GAAG,IAAID,GAAG,CAAyB,CAAC;EAEnD,SAASE,aAAaA,CAAEC,IAAO,EAAG;IACjC,MAAMC,IAAI,GAAGH,SAAS,CAACI,GAAG,CAAEF,IAAK,CAAC;IAClC,IAAK,CAAEC,IAAI,EAAG;MACb;IACD;IACA,KAAM,MAAME,QAAQ,IAAIF,IAAI,EAAG;MAC9BE,QAAQ,CAAC,CAAC;IACX;EACD;EAEA,OAAO;IACND,GAAGA,CAAEF,IAAI,EAAG;MACX,OAAOJ,GAAG,CAACM,GAAG,CAAEF,IAAK,CAAC;IACvB,CAAC;IACDI,GAAGA,CAAEJ,IAAI,EAAEK,KAAK,EAAG;MAClBT,GAAG,CAACQ,GAAG,CAAEJ,IAAI,EAAEK,KAAM,CAAC;MACtBN,aAAa,CAAEC,IAAK,CAAC;IACtB,CAAC;IACDM,MAAMA,CAAEN,IAAI,EAAG;MACdJ,GAAG,CAACU,MAAM,CAAEN,IAAK,CAAC;MAClBD,aAAa,CAAEC,IAAK,CAAC;IACtB,CAAC;IACDO,SAASA,CAAEP,IAAI,EAAEG,QAAQ,EAAG;MAC3B,IAAIF,IAAI,GAAGH,SAAS,CAACI,GAAG,CAAEF,IAAK,CAAC;MAChC,IAAK,CAAEC,IAAI,EAAG;QACbA,IAAI,GAAG,IAAIO,GAAG,CAAC,CAAC;QAChBV,SAAS,CAACM,GAAG,CAAEJ,IAAI,EAAEC,IAAK,CAAC;MAC5B;MACAA,IAAI,CAACQ,GAAG,CAAEN,QAAS,CAAC;MAEpB,OAAO,MAAM;QACZF,IAAI,CAACK,MAAM,CAAEH,QAAS,CAAC;QACvB,IAAKF,IAAI,CAACS,IAAI,KAAK,CAAC,EAAG;UACtBZ,SAAS,CAACQ,MAAM,CAAEN,IAAK,CAAC;QACzB;MACD,CAAC;IACF;EACD,CAAC;AACF","ignoreList":[]}
@@ -18,11 +18,15 @@ export default function useFocusableIframe() {
18
18
  const {
19
19
  ownerDocument
20
20
  } = element;
21
- if (!ownerDocument) return;
21
+ if (!ownerDocument) {
22
+ return;
23
+ }
22
24
  const {
23
25
  defaultView
24
26
  } = ownerDocument;
25
- if (!defaultView) return;
27
+ if (!defaultView) {
28
+ return;
29
+ }
26
30
 
27
31
  /**
28
32
  * Checks whether the iframe is the activeElement, inferring that it has
@@ -1 +1 @@
1
- {"version":3,"names":["useRefEffect","useFocusableIframe","element","ownerDocument","defaultView","checkFocus","activeElement","focus","addEventListener","removeEventListener"],"sources":["@wordpress/compose/src/hooks/use-focusable-iframe/index.ts"],"sourcesContent":["/**\n * External dependencies\n */\nimport type { RefCallback } from 'react';\n\n/**\n * Internal dependencies\n */\nimport useRefEffect from '../use-ref-effect';\n\n/**\n * Dispatches a bubbling focus event when the iframe receives focus. Use\n * `onFocus` as usual on the iframe or a parent element.\n *\n * @return Ref to pass to the iframe.\n */\nexport default function useFocusableIframe(): RefCallback< HTMLIFrameElement > {\n\treturn useRefEffect( ( element ) => {\n\t\tconst { ownerDocument } = element;\n\t\tif ( ! ownerDocument ) return;\n\t\tconst { defaultView } = ownerDocument;\n\t\tif ( ! defaultView ) return;\n\n\t\t/**\n\t\t * Checks whether the iframe is the activeElement, inferring that it has\n\t\t * then received focus, and dispatches a focus event.\n\t\t */\n\t\tfunction checkFocus() {\n\t\t\tif ( ownerDocument && ownerDocument.activeElement === element ) {\n\t\t\t\t( element as HTMLElement ).focus();\n\t\t\t}\n\t\t}\n\n\t\tdefaultView.addEventListener( 'blur', checkFocus );\n\t\treturn () => {\n\t\t\tdefaultView.removeEventListener( 'blur', checkFocus );\n\t\t};\n\t}, [] );\n}\n"],"mappings":"AAAA;AACA;AACA;;AAGA;AACA;AACA;AACA,OAAOA,YAAY,MAAM,mBAAmB;;AAE5C;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,kBAAkBA,CAAA,EAAqC;EAC9E,OAAOD,YAAY,CAAIE,OAAO,IAAM;IACnC,MAAM;MAAEC;IAAc,CAAC,GAAGD,OAAO;IACjC,IAAK,CAAEC,aAAa,EAAG;IACvB,MAAM;MAAEC;IAAY,CAAC,GAAGD,aAAa;IACrC,IAAK,CAAEC,WAAW,EAAG;;IAErB;AACF;AACA;AACA;IACE,SAASC,UAAUA,CAAA,EAAG;MACrB,IAAKF,aAAa,IAAIA,aAAa,CAACG,aAAa,KAAKJ,OAAO,EAAG;QAC7DA,OAAO,CAAkBK,KAAK,CAAC,CAAC;MACnC;IACD;IAEAH,WAAW,CAACI,gBAAgB,CAAE,MAAM,EAAEH,UAAW,CAAC;IAClD,OAAO,MAAM;MACZD,WAAW,CAACK,mBAAmB,CAAE,MAAM,EAAEJ,UAAW,CAAC;IACtD,CAAC;EACF,CAAC,EAAE,EAAG,CAAC;AACR","ignoreList":[]}
1
+ {"version":3,"names":["useRefEffect","useFocusableIframe","element","ownerDocument","defaultView","checkFocus","activeElement","focus","addEventListener","removeEventListener"],"sources":["@wordpress/compose/src/hooks/use-focusable-iframe/index.ts"],"sourcesContent":["/**\n * External dependencies\n */\nimport type { RefCallback } from 'react';\n\n/**\n * Internal dependencies\n */\nimport useRefEffect from '../use-ref-effect';\n\n/**\n * Dispatches a bubbling focus event when the iframe receives focus. Use\n * `onFocus` as usual on the iframe or a parent element.\n *\n * @return Ref to pass to the iframe.\n */\nexport default function useFocusableIframe(): RefCallback< HTMLIFrameElement > {\n\treturn useRefEffect( ( element ) => {\n\t\tconst { ownerDocument } = element;\n\t\tif ( ! ownerDocument ) {\n\t\t\treturn;\n\t\t}\n\t\tconst { defaultView } = ownerDocument;\n\t\tif ( ! defaultView ) {\n\t\t\treturn;\n\t\t}\n\n\t\t/**\n\t\t * Checks whether the iframe is the activeElement, inferring that it has\n\t\t * then received focus, and dispatches a focus event.\n\t\t */\n\t\tfunction checkFocus() {\n\t\t\tif ( ownerDocument && ownerDocument.activeElement === element ) {\n\t\t\t\t( element as HTMLElement ).focus();\n\t\t\t}\n\t\t}\n\n\t\tdefaultView.addEventListener( 'blur', checkFocus );\n\t\treturn () => {\n\t\t\tdefaultView.removeEventListener( 'blur', checkFocus );\n\t\t};\n\t}, [] );\n}\n"],"mappings":"AAAA;AACA;AACA;;AAGA;AACA;AACA;AACA,OAAOA,YAAY,MAAM,mBAAmB;;AAE5C;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,kBAAkBA,CAAA,EAAqC;EAC9E,OAAOD,YAAY,CAAIE,OAAO,IAAM;IACnC,MAAM;MAAEC;IAAc,CAAC,GAAGD,OAAO;IACjC,IAAK,CAAEC,aAAa,EAAG;MACtB;IACD;IACA,MAAM;MAAEC;IAAY,CAAC,GAAGD,aAAa;IACrC,IAAK,CAAEC,WAAW,EAAG;MACpB;IACD;;IAEA;AACF;AACA;AACA;IACE,SAASC,UAAUA,CAAA,EAAG;MACrB,IAAKF,aAAa,IAAIA,aAAa,CAACG,aAAa,KAAKJ,OAAO,EAAG;QAC7DA,OAAO,CAAkBK,KAAK,CAAC,CAAC;MACnC;IACD;IAEAH,WAAW,CAACI,gBAAgB,CAAE,MAAM,EAAEH,UAAW,CAAC;IAClD,OAAO,MAAM;MACZD,WAAW,CAACK,mBAAmB,CAAE,MAAM,EAAEJ,UAAW,CAAC;IACtD,CAAC;EACF,CAAC,EAAE,EAAG,CAAC;AACR","ignoreList":[]}
@@ -39,7 +39,9 @@ function createId(object) {
39
39
  */
40
40
  function useInstanceId(object, prefix, preferredId) {
41
41
  return useMemo(() => {
42
- if (preferredId) return preferredId;
42
+ if (preferredId) {
43
+ return preferredId;
44
+ }
43
45
  const id = createId(object);
44
46
  return prefix ? `${prefix}-${id}` : id;
45
47
  }, [object, preferredId, prefix]);
@@ -1 +1 @@
1
- {"version":3,"names":["useMemo","instanceMap","WeakMap","createId","object","instances","get","set","useInstanceId","prefix","preferredId","id"],"sources":["@wordpress/compose/src/hooks/use-instance-id/index.ts"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useMemo } from '@wordpress/element';\n\nconst instanceMap = new WeakMap< object, number >();\n\n/**\n * Creates a new id for a given object.\n *\n * @param object Object reference to create an id for.\n * @return The instance id (index).\n */\nfunction createId( object: object ): number {\n\tconst instances = instanceMap.get( object ) || 0;\n\tinstanceMap.set( object, instances + 1 );\n\treturn instances;\n}\n\n/**\n * Specify the useInstanceId *function* signatures.\n *\n * More accurately, useInstanceId distinguishes between three different\n * signatures:\n *\n * 1. When only object is given, the returned value is a number\n * 2. When object and prefix is given, the returned value is a string\n * 3. When preferredId is given, the returned value is the type of preferredId\n *\n * @param object Object reference to create an id for.\n */\nfunction useInstanceId( object: object ): number;\nfunction useInstanceId( object: object, prefix: string ): string;\nfunction useInstanceId< T extends string | number >(\n\tobject: object,\n\tprefix: string,\n\tpreferredId?: T\n): T;\n\n/**\n * Provides a unique instance ID.\n *\n * @param object Object reference to create an id for.\n * @param [prefix] Prefix for the unique id.\n * @param [preferredId] Default ID to use.\n * @return The unique instance id.\n */\nfunction useInstanceId(\n\tobject: object,\n\tprefix?: string,\n\tpreferredId?: string | number\n): string | number {\n\treturn useMemo( () => {\n\t\tif ( preferredId ) return preferredId;\n\t\tconst id = createId( object );\n\n\t\treturn prefix ? `${ prefix }-${ id }` : id;\n\t}, [ object, preferredId, prefix ] );\n}\n\nexport default useInstanceId;\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,OAAO,QAAQ,oBAAoB;AAE5C,MAAMC,WAAW,GAAG,IAAIC,OAAO,CAAmB,CAAC;;AAEnD;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,QAAQA,CAAEC,MAAc,EAAW;EAC3C,MAAMC,SAAS,GAAGJ,WAAW,CAACK,GAAG,CAAEF,MAAO,CAAC,IAAI,CAAC;EAChDH,WAAW,CAACM,GAAG,CAAEH,MAAM,EAAEC,SAAS,GAAG,CAAE,CAAC;EACxC,OAAOA,SAAS;AACjB;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AASA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASG,aAAaA,CACrBJ,MAAc,EACdK,MAAe,EACfC,WAA6B,EACX;EAClB,OAAOV,OAAO,CAAE,MAAM;IACrB,IAAKU,WAAW,EAAG,OAAOA,WAAW;IACrC,MAAMC,EAAE,GAAGR,QAAQ,CAAEC,MAAO,CAAC;IAE7B,OAAOK,MAAM,GAAI,GAAGA,MAAQ,IAAIE,EAAI,EAAC,GAAGA,EAAE;EAC3C,CAAC,EAAE,CAAEP,MAAM,EAAEM,WAAW,EAAED,MAAM,CAAG,CAAC;AACrC;AAEA,eAAeD,aAAa","ignoreList":[]}
1
+ {"version":3,"names":["useMemo","instanceMap","WeakMap","createId","object","instances","get","set","useInstanceId","prefix","preferredId","id"],"sources":["@wordpress/compose/src/hooks/use-instance-id/index.ts"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useMemo } from '@wordpress/element';\n\nconst instanceMap = new WeakMap< object, number >();\n\n/**\n * Creates a new id for a given object.\n *\n * @param object Object reference to create an id for.\n * @return The instance id (index).\n */\nfunction createId( object: object ): number {\n\tconst instances = instanceMap.get( object ) || 0;\n\tinstanceMap.set( object, instances + 1 );\n\treturn instances;\n}\n\n/**\n * Specify the useInstanceId *function* signatures.\n *\n * More accurately, useInstanceId distinguishes between three different\n * signatures:\n *\n * 1. When only object is given, the returned value is a number\n * 2. When object and prefix is given, the returned value is a string\n * 3. When preferredId is given, the returned value is the type of preferredId\n *\n * @param object Object reference to create an id for.\n */\nfunction useInstanceId( object: object ): number;\nfunction useInstanceId( object: object, prefix: string ): string;\nfunction useInstanceId< T extends string | number >(\n\tobject: object,\n\tprefix: string,\n\tpreferredId?: T\n): T;\n\n/**\n * Provides a unique instance ID.\n *\n * @param object Object reference to create an id for.\n * @param [prefix] Prefix for the unique id.\n * @param [preferredId] Default ID to use.\n * @return The unique instance id.\n */\nfunction useInstanceId(\n\tobject: object,\n\tprefix?: string,\n\tpreferredId?: string | number\n): string | number {\n\treturn useMemo( () => {\n\t\tif ( preferredId ) {\n\t\t\treturn preferredId;\n\t\t}\n\t\tconst id = createId( object );\n\n\t\treturn prefix ? `${ prefix }-${ id }` : id;\n\t}, [ object, preferredId, prefix ] );\n}\n\nexport default useInstanceId;\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,OAAO,QAAQ,oBAAoB;AAE5C,MAAMC,WAAW,GAAG,IAAIC,OAAO,CAAmB,CAAC;;AAEnD;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,QAAQA,CAAEC,MAAc,EAAW;EAC3C,MAAMC,SAAS,GAAGJ,WAAW,CAACK,GAAG,CAAEF,MAAO,CAAC,IAAI,CAAC;EAChDH,WAAW,CAACM,GAAG,CAAEH,MAAM,EAAEC,SAAS,GAAG,CAAE,CAAC;EACxC,OAAOA,SAAS;AACjB;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AASA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASG,aAAaA,CACrBJ,MAAc,EACdK,MAAe,EACfC,WAA6B,EACX;EAClB,OAAOV,OAAO,CAAE,MAAM;IACrB,IAAKU,WAAW,EAAG;MAClB,OAAOA,WAAW;IACnB;IACA,MAAMC,EAAE,GAAGR,QAAQ,CAAEC,MAAO,CAAC;IAE7B,OAAOK,MAAM,GAAI,GAAGA,MAAQ,IAAIE,EAAI,EAAC,GAAGA,EAAE;EAC3C,CAAC,EAAE,CAAEP,MAAM,EAAEM,WAAW,EAAED,MAAM,CAAG,CAAC;AACrC;AAEA,eAAeD,aAAa","ignoreList":[]}
@@ -2,6 +2,7 @@
2
2
  * WordPress dependencies
3
3
  */
4
4
  import { useMemo, useSyncExternalStore } from '@wordpress/element';
5
+ const matchMediaCache = new Map();
5
6
 
6
7
  /**
7
8
  * A new MediaQueryList object for the media query
@@ -10,8 +11,17 @@ import { useMemo, useSyncExternalStore } from '@wordpress/element';
10
11
  * @return {MediaQueryList|null} A new object for the media query
11
12
  */
12
13
  function getMediaQueryList(query) {
13
- if (query && typeof window !== 'undefined' && typeof window.matchMedia === 'function') {
14
- return window.matchMedia(query);
14
+ if (!query) {
15
+ return null;
16
+ }
17
+ let match = matchMediaCache.get(query);
18
+ if (match) {
19
+ return match;
20
+ }
21
+ if (typeof window !== 'undefined' && typeof window.matchMedia === 'function') {
22
+ match = window.matchMedia(query);
23
+ matchMediaCache.set(query, match);
24
+ return match;
15
25
  }
16
26
  return null;
17
27
  }
@@ -1 +1 @@
1
- {"version":3,"names":["useMemo","useSyncExternalStore","getMediaQueryList","query","window","matchMedia","useMediaQuery","source","mediaQueryList","subscribe","onStoreChange","addEventListener","removeEventListener","getValue","_mediaQueryList$match","matches"],"sources":["@wordpress/compose/src/hooks/use-media-query/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useMemo, useSyncExternalStore } from '@wordpress/element';\n\n/**\n * A new MediaQueryList object for the media query\n *\n * @param {string} [query] Media Query.\n * @return {MediaQueryList|null} A new object for the media query\n */\nfunction getMediaQueryList( query ) {\n\tif (\n\t\tquery &&\n\t\ttypeof window !== 'undefined' &&\n\t\ttypeof window.matchMedia === 'function'\n\t) {\n\t\treturn window.matchMedia( query );\n\t}\n\n\treturn null;\n}\n\n/**\n * Runs a media query and returns its value when it changes.\n *\n * @param {string} [query] Media Query.\n * @return {boolean} return value of the media query.\n */\nexport default function useMediaQuery( query ) {\n\tconst source = useMemo( () => {\n\t\tconst mediaQueryList = getMediaQueryList( query );\n\n\t\treturn {\n\t\t\t/** @type {(onStoreChange: () => void) => () => void} */\n\t\t\tsubscribe( onStoreChange ) {\n\t\t\t\tif ( ! mediaQueryList ) {\n\t\t\t\t\treturn () => {};\n\t\t\t\t}\n\n\t\t\t\t// Avoid a fatal error when browsers don't support `addEventListener` on MediaQueryList.\n\t\t\t\tmediaQueryList.addEventListener?.( 'change', onStoreChange );\n\t\t\t\treturn () => {\n\t\t\t\t\tmediaQueryList.removeEventListener?.(\n\t\t\t\t\t\t'change',\n\t\t\t\t\t\tonStoreChange\n\t\t\t\t\t);\n\t\t\t\t};\n\t\t\t},\n\t\t\tgetValue() {\n\t\t\t\treturn mediaQueryList?.matches ?? false;\n\t\t\t},\n\t\t};\n\t}, [ query ] );\n\n\treturn useSyncExternalStore(\n\t\tsource.subscribe,\n\t\tsource.getValue,\n\t\t() => false\n\t);\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,OAAO,EAAEC,oBAAoB,QAAQ,oBAAoB;;AAElE;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,iBAAiBA,CAAEC,KAAK,EAAG;EACnC,IACCA,KAAK,IACL,OAAOC,MAAM,KAAK,WAAW,IAC7B,OAAOA,MAAM,CAACC,UAAU,KAAK,UAAU,EACtC;IACD,OAAOD,MAAM,CAACC,UAAU,CAAEF,KAAM,CAAC;EAClC;EAEA,OAAO,IAAI;AACZ;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASG,aAAaA,CAAEH,KAAK,EAAG;EAC9C,MAAMI,MAAM,GAAGP,OAAO,CAAE,MAAM;IAC7B,MAAMQ,cAAc,GAAGN,iBAAiB,CAAEC,KAAM,CAAC;IAEjD,OAAO;MACN;MACAM,SAASA,CAAEC,aAAa,EAAG;QAC1B,IAAK,CAAEF,cAAc,EAAG;UACvB,OAAO,MAAM,CAAC,CAAC;QAChB;;QAEA;QACAA,cAAc,CAACG,gBAAgB,GAAI,QAAQ,EAAED,aAAc,CAAC;QAC5D,OAAO,MAAM;UACZF,cAAc,CAACI,mBAAmB,GACjC,QAAQ,EACRF,aACD,CAAC;QACF,CAAC;MACF,CAAC;MACDG,QAAQA,CAAA,EAAG;QAAA,IAAAC,qBAAA;QACV,QAAAA,qBAAA,GAAON,cAAc,EAAEO,OAAO,cAAAD,qBAAA,cAAAA,qBAAA,GAAI,KAAK;MACxC;IACD,CAAC;EACF,CAAC,EAAE,CAAEX,KAAK,CAAG,CAAC;EAEd,OAAOF,oBAAoB,CAC1BM,MAAM,CAACE,SAAS,EAChBF,MAAM,CAACM,QAAQ,EACf,MAAM,KACP,CAAC;AACF","ignoreList":[]}
1
+ {"version":3,"names":["useMemo","useSyncExternalStore","matchMediaCache","Map","getMediaQueryList","query","match","get","window","matchMedia","set","useMediaQuery","source","mediaQueryList","subscribe","onStoreChange","addEventListener","removeEventListener","getValue","_mediaQueryList$match","matches"],"sources":["@wordpress/compose/src/hooks/use-media-query/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useMemo, useSyncExternalStore } from '@wordpress/element';\n\nconst matchMediaCache = new Map();\n\n/**\n * A new MediaQueryList object for the media query\n *\n * @param {string} [query] Media Query.\n * @return {MediaQueryList|null} A new object for the media query\n */\nfunction getMediaQueryList( query ) {\n\tif ( ! query ) {\n\t\treturn null;\n\t}\n\n\tlet match = matchMediaCache.get( query );\n\n\tif ( match ) {\n\t\treturn match;\n\t}\n\n\tif (\n\t\ttypeof window !== 'undefined' &&\n\t\ttypeof window.matchMedia === 'function'\n\t) {\n\t\tmatch = window.matchMedia( query );\n\t\tmatchMediaCache.set( query, match );\n\t\treturn match;\n\t}\n\n\treturn null;\n}\n\n/**\n * Runs a media query and returns its value when it changes.\n *\n * @param {string} [query] Media Query.\n * @return {boolean} return value of the media query.\n */\nexport default function useMediaQuery( query ) {\n\tconst source = useMemo( () => {\n\t\tconst mediaQueryList = getMediaQueryList( query );\n\n\t\treturn {\n\t\t\t/** @type {(onStoreChange: () => void) => () => void} */\n\t\t\tsubscribe( onStoreChange ) {\n\t\t\t\tif ( ! mediaQueryList ) {\n\t\t\t\t\treturn () => {};\n\t\t\t\t}\n\n\t\t\t\t// Avoid a fatal error when browsers don't support `addEventListener` on MediaQueryList.\n\t\t\t\tmediaQueryList.addEventListener?.( 'change', onStoreChange );\n\t\t\t\treturn () => {\n\t\t\t\t\tmediaQueryList.removeEventListener?.(\n\t\t\t\t\t\t'change',\n\t\t\t\t\t\tonStoreChange\n\t\t\t\t\t);\n\t\t\t\t};\n\t\t\t},\n\t\t\tgetValue() {\n\t\t\t\treturn mediaQueryList?.matches ?? false;\n\t\t\t},\n\t\t};\n\t}, [ query ] );\n\n\treturn useSyncExternalStore(\n\t\tsource.subscribe,\n\t\tsource.getValue,\n\t\t() => false\n\t);\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,OAAO,EAAEC,oBAAoB,QAAQ,oBAAoB;AAElE,MAAMC,eAAe,GAAG,IAAIC,GAAG,CAAC,CAAC;;AAEjC;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,iBAAiBA,CAAEC,KAAK,EAAG;EACnC,IAAK,CAAEA,KAAK,EAAG;IACd,OAAO,IAAI;EACZ;EAEA,IAAIC,KAAK,GAAGJ,eAAe,CAACK,GAAG,CAAEF,KAAM,CAAC;EAExC,IAAKC,KAAK,EAAG;IACZ,OAAOA,KAAK;EACb;EAEA,IACC,OAAOE,MAAM,KAAK,WAAW,IAC7B,OAAOA,MAAM,CAACC,UAAU,KAAK,UAAU,EACtC;IACDH,KAAK,GAAGE,MAAM,CAACC,UAAU,CAAEJ,KAAM,CAAC;IAClCH,eAAe,CAACQ,GAAG,CAAEL,KAAK,EAAEC,KAAM,CAAC;IACnC,OAAOA,KAAK;EACb;EAEA,OAAO,IAAI;AACZ;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASK,aAAaA,CAAEN,KAAK,EAAG;EAC9C,MAAMO,MAAM,GAAGZ,OAAO,CAAE,MAAM;IAC7B,MAAMa,cAAc,GAAGT,iBAAiB,CAAEC,KAAM,CAAC;IAEjD,OAAO;MACN;MACAS,SAASA,CAAEC,aAAa,EAAG;QAC1B,IAAK,CAAEF,cAAc,EAAG;UACvB,OAAO,MAAM,CAAC,CAAC;QAChB;;QAEA;QACAA,cAAc,CAACG,gBAAgB,GAAI,QAAQ,EAAED,aAAc,CAAC;QAC5D,OAAO,MAAM;UACZF,cAAc,CAACI,mBAAmB,GACjC,QAAQ,EACRF,aACD,CAAC;QACF,CAAC;MACF,CAAC;MACDG,QAAQA,CAAA,EAAG;QAAA,IAAAC,qBAAA;QACV,QAAAA,qBAAA,GAAON,cAAc,EAAEO,OAAO,cAAAD,qBAAA,cAAAA,qBAAA,GAAI,KAAK;MACxC;IACD,CAAC;EACF,CAAC,EAAE,CAAEd,KAAK,CAAG,CAAC;EAEd,OAAOJ,oBAAoB,CAC1BW,MAAM,CAACE,SAAS,EAChBF,MAAM,CAACM,QAAQ,EACf,MAAM,KACP,CAAC;AACF","ignoreList":[]}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { useMemo, useSyncExternalStore } from '@wordpress/element';
5
+
6
+ /**
7
+ * Internal dependencies
8
+ */
9
+
10
+ /**
11
+ * React hook that lets you observe an entry in an `ObservableMap`. The hook returns the
12
+ * current value corresponding to the key, or `undefined` when there is no value stored.
13
+ * It also observes changes to the value and triggers an update of the calling component
14
+ * in case the value changes.
15
+ *
16
+ * @template K The type of the keys in the map.
17
+ * @template V The type of the values in the map.
18
+ * @param map The `ObservableMap` to observe.
19
+ * @param name The map key to observe.
20
+ * @return The value corresponding to the map key requested.
21
+ */
22
+ export default function useObservableValue(map, name) {
23
+ const [subscribe, getValue] = useMemo(() => [listener => map.subscribe(name, listener), () => map.get(name)], [map, name]);
24
+ return useSyncExternalStore(subscribe, getValue, getValue);
25
+ }
26
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["useMemo","useSyncExternalStore","useObservableValue","map","name","subscribe","getValue","listener","get"],"sources":["@wordpress/compose/src/hooks/use-observable-value/index.ts"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useMemo, useSyncExternalStore } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport type { ObservableMap } from '../../utils/observable-map';\n\n/**\n * React hook that lets you observe an entry in an `ObservableMap`. The hook returns the\n * current value corresponding to the key, or `undefined` when there is no value stored.\n * It also observes changes to the value and triggers an update of the calling component\n * in case the value changes.\n *\n * @template K The type of the keys in the map.\n * @template V The type of the values in the map.\n * @param map The `ObservableMap` to observe.\n * @param name The map key to observe.\n * @return The value corresponding to the map key requested.\n */\nexport default function useObservableValue< K, V >(\n\tmap: ObservableMap< K, V >,\n\tname: K\n): V | undefined {\n\tconst [ subscribe, getValue ] = useMemo(\n\t\t() => [\n\t\t\t( listener: () => void ) => map.subscribe( name, listener ),\n\t\t\t() => map.get( name ),\n\t\t],\n\t\t[ map, name ]\n\t);\n\treturn useSyncExternalStore( subscribe, getValue, getValue );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,OAAO,EAAEC,oBAAoB,QAAQ,oBAAoB;;AAElE;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,kBAAkBA,CACzCC,GAA0B,EAC1BC,IAAO,EACS;EAChB,MAAM,CAAEC,SAAS,EAAEC,QAAQ,CAAE,GAAGN,OAAO,CACtC,MAAM,CACHO,QAAoB,IAAMJ,GAAG,CAACE,SAAS,CAAED,IAAI,EAAEG,QAAS,CAAC,EAC3D,MAAMJ,GAAG,CAACK,GAAG,CAAEJ,IAAK,CAAC,CACrB,EACD,CAAED,GAAG,EAAEC,IAAI,CACZ,CAAC;EACD,OAAOH,oBAAoB,CAAEI,SAAS,EAAEC,QAAQ,EAAEA,QAAS,CAAC;AAC7D","ignoreList":[]}
@@ -4,6 +4,8 @@ export * from './utils/create-higher-order-component';
4
4
  export * from './utils/debounce';
5
5
  // The `throttle` helper and its types.
6
6
  export * from './utils/throttle';
7
+ // The `ObservableMap` data structure
8
+ export * from './utils/observable-map';
7
9
 
8
10
  // The `compose` and `pipe` helpers (inspired by `flowRight` and `flow` from Lodash).
9
11
  export { default as compose } from './higher-order/compose';
@@ -46,4 +48,5 @@ export { default as useRefEffect } from './hooks/use-ref-effect';
46
48
  export { default as __experimentalUseDropZone } from './hooks/use-drop-zone';
47
49
  export { default as useFocusableIframe } from './hooks/use-focusable-iframe';
48
50
  export { default as __experimentalUseFixedWindowList } from './hooks/use-fixed-window-list';
51
+ export { default as useObservableValue } from './hooks/use-observable-value';
49
52
  //# sourceMappingURL=index.js.map