@wordpress/format-library 3.0.5 → 3.0.9

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 (79) hide show
  1. package/build/bold/index.js +8 -6
  2. package/build/bold/index.js.map +1 -1
  3. package/build/code/index.js +8 -6
  4. package/build/code/index.js.map +1 -1
  5. package/build/image/index.js +27 -23
  6. package/build/image/index.js.map +1 -1
  7. package/build/index.js +7 -4
  8. package/build/index.js.map +1 -1
  9. package/build/italic/index.js +8 -6
  10. package/build/italic/index.js.map +1 -1
  11. package/build/keyboard/index.js +8 -6
  12. package/build/keyboard/index.js.map +1 -1
  13. package/build/link/index.js +15 -12
  14. package/build/link/index.js.map +1 -1
  15. package/build/link/inline.js +22 -11
  16. package/build/link/inline.js.map +1 -1
  17. package/build/link/modal-screens/link-picker-screen.native.js +6 -4
  18. package/build/link/modal-screens/link-picker-screen.native.js.map +1 -1
  19. package/build/link/modal-screens/link-settings-screen.native.js +15 -12
  20. package/build/link/modal-screens/link-settings-screen.native.js.map +1 -1
  21. package/build/link/modal.native.js +5 -4
  22. package/build/link/modal.native.js.map +1 -1
  23. package/build/link/use-link-instance-key.js +40 -0
  24. package/build/link/use-link-instance-key.js.map +1 -0
  25. package/build/link/utils.js +11 -8
  26. package/build/link/utils.js.map +1 -1
  27. package/build/strikethrough/index.js +8 -6
  28. package/build/strikethrough/index.js.map +1 -1
  29. package/build/subscript/index.js +8 -6
  30. package/build/subscript/index.js.map +1 -1
  31. package/build/superscript/index.js +8 -6
  32. package/build/superscript/index.js.map +1 -1
  33. package/build/text-color/index.js +18 -13
  34. package/build/text-color/index.js.map +1 -1
  35. package/build/text-color/inline.js +22 -16
  36. package/build/text-color/inline.js.map +1 -1
  37. package/build/underline/index.js +6 -4
  38. package/build/underline/index.js.map +1 -1
  39. package/build-module/bold/index.js +8 -6
  40. package/build-module/bold/index.js.map +1 -1
  41. package/build-module/code/index.js +8 -6
  42. package/build-module/code/index.js.map +1 -1
  43. package/build-module/image/index.js +27 -23
  44. package/build-module/image/index.js.map +1 -1
  45. package/build-module/index.js +7 -4
  46. package/build-module/index.js.map +1 -1
  47. package/build-module/italic/index.js +8 -6
  48. package/build-module/italic/index.js.map +1 -1
  49. package/build-module/keyboard/index.js +8 -6
  50. package/build-module/keyboard/index.js.map +1 -1
  51. package/build-module/link/index.js +15 -12
  52. package/build-module/link/index.js.map +1 -1
  53. package/build-module/link/inline.js +19 -11
  54. package/build-module/link/inline.js.map +1 -1
  55. package/build-module/link/modal-screens/link-picker-screen.native.js +6 -4
  56. package/build-module/link/modal-screens/link-picker-screen.native.js.map +1 -1
  57. package/build-module/link/modal-screens/link-settings-screen.native.js +15 -12
  58. package/build-module/link/modal-screens/link-settings-screen.native.js.map +1 -1
  59. package/build-module/link/modal.native.js +5 -4
  60. package/build-module/link/modal.native.js.map +1 -1
  61. package/build-module/link/use-link-instance-key.js +33 -0
  62. package/build-module/link/use-link-instance-key.js.map +1 -0
  63. package/build-module/link/utils.js +10 -7
  64. package/build-module/link/utils.js.map +1 -1
  65. package/build-module/strikethrough/index.js +8 -6
  66. package/build-module/strikethrough/index.js.map +1 -1
  67. package/build-module/subscript/index.js +8 -6
  68. package/build-module/subscript/index.js.map +1 -1
  69. package/build-module/superscript/index.js +8 -6
  70. package/build-module/superscript/index.js.map +1 -1
  71. package/build-module/text-color/index.js +14 -11
  72. package/build-module/text-color/index.js.map +1 -1
  73. package/build-module/text-color/inline.js +21 -15
  74. package/build-module/text-color/inline.js.map +1 -1
  75. package/build-module/underline/index.js +6 -4
  76. package/build-module/underline/index.js.map +1 -1
  77. package/package.json +16 -16
  78. package/src/link/inline.js +8 -0
  79. package/src/link/use-link-instance-key.js +34 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/format-library",
3
- "version": "3.0.5",
3
+ "version": "3.0.9",
4
4
  "description": "Format library for the WordPress editor.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -25,24 +25,24 @@
25
25
  "module": "build-module/index.js",
26
26
  "react-native": "src/index",
27
27
  "dependencies": {
28
- "@babel/runtime": "^7.13.10",
29
- "@wordpress/a11y": "^3.2.3",
30
- "@wordpress/block-editor": "^8.0.0",
31
- "@wordpress/components": "^19.0.1",
32
- "@wordpress/compose": "^5.0.5",
33
- "@wordpress/data": "^6.1.3",
34
- "@wordpress/dom": "^3.2.6",
35
- "@wordpress/element": "^4.0.3",
36
- "@wordpress/html-entities": "^3.2.2",
37
- "@wordpress/i18n": "^4.2.3",
38
- "@wordpress/icons": "^6.1.0",
39
- "@wordpress/keycodes": "^3.2.3",
40
- "@wordpress/rich-text": "^5.0.5",
41
- "@wordpress/url": "^3.3.0",
28
+ "@babel/runtime": "^7.16.0",
29
+ "@wordpress/a11y": "^3.2.4",
30
+ "@wordpress/block-editor": "^8.0.3",
31
+ "@wordpress/components": "^19.0.3",
32
+ "@wordpress/compose": "^5.0.6",
33
+ "@wordpress/data": "^6.1.4",
34
+ "@wordpress/dom": "^3.2.7",
35
+ "@wordpress/element": "^4.0.4",
36
+ "@wordpress/html-entities": "^3.2.3",
37
+ "@wordpress/i18n": "^4.2.4",
38
+ "@wordpress/icons": "^6.1.1",
39
+ "@wordpress/keycodes": "^3.2.4",
40
+ "@wordpress/rich-text": "^5.0.6",
41
+ "@wordpress/url": "^3.3.1",
42
42
  "lodash": "^4.17.21"
43
43
  },
44
44
  "publishConfig": {
45
45
  "access": "public"
46
46
  },
47
- "gitHead": "393c2b5533837fd637e998d23f0124c081a10df0"
47
+ "gitHead": "c6594e767659bd3289e633a17c44fdf6a4933194"
48
48
  }
@@ -26,6 +26,7 @@ import { useSelect } from '@wordpress/data';
26
26
  */
27
27
  import { createLinkFormat, isValidHref, getFormatBoundary } from './utils';
28
28
  import { link as settings } from './index';
29
+ import useLinkInstanceKey from './use-link-instance-key';
29
30
 
30
31
  function InlineLinkUI( {
31
32
  isActive,
@@ -184,6 +185,12 @@ function InlineLinkUI( {
184
185
 
185
186
  const anchorRef = useAnchorRef( { ref: contentRef, value, settings } );
186
187
 
188
+ // Generate a string based key that is unique to this anchor reference.
189
+ // This is used to force re-mount the LinkControl component to avoid
190
+ // potential stale state bugs caused by the component not being remounted
191
+ // See https://github.com/WordPress/gutenberg/pull/34742.
192
+ const forceRemountKey = useLinkInstanceKey( anchorRef );
193
+
187
194
  // The focusOnMount prop shouldn't evolve during render of a Popover
188
195
  // otherwise it causes a render of the content.
189
196
  const focusOnMount = useRef( addingLink ? 'firstElement' : false );
@@ -222,6 +229,7 @@ function InlineLinkUI( {
222
229
  position="bottom center"
223
230
  >
224
231
  <LinkControl
232
+ key={ forceRemountKey }
225
233
  value={ linkValue }
226
234
  onChange={ onChangeLink }
227
235
  onRemove={ removeLink }
@@ -0,0 +1,34 @@
1
+ // Weakly referenced map allows unused ids to be garbage collected.
2
+ const weakMap = new WeakMap();
3
+
4
+ // Incrementing zero-based ID value
5
+ let id = -1;
6
+
7
+ const prefix = 'link-control-instance';
8
+
9
+ function getKey( _id ) {
10
+ return `${ prefix }-${ _id }`;
11
+ }
12
+
13
+ /**
14
+ * Builds a unique link control key for the given object reference.
15
+ *
16
+ * @param {Object} instance an unique object reference specific to this link control instance.
17
+ * @return {string} the unique key to use for this link control.
18
+ */
19
+ function useLinkInstanceKey( instance ) {
20
+ if ( ! instance ) {
21
+ return;
22
+ }
23
+ if ( weakMap.has( instance ) ) {
24
+ return getKey( weakMap.get( instance ) );
25
+ }
26
+
27
+ id += 1;
28
+
29
+ weakMap.set( instance, id );
30
+
31
+ return getKey( id );
32
+ }
33
+
34
+ export default useLinkInstanceKey;