@wordpress/format-library 3.0.2 → 3.0.6

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 (71) hide show
  1. package/README.md +1 -1
  2. package/build/bold/index.js +5 -2
  3. package/build/bold/index.js.map +1 -1
  4. package/build/code/index.js +4 -2
  5. package/build/code/index.js.map +1 -1
  6. package/build/italic/index.js +5 -2
  7. package/build/italic/index.js.map +1 -1
  8. package/build/keyboard/index.js +4 -2
  9. package/build/keyboard/index.js.map +1 -1
  10. package/build/link/inline.js +110 -6
  11. package/build/link/inline.js.map +1 -1
  12. package/build/link/use-link-instance-key.js +36 -0
  13. package/build/link/use-link-instance-key.js.map +1 -0
  14. package/build/link/utils.js +112 -0
  15. package/build/link/utils.js.map +1 -1
  16. package/build/strikethrough/index.js +4 -2
  17. package/build/strikethrough/index.js.map +1 -1
  18. package/build/subscript/index.js +4 -2
  19. package/build/subscript/index.js.map +1 -1
  20. package/build/superscript/index.js +4 -2
  21. package/build/superscript/index.js.map +1 -1
  22. package/build/text-color/index.js +60 -21
  23. package/build/text-color/index.js.map +1 -1
  24. package/build/text-color/inline.js +105 -37
  25. package/build/text-color/inline.js.map +1 -1
  26. package/build/underline/index.js +4 -2
  27. package/build/underline/index.js.map +1 -1
  28. package/build-module/bold/index.js +5 -2
  29. package/build-module/bold/index.js.map +1 -1
  30. package/build-module/code/index.js +4 -2
  31. package/build-module/code/index.js.map +1 -1
  32. package/build-module/italic/index.js +5 -2
  33. package/build-module/italic/index.js.map +1 -1
  34. package/build-module/keyboard/index.js +4 -2
  35. package/build-module/keyboard/index.js.map +1 -1
  36. package/build-module/link/inline.js +111 -11
  37. package/build-module/link/inline.js.map +1 -1
  38. package/build-module/link/use-link-instance-key.js +29 -0
  39. package/build-module/link/use-link-instance-key.js.map +1 -0
  40. package/build-module/link/utils.js +110 -1
  41. package/build-module/link/utils.js.map +1 -1
  42. package/build-module/strikethrough/index.js +4 -2
  43. package/build-module/strikethrough/index.js.map +1 -1
  44. package/build-module/subscript/index.js +4 -2
  45. package/build-module/subscript/index.js.map +1 -1
  46. package/build-module/superscript/index.js +4 -2
  47. package/build-module/superscript/index.js.map +1 -1
  48. package/build-module/text-color/index.js +61 -22
  49. package/build-module/text-color/index.js.map +1 -1
  50. package/build-module/text-color/inline.js +104 -37
  51. package/build-module/text-color/inline.js.map +1 -1
  52. package/build-module/underline/index.js +6 -2
  53. package/build-module/underline/index.js.map +1 -1
  54. package/build-style/style-rtl.css +2 -25
  55. package/build-style/style.css +2 -25
  56. package/package.json +15 -15
  57. package/src/bold/index.js +2 -2
  58. package/src/code/index.js +2 -1
  59. package/src/italic/index.js +2 -2
  60. package/src/keyboard/index.js +2 -1
  61. package/src/link/inline.js +121 -8
  62. package/src/link/test/utils.js +362 -1
  63. package/src/link/use-link-instance-key.js +31 -0
  64. package/src/link/utils.js +132 -1
  65. package/src/strikethrough/index.js +2 -1
  66. package/src/subscript/index.js +2 -1
  67. package/src/superscript/index.js +2 -1
  68. package/src/text-color/index.js +66 -23
  69. package/src/text-color/inline.js +125 -49
  70. package/src/text-color/style.scss +2 -24
  71. package/src/underline/index.js +3 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/format-library/src/italic/index.js"],"names":["__","toggleFormat","RichTextToolbarButton","RichTextShortcut","__unstableRichTextInputEvent","formatItalic","name","title","italic","tagName","className","edit","isActive","value","onChange","onFocus","onToggle","type","onClick"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,EAAT,QAAmB,iBAAnB;AACA,SAASC,YAAT,QAA6B,sBAA7B;AACA,SACCC,qBADD,EAECC,gBAFD,EAGCC,4BAHD,QAIO,yBAJP;AAKA,SAASC,YAAT,QAA6B,kBAA7B;AAEA,MAAMC,IAAI,GAAG,aAAb;;AACA,MAAMC,KAAK,GAAGP,EAAE,CAAE,QAAF,CAAhB;;AAEA,OAAO,MAAMQ,MAAM,GAAG;AACrBF,EAAAA,IADqB;AAErBC,EAAAA,KAFqB;AAGrBE,EAAAA,OAAO,EAAE,IAHY;AAIrBC,EAAAA,SAAS,EAAE,IAJU;;AAKrBC,EAAAA,IAAI,CAAE;AAAEC,IAAAA,QAAF;AAAYC,IAAAA,KAAZ;AAAmBC,IAAAA,QAAnB;AAA6BC,IAAAA;AAA7B,GAAF,EAA2C;AAC9C,aAASC,QAAT,GAAoB;AACnBF,MAAAA,QAAQ,CAAEb,YAAY,CAAEY,KAAF,EAAS;AAAEI,QAAAA,IAAI,EAAEX;AAAR,OAAT,CAAd,CAAR;AACA;;AAED,aAASY,OAAT,GAAmB;AAClBF,MAAAA,QAAQ;AACRD,MAAAA,OAAO;AACP;;AAED,WACC,8BACC,cAAC,gBAAD;AACC,MAAA,IAAI,EAAC,SADN;AAEC,MAAA,SAAS,EAAC,GAFX;AAGC,MAAA,KAAK,EAAGC;AAHT,MADD,EAMC,cAAC,qBAAD;AACC,MAAA,IAAI,EAAC,QADN;AAEC,MAAA,IAAI,EAAGX,YAFR;AAGC,MAAA,KAAK,EAAGE,KAHT;AAIC,MAAA,OAAO,EAAGW,OAJX;AAKC,MAAA,QAAQ,EAAGN,QALZ;AAMC,MAAA,YAAY,EAAC,SANd;AAOC,MAAA,iBAAiB,EAAC;AAPnB,MAND,EAeC,cAAC,4BAAD;AACC,MAAA,SAAS,EAAC,cADX;AAEC,MAAA,OAAO,EAAGI;AAFX,MAfD,CADD;AAsBA;;AArCoB,CAAf","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { toggleFormat } from '@wordpress/rich-text';\nimport {\n\tRichTextToolbarButton,\n\tRichTextShortcut,\n\t__unstableRichTextInputEvent,\n} from '@wordpress/block-editor';\nimport { formatItalic } from '@wordpress/icons';\n\nconst name = 'core/italic';\nconst title = __( 'Italic' );\n\nexport const italic = {\n\tname,\n\ttitle,\n\ttagName: 'em',\n\tclassName: null,\n\tedit( { isActive, value, onChange, onFocus } ) {\n\t\tfunction onToggle() {\n\t\t\tonChange( toggleFormat( value, { type: name } ) );\n\t\t}\n\n\t\tfunction onClick() {\n\t\t\tonToggle();\n\t\t\tonFocus();\n\t\t}\n\n\t\treturn (\n\t\t\t<>\n\t\t\t\t<RichTextShortcut\n\t\t\t\t\ttype=\"primary\"\n\t\t\t\t\tcharacter=\"i\"\n\t\t\t\t\tonUse={ onToggle }\n\t\t\t\t/>\n\t\t\t\t<RichTextToolbarButton\n\t\t\t\t\tname=\"italic\"\n\t\t\t\t\ticon={ formatItalic }\n\t\t\t\t\ttitle={ title }\n\t\t\t\t\tonClick={ onClick }\n\t\t\t\t\tisActive={ isActive }\n\t\t\t\t\tshortcutType=\"primary\"\n\t\t\t\t\tshortcutCharacter=\"i\"\n\t\t\t\t/>\n\t\t\t\t<__unstableRichTextInputEvent\n\t\t\t\t\tinputType=\"formatItalic\"\n\t\t\t\t\tonInput={ onToggle }\n\t\t\t\t/>\n\t\t\t</>\n\t\t);\n\t},\n};\n"]}
1
+ {"version":3,"sources":["@wordpress/format-library/src/italic/index.js"],"names":["__","toggleFormat","RichTextToolbarButton","RichTextShortcut","__unstableRichTextInputEvent","formatItalic","name","title","italic","tagName","className","edit","isActive","value","onChange","onFocus","onToggle","type","onClick"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,EAAT,QAAmB,iBAAnB;AACA,SAASC,YAAT,QAA6B,sBAA7B;AACA,SACCC,qBADD,EAECC,gBAFD,EAGCC,4BAHD,QAIO,yBAJP;AAKA,SAASC,YAAT,QAA6B,kBAA7B;AAEA,MAAMC,IAAI,GAAG,aAAb;;AACA,MAAMC,KAAK,GAAGP,EAAE,CAAE,QAAF,CAAhB;;AAEA,OAAO,MAAMQ,MAAM,GAAG;AACrBF,EAAAA,IADqB;AAErBC,EAAAA,KAFqB;AAGrBE,EAAAA,OAAO,EAAE,IAHY;AAIrBC,EAAAA,SAAS,EAAE,IAJU;;AAKrBC,EAAAA,IAAI,CAAE;AAAEC,IAAAA,QAAF;AAAYC,IAAAA,KAAZ;AAAmBC,IAAAA,QAAnB;AAA6BC,IAAAA;AAA7B,GAAF,EAA2C;AAC9C,aAASC,QAAT,GAAoB;AACnBF,MAAAA,QAAQ,CAAEb,YAAY,CAAEY,KAAF,EAAS;AAAEI,QAAAA,IAAI,EAAEX,IAAR;AAAcC,QAAAA;AAAd,OAAT,CAAd,CAAR;AACA;;AAED,aAASW,OAAT,GAAmB;AAClBJ,MAAAA,QAAQ,CAAEb,YAAY,CAAEY,KAAF,EAAS;AAAEI,QAAAA,IAAI,EAAEX;AAAR,OAAT,CAAd,CAAR;AACAS,MAAAA,OAAO;AACP;;AAED,WACC,8BACC,cAAC,gBAAD;AACC,MAAA,IAAI,EAAC,SADN;AAEC,MAAA,SAAS,EAAC,GAFX;AAGC,MAAA,KAAK,EAAGC;AAHT,MADD,EAMC,cAAC,qBAAD;AACC,MAAA,IAAI,EAAC,QADN;AAEC,MAAA,IAAI,EAAGX,YAFR;AAGC,MAAA,KAAK,EAAGE,KAHT;AAIC,MAAA,OAAO,EAAGW,OAJX;AAKC,MAAA,QAAQ,EAAGN,QALZ;AAMC,MAAA,YAAY,EAAC,SANd;AAOC,MAAA,iBAAiB,EAAC;AAPnB,MAND,EAeC,cAAC,4BAAD;AACC,MAAA,SAAS,EAAC,cADX;AAEC,MAAA,OAAO,EAAGI;AAFX,MAfD,CADD;AAsBA;;AArCoB,CAAf","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { toggleFormat } from '@wordpress/rich-text';\nimport {\n\tRichTextToolbarButton,\n\tRichTextShortcut,\n\t__unstableRichTextInputEvent,\n} from '@wordpress/block-editor';\nimport { formatItalic } from '@wordpress/icons';\n\nconst name = 'core/italic';\nconst title = __( 'Italic' );\n\nexport const italic = {\n\tname,\n\ttitle,\n\ttagName: 'em',\n\tclassName: null,\n\tedit( { isActive, value, onChange, onFocus } ) {\n\t\tfunction onToggle() {\n\t\t\tonChange( toggleFormat( value, { type: name, title } ) );\n\t\t}\n\n\t\tfunction onClick() {\n\t\t\tonChange( toggleFormat( value, { type: name } ) );\n\t\t\tonFocus();\n\t\t}\n\n\t\treturn (\n\t\t\t<>\n\t\t\t\t<RichTextShortcut\n\t\t\t\t\ttype=\"primary\"\n\t\t\t\t\tcharacter=\"i\"\n\t\t\t\t\tonUse={ onToggle }\n\t\t\t\t/>\n\t\t\t\t<RichTextToolbarButton\n\t\t\t\t\tname=\"italic\"\n\t\t\t\t\ticon={ formatItalic }\n\t\t\t\t\ttitle={ title }\n\t\t\t\t\tonClick={ onClick }\n\t\t\t\t\tisActive={ isActive }\n\t\t\t\t\tshortcutType=\"primary\"\n\t\t\t\t\tshortcutCharacter=\"i\"\n\t\t\t\t/>\n\t\t\t\t<__unstableRichTextInputEvent\n\t\t\t\t\tinputType=\"formatItalic\"\n\t\t\t\t\tonInput={ onToggle }\n\t\t\t\t/>\n\t\t\t</>\n\t\t);\n\t},\n};\n"]}
@@ -25,7 +25,8 @@ export const keyboard = {
25
25
  }) {
26
26
  function onToggle() {
27
27
  onChange(toggleFormat(value, {
28
- type: name
28
+ type: name,
29
+ title
29
30
  }));
30
31
  }
31
32
 
@@ -38,7 +39,8 @@ export const keyboard = {
38
39
  icon: button,
39
40
  title: title,
40
41
  onClick: onClick,
41
- isActive: isActive
42
+ isActive: isActive,
43
+ role: "menuitemcheckbox"
42
44
  });
43
45
  }
44
46
 
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/format-library/src/keyboard/index.js"],"names":["__","toggleFormat","RichTextToolbarButton","button","name","title","keyboard","tagName","className","edit","isActive","value","onChange","onFocus","onToggle","type","onClick"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,EAAT,QAAmB,iBAAnB;AACA,SAASC,YAAT,QAA6B,sBAA7B;AACA,SAASC,qBAAT,QAAsC,yBAAtC;AACA,SAASC,MAAT,QAAuB,kBAAvB;AAEA,MAAMC,IAAI,GAAG,eAAb;;AACA,MAAMC,KAAK,GAAGL,EAAE,CAAE,gBAAF,CAAhB;;AAEA,OAAO,MAAMM,QAAQ,GAAG;AACvBF,EAAAA,IADuB;AAEvBC,EAAAA,KAFuB;AAGvBE,EAAAA,OAAO,EAAE,KAHc;AAIvBC,EAAAA,SAAS,EAAE,IAJY;;AAKvBC,EAAAA,IAAI,CAAE;AAAEC,IAAAA,QAAF;AAAYC,IAAAA,KAAZ;AAAmBC,IAAAA,QAAnB;AAA6BC,IAAAA;AAA7B,GAAF,EAA2C;AAC9C,aAASC,QAAT,GAAoB;AACnBF,MAAAA,QAAQ,CAAEX,YAAY,CAAEU,KAAF,EAAS;AAAEI,QAAAA,IAAI,EAAEX;AAAR,OAAT,CAAd,CAAR;AACA;;AAED,aAASY,OAAT,GAAmB;AAClBF,MAAAA,QAAQ;AACRD,MAAAA,OAAO;AACP;;AAED,WACC,cAAC,qBAAD;AACC,MAAA,IAAI,EAAGV,MADR;AAEC,MAAA,KAAK,EAAGE,KAFT;AAGC,MAAA,OAAO,EAAGW,OAHX;AAIC,MAAA,QAAQ,EAAGN;AAJZ,MADD;AAQA;;AAvBsB,CAAjB","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { toggleFormat } from '@wordpress/rich-text';\nimport { RichTextToolbarButton } from '@wordpress/block-editor';\nimport { button } from '@wordpress/icons';\n\nconst name = 'core/keyboard';\nconst title = __( 'Keyboard input' );\n\nexport const keyboard = {\n\tname,\n\ttitle,\n\ttagName: 'kbd',\n\tclassName: null,\n\tedit( { isActive, value, onChange, onFocus } ) {\n\t\tfunction onToggle() {\n\t\t\tonChange( toggleFormat( value, { type: name } ) );\n\t\t}\n\n\t\tfunction onClick() {\n\t\t\tonToggle();\n\t\t\tonFocus();\n\t\t}\n\n\t\treturn (\n\t\t\t<RichTextToolbarButton\n\t\t\t\ticon={ button }\n\t\t\t\ttitle={ title }\n\t\t\t\tonClick={ onClick }\n\t\t\t\tisActive={ isActive }\n\t\t\t/>\n\t\t);\n\t},\n};\n"]}
1
+ {"version":3,"sources":["@wordpress/format-library/src/keyboard/index.js"],"names":["__","toggleFormat","RichTextToolbarButton","button","name","title","keyboard","tagName","className","edit","isActive","value","onChange","onFocus","onToggle","type","onClick"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,EAAT,QAAmB,iBAAnB;AACA,SAASC,YAAT,QAA6B,sBAA7B;AACA,SAASC,qBAAT,QAAsC,yBAAtC;AACA,SAASC,MAAT,QAAuB,kBAAvB;AAEA,MAAMC,IAAI,GAAG,eAAb;;AACA,MAAMC,KAAK,GAAGL,EAAE,CAAE,gBAAF,CAAhB;;AAEA,OAAO,MAAMM,QAAQ,GAAG;AACvBF,EAAAA,IADuB;AAEvBC,EAAAA,KAFuB;AAGvBE,EAAAA,OAAO,EAAE,KAHc;AAIvBC,EAAAA,SAAS,EAAE,IAJY;;AAKvBC,EAAAA,IAAI,CAAE;AAAEC,IAAAA,QAAF;AAAYC,IAAAA,KAAZ;AAAmBC,IAAAA,QAAnB;AAA6BC,IAAAA;AAA7B,GAAF,EAA2C;AAC9C,aAASC,QAAT,GAAoB;AACnBF,MAAAA,QAAQ,CAAEX,YAAY,CAAEU,KAAF,EAAS;AAAEI,QAAAA,IAAI,EAAEX,IAAR;AAAcC,QAAAA;AAAd,OAAT,CAAd,CAAR;AACA;;AAED,aAASW,OAAT,GAAmB;AAClBF,MAAAA,QAAQ;AACRD,MAAAA,OAAO;AACP;;AAED,WACC,cAAC,qBAAD;AACC,MAAA,IAAI,EAAGV,MADR;AAEC,MAAA,KAAK,EAAGE,KAFT;AAGC,MAAA,OAAO,EAAGW,OAHX;AAIC,MAAA,QAAQ,EAAGN,QAJZ;AAKC,MAAA,IAAI,EAAC;AALN,MADD;AASA;;AAxBsB,CAAjB","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { toggleFormat } from '@wordpress/rich-text';\nimport { RichTextToolbarButton } from '@wordpress/block-editor';\nimport { button } from '@wordpress/icons';\n\nconst name = 'core/keyboard';\nconst title = __( 'Keyboard input' );\n\nexport const keyboard = {\n\tname,\n\ttitle,\n\ttagName: 'kbd',\n\tclassName: null,\n\tedit( { isActive, value, onChange, onFocus } ) {\n\t\tfunction onToggle() {\n\t\t\tonChange( toggleFormat( value, { type: name, title } ) );\n\t\t}\n\n\t\tfunction onClick() {\n\t\t\tonToggle();\n\t\t\tonFocus();\n\t\t}\n\n\t\treturn (\n\t\t\t<RichTextToolbarButton\n\t\t\t\ticon={ button }\n\t\t\t\ttitle={ title }\n\t\t\t\tonClick={ onClick }\n\t\t\t\tisActive={ isActive }\n\t\t\t\trole=\"menuitemcheckbox\"\n\t\t\t/>\n\t\t);\n\t},\n};\n"]}
@@ -3,18 +3,20 @@ import { createElement } from "@wordpress/element";
3
3
  /**
4
4
  * WordPress dependencies
5
5
  */
6
- import { useState, useRef } from '@wordpress/element';
7
- import { __ } from '@wordpress/i18n';
6
+ import { useState, useRef, createInterpolateElement } from '@wordpress/element';
7
+ import { __, sprintf } from '@wordpress/i18n';
8
8
  import { withSpokenMessages, Popover } from '@wordpress/components';
9
9
  import { prependHTTP } from '@wordpress/url';
10
- import { create, insert, isCollapsed, applyFormat, useAnchorRef, removeFormat } from '@wordpress/rich-text';
11
- import { __experimentalLinkControl as LinkControl } from '@wordpress/block-editor';
10
+ import { create, insert, isCollapsed, applyFormat, useAnchorRef, removeFormat, slice, replace } from '@wordpress/rich-text';
11
+ import { __experimentalLinkControl as LinkControl, store as blockEditorStore } from '@wordpress/block-editor';
12
+ import { useSelect } from '@wordpress/data';
12
13
  /**
13
14
  * Internal dependencies
14
15
  */
15
16
 
16
- import { createLinkFormat, isValidHref } from './utils';
17
+ import { createLinkFormat, isValidHref, getFormatBoundary } from './utils';
17
18
  import { link as settings } from './index';
19
+ import useLinkInstanceKey from './use-link-instance-key';
18
20
 
19
21
  function InlineLinkUI({
20
22
  isActive,
@@ -26,6 +28,9 @@ function InlineLinkUI({
26
28
  stopAddingLink,
27
29
  contentRef
28
30
  }) {
31
+ const richLinkTextValue = getRichTextValueFromSelection(value, isActive); // Get the text content minus any HTML tags.
32
+
33
+ const richTextText = richLinkTextValue.text;
29
34
  /**
30
35
  * Pending settings to be applied to the next link. When inserting a new
31
36
  * link, toggle values cannot be applied immediately, because there is not
@@ -34,12 +39,29 @@ function InlineLinkUI({
34
39
  *
35
40
  * @type {[Object|undefined,Function]}
36
41
  */
42
+
37
43
  const [nextLinkValue, setNextLinkValue] = useState();
44
+ const {
45
+ createPageEntity,
46
+ userCanCreatePages
47
+ } = useSelect(select => {
48
+ const {
49
+ getSettings
50
+ } = select(blockEditorStore);
51
+
52
+ const _settings = getSettings();
53
+
54
+ return {
55
+ createPageEntity: _settings.__experimentalCreatePageEntity,
56
+ userCanCreatePages: _settings.__experimentalUserCanCreatePages
57
+ };
58
+ }, []);
38
59
  const linkValue = {
39
60
  url: activeAttributes.url,
40
61
  type: activeAttributes.type,
41
62
  id: activeAttributes.id,
42
63
  opensInNewTab: activeAttributes.target === '_blank',
64
+ title: richTextText,
43
65
  ...nextLinkValue
44
66
  };
45
67
 
@@ -72,21 +94,45 @@ function InlineLinkUI({
72
94
  }
73
95
 
74
96
  const newUrl = prependHTTP(nextValue.url);
75
- const format = createLinkFormat({
97
+ const linkFormat = createLinkFormat({
76
98
  url: newUrl,
77
99
  type: nextValue.type,
78
100
  id: nextValue.id !== undefined && nextValue.id !== null ? String(nextValue.id) : undefined,
79
101
  opensInNewWindow: nextValue.opensInNewTab
80
102
  });
103
+ const newText = nextValue.title || newUrl;
81
104
 
82
105
  if (isCollapsed(value) && !isActive) {
83
- const newText = nextValue.title || newUrl;
106
+ // Scenario: we don't have any actively selected text or formats.
84
107
  const toInsert = applyFormat(create({
85
108
  text: newText
86
- }), format, 0, newText.length);
109
+ }), linkFormat, 0, newText.length);
87
110
  onChange(insert(value, toInsert));
88
111
  } else {
89
- const newValue = applyFormat(value, format);
112
+ // Scenario: we have any active text selection or an active format
113
+ let newValue;
114
+
115
+ if (newText === richTextText) {
116
+ // If we're not updating the text then ignore
117
+ newValue = applyFormat(value, linkFormat);
118
+ } else {
119
+ // Create new RichText value for the new text in order that we
120
+ // can apply formats to it.
121
+ newValue = create({
122
+ text: newText
123
+ }); // Apply the new Link format to this new text value.
124
+
125
+ newValue = applyFormat(newValue, linkFormat, 0, newText.length); // Update the original (full) RichTextValue replacing the
126
+ // target text with the *new* RichTextValue containing:
127
+ // 1. The new text content.
128
+ // 2. The new link format.
129
+ // Note original formats will be lost when applying this change.
130
+ // That is expected behaviour.
131
+ // See: https://github.com/WordPress/gutenberg/pull/33849#issuecomment-936134179.
132
+
133
+ newValue = replace(value, richTextText, newValue);
134
+ }
135
+
90
136
  newValue.start = newValue.end;
91
137
  newValue.activeFormats = [];
92
138
  onChange(newValue);
@@ -111,23 +157,77 @@ function InlineLinkUI({
111
157
  ref: contentRef,
112
158
  value,
113
159
  settings
114
- }); // The focusOnMount prop shouldn't evolve during render of a Popover
160
+ }); // Generate a string based key that is unique to this anchor reference.
161
+ // This is used to force re-mount the LinkControl component to avoid
162
+ // potential stale state bugs caused by the component not being remounted
163
+ // See https://github.com/WordPress/gutenberg/pull/34742.
164
+
165
+ const forceRemountKey = useLinkInstanceKey(anchorRef); // The focusOnMount prop shouldn't evolve during render of a Popover
115
166
  // otherwise it causes a render of the content.
116
167
 
117
168
  const focusOnMount = useRef(addingLink ? 'firstElement' : false);
169
+
170
+ async function handleCreate(pageTitle) {
171
+ const page = await createPageEntity({
172
+ title: pageTitle,
173
+ status: 'draft'
174
+ });
175
+ return {
176
+ id: page.id,
177
+ type: page.type,
178
+ title: page.title.rendered,
179
+ url: page.link,
180
+ kind: 'post-type'
181
+ };
182
+ }
183
+
184
+ function createButtonText(searchTerm) {
185
+ return createInterpolateElement(sprintf(
186
+ /* translators: %s: search term. */
187
+ __('Create Page: <mark>%s</mark>'), searchTerm), {
188
+ mark: createElement("mark", null)
189
+ });
190
+ }
191
+
118
192
  return createElement(Popover, {
119
193
  anchorRef: anchorRef,
120
194
  focusOnMount: focusOnMount.current,
121
195
  onClose: stopAddingLink,
122
196
  position: "bottom center"
123
197
  }, createElement(LinkControl, {
198
+ key: forceRemountKey,
124
199
  value: linkValue,
125
200
  onChange: onChangeLink,
126
201
  onRemove: removeLink,
127
202
  forceIsEditingLink: addingLink,
128
- hasRichPreviews: true
203
+ hasRichPreviews: true,
204
+ createSuggestion: createPageEntity && handleCreate,
205
+ withCreateSuggestion: userCanCreatePages,
206
+ createSuggestionButtonText: createButtonText,
207
+ hasTextControl: true
129
208
  }));
130
209
  }
131
210
 
211
+ function getRichTextValueFromSelection(value, isActive) {
212
+ // Default to the selection ranges on the RichTextValue object.
213
+ let textStart = value.start;
214
+ let textEnd = value.end; // If the format is currently active then the rich text value
215
+ // should always be taken from the bounds of the active format
216
+ // and not the selected text.
217
+
218
+ if (isActive) {
219
+ const boundary = getFormatBoundary(value, {
220
+ type: 'core/link'
221
+ });
222
+ textStart = boundary.start; // Text *selection* always extends +1 beyond the edge of the format.
223
+ // We account for that here.
224
+
225
+ textEnd = boundary.end + 1;
226
+ } // Get a RichTextValue containing the selected text content.
227
+
228
+
229
+ return slice(value, textStart, textEnd);
230
+ }
231
+
132
232
  export default withSpokenMessages(InlineLinkUI);
133
233
  //# sourceMappingURL=inline.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/format-library/src/link/inline.js"],"names":["useState","useRef","__","withSpokenMessages","Popover","prependHTTP","create","insert","isCollapsed","applyFormat","useAnchorRef","removeFormat","__experimentalLinkControl","LinkControl","createLinkFormat","isValidHref","link","settings","InlineLinkUI","isActive","activeAttributes","addingLink","value","onChange","speak","stopAddingLink","contentRef","nextLinkValue","setNextLinkValue","linkValue","url","type","id","opensInNewTab","target","removeLink","newValue","onChangeLink","nextValue","didToggleSetting","didToggleSettingForNewLink","undefined","newUrl","format","String","opensInNewWindow","newText","title","toInsert","text","length","start","end","activeFormats","anchorRef","ref","focusOnMount","current"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,QAAT,EAAmBC,MAAnB,QAA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AJtB;AAKC,IAAA,eAAe;AALhB,IAND,CADD;AAgBA;;AAED,eAAelB,kBAAkB,CAAEe,YAAF,CAAjC","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useState, useRef } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport { withSpokenMessages, Popover } from '@wordpress/components';\nimport { prependHTTP } from '@wordpress/url';\nimport {\n\tcreate,\n\tinsert,\n\tisCollapsed,\n\tapplyFormat,\n\tuseAnchorRef,\n\tremoveFormat,\n} from '@wordpress/rich-text';\nimport { __experimentalLinkControl as LinkControl } from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport { createLinkFormat, isValidHref } from './utils';\nimport { link as settings } from './index';\n\nfunction InlineLinkUI( {\n\tisActive,\n\tactiveAttributes,\n\taddingLink,\n\tvalue,\n\tonChange,\n\tspeak,\n\tstopAddingLink,\n\tcontentRef,\n} ) {\n\t/**\n\t * Pending settings to be applied to the next link. When inserting a new\n\t * link, toggle values cannot be applied immediately, because there is not\n\t * yet a link for them to apply to. Thus, they are maintained in a state\n\t * value until the time that the link can be inserted or edited.\n\t *\n\t * @type {[Object|undefined,Function]}\n\t */\n\tconst [ nextLinkValue, setNextLinkValue ] = useState();\n\n\tconst linkValue = {\n\t\turl: activeAttributes.url,\n\t\ttype: activeAttributes.type,\n\t\tid: activeAttributes.id,\n\t\topensInNewTab: activeAttributes.target === '_blank',\n\t\t...nextLinkValue,\n\t};\n\n\tfunction removeLink() {\n\t\tconst newValue = removeFormat( value, 'core/link' );\n\t\tonChange( newValue );\n\t\tstopAddingLink();\n\t\tspeak( __( 'Link removed.' ), 'assertive' );\n\t}\n\n\tfunction onChangeLink( nextValue ) {\n\t\t// Merge with values from state, both for the purpose of assigning the\n\t\t// next state value, and for use in constructing the new link format if\n\t\t// the link is ready to be applied.\n\t\tnextValue = {\n\t\t\t...nextLinkValue,\n\t\t\t...nextValue,\n\t\t};\n\n\t\t// LinkControl calls `onChange` immediately upon the toggling a setting.\n\t\tconst didToggleSetting =\n\t\t\tlinkValue.opensInNewTab !== nextValue.opensInNewTab &&\n\t\t\tlinkValue.url === nextValue.url;\n\n\t\t// If change handler was called as a result of a settings change during\n\t\t// link insertion, it must be held in state until the link is ready to\n\t\t// be applied.\n\t\tconst didToggleSettingForNewLink =\n\t\t\tdidToggleSetting && nextValue.url === undefined;\n\n\t\t// If link will be assigned, the state value can be considered flushed.\n\t\t// Otherwise, persist the pending changes.\n\t\tsetNextLinkValue( didToggleSettingForNewLink ? nextValue : undefined );\n\n\t\tif ( didToggleSettingForNewLink ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst newUrl = prependHTTP( nextValue.url );\n\t\tconst format = createLinkFormat( {\n\t\t\turl: newUrl,\n\t\t\ttype: nextValue.type,\n\t\t\tid:\n\t\t\t\tnextValue.id !== undefined && nextValue.id !== null\n\t\t\t\t\t? String( nextValue.id )\n\t\t\t\t\t: undefined,\n\t\t\topensInNewWindow: nextValue.opensInNewTab,\n\t\t} );\n\n\t\tif ( isCollapsed( value ) && ! isActive ) {\n\t\t\tconst newText = nextValue.title || newUrl;\n\t\t\tconst toInsert = applyFormat(\n\t\t\t\tcreate( { text: newText } ),\n\t\t\t\tformat,\n\t\t\t\t0,\n\t\t\t\tnewText.length\n\t\t\t);\n\t\t\tonChange( insert( value, toInsert ) );\n\t\t} else {\n\t\t\tconst newValue = applyFormat( value, format );\n\t\t\tnewValue.start = newValue.end;\n\t\t\tnewValue.activeFormats = [];\n\t\t\tonChange( newValue );\n\t\t}\n\n\t\t// Focus should only be shifted back to the formatted segment when the\n\t\t// URL is submitted.\n\t\tif ( ! didToggleSetting ) {\n\t\t\tstopAddingLink();\n\t\t}\n\n\t\tif ( ! isValidHref( newUrl ) ) {\n\t\t\tspeak(\n\t\t\t\t__(\n\t\t\t\t\t'Warning: the link has been inserted but may have errors. Please test it.'\n\t\t\t\t),\n\t\t\t\t'assertive'\n\t\t\t);\n\t\t} else if ( isActive ) {\n\t\t\tspeak( __( 'Link edited.' ), 'assertive' );\n\t\t} else {\n\t\t\tspeak( __( 'Link inserted.' ), 'assertive' );\n\t\t}\n\t}\n\n\tconst anchorRef = useAnchorRef( { ref: contentRef, value, settings } );\n\n\t// The focusOnMount prop shouldn't evolve during render of a Popover\n\t// otherwise it causes a render of the content.\n\tconst focusOnMount = useRef( addingLink ? 'firstElement' : false );\n\n\treturn (\n\t\t<Popover\n\t\t\tanchorRef={ anchorRef }\n\t\t\tfocusOnMount={ focusOnMount.current }\n\t\t\tonClose={ stopAddingLink }\n\t\t\tposition=\"bottom center\"\n\t\t>\n\t\t\t<LinkControl\n\t\t\t\tvalue={ linkValue }\n\t\t\t\tonChange={ onChangeLink }\n\t\t\t\tonRemove={ removeLink }\n\t\t\t\tforceIsEditingLink={ addingLink }\n\t\t\t\thasRichPreviews\n\t\t\t/>\n\t\t</Popover>\n\t);\n}\n\nexport default withSpokenMessages( InlineLinkUI );\n"]}
1
+ {"version":3,"sources":["@wordpress/format-library/src/link/inline.js"],"names":["useState","useRef","createInterpolateElement","__","sprintf","withSpokenMessages","Popover","prependHTTP","create","insert","isCollapsed","applyFormat","useAnchorRef","removeFormat","slice","replace","__experimentalLinkControl","LinkControl","store","blockEditorStore","useSelect","createLinkFormat","isValidHref","getFormatBoundary","link","settings","useLinkInstanceKey","InlineLinkUI","isActive","activeAttributes","addingLink","value","onChange","speak","stopAddingLink","contentRef","richLinkTextValue","getRichTextValueFromSelection","richTextText","text","nextLinkValue","setNextLinkValue","createPageEntity","userCanCreatePages","select","getSettings","_settings","__experimentalCreatePageEntity","__experimentalUserCanCreatePages","linkValue","url","type","id","opensInNewTab","target","title","removeLink","newValue","onChangeLink","nextValue","didToggleSetting","didToggleSettingForNewLink","undefined","newUrl","linkFormat","String","opensInNewWindow","newText","toInsert","length","start","end","activeFormats","anchorRef","ref","forceRemountKey","focusOnMount","handleCreate","pageTitle","page","status","rendered","kind","createButtonText","searchTerm","mark","current","textStart","textEnd","boundary"],"mappings":";;AAAA;AACA;AACA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AT,CAAlC;AAIAoC,IAAAA,SAAS,GAAGE,QAAQ,CAACnB,KAArB,CALe,CAOf;AACA;;AACAkB,IAAAA,OAAO,GAAGC,QAAQ,CAAClB,GAAT,GAAe,CAAzB;AACA,GAlBwD,CAoBzD;;;AACA,SAAOzD,KAAK,CAAEiB,KAAF,EAASwD,SAAT,EAAoBC,OAApB,CAAZ;AACA;;AAED,eAAenF,kBAAkB,CAAEsB,YAAF,CAAjC","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useState, useRef, createInterpolateElement } from '@wordpress/element';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { withSpokenMessages, Popover } from '@wordpress/components';\nimport { prependHTTP } from '@wordpress/url';\nimport {\n\tcreate,\n\tinsert,\n\tisCollapsed,\n\tapplyFormat,\n\tuseAnchorRef,\n\tremoveFormat,\n\tslice,\n\treplace,\n} from '@wordpress/rich-text';\nimport {\n\t__experimentalLinkControl as LinkControl,\n\tstore as blockEditorStore,\n} from '@wordpress/block-editor';\nimport { useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { createLinkFormat, isValidHref, getFormatBoundary } from './utils';\nimport { link as settings } from './index';\nimport useLinkInstanceKey from './use-link-instance-key';\n\nfunction InlineLinkUI( {\n\tisActive,\n\tactiveAttributes,\n\taddingLink,\n\tvalue,\n\tonChange,\n\tspeak,\n\tstopAddingLink,\n\tcontentRef,\n} ) {\n\tconst richLinkTextValue = getRichTextValueFromSelection( value, isActive );\n\n\t// Get the text content minus any HTML tags.\n\tconst richTextText = richLinkTextValue.text;\n\n\t/**\n\t * Pending settings to be applied to the next link. When inserting a new\n\t * link, toggle values cannot be applied immediately, because there is not\n\t * yet a link for them to apply to. Thus, they are maintained in a state\n\t * value until the time that the link can be inserted or edited.\n\t *\n\t * @type {[Object|undefined,Function]}\n\t */\n\tconst [ nextLinkValue, setNextLinkValue ] = useState();\n\n\tconst { createPageEntity, userCanCreatePages } = useSelect( ( select ) => {\n\t\tconst { getSettings } = select( blockEditorStore );\n\t\tconst _settings = getSettings();\n\n\t\treturn {\n\t\t\tcreatePageEntity: _settings.__experimentalCreatePageEntity,\n\t\t\tuserCanCreatePages: _settings.__experimentalUserCanCreatePages,\n\t\t};\n\t}, [] );\n\n\tconst linkValue = {\n\t\turl: activeAttributes.url,\n\t\ttype: activeAttributes.type,\n\t\tid: activeAttributes.id,\n\t\topensInNewTab: activeAttributes.target === '_blank',\n\t\ttitle: richTextText,\n\t\t...nextLinkValue,\n\t};\n\n\tfunction removeLink() {\n\t\tconst newValue = removeFormat( value, 'core/link' );\n\t\tonChange( newValue );\n\t\tstopAddingLink();\n\t\tspeak( __( 'Link removed.' ), 'assertive' );\n\t}\n\n\tfunction onChangeLink( nextValue ) {\n\t\t// Merge with values from state, both for the purpose of assigning the\n\t\t// next state value, and for use in constructing the new link format if\n\t\t// the link is ready to be applied.\n\t\tnextValue = {\n\t\t\t...nextLinkValue,\n\t\t\t...nextValue,\n\t\t};\n\n\t\t// LinkControl calls `onChange` immediately upon the toggling a setting.\n\t\tconst didToggleSetting =\n\t\t\tlinkValue.opensInNewTab !== nextValue.opensInNewTab &&\n\t\t\tlinkValue.url === nextValue.url;\n\n\t\t// If change handler was called as a result of a settings change during\n\t\t// link insertion, it must be held in state until the link is ready to\n\t\t// be applied.\n\t\tconst didToggleSettingForNewLink =\n\t\t\tdidToggleSetting && nextValue.url === undefined;\n\n\t\t// If link will be assigned, the state value can be considered flushed.\n\t\t// Otherwise, persist the pending changes.\n\t\tsetNextLinkValue( didToggleSettingForNewLink ? nextValue : undefined );\n\n\t\tif ( didToggleSettingForNewLink ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst newUrl = prependHTTP( nextValue.url );\n\t\tconst linkFormat = createLinkFormat( {\n\t\t\turl: newUrl,\n\t\t\ttype: nextValue.type,\n\t\t\tid:\n\t\t\t\tnextValue.id !== undefined && nextValue.id !== null\n\t\t\t\t\t? String( nextValue.id )\n\t\t\t\t\t: undefined,\n\t\t\topensInNewWindow: nextValue.opensInNewTab,\n\t\t} );\n\n\t\tconst newText = nextValue.title || newUrl;\n\t\tif ( isCollapsed( value ) && ! isActive ) {\n\t\t\t// Scenario: we don't have any actively selected text or formats.\n\t\t\tconst toInsert = applyFormat(\n\t\t\t\tcreate( { text: newText } ),\n\t\t\t\tlinkFormat,\n\t\t\t\t0,\n\t\t\t\tnewText.length\n\t\t\t);\n\t\t\tonChange( insert( value, toInsert ) );\n\t\t} else {\n\t\t\t// Scenario: we have any active text selection or an active format\n\t\t\tlet newValue;\n\n\t\t\tif ( newText === richTextText ) {\n\t\t\t\t// If we're not updating the text then ignore\n\t\t\t\tnewValue = applyFormat( value, linkFormat );\n\t\t\t} else {\n\t\t\t\t// Create new RichText value for the new text in order that we\n\t\t\t\t// can apply formats to it.\n\t\t\t\tnewValue = create( { text: newText } );\n\n\t\t\t\t// Apply the new Link format to this new text value.\n\t\t\t\tnewValue = applyFormat(\n\t\t\t\t\tnewValue,\n\t\t\t\t\tlinkFormat,\n\t\t\t\t\t0,\n\t\t\t\t\tnewText.length\n\t\t\t\t);\n\n\t\t\t\t// Update the original (full) RichTextValue replacing the\n\t\t\t\t// target text with the *new* RichTextValue containing:\n\t\t\t\t// 1. The new text content.\n\t\t\t\t// 2. The new link format.\n\t\t\t\t// Note original formats will be lost when applying this change.\n\t\t\t\t// That is expected behaviour.\n\t\t\t\t// See: https://github.com/WordPress/gutenberg/pull/33849#issuecomment-936134179.\n\t\t\t\tnewValue = replace( value, richTextText, newValue );\n\t\t\t}\n\n\t\t\tnewValue.start = newValue.end;\n\t\t\tnewValue.activeFormats = [];\n\t\t\tonChange( newValue );\n\t\t}\n\n\t\t// Focus should only be shifted back to the formatted segment when the\n\t\t// URL is submitted.\n\t\tif ( ! didToggleSetting ) {\n\t\t\tstopAddingLink();\n\t\t}\n\n\t\tif ( ! isValidHref( newUrl ) ) {\n\t\t\tspeak(\n\t\t\t\t__(\n\t\t\t\t\t'Warning: the link has been inserted but may have errors. Please test it.'\n\t\t\t\t),\n\t\t\t\t'assertive'\n\t\t\t);\n\t\t} else if ( isActive ) {\n\t\t\tspeak( __( 'Link edited.' ), 'assertive' );\n\t\t} else {\n\t\t\tspeak( __( 'Link inserted.' ), 'assertive' );\n\t\t}\n\t}\n\n\tconst anchorRef = useAnchorRef( { ref: contentRef, value, settings } );\n\n\t// Generate a string based key that is unique to this anchor reference.\n\t// This is used to force re-mount the LinkControl component to avoid\n\t// potential stale state bugs caused by the component not being remounted\n\t// See https://github.com/WordPress/gutenberg/pull/34742.\n\tconst forceRemountKey = useLinkInstanceKey( anchorRef );\n\n\t// The focusOnMount prop shouldn't evolve during render of a Popover\n\t// otherwise it causes a render of the content.\n\tconst focusOnMount = useRef( addingLink ? 'firstElement' : false );\n\n\tasync function handleCreate( pageTitle ) {\n\t\tconst page = await createPageEntity( {\n\t\t\ttitle: pageTitle,\n\t\t\tstatus: 'draft',\n\t\t} );\n\n\t\treturn {\n\t\t\tid: page.id,\n\t\t\ttype: page.type,\n\t\t\ttitle: page.title.rendered,\n\t\t\turl: page.link,\n\t\t\tkind: 'post-type',\n\t\t};\n\t}\n\n\tfunction createButtonText( searchTerm ) {\n\t\treturn createInterpolateElement(\n\t\t\tsprintf(\n\t\t\t\t/* translators: %s: search term. */\n\t\t\t\t__( 'Create Page: <mark>%s</mark>' ),\n\t\t\t\tsearchTerm\n\t\t\t),\n\t\t\t{ mark: <mark /> }\n\t\t);\n\t}\n\n\treturn (\n\t\t<Popover\n\t\t\tanchorRef={ anchorRef }\n\t\t\tfocusOnMount={ focusOnMount.current }\n\t\t\tonClose={ stopAddingLink }\n\t\t\tposition=\"bottom center\"\n\t\t>\n\t\t\t<LinkControl\n\t\t\t\tkey={ forceRemountKey }\n\t\t\t\tvalue={ linkValue }\n\t\t\t\tonChange={ onChangeLink }\n\t\t\t\tonRemove={ removeLink }\n\t\t\t\tforceIsEditingLink={ addingLink }\n\t\t\t\thasRichPreviews\n\t\t\t\tcreateSuggestion={ createPageEntity && handleCreate }\n\t\t\t\twithCreateSuggestion={ userCanCreatePages }\n\t\t\t\tcreateSuggestionButtonText={ createButtonText }\n\t\t\t\thasTextControl\n\t\t\t/>\n\t\t</Popover>\n\t);\n}\n\nfunction getRichTextValueFromSelection( value, isActive ) {\n\t// Default to the selection ranges on the RichTextValue object.\n\tlet textStart = value.start;\n\tlet textEnd = value.end;\n\n\t// If the format is currently active then the rich text value\n\t// should always be taken from the bounds of the active format\n\t// and not the selected text.\n\tif ( isActive ) {\n\t\tconst boundary = getFormatBoundary( value, {\n\t\t\ttype: 'core/link',\n\t\t} );\n\n\t\ttextStart = boundary.start;\n\n\t\t// Text *selection* always extends +1 beyond the edge of the format.\n\t\t// We account for that here.\n\t\ttextEnd = boundary.end + 1;\n\t}\n\n\t// Get a RichTextValue containing the selected text content.\n\treturn slice( value, textStart, textEnd );\n}\n\nexport default withSpokenMessages( InlineLinkUI );\n"]}
@@ -0,0 +1,29 @@
1
+ // Weakly referenced map allows unused ids to be garbage collected.
2
+ const weakMap = new WeakMap(); // Incrementing zero-based ID value
3
+
4
+ let id = -1;
5
+ const prefix = 'link-control-instance';
6
+
7
+ function getKey(_id) {
8
+ return `${prefix}-${_id}`;
9
+ }
10
+ /**
11
+ * Builds a unique link control key for the given object reference.
12
+ *
13
+ * @param {Object} instance an unique object reference specific to this link control instance.
14
+ * @return {string} the unique key to use for this link control.
15
+ */
16
+
17
+
18
+ function useLinkInstanceKey(instance) {
19
+ if (weakMap.has(instance)) {
20
+ return getKey(weakMap.get(instance));
21
+ }
22
+
23
+ id += 1;
24
+ weakMap.set(instance, id);
25
+ return getKey(id);
26
+ }
27
+
28
+ export default useLinkInstanceKey;
29
+ //# sourceMappingURL=use-link-instance-key.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["@wordpress/format-library/src/link/use-link-instance-key.js"],"names":["weakMap","WeakMap","id","prefix","getKey","_id","useLinkInstanceKey","instance","has","get","set"],"mappings":"AAAA;AACA,MAAMA,OAAO,GAAG,IAAIC,OAAJ,EAAhB,C,CAEA;;AACA,IAAIC,EAAE,GAAG,CAAC,CAAV;AAEA,MAAMC,MAAM,GAAG,uBAAf;;AAEA,SAASC,MAAT,CAAiBC,GAAjB,EAAuB;AACtB,SAAQ,GAAGF,MAAQ,IAAIE,GAAK,EAA5B;AACA;AAED;AACA;AACA;AACA;AACA;AACA;;;AACA,SAASC,kBAAT,CAA6BC,QAA7B,EAAwC;AACvC,MAAKP,OAAO,CAACQ,GAAR,CAAaD,QAAb,CAAL,EAA+B;AAC9B,WAAOH,MAAM,CAAEJ,OAAO,CAACS,GAAR,CAAaF,QAAb,CAAF,CAAb;AACA;;AAEDL,EAAAA,EAAE,IAAI,CAAN;AAEAF,EAAAA,OAAO,CAACU,GAAR,CAAaH,QAAb,EAAuBL,EAAvB;AAEA,SAAOE,MAAM,CAAEF,EAAF,CAAb;AACA;;AAED,eAAeI,kBAAf","sourcesContent":["// Weakly referenced map allows unused ids to be garbage collected.\nconst weakMap = new WeakMap();\n\n// Incrementing zero-based ID value\nlet id = -1;\n\nconst prefix = 'link-control-instance';\n\nfunction getKey( _id ) {\n\treturn `${ prefix }-${ _id }`;\n}\n\n/**\n * Builds a unique link control key for the given object reference.\n *\n * @param {Object} instance an unique object reference specific to this link control instance.\n * @return {string} the unique key to use for this link control.\n */\nfunction useLinkInstanceKey( instance ) {\n\tif ( weakMap.has( instance ) ) {\n\t\treturn getKey( weakMap.get( instance ) );\n\t}\n\n\tid += 1;\n\n\tweakMap.set( instance, id );\n\n\treturn getKey( id );\n}\n\nexport default useLinkInstanceKey;\n"]}
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * External dependencies
3
3
  */
4
- import { startsWith } from 'lodash';
4
+ import { startsWith, find, partialRight } from 'lodash';
5
5
  /**
6
6
  * WordPress dependencies
7
7
  */
@@ -106,4 +106,113 @@ export function createLinkFormat({
106
106
 
107
107
  return format;
108
108
  }
109
+ /* eslint-disable jsdoc/no-undefined-types */
110
+
111
+ /**
112
+ * Get the start and end boundaries of a given format from a rich text value.
113
+ *
114
+ *
115
+ * @param {RichTextValue} value the rich text value to interrogate.
116
+ * @param {string} format the identifier for the target format (e.g. `core/link`, `core/bold`).
117
+ * @param {number?} startIndex optional startIndex to seek from.
118
+ * @param {number?} endIndex optional endIndex to seek from.
119
+ * @return {Object} object containing start and end values for the given format.
120
+ */
121
+
122
+ /* eslint-enable jsdoc/no-undefined-types */
123
+
124
+ export function getFormatBoundary(value, format, startIndex = value.start, endIndex = value.end) {
125
+ const EMPTY_BOUNDARIES = {
126
+ start: null,
127
+ end: null
128
+ };
129
+ const {
130
+ formats
131
+ } = value;
132
+ let targetFormat;
133
+ let initialIndex;
134
+
135
+ if (!(formats !== null && formats !== void 0 && formats.length)) {
136
+ return EMPTY_BOUNDARIES;
137
+ } // Clone formats to avoid modifying source formats.
138
+
139
+
140
+ const newFormats = formats.slice();
141
+ const formatAtStart = find(newFormats[startIndex], {
142
+ type: format.type
143
+ });
144
+ const formatAtEnd = find(newFormats[endIndex], {
145
+ type: format.type
146
+ });
147
+ const formatAtEndMinusOne = find(newFormats[endIndex - 1], {
148
+ type: format.type
149
+ });
150
+
151
+ if (!!formatAtStart) {
152
+ // Set values to conform to "start"
153
+ targetFormat = formatAtStart;
154
+ initialIndex = startIndex;
155
+ } else if (!!formatAtEnd) {
156
+ // Set values to conform to "end"
157
+ targetFormat = formatAtEnd;
158
+ initialIndex = endIndex;
159
+ } else if (!!formatAtEndMinusOne) {
160
+ // This is an edge case which will occur if you create a format, then place
161
+ // the caret just before the format and hit the back ARROW key. The resulting
162
+ // value object will have start and end +1 beyond the edge of the format boundary.
163
+ targetFormat = formatAtEndMinusOne;
164
+ initialIndex = endIndex - 1;
165
+ } else {
166
+ return EMPTY_BOUNDARIES;
167
+ }
168
+
169
+ const index = newFormats[initialIndex].indexOf(targetFormat);
170
+ const walkingArgs = [newFormats, initialIndex, targetFormat, index]; // Walk the startIndex "backwards" to the leading "edge" of the matching format.
171
+
172
+ startIndex = walkToStart(...walkingArgs); // Walk the endIndex "forwards" until the trailing "edge" of the matching format.
173
+
174
+ endIndex = walkToEnd(...walkingArgs); // Safe guard: start index cannot be less than 0
175
+
176
+ startIndex = startIndex < 0 ? 0 : startIndex; // // Return the indicies of the "edges" as the boundaries.
177
+
178
+ return {
179
+ start: startIndex,
180
+ end: endIndex
181
+ };
182
+ }
183
+ /**
184
+ * Walks forwards/backwards towards the boundary of a given format within an
185
+ * array of format objects. Returns the index of the boundary.
186
+ *
187
+ * @param {Array} formats the formats to search for the given format type.
188
+ * @param {number} initialIndex the starting index from which to walk.
189
+ * @param {Object} targetFormatRef a reference to the format type object being sought.
190
+ * @param {number} formatIndex the index at which we expect the target format object to be.
191
+ * @param {string} direction either 'forwards' or 'backwards' to indicate the direction.
192
+ * @return {number} the index of the boundary of the given format.
193
+ */
194
+
195
+ function walkToBoundary(formats, initialIndex, targetFormatRef, formatIndex, direction) {
196
+ let index = initialIndex;
197
+ const directions = {
198
+ forwards: 1,
199
+ backwards: -1
200
+ };
201
+ const directionIncrement = directions[direction] || 1; // invalid direction arg default to forwards
202
+
203
+ const inverseDirectionIncrement = directionIncrement * -1;
204
+
205
+ while (formats[index] && formats[index][formatIndex] === targetFormatRef) {
206
+ // Increment/decrement in the direction of operation.
207
+ index = index + directionIncrement;
208
+ } // Restore by one in inverse direction of operation
209
+ // to avoid out of bounds.
210
+
211
+
212
+ index = index + inverseDirectionIncrement;
213
+ return index;
214
+ }
215
+
216
+ const walkToStart = partialRight(walkToBoundary, 'backwards');
217
+ const walkToEnd = partialRight(walkToBoundary, 'forwards');
109
218
  //# sourceMappingURL=utils.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/format-library/src/link/utils.js"],"names":["startsWith","getProtocol","isValidProtocol","getAuthority","isValidAuthority","getPath","isValidPath","getQueryString","isValidQueryString","getFragment","isValidFragment","isValidHref","href","trimmedHref","trim","test","protocol","authority","path","queryString","fragment","createLinkFormat","url","type","id","opensInNewWindow","format","attributes","target","rel"],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AAQ,GAAGX,WAAW,CAAEI,WAAF,CAA5B;;AACA,QAAKO,QAAQ,IAAI,CAAEV,eAAe,CAAEU,QAAF,CAAlC,EAAiD;AAChD,aAAO,KAAP;AACA;AACD,GA9CkC,CAgDnC;;;AACA,MAAKpB,UAAU,CAAEa,WAAF,EAAe,GAAf,CAAV,IAAkC,CAAEH,eAAe,CAAEG,WAAF,CAAxD,EAA0E;AACzE,WAAO,KAAP;AACA;;AAED,SAAO,IAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASQ,gBAAT,CAA2B;AAAEC,EAAAA,GAAF;AAAOC,EAAAA,IAAP;AAAaC,EAAAA,EAAb;AAAiBC,EAAAA;AAAjB,CAA3B,EAAiE;AACvE,QAAMC,MAAM,GAAG;AACdH,IAAAA,IAAI,EAAE,WADQ;AAEdI,IAAAA,UAAU,EAAE;AACXL,MAAAA;AADW;AAFE,GAAf;AAOA,MAAKC,IAAL,EAAYG,MAAM,CAACC,UAAP,CAAkBJ,IAAlB,GAAyBA,IAAzB;AACZ,MAAKC,EAAL,EAAUE,MAAM,CAACC,UAAP,CAAkBH,EAAlB,GAAuBA,EAAvB;;AAEV,MAAKC,gBAAL,EAAwB;AACvBC,IAAAA,MAAM,CAACC,UAAP,CAAkBC,MAAlB,GAA2B,QAA3B;AACAF,IAAAA,MAAM,CAACC,UAAP,CAAkBE,GAAlB,GAAwB,qBAAxB;AACA;;AAED,SAAOH,MAAP;AACA","sourcesContent":["/**\n * External dependencies\n */\nimport { startsWith } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tgetProtocol,\n\tisValidProtocol,\n\tgetAuthority,\n\tisValidAuthority,\n\tgetPath,\n\tisValidPath,\n\tgetQueryString,\n\tisValidQueryString,\n\tgetFragment,\n\tisValidFragment,\n} from '@wordpress/url';\n\n/**\n * Check for issues with the provided href.\n *\n * @param {string} href The href.\n *\n * @return {boolean} Is the href invalid?\n */\nexport function isValidHref( href ) {\n\tif ( ! href ) {\n\t\treturn false;\n\t}\n\n\tconst trimmedHref = href.trim();\n\n\tif ( ! trimmedHref ) {\n\t\treturn false;\n\t}\n\n\t// Does the href start with something that looks like a URL protocol?\n\tif ( /^\\S+:/.test( trimmedHref ) ) {\n\t\tconst protocol = getProtocol( trimmedHref );\n\t\tif ( ! isValidProtocol( protocol ) ) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// Add some extra checks for http(s) URIs, since these are the most common use-case.\n\t\t// This ensures URIs with an http protocol have exactly two forward slashes following the protocol.\n\t\tif (\n\t\t\tstartsWith( protocol, 'http' ) &&\n\t\t\t! /^https?:\\/\\/[^\\/\\s]/i.test( trimmedHref )\n\t\t) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst authority = getAuthority( trimmedHref );\n\t\tif ( ! isValidAuthority( authority ) ) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst path = getPath( trimmedHref );\n\t\tif ( path && ! isValidPath( path ) ) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst queryString = getQueryString( trimmedHref );\n\t\tif ( queryString && ! isValidQueryString( queryString ) ) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst fragment = getFragment( trimmedHref );\n\t\tif ( fragment && ! isValidFragment( fragment ) ) {\n\t\t\treturn false;\n\t\t}\n\t}\n\n\t// Validate anchor links.\n\tif ( startsWith( trimmedHref, '#' ) && ! isValidFragment( trimmedHref ) ) {\n\t\treturn false;\n\t}\n\n\treturn true;\n}\n\n/**\n * Generates the format object that will be applied to the link text.\n *\n * @param {Object} options\n * @param {string} options.url The href of the link.\n * @param {string} options.type The type of the link.\n * @param {string} options.id The ID of the link.\n * @param {boolean} options.opensInNewWindow Whether this link will open in a new window.\n *\n * @return {Object} The final format object.\n */\nexport function createLinkFormat( { url, type, id, opensInNewWindow } ) {\n\tconst format = {\n\t\ttype: 'core/link',\n\t\tattributes: {\n\t\t\turl,\n\t\t},\n\t};\n\n\tif ( type ) format.attributes.type = type;\n\tif ( id ) format.attributes.id = id;\n\n\tif ( opensInNewWindow ) {\n\t\tformat.attributes.target = '_blank';\n\t\tformat.attributes.rel = 'noreferrer noopener';\n\t}\n\n\treturn format;\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/format-library/src/link/utils.js"],"names":["startsWith","find","partialRight","getProtocol","isValidProtocol","getAuthority","isValidAuthority","getPath","isValidPath","getQueryString","isValidQueryString","getFragment","isValidFragment","isValidHref","href","trimmedHref","trim","test","protocol","authority","path","queryString","fragment","createLinkFormat","url","type","id","opensInNewWindow","format","attributes","target","rel","getFormatBoundary","value","startIndex","start","endIndex","end","EMPTY_BOUNDARIES","formats","targetFormat","initialIndex","length","newFormats","slice","formatAtStart","formatAtEnd","formatAtEndMinusOne","index","indexOf","walkingArgs","walkToStart","walkToEnd","walkToBoundary","targetFormatRef","formatIndex","direction","directions","forwards","backwards","directionIncrement","inverseDirectionIncrement"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,UAAT,EAAqBC,IAArB,EAA2BC,YAA3B,QAA+C,QAA/C;AAEA;AACA;AACA;;AACA,SACCC,WADD,EAECC,eAFD,EAGCC,YAHD,EAICC,gBAJD,EAKCC,OALD,EAMCC,WAND,EAOCC,cAPD,EAQCC,kBARD,EASCC,WATD,EAUCC,eAVD,QAWO,gBAXP;AAaA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,WAAT,CAAsBC,IAAtB,EAA6B;AACnC,MAAK,CAAEA,IAAP,EAAc;AACb,WAAO,KAAP;AACA;;AAED,QAAMC,WAAW,GAAGD,IAAI,CAACE,IAAL,EAApB;;AAEA,MAAK,CAAED,WAAP,EAAqB;AACpB,WAAO,KAAP;AACA,GATkC,CAWnC;;;AACA,MAAK,QAAQE,IAAR,CAAcF,WAAd,CAAL,EAAmC;AAClC,UAAMG,QAAQ,GAAGf,WAAW,CAAEY,WAAF,CAA5B;;AACA,QAAK,CAAEX,eAAe,CAAEc,QAAF,CAAtB,EAAqC;AACp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AS,EAAE,CAAC;AAFM,GAAnB;AAKA,QAAMC,kBAAkB,GAAGH,UAAU,CAAED,SAAF,CAAV,IAA2B,CAAtD,CARC,CAQwD;;AACzD,QAAMK,yBAAyB,GAAGD,kBAAkB,GAAG,CAAC,CAAxD;;AAEA,SACCrB,OAAO,CAAES,KAAF,CAAP,IACAT,OAAO,CAAES,KAAF,CAAP,CAAkBO,WAAlB,MAAoCD,eAFrC,EAGE;AACD;AACAN,IAAAA,KAAK,GAAGA,KAAK,GAAGY,kBAAhB;AACA,GAjBA,CAmBD;AACA;;;AACAZ,EAAAA,KAAK,GAAGA,KAAK,GAAGa,yBAAhB;AAEA,SAAOb,KAAP;AACA;;AAED,MAAMG,WAAW,GAAGjD,YAAY,CAAEmD,cAAF,EAAkB,WAAlB,CAAhC;AAEA,MAAMD,SAAS,GAAGlD,YAAY,CAAEmD,cAAF,EAAkB,UAAlB,CAA9B","sourcesContent":["/**\n * External dependencies\n */\nimport { startsWith, find, partialRight } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tgetProtocol,\n\tisValidProtocol,\n\tgetAuthority,\n\tisValidAuthority,\n\tgetPath,\n\tisValidPath,\n\tgetQueryString,\n\tisValidQueryString,\n\tgetFragment,\n\tisValidFragment,\n} from '@wordpress/url';\n\n/**\n * Check for issues with the provided href.\n *\n * @param {string} href The href.\n *\n * @return {boolean} Is the href invalid?\n */\nexport function isValidHref( href ) {\n\tif ( ! href ) {\n\t\treturn false;\n\t}\n\n\tconst trimmedHref = href.trim();\n\n\tif ( ! trimmedHref ) {\n\t\treturn false;\n\t}\n\n\t// Does the href start with something that looks like a URL protocol?\n\tif ( /^\\S+:/.test( trimmedHref ) ) {\n\t\tconst protocol = getProtocol( trimmedHref );\n\t\tif ( ! isValidProtocol( protocol ) ) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// Add some extra checks for http(s) URIs, since these are the most common use-case.\n\t\t// This ensures URIs with an http protocol have exactly two forward slashes following the protocol.\n\t\tif (\n\t\t\tstartsWith( protocol, 'http' ) &&\n\t\t\t! /^https?:\\/\\/[^\\/\\s]/i.test( trimmedHref )\n\t\t) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst authority = getAuthority( trimmedHref );\n\t\tif ( ! isValidAuthority( authority ) ) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst path = getPath( trimmedHref );\n\t\tif ( path && ! isValidPath( path ) ) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst queryString = getQueryString( trimmedHref );\n\t\tif ( queryString && ! isValidQueryString( queryString ) ) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst fragment = getFragment( trimmedHref );\n\t\tif ( fragment && ! isValidFragment( fragment ) ) {\n\t\t\treturn false;\n\t\t}\n\t}\n\n\t// Validate anchor links.\n\tif ( startsWith( trimmedHref, '#' ) && ! isValidFragment( trimmedHref ) ) {\n\t\treturn false;\n\t}\n\n\treturn true;\n}\n\n/**\n * Generates the format object that will be applied to the link text.\n *\n * @param {Object} options\n * @param {string} options.url The href of the link.\n * @param {string} options.type The type of the link.\n * @param {string} options.id The ID of the link.\n * @param {boolean} options.opensInNewWindow Whether this link will open in a new window.\n *\n * @return {Object} The final format object.\n */\nexport function createLinkFormat( { url, type, id, opensInNewWindow } ) {\n\tconst format = {\n\t\ttype: 'core/link',\n\t\tattributes: {\n\t\t\turl,\n\t\t},\n\t};\n\n\tif ( type ) format.attributes.type = type;\n\tif ( id ) format.attributes.id = id;\n\n\tif ( opensInNewWindow ) {\n\t\tformat.attributes.target = '_blank';\n\t\tformat.attributes.rel = 'noreferrer noopener';\n\t}\n\n\treturn format;\n}\n\n/* eslint-disable jsdoc/no-undefined-types */\n/**\n * Get the start and end boundaries of a given format from a rich text value.\n *\n *\n * @param {RichTextValue} value the rich text value to interrogate.\n * @param {string} format the identifier for the target format (e.g. `core/link`, `core/bold`).\n * @param {number?} startIndex optional startIndex to seek from.\n * @param {number?} endIndex optional endIndex to seek from.\n * @return {Object}\tobject containing start and end values for the given format.\n */\n/* eslint-enable jsdoc/no-undefined-types */\nexport function getFormatBoundary(\n\tvalue,\n\tformat,\n\tstartIndex = value.start,\n\tendIndex = value.end\n) {\n\tconst EMPTY_BOUNDARIES = {\n\t\tstart: null,\n\t\tend: null,\n\t};\n\n\tconst { formats } = value;\n\tlet targetFormat;\n\tlet initialIndex;\n\n\tif ( ! formats?.length ) {\n\t\treturn EMPTY_BOUNDARIES;\n\t}\n\n\t// Clone formats to avoid modifying source formats.\n\tconst newFormats = formats.slice();\n\n\tconst formatAtStart = find( newFormats[ startIndex ], {\n\t\ttype: format.type,\n\t} );\n\n\tconst formatAtEnd = find( newFormats[ endIndex ], {\n\t\ttype: format.type,\n\t} );\n\n\tconst formatAtEndMinusOne = find( newFormats[ endIndex - 1 ], {\n\t\ttype: format.type,\n\t} );\n\n\tif ( !! formatAtStart ) {\n\t\t// Set values to conform to \"start\"\n\t\ttargetFormat = formatAtStart;\n\t\tinitialIndex = startIndex;\n\t} else if ( !! formatAtEnd ) {\n\t\t// Set values to conform to \"end\"\n\t\ttargetFormat = formatAtEnd;\n\t\tinitialIndex = endIndex;\n\t} else if ( !! formatAtEndMinusOne ) {\n\t\t// This is an edge case which will occur if you create a format, then place\n\t\t// the caret just before the format and hit the back ARROW key. The resulting\n\t\t// value object will have start and end +1 beyond the edge of the format boundary.\n\t\ttargetFormat = formatAtEndMinusOne;\n\t\tinitialIndex = endIndex - 1;\n\t} else {\n\t\treturn EMPTY_BOUNDARIES;\n\t}\n\n\tconst index = newFormats[ initialIndex ].indexOf( targetFormat );\n\n\tconst walkingArgs = [ newFormats, initialIndex, targetFormat, index ];\n\n\t// Walk the startIndex \"backwards\" to the leading \"edge\" of the matching format.\n\tstartIndex = walkToStart( ...walkingArgs );\n\n\t// Walk the endIndex \"forwards\" until the trailing \"edge\" of the matching format.\n\tendIndex = walkToEnd( ...walkingArgs );\n\n\t// Safe guard: start index cannot be less than 0\n\tstartIndex = startIndex < 0 ? 0 : startIndex;\n\n\t// // Return the indicies of the \"edges\" as the boundaries.\n\treturn {\n\t\tstart: startIndex,\n\t\tend: endIndex,\n\t};\n}\n\n/**\n * Walks forwards/backwards towards the boundary of a given format within an\n * array of format objects. Returns the index of the boundary.\n *\n * @param {Array} formats the formats to search for the given format type.\n * @param {number} initialIndex the starting index from which to walk.\n * @param {Object} targetFormatRef a reference to the format type object being sought.\n * @param {number} formatIndex the index at which we expect the target format object to be.\n * @param {string} direction either 'forwards' or 'backwards' to indicate the direction.\n * @return {number} the index of the boundary of the given format.\n */\nfunction walkToBoundary(\n\tformats,\n\tinitialIndex,\n\ttargetFormatRef,\n\tformatIndex,\n\tdirection\n) {\n\tlet index = initialIndex;\n\n\tconst directions = {\n\t\tforwards: 1,\n\t\tbackwards: -1,\n\t};\n\n\tconst directionIncrement = directions[ direction ] || 1; // invalid direction arg default to forwards\n\tconst inverseDirectionIncrement = directionIncrement * -1;\n\n\twhile (\n\t\tformats[ index ] &&\n\t\tformats[ index ][ formatIndex ] === targetFormatRef\n\t) {\n\t\t// Increment/decrement in the direction of operation.\n\t\tindex = index + directionIncrement;\n\t}\n\n\t// Restore by one in inverse direction of operation\n\t// to avoid out of bounds.\n\tindex = index + inverseDirectionIncrement;\n\n\treturn index;\n}\n\nconst walkToStart = partialRight( walkToBoundary, 'backwards' );\n\nconst walkToEnd = partialRight( walkToBoundary, 'forwards' );\n"]}
@@ -25,7 +25,8 @@ export const strikethrough = {
25
25
  }) {
26
26
  function onClick() {
27
27
  onChange(toggleFormat(value, {
28
- type: name
28
+ type: name,
29
+ title
29
30
  }));
30
31
  onFocus();
31
32
  }
@@ -34,7 +35,8 @@ export const strikethrough = {
34
35
  icon: formatStrikethrough,
35
36
  title: title,
36
37
  onClick: onClick,
37
- isActive: isActive
38
+ isActive: isActive,
39
+ role: "menuitemcheckbox"
38
40
  });
39
41
  }
40
42
 
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/format-library/src/strikethrough/index.js"],"names":["__","toggleFormat","RichTextToolbarButton","formatStrikethrough","name","title","strikethrough","tagName","className","edit","isActive","value","onChange","onFocus","onClick","type"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,EAAT,QAAmB,iBAAnB;AACA,SAASC,YAAT,QAA6B,sBAA7B;AACA,SAASC,qBAAT,QAAsC,yBAAtC;AACA,SAASC,mBAAT,QAAoC,kBAApC;AAEA,MAAMC,IAAI,GAAG,oBAAb;;AACA,MAAMC,KAAK,GAAGL,EAAE,CAAE,eAAF,CAAhB;;AAEA,OAAO,MAAMM,aAAa,GAAG;AAC5BF,EAAAA,IAD4B;AAE5BC,EAAAA,KAF4B;AAG5BE,EAAAA,OAAO,EAAE,GAHmB;AAI5BC,EAAAA,SAAS,EAAE,IAJiB;;AAK5BC,EAAAA,IAAI,CAAE;AAAEC,IAAAA,QAAF;AAAYC,IAAAA,KAAZ;AAAmBC,IAAAA,QAAnB;AAA6BC,IAAAA;AAA7B,GAAF,EAA2C;AAC9C,aAASC,OAAT,GAAmB;AAClBF,MAAAA,QAAQ,CAAEX,YAAY,CAAEU,KAAF,EAAS;AAAEI,QAAAA,IAAI,EAAEX;AAAR,OAAT,CAAd,CAAR;AACAS,MAAAA,OAAO;AACP;;AAED,WACC,cAAC,qBAAD;AACC,MAAA,IAAI,EAAGV,mBADR;AAEC,MAAA,KAAK,EAAGE,KAFT;AAGC,MAAA,OAAO,EAAGS,OAHX;AAIC,MAAA,QAAQ,EAAGJ;AAJZ,MADD;AAQA;;AAnB2B,CAAtB","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { toggleFormat } from '@wordpress/rich-text';\nimport { RichTextToolbarButton } from '@wordpress/block-editor';\nimport { formatStrikethrough } from '@wordpress/icons';\n\nconst name = 'core/strikethrough';\nconst title = __( 'Strikethrough' );\n\nexport const strikethrough = {\n\tname,\n\ttitle,\n\ttagName: 's',\n\tclassName: null,\n\tedit( { isActive, value, onChange, onFocus } ) {\n\t\tfunction onClick() {\n\t\t\tonChange( toggleFormat( value, { type: name } ) );\n\t\t\tonFocus();\n\t\t}\n\n\t\treturn (\n\t\t\t<RichTextToolbarButton\n\t\t\t\ticon={ formatStrikethrough }\n\t\t\t\ttitle={ title }\n\t\t\t\tonClick={ onClick }\n\t\t\t\tisActive={ isActive }\n\t\t\t/>\n\t\t);\n\t},\n};\n"]}
1
+ {"version":3,"sources":["@wordpress/format-library/src/strikethrough/index.js"],"names":["__","toggleFormat","RichTextToolbarButton","formatStrikethrough","name","title","strikethrough","tagName","className","edit","isActive","value","onChange","onFocus","onClick","type"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,EAAT,QAAmB,iBAAnB;AACA,SAASC,YAAT,QAA6B,sBAA7B;AACA,SAASC,qBAAT,QAAsC,yBAAtC;AACA,SAASC,mBAAT,QAAoC,kBAApC;AAEA,MAAMC,IAAI,GAAG,oBAAb;;AACA,MAAMC,KAAK,GAAGL,EAAE,CAAE,eAAF,CAAhB;;AAEA,OAAO,MAAMM,aAAa,GAAG;AAC5BF,EAAAA,IAD4B;AAE5BC,EAAAA,KAF4B;AAG5BE,EAAAA,OAAO,EAAE,GAHmB;AAI5BC,EAAAA,SAAS,EAAE,IAJiB;;AAK5BC,EAAAA,IAAI,CAAE;AAAEC,IAAAA,QAAF;AAAYC,IAAAA,KAAZ;AAAmBC,IAAAA,QAAnB;AAA6BC,IAAAA;AAA7B,GAAF,EAA2C;AAC9C,aAASC,OAAT,GAAmB;AAClBF,MAAAA,QAAQ,CAAEX,YAAY,CAAEU,KAAF,EAAS;AAAEI,QAAAA,IAAI,EAAEX,IAAR;AAAcC,QAAAA;AAAd,OAAT,CAAd,CAAR;AACAQ,MAAAA,OAAO;AACP;;AAED,WACC,cAAC,qBAAD;AACC,MAAA,IAAI,EAAGV,mBADR;AAEC,MAAA,KAAK,EAAGE,KAFT;AAGC,MAAA,OAAO,EAAGS,OAHX;AAIC,MAAA,QAAQ,EAAGJ,QAJZ;AAKC,MAAA,IAAI,EAAC;AALN,MADD;AASA;;AApB2B,CAAtB","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { toggleFormat } from '@wordpress/rich-text';\nimport { RichTextToolbarButton } from '@wordpress/block-editor';\nimport { formatStrikethrough } from '@wordpress/icons';\n\nconst name = 'core/strikethrough';\nconst title = __( 'Strikethrough' );\n\nexport const strikethrough = {\n\tname,\n\ttitle,\n\ttagName: 's',\n\tclassName: null,\n\tedit( { isActive, value, onChange, onFocus } ) {\n\t\tfunction onClick() {\n\t\t\tonChange( toggleFormat( value, { type: name, title } ) );\n\t\t\tonFocus();\n\t\t}\n\n\t\treturn (\n\t\t\t<RichTextToolbarButton\n\t\t\t\ticon={ formatStrikethrough }\n\t\t\t\ttitle={ title }\n\t\t\t\tonClick={ onClick }\n\t\t\t\tisActive={ isActive }\n\t\t\t\trole=\"menuitemcheckbox\"\n\t\t\t/>\n\t\t);\n\t},\n};\n"]}
@@ -25,7 +25,8 @@ export const subscript = {
25
25
  }) {
26
26
  function onToggle() {
27
27
  onChange(toggleFormat(value, {
28
- type: name
28
+ type: name,
29
+ title
29
30
  }));
30
31
  }
31
32
 
@@ -38,7 +39,8 @@ export const subscript = {
38
39
  icon: subscriptIcon,
39
40
  title: title,
40
41
  onClick: onClick,
41
- isActive: isActive
42
+ isActive: isActive,
43
+ role: "menuitemcheckbox"
42
44
  });
43
45
  }
44
46
 
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/format-library/src/subscript/index.js"],"names":["__","toggleFormat","RichTextToolbarButton","subscript","subscriptIcon","name","title","tagName","className","edit","isActive","value","onChange","onFocus","onToggle","type","onClick"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,EAAT,QAAmB,iBAAnB;AACA,SAASC,YAAT,QAA6B,sBAA7B;AACA,SAASC,qBAAT,QAAsC,yBAAtC;AACA,SAASC,SAAS,IAAIC,aAAtB,QAA2C,kBAA3C;AAEA,MAAMC,IAAI,GAAG,gBAAb;;AACA,MAAMC,KAAK,GAAGN,EAAE,CAAE,WAAF,CAAhB;;AAEA,OAAO,MAAMG,SAAS,GAAG;AACxBE,EAAAA,IADwB;AAExBC,EAAAA,KAFwB;AAGxBC,EAAAA,OAAO,EAAE,KAHe;AAIxBC,EAAAA,SAAS,EAAE,IAJa;;AAKxBC,EAAAA,IAAI,CAAE;AAAEC,IAAAA,QAAF;AAAYC,IAAAA,KAAZ;AAAmBC,IAAAA,QAAnB;AAA6BC,IAAAA;AAA7B,GAAF,EAA2C;AAC9C,aAASC,QAAT,GAAoB;AACnBF,MAAAA,QAAQ,CAAEX,YAAY,CAAEU,KAAF,EAAS;AAAEI,QAAAA,IAAI,EAAEV;AAAR,OAAT,CAAd,CAAR;AACA;;AAED,aAASW,OAAT,GAAmB;AAClBF,MAAAA,QAAQ;AACRD,MAAAA,OAAO;AACP;;AAED,WACC,cAAC,qBAAD;AACC,MAAA,IAAI,EAAGT,aADR;AAEC,MAAA,KAAK,EAAGE,KAFT;AAGC,MAAA,OAAO,EAAGU,OAHX;AAIC,MAAA,QAAQ,EAAGN;AAJZ,MADD;AAQA;;AAvBuB,CAAlB","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { toggleFormat } from '@wordpress/rich-text';\nimport { RichTextToolbarButton } from '@wordpress/block-editor';\nimport { subscript as subscriptIcon } from '@wordpress/icons';\n\nconst name = 'core/subscript';\nconst title = __( 'Subscript' );\n\nexport const subscript = {\n\tname,\n\ttitle,\n\ttagName: 'sub',\n\tclassName: null,\n\tedit( { isActive, value, onChange, onFocus } ) {\n\t\tfunction onToggle() {\n\t\t\tonChange( toggleFormat( value, { type: name } ) );\n\t\t}\n\n\t\tfunction onClick() {\n\t\t\tonToggle();\n\t\t\tonFocus();\n\t\t}\n\n\t\treturn (\n\t\t\t<RichTextToolbarButton\n\t\t\t\ticon={ subscriptIcon }\n\t\t\t\ttitle={ title }\n\t\t\t\tonClick={ onClick }\n\t\t\t\tisActive={ isActive }\n\t\t\t/>\n\t\t);\n\t},\n};\n"]}
1
+ {"version":3,"sources":["@wordpress/format-library/src/subscript/index.js"],"names":["__","toggleFormat","RichTextToolbarButton","subscript","subscriptIcon","name","title","tagName","className","edit","isActive","value","onChange","onFocus","onToggle","type","onClick"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,EAAT,QAAmB,iBAAnB;AACA,SAASC,YAAT,QAA6B,sBAA7B;AACA,SAASC,qBAAT,QAAsC,yBAAtC;AACA,SAASC,SAAS,IAAIC,aAAtB,QAA2C,kBAA3C;AAEA,MAAMC,IAAI,GAAG,gBAAb;;AACA,MAAMC,KAAK,GAAGN,EAAE,CAAE,WAAF,CAAhB;;AAEA,OAAO,MAAMG,SAAS,GAAG;AACxBE,EAAAA,IADwB;AAExBC,EAAAA,KAFwB;AAGxBC,EAAAA,OAAO,EAAE,KAHe;AAIxBC,EAAAA,SAAS,EAAE,IAJa;;AAKxBC,EAAAA,IAAI,CAAE;AAAEC,IAAAA,QAAF;AAAYC,IAAAA,KAAZ;AAAmBC,IAAAA,QAAnB;AAA6BC,IAAAA;AAA7B,GAAF,EAA2C;AAC9C,aAASC,QAAT,GAAoB;AACnBF,MAAAA,QAAQ,CAAEX,YAAY,CAAEU,KAAF,EAAS;AAAEI,QAAAA,IAAI,EAAEV,IAAR;AAAcC,QAAAA;AAAd,OAAT,CAAd,CAAR;AACA;;AAED,aAASU,OAAT,GAAmB;AAClBF,MAAAA,QAAQ;AACRD,MAAAA,OAAO;AACP;;AAED,WACC,cAAC,qBAAD;AACC,MAAA,IAAI,EAAGT,aADR;AAEC,MAAA,KAAK,EAAGE,KAFT;AAGC,MAAA,OAAO,EAAGU,OAHX;AAIC,MAAA,QAAQ,EAAGN,QAJZ;AAKC,MAAA,IAAI,EAAC;AALN,MADD;AASA;;AAxBuB,CAAlB","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { toggleFormat } from '@wordpress/rich-text';\nimport { RichTextToolbarButton } from '@wordpress/block-editor';\nimport { subscript as subscriptIcon } from '@wordpress/icons';\n\nconst name = 'core/subscript';\nconst title = __( 'Subscript' );\n\nexport const subscript = {\n\tname,\n\ttitle,\n\ttagName: 'sub',\n\tclassName: null,\n\tedit( { isActive, value, onChange, onFocus } ) {\n\t\tfunction onToggle() {\n\t\t\tonChange( toggleFormat( value, { type: name, title } ) );\n\t\t}\n\n\t\tfunction onClick() {\n\t\t\tonToggle();\n\t\t\tonFocus();\n\t\t}\n\n\t\treturn (\n\t\t\t<RichTextToolbarButton\n\t\t\t\ticon={ subscriptIcon }\n\t\t\t\ttitle={ title }\n\t\t\t\tonClick={ onClick }\n\t\t\t\tisActive={ isActive }\n\t\t\t\trole=\"menuitemcheckbox\"\n\t\t\t/>\n\t\t);\n\t},\n};\n"]}
@@ -25,7 +25,8 @@ export const superscript = {
25
25
  }) {
26
26
  function onToggle() {
27
27
  onChange(toggleFormat(value, {
28
- type: name
28
+ type: name,
29
+ title
29
30
  }));
30
31
  }
31
32
 
@@ -38,7 +39,8 @@ export const superscript = {
38
39
  icon: superscriptIcon,
39
40
  title: title,
40
41
  onClick: onClick,
41
- isActive: isActive
42
+ isActive: isActive,
43
+ role: "menuitemcheckbox"
42
44
  });
43
45
  }
44
46
 
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/format-library/src/superscript/index.js"],"names":["__","toggleFormat","RichTextToolbarButton","superscript","superscriptIcon","name","title","tagName","className","edit","isActive","value","onChange","onFocus","onToggle","type","onClick"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,EAAT,QAAmB,iBAAnB;AACA,SAASC,YAAT,QAA6B,sBAA7B;AACA,SAASC,qBAAT,QAAsC,yBAAtC;AACA,SAASC,WAAW,IAAIC,eAAxB,QAA+C,kBAA/C;AAEA,MAAMC,IAAI,GAAG,kBAAb;;AACA,MAAMC,KAAK,GAAGN,EAAE,CAAE,aAAF,CAAhB;;AAEA,OAAO,MAAMG,WAAW,GAAG;AAC1BE,EAAAA,IAD0B;AAE1BC,EAAAA,KAF0B;AAG1BC,EAAAA,OAAO,EAAE,KAHiB;AAI1BC,EAAAA,SAAS,EAAE,IAJe;;AAK1BC,EAAAA,IAAI,CAAE;AAAEC,IAAAA,QAAF;AAAYC,IAAAA,KAAZ;AAAmBC,IAAAA,QAAnB;AAA6BC,IAAAA;AAA7B,GAAF,EAA2C;AAC9C,aAASC,QAAT,GAAoB;AACnBF,MAAAA,QAAQ,CAAEX,YAAY,CAAEU,KAAF,EAAS;AAAEI,QAAAA,IAAI,EAAEV;AAAR,OAAT,CAAd,CAAR;AACA;;AAED,aAASW,OAAT,GAAmB;AAClBF,MAAAA,QAAQ;AACRD,MAAAA,OAAO;AACP;;AAED,WACC,cAAC,qBAAD;AACC,MAAA,IAAI,EAAGT,eADR;AAEC,MAAA,KAAK,EAAGE,KAFT;AAGC,MAAA,OAAO,EAAGU,OAHX;AAIC,MAAA,QAAQ,EAAGN;AAJZ,MADD;AAQA;;AAvByB,CAApB","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { toggleFormat } from '@wordpress/rich-text';\nimport { RichTextToolbarButton } from '@wordpress/block-editor';\nimport { superscript as superscriptIcon } from '@wordpress/icons';\n\nconst name = 'core/superscript';\nconst title = __( 'Superscript' );\n\nexport const superscript = {\n\tname,\n\ttitle,\n\ttagName: 'sup',\n\tclassName: null,\n\tedit( { isActive, value, onChange, onFocus } ) {\n\t\tfunction onToggle() {\n\t\t\tonChange( toggleFormat( value, { type: name } ) );\n\t\t}\n\n\t\tfunction onClick() {\n\t\t\tonToggle();\n\t\t\tonFocus();\n\t\t}\n\n\t\treturn (\n\t\t\t<RichTextToolbarButton\n\t\t\t\ticon={ superscriptIcon }\n\t\t\t\ttitle={ title }\n\t\t\t\tonClick={ onClick }\n\t\t\t\tisActive={ isActive }\n\t\t\t/>\n\t\t);\n\t},\n};\n"]}
1
+ {"version":3,"sources":["@wordpress/format-library/src/superscript/index.js"],"names":["__","toggleFormat","RichTextToolbarButton","superscript","superscriptIcon","name","title","tagName","className","edit","isActive","value","onChange","onFocus","onToggle","type","onClick"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,EAAT,QAAmB,iBAAnB;AACA,SAASC,YAAT,QAA6B,sBAA7B;AACA,SAASC,qBAAT,QAAsC,yBAAtC;AACA,SAASC,WAAW,IAAIC,eAAxB,QAA+C,kBAA/C;AAEA,MAAMC,IAAI,GAAG,kBAAb;;AACA,MAAMC,KAAK,GAAGN,EAAE,CAAE,aAAF,CAAhB;;AAEA,OAAO,MAAMG,WAAW,GAAG;AAC1BE,EAAAA,IAD0B;AAE1BC,EAAAA,KAF0B;AAG1BC,EAAAA,OAAO,EAAE,KAHiB;AAI1BC,EAAAA,SAAS,EAAE,IAJe;;AAK1BC,EAAAA,IAAI,CAAE;AAAEC,IAAAA,QAAF;AAAYC,IAAAA,KAAZ;AAAmBC,IAAAA,QAAnB;AAA6BC,IAAAA;AAA7B,GAAF,EAA2C;AAC9C,aAASC,QAAT,GAAoB;AACnBF,MAAAA,QAAQ,CAAEX,YAAY,CAAEU,KAAF,EAAS;AAAEI,QAAAA,IAAI,EAAEV,IAAR;AAAcC,QAAAA;AAAd,OAAT,CAAd,CAAR;AACA;;AAED,aAASU,OAAT,GAAmB;AAClBF,MAAAA,QAAQ;AACRD,MAAAA,OAAO;AACP;;AAED,WACC,cAAC,qBAAD;AACC,MAAA,IAAI,EAAGT,eADR;AAEC,MAAA,KAAK,EAAGE,KAFT;AAGC,MAAA,OAAO,EAAGU,OAHX;AAIC,MAAA,QAAQ,EAAGN,QAJZ;AAKC,MAAA,IAAI,EAAC;AALN,MADD;AASA;;AAxByB,CAApB","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { toggleFormat } from '@wordpress/rich-text';\nimport { RichTextToolbarButton } from '@wordpress/block-editor';\nimport { superscript as superscriptIcon } from '@wordpress/icons';\n\nconst name = 'core/superscript';\nconst title = __( 'Superscript' );\n\nexport const superscript = {\n\tname,\n\ttitle,\n\ttagName: 'sup',\n\tclassName: null,\n\tedit( { isActive, value, onChange, onFocus } ) {\n\t\tfunction onToggle() {\n\t\t\tonChange( toggleFormat( value, { type: name, title } ) );\n\t\t}\n\n\t\tfunction onClick() {\n\t\t\tonToggle();\n\t\t\tonFocus();\n\t\t}\n\n\t\treturn (\n\t\t\t<RichTextToolbarButton\n\t\t\t\ticon={ superscriptIcon }\n\t\t\t\ttitle={ title }\n\t\t\t\tonClick={ onClick }\n\t\t\t\tisActive={ isActive }\n\t\t\t\trole=\"menuitemcheckbox\"\n\t\t\t/>\n\t\t);\n\t},\n};\n"]}