@wordpress/format-library 3.0.4 → 3.0.5

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 (62) hide show
  1. package/build/bold/index.js +5 -2
  2. package/build/bold/index.js.map +1 -1
  3. package/build/code/index.js +4 -2
  4. package/build/code/index.js.map +1 -1
  5. package/build/italic/index.js +5 -2
  6. package/build/italic/index.js.map +1 -1
  7. package/build/keyboard/index.js +4 -2
  8. package/build/keyboard/index.js.map +1 -1
  9. package/build/link/inline.js +56 -5
  10. package/build/link/inline.js.map +1 -1
  11. package/build/link/utils.js +112 -0
  12. package/build/link/utils.js.map +1 -1
  13. package/build/strikethrough/index.js +4 -2
  14. package/build/strikethrough/index.js.map +1 -1
  15. package/build/subscript/index.js +4 -2
  16. package/build/subscript/index.js.map +1 -1
  17. package/build/superscript/index.js +4 -2
  18. package/build/superscript/index.js.map +1 -1
  19. package/build/text-color/index.js +2 -1
  20. package/build/text-color/index.js.map +1 -1
  21. package/build/text-color/inline.js +9 -2
  22. package/build/text-color/inline.js.map +1 -1
  23. package/build/underline/index.js +4 -2
  24. package/build/underline/index.js.map +1 -1
  25. package/build-module/bold/index.js +5 -2
  26. package/build-module/bold/index.js.map +1 -1
  27. package/build-module/code/index.js +4 -2
  28. package/build-module/code/index.js.map +1 -1
  29. package/build-module/italic/index.js +5 -2
  30. package/build-module/italic/index.js.map +1 -1
  31. package/build-module/keyboard/index.js +4 -2
  32. package/build-module/keyboard/index.js.map +1 -1
  33. package/build-module/link/inline.js +58 -7
  34. package/build-module/link/inline.js.map +1 -1
  35. package/build-module/link/utils.js +110 -1
  36. package/build-module/link/utils.js.map +1 -1
  37. package/build-module/strikethrough/index.js +4 -2
  38. package/build-module/strikethrough/index.js.map +1 -1
  39. package/build-module/subscript/index.js +4 -2
  40. package/build-module/subscript/index.js.map +1 -1
  41. package/build-module/superscript/index.js +4 -2
  42. package/build-module/superscript/index.js.map +1 -1
  43. package/build-module/text-color/index.js +2 -1
  44. package/build-module/text-color/index.js.map +1 -1
  45. package/build-module/text-color/inline.js +10 -3
  46. package/build-module/text-color/inline.js.map +1 -1
  47. package/build-module/underline/index.js +6 -2
  48. package/build-module/underline/index.js.map +1 -1
  49. package/package.json +10 -10
  50. package/src/bold/index.js +2 -2
  51. package/src/code/index.js +2 -1
  52. package/src/italic/index.js +2 -2
  53. package/src/keyboard/index.js +2 -1
  54. package/src/link/inline.js +67 -5
  55. package/src/link/test/utils.js +362 -1
  56. package/src/link/utils.js +132 -1
  57. package/src/strikethrough/index.js +2 -1
  58. package/src/subscript/index.js +2 -1
  59. package/src/superscript/index.js +2 -1
  60. package/src/text-color/index.js +1 -0
  61. package/src/text-color/inline.js +12 -1
  62. package/src/underline/index.js +3 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/format-library/src/text-color/index.js"],"names":["name","title","EMPTY_ARRAY","getComputedStyleProperty","element","property","ownerDocument","defaultView","style","getComputedStyle","value","getPropertyValue","parentElement","fillComputedColors","color","backgroundColor","TextColorEdit","onChange","isActive","activeAttributes","contentRef","allowCustomControl","colors","isAddingColor","setIsAddingColor","enableIsAddingColor","disableIsAddingColor","colorIndicatorStyle","current","hasColorsToChoose","textColorIcon","textColor","tagName","className","attributes","class","__unstableFilterAttributeValue","key","includes","addedCSS","join","edit"],"mappings":";;;;;;;;;AASA;;AANA;;AAKA;;AAEA;;AACA;;AACA;;AAKA;;AAjBA;AACA;AACA;;AAGA;AACA;AACA;;AAOA;AACA;AACA;AAGA,MAAMA,IAAI,GAAG,iBAAb;AACA,MAAMC,KAAK,GAAG,cAAI,WAAJ,CAAd;AAEA,MAAMC,WAAW,GAAG,EAApB;;AAEA,SAASC,wBAAT,CAAmCC,OAAnC,EAA4CC,QAA5C,EAAuD;AACtD,QAAM;AAAEC,IAAAA;AAAF,MAAoBF,OAA1B;AACA,QAAM;AAAEG,IAAAA;AAAF,MAAkBD,aAAxB;AACA,QAAME,KAAK,GAAGD,WAAW,CAACE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AO3B,KAAP,EAAe;AAC5C,QAAK2B,GAAG,KAAK,OAAb,EAAuB,OAAO3B,KAAP,CADqB,CAE5C;;AACA,QAAKA,KAAK,IAAIA,KAAK,CAAC4B,QAAN,CAAgB,kBAAhB,CAAd,EAAqD,OAAO5B,KAAP;AACrD,UAAM6B,QAAQ,GAAG,CAAE,kBAAF,EAAsB,kBAAtB,EAA2CC,IAA3C,CAAiD,GAAjD,CAAjB,CAJ4C,CAK5C;AACA;;AACA,WAAO9B,KAAK,GAAG,CAAE6B,QAAF,EAAY7B,KAAZ,EAAoB8B,IAApB,CAA0B,GAA1B,CAAH,GAAqCD,QAAjD;AACA,GA1BuB;;AA2BxBE,EAAAA,IAAI,EAAEzB;AA3BkB,CAAlB","sourcesContent":["/**\n * External dependencies\n */\nimport { isEmpty } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useCallback, useMemo, useState } from '@wordpress/element';\nimport { RichTextToolbarButton, useSetting } from '@wordpress/block-editor';\nimport { Icon, textColor as textColorIcon } from '@wordpress/icons';\nimport { removeFormat } from '@wordpress/rich-text';\n\n/**\n * Internal dependencies\n */\nimport { default as InlineColorUI, getActiveColors } from './inline';\n\nconst name = 'core/text-color';\nconst title = __( 'Highlight' );\n\nconst EMPTY_ARRAY = [];\n\nfunction getComputedStyleProperty( element, property ) {\n\tconst { ownerDocument } = element;\n\tconst { defaultView } = ownerDocument;\n\tconst style = defaultView.getComputedStyle( element );\n\tconst value = style.getPropertyValue( property );\n\n\tif (\n\t\tproperty === 'background-color' &&\n\t\tvalue === 'rgba(0, 0, 0, 0)' &&\n\t\telement.parentElement\n\t) {\n\t\treturn getComputedStyleProperty( element.parentElement, property );\n\t}\n\n\treturn value;\n}\n\nfunction fillComputedColors( element, { color, backgroundColor } ) {\n\tif ( ! color && ! backgroundColor ) {\n\t\treturn;\n\t}\n\n\treturn {\n\t\tcolor: color || getComputedStyleProperty( element, 'color' ),\n\t\tbackgroundColor:\n\t\t\tbackgroundColor === 'rgba(0, 0, 0, 0)'\n\t\t\t\t? getComputedStyleProperty( element, 'background-color' )\n\t\t\t\t: backgroundColor,\n\t};\n}\n\nfunction TextColorEdit( {\n\tvalue,\n\tonChange,\n\tisActive,\n\tactiveAttributes,\n\tcontentRef,\n} ) {\n\tconst allowCustomControl = useSetting( 'color.custom' );\n\tconst colors = useSetting( 'color.palette' ) || EMPTY_ARRAY;\n\tconst [ isAddingColor, setIsAddingColor ] = useState( false );\n\tconst enableIsAddingColor = useCallback( () => setIsAddingColor( true ), [\n\t\tsetIsAddingColor,\n\t] );\n\tconst disableIsAddingColor = useCallback( () => setIsAddingColor( false ), [\n\t\tsetIsAddingColor,\n\t] );\n\tconst colorIndicatorStyle = useMemo(\n\t\t() =>\n\t\t\tfillComputedColors(\n\t\t\t\tcontentRef.current,\n\t\t\t\tgetActiveColors( value, name, colors )\n\t\t\t),\n\t\t[ value, colors ]\n\t);\n\n\tconst hasColorsToChoose = ! isEmpty( colors ) || ! allowCustomControl;\n\tif ( ! hasColorsToChoose && ! isActive ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t<RichTextToolbarButton\n\t\t\t\tclassName=\"format-library-text-color-button\"\n\t\t\t\tisActive={ isActive }\n\t\t\t\ticon={\n\t\t\t\t\t<Icon\n\t\t\t\t\t\ticon={ textColorIcon }\n\t\t\t\t\t\tstyle={ colorIndicatorStyle }\n\t\t\t\t\t/>\n\t\t\t\t}\n\t\t\t\ttitle={ title }\n\t\t\t\t// If has no colors to choose but a color is active remove the color onClick\n\t\t\t\tonClick={\n\t\t\t\t\thasColorsToChoose\n\t\t\t\t\t\t? enableIsAddingColor\n\t\t\t\t\t\t: () => onChange( removeFormat( value, name ) )\n\t\t\t\t}\n\t\t\t/>\n\t\t\t{ isAddingColor && (\n\t\t\t\t<InlineColorUI\n\t\t\t\t\tname={ name }\n\t\t\t\t\tonClose={ disableIsAddingColor }\n\t\t\t\t\tactiveAttributes={ activeAttributes }\n\t\t\t\t\tvalue={ value }\n\t\t\t\t\tonChange={ onChange }\n\t\t\t\t\tcontentRef={ contentRef }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nexport const textColor = {\n\tname,\n\ttitle,\n\ttagName: 'mark',\n\tclassName: 'has-inline-color',\n\tattributes: {\n\t\tstyle: 'style',\n\t\tclass: 'class',\n\t},\n\t/*\n\t * Since this format relies on the <mark> tag, it's important to\n\t * prevent the default yellow background color applied by most\n\t * browsers. The solution is to detect when this format is used with a\n\t * text color but no background color, and in such cases to override\n\t * the default styling with a transparent background.\n\t *\n\t * @see https://github.com/WordPress/gutenberg/pull/35516\n\t */\n\t__unstableFilterAttributeValue( key, value ) {\n\t\tif ( key !== 'style' ) return value;\n\t\t// We should not add a background-color if it's already set\n\t\tif ( value && value.includes( 'background-color' ) ) return value;\n\t\tconst addedCSS = [ 'background-color', 'rgba(0, 0, 0, 0)' ].join( ':' );\n\t\t// Prepend `addedCSS` to avoid a double `;;` as any the existing CSS\n\t\t// rules will already include a `;`.\n\t\treturn value ? [ addedCSS, value ].join( ';' ) : addedCSS;\n\t},\n\tedit: TextColorEdit,\n};\n"]}
1
+ {"version":3,"sources":["@wordpress/format-library/src/text-color/index.js"],"names":["name","title","EMPTY_ARRAY","getComputedStyleProperty","element","property","ownerDocument","defaultView","style","getComputedStyle","value","getPropertyValue","parentElement","fillComputedColors","color","backgroundColor","TextColorEdit","onChange","isActive","activeAttributes","contentRef","allowCustomControl","colors","isAddingColor","setIsAddingColor","enableIsAddingColor","disableIsAddingColor","colorIndicatorStyle","current","hasColorsToChoose","textColorIcon","textColor","tagName","className","attributes","class","__unstableFilterAttributeValue","key","includes","addedCSS","join","edit"],"mappings":";;;;;;;;;AASA;;AANA;;AAKA;;AAEA;;AACA;;AACA;;AAKA;;AAjBA;AACA;AACA;;AAGA;AACA;AACA;;AAOA;AACA;AACA;AAGA,MAAMA,IAAI,GAAG,iBAAb;AACA,MAAMC,KAAK,GAAG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AAExBC,EAAAA,KAFwB;AAGxB+B,EAAAA,OAAO,EAAE,MAHe;AAIxBC,EAAAA,SAAS,EAAE,kBAJa;AAKxBC,EAAAA,UAAU,EAAE;AACX1B,IAAAA,KAAK,EAAE,OADI;AAEX2B,IAAAA,KAAK,EAAE;AAFI,GALY;;AASxB;AACD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACCC,EAAAA,8BAA8B,CAAEC,GAAF,EAAO3B,KAAP,EAAe;AAC5C,QAAK2B,GAAG,KAAK,OAAb,EAAuB,OAAO3B,KAAP,CADqB,CAE5C;;AACA,QAAKA,KAAK,IAAIA,KAAK,CAAC4B,QAAN,CAAgB,kBAAhB,CAAd,EAAqD,OAAO5B,KAAP;AACrD,UAAM6B,QAAQ,GAAG,CAAE,kBAAF,EAAsB,kBAAtB,EAA2CC,IAA3C,CAAiD,GAAjD,CAAjB,CAJ4C,CAK5C;AACA;;AACA,WAAO9B,KAAK,GAAG,CAAE6B,QAAF,EAAY7B,KAAZ,EAAoB8B,IAApB,CAA0B,GAA1B,CAAH,GAAqCD,QAAjD;AACA,GA1BuB;;AA2BxBE,EAAAA,IAAI,EAAEzB;AA3BkB,CAAlB","sourcesContent":["/**\n * External dependencies\n */\nimport { isEmpty } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useCallback, useMemo, useState } from '@wordpress/element';\nimport { RichTextToolbarButton, useSetting } from '@wordpress/block-editor';\nimport { Icon, textColor as textColorIcon } from '@wordpress/icons';\nimport { removeFormat } from '@wordpress/rich-text';\n\n/**\n * Internal dependencies\n */\nimport { default as InlineColorUI, getActiveColors } from './inline';\n\nconst name = 'core/text-color';\nconst title = __( 'Highlight' );\n\nconst EMPTY_ARRAY = [];\n\nfunction getComputedStyleProperty( element, property ) {\n\tconst { ownerDocument } = element;\n\tconst { defaultView } = ownerDocument;\n\tconst style = defaultView.getComputedStyle( element );\n\tconst value = style.getPropertyValue( property );\n\n\tif (\n\t\tproperty === 'background-color' &&\n\t\tvalue === 'rgba(0, 0, 0, 0)' &&\n\t\telement.parentElement\n\t) {\n\t\treturn getComputedStyleProperty( element.parentElement, property );\n\t}\n\n\treturn value;\n}\n\nfunction fillComputedColors( element, { color, backgroundColor } ) {\n\tif ( ! color && ! backgroundColor ) {\n\t\treturn;\n\t}\n\n\treturn {\n\t\tcolor: color || getComputedStyleProperty( element, 'color' ),\n\t\tbackgroundColor:\n\t\t\tbackgroundColor === 'rgba(0, 0, 0, 0)'\n\t\t\t\t? getComputedStyleProperty( element, 'background-color' )\n\t\t\t\t: backgroundColor,\n\t};\n}\n\nfunction TextColorEdit( {\n\tvalue,\n\tonChange,\n\tisActive,\n\tactiveAttributes,\n\tcontentRef,\n} ) {\n\tconst allowCustomControl = useSetting( 'color.custom' );\n\tconst colors = useSetting( 'color.palette' ) || EMPTY_ARRAY;\n\tconst [ isAddingColor, setIsAddingColor ] = useState( false );\n\tconst enableIsAddingColor = useCallback( () => setIsAddingColor( true ), [\n\t\tsetIsAddingColor,\n\t] );\n\tconst disableIsAddingColor = useCallback( () => setIsAddingColor( false ), [\n\t\tsetIsAddingColor,\n\t] );\n\tconst colorIndicatorStyle = useMemo(\n\t\t() =>\n\t\t\tfillComputedColors(\n\t\t\t\tcontentRef.current,\n\t\t\t\tgetActiveColors( value, name, colors )\n\t\t\t),\n\t\t[ value, colors ]\n\t);\n\n\tconst hasColorsToChoose = ! isEmpty( colors ) || ! allowCustomControl;\n\tif ( ! hasColorsToChoose && ! isActive ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t<RichTextToolbarButton\n\t\t\t\tclassName=\"format-library-text-color-button\"\n\t\t\t\tisActive={ isActive }\n\t\t\t\ticon={\n\t\t\t\t\t<Icon\n\t\t\t\t\t\ticon={ textColorIcon }\n\t\t\t\t\t\tstyle={ colorIndicatorStyle }\n\t\t\t\t\t/>\n\t\t\t\t}\n\t\t\t\ttitle={ title }\n\t\t\t\t// If has no colors to choose but a color is active remove the color onClick\n\t\t\t\tonClick={\n\t\t\t\t\thasColorsToChoose\n\t\t\t\t\t\t? enableIsAddingColor\n\t\t\t\t\t\t: () => onChange( removeFormat( value, name ) )\n\t\t\t\t}\n\t\t\t\trole=\"menuitemcheckbox\"\n\t\t\t/>\n\t\t\t{ isAddingColor && (\n\t\t\t\t<InlineColorUI\n\t\t\t\t\tname={ name }\n\t\t\t\t\tonClose={ disableIsAddingColor }\n\t\t\t\t\tactiveAttributes={ activeAttributes }\n\t\t\t\t\tvalue={ value }\n\t\t\t\t\tonChange={ onChange }\n\t\t\t\t\tcontentRef={ contentRef }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nexport const textColor = {\n\tname,\n\ttitle,\n\ttagName: 'mark',\n\tclassName: 'has-inline-color',\n\tattributes: {\n\t\tstyle: 'style',\n\t\tclass: 'class',\n\t},\n\t/*\n\t * Since this format relies on the <mark> tag, it's important to\n\t * prevent the default yellow background color applied by most\n\t * browsers. The solution is to detect when this format is used with a\n\t * text color but no background color, and in such cases to override\n\t * the default styling with a transparent background.\n\t *\n\t * @see https://github.com/WordPress/gutenberg/pull/35516\n\t */\n\t__unstableFilterAttributeValue( key, value ) {\n\t\tif ( key !== 'style' ) return value;\n\t\t// We should not add a background-color if it's already set\n\t\tif ( value && value.includes( 'background-color' ) ) return value;\n\t\tconst addedCSS = [ 'background-color', 'rgba(0, 0, 0, 0)' ].join( ':' );\n\t\t// Prepend `addedCSS` to avoid a double `;;` as any the existing CSS\n\t\t// rules will already include a `;`.\n\t\treturn value ? [ addedCSS, value ].join( ';' ) : addedCSS;\n\t},\n\tedit: TextColorEdit,\n};\n"]}
@@ -143,11 +143,18 @@ function InlineColorUI({
143
143
  onClose,
144
144
  contentRef
145
145
  }) {
146
- const anchorRef = (0, _richText.useAnchorRef)({
146
+ /*
147
+ As you change the text color by typing a HEX value into a field,
148
+ the return value of document.getSelection jumps to the field you're editing,
149
+ not the highlighted text. Given that useAnchorRef uses document.getSelection,
150
+ it will return null, since it can't find the <mark> element within the HEX input.
151
+ This caches the last truthy value of the selection anchor reference.
152
+ */
153
+ const anchorRef = (0, _blockEditor.useCachedTruthy)((0, _richText.useAnchorRef)({
147
154
  ref: contentRef,
148
155
  value,
149
156
  settings: _index.textColor
150
- });
157
+ }));
151
158
  return (0, _element.createElement)(_components.Popover, {
152
159
  onClose: onClose,
153
160
  className: "components-inline-color-popover",
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/format-library/src/text-color/inline.js"],"names":["parseCSS","css","split","reduce","accumulator","rule","property","value","color","backgroundColor","parseClassName","className","colorSettings","name","match","colorSlug","colorObject","getActiveColors","activeColorFormat","attributes","style","class","setColors","colors","styles","classNames","push","join","slug","length","type","ColorPicker","onChange","select","getSettings","blockEditorStore","onColorChange","activeColors","InlineColorUI","onClose","contentRef","anchorRef","ref","settings","title","tab"],"mappings":";;;;;;;;AAQA;;AALA;;AAMA;;AACA;;AAMA;;AAOA;;AACA;;AAKA;;AA7BA;AACA;AACA;;AAGA;AACA;AACA;;AAmBA;AACA;AACA;AAGA,SAASA,QAAT,CAAmBC,GAAG,GAAG,EAAzB,EAA8B;AAC7B,SAAOA,GAAG,CAACC,KAAJ,CAAW,GAAX,EAAiBC,MAAjB,CAAyB,CAAEC,WAAF,EAAeC,IAAf,KAAyB;AACxD,QAAKA,IAAL,EAAY;AACX,YAAM,CAAEC,QAAF,EAAYC,KAAZ,IAAsBF,IAAI,CAACH,KAAL,CAAY,GAAZ,CAA5B;AACA,UAAKI,QAAQ,KAAK,OAAlB,EAA4BF,WAAW,CAACI,KAAZ,GAAoBD,KAApB;AAC5B,UAAKD,QAAQ,KAAK,kBAAlB,EACCF,WAAW,CAACK,eAAZ,GAA8BF,KAA9B;AACD;;AACD,WAAOH,WAAP;AACA,GARM,EAQJ,EARI,CAAP;AASA;;AAED,SAASM,cAAT,CAAyBC,SAAS,GAAG,EAArC,EAAyCC,aAAzC,EAAyD;AACxD,SAAOD,SAAS,CAACT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IACD,4BAAC,WAAD;AACC,IAAA,IAAI,EAAGhC,IADR;AAEC,IAAA,QAAQ,EAAGgC,GAAG,CAAChC,IAFhB;AAGC,IAAA,KAAK,EAAGN,KAHT;AAIC,IAAA,QAAQ,EAAGyB;AAJZ,IAbF,CALD,CADD;AA6BA","sourcesContent":["/**\n * External dependencies\n */\nimport { get } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { useCallback, useMemo } from '@wordpress/element';\nimport { useSelect } from '@wordpress/data';\nimport {\n\tapplyFormat,\n\tremoveFormat,\n\tgetActiveFormat,\n\tuseAnchorRef,\n} from '@wordpress/rich-text';\nimport {\n\tColorPalette,\n\tgetColorClassName,\n\tgetColorObjectByColorValue,\n\tgetColorObjectByAttributeValues,\n\tstore as blockEditorStore,\n} from '@wordpress/block-editor';\nimport { Popover, TabPanel } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { textColor as settings } from './index';\n\nfunction parseCSS( css = '' ) {\n\treturn css.split( ';' ).reduce( ( accumulator, rule ) => {\n\t\tif ( rule ) {\n\t\t\tconst [ property, value ] = rule.split( ':' );\n\t\t\tif ( property === 'color' ) accumulator.color = value;\n\t\t\tif ( property === 'background-color' )\n\t\t\t\taccumulator.backgroundColor = value;\n\t\t}\n\t\treturn accumulator;\n\t}, {} );\n}\n\nfunction parseClassName( className = '', colorSettings ) {\n\treturn className.split( ' ' ).reduce( ( accumulator, name ) => {\n\t\tconst match = name.match( /^has-([^-]+)-color$/ );\n\t\tif ( match ) {\n\t\t\tconst [ , colorSlug ] = name.match( /^has-([^-]+)-color$/ );\n\t\t\tconst colorObject = getColorObjectByAttributeValues(\n\t\t\t\tcolorSettings,\n\t\t\t\tcolorSlug\n\t\t\t);\n\t\t\taccumulator.color = colorObject.color;\n\t\t}\n\t\treturn accumulator;\n\t}, {} );\n}\n\nexport function getActiveColors( value, name, colorSettings ) {\n\tconst activeColorFormat = getActiveFormat( value, name );\n\n\tif ( ! activeColorFormat ) {\n\t\treturn {};\n\t}\n\n\treturn {\n\t\t...parseCSS( activeColorFormat.attributes.style ),\n\t\t...parseClassName( activeColorFormat.attributes.class, colorSettings ),\n\t};\n}\n\nfunction setColors( value, name, colorSettings, colors ) {\n\tconst { color, backgroundColor } = {\n\t\t...getActiveColors( value, name, colorSettings ),\n\t\t...colors,\n\t};\n\n\tif ( ! color && ! backgroundColor ) {\n\t\treturn removeFormat( value, name );\n\t}\n\n\tconst styles = [];\n\tconst classNames = [];\n\tconst attributes = {};\n\n\tif ( backgroundColor ) {\n\t\tstyles.push( [ 'background-color', backgroundColor ].join( ':' ) );\n\t} else {\n\t\t// Override default browser color for mark element.\n\t\tstyles.push( [ 'background-color', 'rgba(0, 0, 0, 0)' ].join( ':' ) );\n\t}\n\n\tif ( color ) {\n\t\tconst colorObject = getColorObjectByColorValue( colorSettings, color );\n\n\t\tif ( colorObject ) {\n\t\t\tclassNames.push( getColorClassName( 'color', colorObject.slug ) );\n\t\t} else {\n\t\t\tstyles.push( [ 'color', color ].join( ':' ) );\n\t\t}\n\t}\n\n\tif ( styles.length ) attributes.style = styles.join( ';' );\n\tif ( classNames.length ) attributes.class = classNames.join( ' ' );\n\n\treturn applyFormat( value, { type: name, attributes } );\n}\n\nfunction ColorPicker( { name, property, value, onChange } ) {\n\tconst colors = useSelect( ( select ) => {\n\t\tconst { getSettings } = select( blockEditorStore );\n\t\treturn get( getSettings(), [ 'colors' ], [] );\n\t}, [] );\n\tconst onColorChange = useCallback(\n\t\t( color ) => {\n\t\t\tonChange(\n\t\t\t\tsetColors( value, name, colors, { [ property ]: color } )\n\t\t\t);\n\t\t},\n\t\t[ colors, onChange, property ]\n\t);\n\tconst activeColors = useMemo(\n\t\t() => getActiveColors( value, name, colors ),\n\t\t[ name, value, colors ]\n\t);\n\n\treturn (\n\t\t<ColorPalette\n\t\t\tvalue={ activeColors[ property ] }\n\t\t\tonChange={ onColorChange }\n\t\t/>\n\t);\n}\n\nexport default function InlineColorUI( {\n\tname,\n\tvalue,\n\tonChange,\n\tonClose,\n\tcontentRef,\n} ) {\n\tconst anchorRef = useAnchorRef( { ref: contentRef, value, settings } );\n\treturn (\n\t\t<Popover\n\t\t\tonClose={ onClose }\n\t\t\tclassName=\"components-inline-color-popover\"\n\t\t\tanchorRef={ anchorRef }\n\t\t>\n\t\t\t<TabPanel\n\t\t\t\ttabs={ [\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'color',\n\t\t\t\t\t\ttitle: __( 'Text' ),\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'backgroundColor',\n\t\t\t\t\t\ttitle: __( 'Background' ),\n\t\t\t\t\t},\n\t\t\t\t] }\n\t\t\t>\n\t\t\t\t{ ( tab ) => (\n\t\t\t\t\t<ColorPicker\n\t\t\t\t\t\tname={ name }\n\t\t\t\t\t\tproperty={ tab.name }\n\t\t\t\t\t\tvalue={ value }\n\t\t\t\t\t\tonChange={ onChange }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t</TabPanel>\n\t\t</Popover>\n\t);\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/format-library/src/text-color/inline.js"],"names":["parseCSS","css","split","reduce","accumulator","rule","property","value","color","backgroundColor","parseClassName","className","colorSettings","name","match","colorSlug","colorObject","getActiveColors","activeColorFormat","attributes","style","class","setColors","colors","styles","classNames","push","join","slug","length","type","ColorPicker","onChange","select","getSettings","blockEditorStore","onColorChange","activeColors","InlineColorUI","onClose","contentRef","anchorRef","ref","settings","title","tab"],"mappings":";;;;;;;;AAQA;;AALA;;AAMA;;AACA;;AAMA;;AAQA;;AACA;;AAKA;;AA9BA;AACA;AACA;;AAGA;AACA;AACA;;AAoBA;AACA;AACA;AAGA,SAASA,QAAT,CAAmBC,GAAG,GAAG,EAAzB,EAA8B;AAC7B,SAAOA,GAAG,CAACC,KAAJ,CAAW,GAAX,EAAiBC,MAAjB,CAAyB,CAAEC,WAAF,EAAeC,IAAf,KAAyB;AACxD,Q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EAAEF,UAAP;AAAmBjC,IAAAA,KAAnB;AAA0BoC,IAAAA,QAAQ,EAARA;AAA1B,GAAd,CADiB,CAAlB;AAIA,SACC,4BAAC,mBAAD;AACC,IAAA,OAAO,EAAGJ,OADX;AAEC,IAAA,SAAS,EAAC,iCAFX;AAGC,IAAA,SAAS,EAAGE;AAHb,KAKC,4BAAC,oBAAD;AACC,IAAA,IAAI,EAAG,CACN;AACC5B,MAAAA,IAAI,EAAE,OADP;AAEC+B,MAAAA,KAAK,EAAE,cAAI,MAAJ;AAFR,KADM,EAKN;AACC/B,MAAAA,IAAI,EAAE,iBADP;AAEC+B,MAAAA,KAAK,EAAE,cAAI,YAAJ;AAFR,KALM;AADR,KAYKC,GAAF,IACD,4BAAC,WAAD;AACC,IAAA,IAAI,EAAGhC,IADR;AAEC,IAAA,QAAQ,EAAGgC,GAAG,CAAChC,IAFhB;AAGC,IAAA,KAAK,EAAGN,KAHT;AAIC,IAAA,QAAQ,EAAGyB;AAJZ,IAbF,CALD,CADD;AA6BA","sourcesContent":["/**\n * External dependencies\n */\nimport { get } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { useCallback, useMemo } from '@wordpress/element';\nimport { useSelect } from '@wordpress/data';\nimport {\n\tapplyFormat,\n\tremoveFormat,\n\tgetActiveFormat,\n\tuseAnchorRef,\n} from '@wordpress/rich-text';\nimport {\n\tColorPalette,\n\tgetColorClassName,\n\tgetColorObjectByColorValue,\n\tgetColorObjectByAttributeValues,\n\tstore as blockEditorStore,\n\tuseCachedTruthy,\n} from '@wordpress/block-editor';\nimport { Popover, TabPanel } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { textColor as settings } from './index';\n\nfunction parseCSS( css = '' ) {\n\treturn css.split( ';' ).reduce( ( accumulator, rule ) => {\n\t\tif ( rule ) {\n\t\t\tconst [ property, value ] = rule.split( ':' );\n\t\t\tif ( property === 'color' ) accumulator.color = value;\n\t\t\tif ( property === 'background-color' )\n\t\t\t\taccumulator.backgroundColor = value;\n\t\t}\n\t\treturn accumulator;\n\t}, {} );\n}\n\nfunction parseClassName( className = '', colorSettings ) {\n\treturn className.split( ' ' ).reduce( ( accumulator, name ) => {\n\t\tconst match = name.match( /^has-([^-]+)-color$/ );\n\t\tif ( match ) {\n\t\t\tconst [ , colorSlug ] = name.match( /^has-([^-]+)-color$/ );\n\t\t\tconst colorObject = getColorObjectByAttributeValues(\n\t\t\t\tcolorSettings,\n\t\t\t\tcolorSlug\n\t\t\t);\n\t\t\taccumulator.color = colorObject.color;\n\t\t}\n\t\treturn accumulator;\n\t}, {} );\n}\n\nexport function getActiveColors( value, name, colorSettings ) {\n\tconst activeColorFormat = getActiveFormat( value, name );\n\n\tif ( ! activeColorFormat ) {\n\t\treturn {};\n\t}\n\n\treturn {\n\t\t...parseCSS( activeColorFormat.attributes.style ),\n\t\t...parseClassName( activeColorFormat.attributes.class, colorSettings ),\n\t};\n}\n\nfunction setColors( value, name, colorSettings, colors ) {\n\tconst { color, backgroundColor } = {\n\t\t...getActiveColors( value, name, colorSettings ),\n\t\t...colors,\n\t};\n\n\tif ( ! color && ! backgroundColor ) {\n\t\treturn removeFormat( value, name );\n\t}\n\n\tconst styles = [];\n\tconst classNames = [];\n\tconst attributes = {};\n\n\tif ( backgroundColor ) {\n\t\tstyles.push( [ 'background-color', backgroundColor ].join( ':' ) );\n\t} else {\n\t\t// Override default browser color for mark element.\n\t\tstyles.push( [ 'background-color', 'rgba(0, 0, 0, 0)' ].join( ':' ) );\n\t}\n\n\tif ( color ) {\n\t\tconst colorObject = getColorObjectByColorValue( colorSettings, color );\n\n\t\tif ( colorObject ) {\n\t\t\tclassNames.push( getColorClassName( 'color', colorObject.slug ) );\n\t\t} else {\n\t\t\tstyles.push( [ 'color', color ].join( ':' ) );\n\t\t}\n\t}\n\n\tif ( styles.length ) attributes.style = styles.join( ';' );\n\tif ( classNames.length ) attributes.class = classNames.join( ' ' );\n\n\treturn applyFormat( value, { type: name, attributes } );\n}\n\nfunction ColorPicker( { name, property, value, onChange } ) {\n\tconst colors = useSelect( ( select ) => {\n\t\tconst { getSettings } = select( blockEditorStore );\n\t\treturn get( getSettings(), [ 'colors' ], [] );\n\t}, [] );\n\tconst onColorChange = useCallback(\n\t\t( color ) => {\n\t\t\tonChange(\n\t\t\t\tsetColors( value, name, colors, { [ property ]: color } )\n\t\t\t);\n\t\t},\n\t\t[ colors, onChange, property ]\n\t);\n\tconst activeColors = useMemo(\n\t\t() => getActiveColors( value, name, colors ),\n\t\t[ name, value, colors ]\n\t);\n\n\treturn (\n\t\t<ColorPalette\n\t\t\tvalue={ activeColors[ property ] }\n\t\t\tonChange={ onColorChange }\n\t\t/>\n\t);\n}\n\nexport default function InlineColorUI( {\n\tname,\n\tvalue,\n\tonChange,\n\tonClose,\n\tcontentRef,\n} ) {\n\t/* \n\t As you change the text color by typing a HEX value into a field,\n\t the return value of document.getSelection jumps to the field you're editing,\n\t not the highlighted text. Given that useAnchorRef uses document.getSelection,\n\t it will return null, since it can't find the <mark> element within the HEX input.\n\t This caches the last truthy value of the selection anchor reference.\n\t */\n\tconst anchorRef = useCachedTruthy(\n\t\tuseAnchorRef( { ref: contentRef, value, settings } )\n\t);\n\n\treturn (\n\t\t<Popover\n\t\t\tonClose={ onClose }\n\t\t\tclassName=\"components-inline-color-popover\"\n\t\t\tanchorRef={ anchorRef }\n\t\t>\n\t\t\t<TabPanel\n\t\t\t\ttabs={ [\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'color',\n\t\t\t\t\t\ttitle: __( 'Text' ),\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'backgroundColor',\n\t\t\t\t\t\ttitle: __( 'Background' ),\n\t\t\t\t\t},\n\t\t\t\t] }\n\t\t\t>\n\t\t\t\t{ ( tab ) => (\n\t\t\t\t\t<ColorPicker\n\t\t\t\t\t\tname={ name }\n\t\t\t\t\t\tproperty={ tab.name }\n\t\t\t\t\t\tvalue={ value }\n\t\t\t\t\t\tonChange={ onChange }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t</TabPanel>\n\t\t</Popover>\n\t);\n}\n"]}
@@ -17,9 +17,10 @@ var _blockEditor = require("@wordpress/block-editor");
17
17
  * WordPress dependencies
18
18
  */
19
19
  const name = 'core/underline';
20
+ const title = (0, _i18n.__)('Underline');
20
21
  const underline = {
21
22
  name,
22
- title: (0, _i18n.__)('Underline'),
23
+ title,
23
24
  tagName: 'span',
24
25
  className: null,
25
26
  attributes: {
@@ -35,7 +36,8 @@ const underline = {
35
36
  type: name,
36
37
  attributes: {
37
38
  style: 'text-decoration: underline;'
38
- }
39
+ },
40
+ title
39
41
  }));
40
42
  };
41
43
 
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/format-library/src/underline/index.js"],"names":["name","underline","title","tagName","className","attributes","style","edit","value","onChange","onToggle","type"],"mappings":";;;;;;;;;AAGA;;AACA;;AACA;;AALA;AACA;AACA;AAQA,MAAMA,IAAI,GAAG,gBAAb;AAEO,MAAMC,SAAS,GAAG;AACxBD,EAAAA,IADwB;AAExBE,EAAAA,KAAK,EAAE,cAAI,WAAJ,CAFiB;AAGxBC,EAAAA,OAAO,EAAE,MAHe;AAIxBC,EAAAA,SAAS,EAAE,IAJa;AAKxBC,EAAAA,UAAU,EAAE;AACXC,IAAAA,KAAK,EAAE;AADI,GALY;;AAQxBC,EAAAA,IAAI,CAAE;AAAEC,IAAAA,KAAF;AAASC,IAAAA;AAAT,GAAF,EAAwB;AAC3B,UAAMC,QAAQ,GAAG,MAAM;AACtBD,MAAAA,QAAQ,CACP,4BAAcD,KAAd,EAAqB;AACpBG,QAAAA,IAAI,EAAEX,IADc;AAEpBK,QAAAA,UAAU,EAAE;AACXC,UAAAA,KAAK,EAAE;AADI;AAFQ,OAArB,CADO,CAAR;AAQA,KATD;;AAWA,WACC,qDACC,4BAAC,6BAAD;AACC,MAAA,IAAI,EAAC,SADN;AAEC,MAAA,SAAS,EAAC,GAFX;AAGC,MAAA,KAAK,EAAGI;AAHT,MADD,EAMC,4BAAC,yCAAD;AACC,MAAA,SAAS,EAAC,iBADX;AAEC,MAAA,OAAO,EAAGA;AAFX,MAND,CADD;AAaA;;AAjCuB,CAAlB","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { toggleFormat } from '@wordpress/rich-text';\nimport {\n\tRichTextShortcut,\n\t__unstableRichTextInputEvent,\n} from '@wordpress/block-editor';\n\nconst name = 'core/underline';\n\nexport const underline = {\n\tname,\n\ttitle: __( 'Underline' ),\n\ttagName: 'span',\n\tclassName: null,\n\tattributes: {\n\t\tstyle: 'style',\n\t},\n\tedit( { value, onChange } ) {\n\t\tconst onToggle = () => {\n\t\t\tonChange(\n\t\t\t\ttoggleFormat( value, {\n\t\t\t\t\ttype: name,\n\t\t\t\t\tattributes: {\n\t\t\t\t\t\tstyle: 'text-decoration: underline;',\n\t\t\t\t\t},\n\t\t\t\t} )\n\t\t\t);\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=\"u\"\n\t\t\t\t\tonUse={ onToggle }\n\t\t\t\t/>\n\t\t\t\t<__unstableRichTextInputEvent\n\t\t\t\t\tinputType=\"formatUnderline\"\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/underline/index.js"],"names":["name","title","underline","tagName","className","attributes","style","edit","value","onChange","onToggle","type"],"mappings":";;;;;;;;;AAGA;;AACA;;AACA;;AALA;AACA;AACA;AAQA,MAAMA,IAAI,GAAG,gBAAb;AACA,MAAMC,KAAK,GAAG,cAAI,WAAJ,CAAd;AAEO,MAAMC,SAAS,GAAG;AACxBF,EAAAA,IADwB;AAExBC,EAAAA,KAFwB;AAGxBE,EAAAA,OAAO,EAAE,MAHe;AAIxBC,EAAAA,SAAS,EAAE,IAJa;AAKxBC,EAAAA,UAAU,EAAE;AACXC,IAAAA,KAAK,EAAE;AADI,GALY;;AAQxBC,EAAAA,IAAI,CAAE;AAAEC,IAAAA,KAAF;AAASC,IAAAA;AAAT,GAAF,EAAwB;AAC3B,UAAMC,QAAQ,GAAG,MAAM;AACtBD,MAAAA,QAAQ,CACP,4BAAcD,KAAd,EAAqB;AACpBG,QAAAA,IAAI,EAAEX,IADc;AAEpBK,QAAAA,UAAU,EAAE;AACXC,UAAAA,KAAK,EAAE;AADI,SAFQ;AAKpBL,QAAAA;AALoB,OAArB,CADO,CAAR;AASA,KAVD;;AAYA,WACC,qDACC,4BAAC,6BAAD;AACC,MAAA,IAAI,EAAC,SADN;AAEC,MAAA,SAAS,EAAC,GAFX;AAGC,MAAA,KAAK,EAAGS;AAHT,MADD,EAMC,4BAAC,yCAAD;AACC,MAAA,SAAS,EAAC,iBADX;AAEC,MAAA,OAAO,EAAGA;AAFX,MAND,CADD;AAaA;;AAlCuB,CAAlB","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { toggleFormat } from '@wordpress/rich-text';\nimport {\n\tRichTextShortcut,\n\t__unstableRichTextInputEvent,\n} from '@wordpress/block-editor';\n\nconst name = 'core/underline';\nconst title = __( 'Underline' );\n\nexport const underline = {\n\tname,\n\ttitle,\n\ttagName: 'span',\n\tclassName: null,\n\tattributes: {\n\t\tstyle: 'style',\n\t},\n\tedit( { value, onChange } ) {\n\t\tconst onToggle = () => {\n\t\t\tonChange(\n\t\t\t\ttoggleFormat( value, {\n\t\t\t\t\ttype: name,\n\t\t\t\t\tattributes: {\n\t\t\t\t\t\tstyle: 'text-decoration: underline;',\n\t\t\t\t\t},\n\t\t\t\t\ttitle,\n\t\t\t\t} )\n\t\t\t);\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=\"u\"\n\t\t\t\t\tonUse={ onToggle }\n\t\t\t\t/>\n\t\t\t\t<__unstableRichTextInputEvent\n\t\t\t\t\tinputType=\"formatUnderline\"\n\t\t\t\t\tonInput={ onToggle }\n\t\t\t\t/>\n\t\t\t</>\n\t\t);\n\t},\n};\n"]}
@@ -25,12 +25,15 @@ export const bold = {
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
 
32
33
  function onClick() {
33
- onToggle();
34
+ onChange(toggleFormat(value, {
35
+ type: name
36
+ }));
34
37
  onFocus();
35
38
  }
36
39
 
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/format-library/src/bold/index.js"],"names":["__","toggleFormat","RichTextToolbarButton","RichTextShortcut","__unstableRichTextInputEvent","formatBold","name","title","bold","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,UAAT,QAA2B,kBAA3B;AAEA,MAAMC,IAAI,GAAG,WAAb;;AACA,MAAMC,KAAK,GAAGP,EAAE,CAAE,MAAF,CAAhB;;AAEA,OAAO,MAAMQ,IAAI,GAAG;AACnBF,EAAAA,IADmB;AAEnBC,EAAAA,KAFmB;AAGnBE,EAAAA,OAAO,EAAE,QAHU;AAInBC,EAAAA,SAAS,EAAE,IAJQ;;AAKnBC,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,MADN;AAEC,MAAA,IAAI,EAAGX,UAFR;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,YADX;AAEC,MAAA,OAAO,EAAGI;AAFX,MAfD,CADD;AAsBA;;AArCkB,CAAb","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 { formatBold } from '@wordpress/icons';\n\nconst name = 'core/bold';\nconst title = __( 'Bold' );\n\nexport const bold = {\n\tname,\n\ttitle,\n\ttagName: 'strong',\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=\"b\"\n\t\t\t\t\tonUse={ onToggle }\n\t\t\t\t/>\n\t\t\t\t<RichTextToolbarButton\n\t\t\t\t\tname=\"bold\"\n\t\t\t\t\ticon={ formatBold }\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=\"b\"\n\t\t\t\t/>\n\t\t\t\t<__unstableRichTextInputEvent\n\t\t\t\t\tinputType=\"formatBold\"\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/bold/index.js"],"names":["__","toggleFormat","RichTextToolbarButton","RichTextShortcut","__unstableRichTextInputEvent","formatBold","name","title","bold","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,UAAT,QAA2B,kBAA3B;AAEA,MAAMC,IAAI,GAAG,WAAb;;AACA,MAAMC,KAAK,GAAGP,EAAE,CAAE,MAAF,CAAhB;;AAEA,OAAO,MAAMQ,IAAI,GAAG;AACnBF,EAAAA,IADmB;AAEnBC,EAAAA,KAFmB;AAGnBE,EAAAA,OAAO,EAAE,QAHU;AAInBC,EAAAA,SAAS,EAAE,IAJQ;;AAKnBC,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,MADN;AAEC,MAAA,IAAI,EAAGX,UAFR;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,YADX;AAEC,MAAA,OAAO,EAAGI;AAFX,MAfD,CADD;AAsBA;;AArCkB,CAAb","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 { formatBold } from '@wordpress/icons';\n\nconst name = 'core/bold';\nconst title = __( 'Bold' );\n\nexport const bold = {\n\tname,\n\ttitle,\n\ttagName: 'strong',\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=\"b\"\n\t\t\t\t\tonUse={ onToggle }\n\t\t\t\t/>\n\t\t\t\t<RichTextToolbarButton\n\t\t\t\t\tname=\"bold\"\n\t\t\t\t\ticon={ formatBold }\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=\"b\"\n\t\t\t\t/>\n\t\t\t\t<__unstableRichTextInputEvent\n\t\t\t\t\tinputType=\"formatBold\"\n\t\t\t\t\tonInput={ onToggle }\n\t\t\t\t/>\n\t\t\t</>\n\t\t);\n\t},\n};\n"]}
@@ -59,7 +59,8 @@ export const code = {
59
59
  }) {
60
60
  function onClick() {
61
61
  onChange(toggleFormat(value, {
62
- type: name
62
+ type: name,
63
+ title
63
64
  }));
64
65
  onFocus();
65
66
  }
@@ -68,7 +69,8 @@ export const code = {
68
69
  icon: codeIcon,
69
70
  title: title,
70
71
  onClick: onClick,
71
- isActive: isActive
72
+ isActive: isActive,
73
+ role: "menuitemcheckbox"
72
74
  });
73
75
  }
74
76
 
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/format-library/src/code/index.js"],"names":["__","toggleFormat","remove","applyFormat","RichTextToolbarButton","code","codeIcon","name","title","tagName","className","__unstableInputRule","value","BACKTICK","start","text","characterBefore","slice","textBefore","indexBefore","lastIndexOf","startIndex","endIndex","type","edit","onChange","onFocus","isActive","onClick"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,EAAT,QAAmB,iBAAnB;AACA,SAASC,YAAT,EAAuBC,MAAvB,EAA+BC,WAA/B,QAAkD,sBAAlD;AACA,SAASC,qBAAT,QAAsC,yBAAtC;AACA,SAASC,IAAI,IAAIC,QAAjB,QAAiC,kBAAjC;AAEA,MAAMC,IAAI,GAAG,WAAb;;AACA,MAAMC,KAAK,GAAGR,EAAE,CAAE,aAAF,CAAhB;;AAEA,OAAO,MAAMK,IAAI,GAAG;AACnBE,EAAAA,IADmB;AAEnBC,EAAAA,KAFmB;AAGnBC,EAAAA,OAAO,EAAE,MAHU;AAInBC,EAAAA,SAAS,EAAE,IAJQ;;AAKnBC,EAAAA,mBAAmB,CAAEC,KAAF,EAAU;AAC5B,UAAMC,QAAQ,G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;AACAmB,MAAAA,OAAO;AACP;;AAED,WACC,cAAC,qBAAD;AACC,MAAA,IAAI,EAAGpB,QADR;AAEC,MAAA,KAAK,EAAGE,KAFT;AAGC,MAAA,OAAO,EAAGoB,OAHX;AAIC,MAAA,QAAQ,EAAGD;AAJZ,MADD;AAQA;;AAjDkB,CAAb","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { toggleFormat, remove, applyFormat } from '@wordpress/rich-text';\nimport { RichTextToolbarButton } from '@wordpress/block-editor';\nimport { code as codeIcon } from '@wordpress/icons';\n\nconst name = 'core/code';\nconst title = __( 'Inline code' );\n\nexport const code = {\n\tname,\n\ttitle,\n\ttagName: 'code',\n\tclassName: null,\n\t__unstableInputRule( value ) {\n\t\tconst BACKTICK = '`';\n\t\tconst { start, text } = value;\n\t\tconst characterBefore = text.slice( start - 1, start );\n\n\t\t// Quick check the text for the necessary character.\n\t\tif ( characterBefore !== BACKTICK ) {\n\t\t\treturn value;\n\t\t}\n\n\t\tconst textBefore = text.slice( 0, start - 1 );\n\t\tconst indexBefore = textBefore.lastIndexOf( BACKTICK );\n\n\t\tif ( indexBefore === -1 ) {\n\t\t\treturn value;\n\t\t}\n\n\t\tconst startIndex = indexBefore;\n\t\tconst endIndex = start - 2;\n\n\t\tif ( startIndex === endIndex ) {\n\t\t\treturn value;\n\t\t}\n\n\t\tvalue = remove( value, startIndex, startIndex + 1 );\n\t\tvalue = remove( value, endIndex, endIndex + 1 );\n\t\tvalue = applyFormat( value, { type: name }, startIndex, endIndex );\n\n\t\treturn value;\n\t},\n\tedit( { value, onChange, onFocus, isActive } ) {\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={ codeIcon }\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/code/index.js"],"names":["__","toggleFormat","remove","applyFormat","RichTextToolbarButton","code","codeIcon","name","title","tagName","className","__unstableInputRule","value","BACKTICK","start","text","characterBefore","slice","textBefore","indexBefore","lastIndexOf","startIndex","endIndex","type","edit","onChange","onFocus","isActive","onClick"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,EAAT,QAAmB,iBAAnB;AACA,SAASC,YAAT,EAAuBC,MAAvB,EAA+BC,WAA/B,QAAkD,sBAAlD;AACA,SAASC,qBAAT,QAAsC,yBAAtC;AACA,SAASC,IAAI,IAAIC,QAAjB,QAAiC,kBAAjC;AAEA,MAAMC,IAAI,GAAG,WAAb;;AACA,MAAMC,KAAK,GAAGR,EAAE,CAAE,aAAF,CAAhB;;AAEA,OAAO,MAAMK,IAAI,GAAG;AACnBE,EAAAA,IADmB;AAEnBC,EAAAA,KAFmB;AAGnBC,EAAAA,OAAO,EAAE,MAHU;AAInBC,EAAAA,SAAS,EAAE,IAJQ;;AAKnBC,EAAAA,mBAAmB,CAAEC,KAAF,EAAU;AAC5B,UAAMC,QAAQ,GAAG,GAAjB;AACA,UAAM;AAAEC,MAAAA,KAAF;AAASC,MAAAA;AAAT,QAAkBH,KAAxB;AACA,UAAMI,eAAe,GAAGD,IAAI,CAACE,KAAL,CAAYH,KAAK,GAAG,CAApB,EAAuBA,KAAvB,CAAxB,CAH4B,CAK5B;;AACA,QAAKE,eAAe,KAAKH,QAAzB,EAAoC;AACnC,aAAOD,KAAP;AACA;;AAED,UAAMM,UAAU,GAAGH,IAAI,CAACE,KAAL,CAAY,CAAZ,EAAeH,KAAK,GAAG,CAAvB,CAAnB;AACA,UAAMK,WAAW,GAAGD,UAAU,CAACE,WAAX,CAAwBP,QAAxB,CAApB;;AAEA,QAAKM,WAAW,KAAK,CAAC,CAAtB,EAA0B;AACzB,aAAOP,KAAP;AACA;;AAED,UAAMS,UAAU,GAAGF,WAAnB;AACA,UAAMG,QAAQ,GAAGR,KAAK,GAAG,CAAzB;;AAEA,QAAKO,UAAU,KAAKC,QAApB,EAA+B;AAC9B,aAAOV,KAAP;AACA;;AAEDA,IAAAA,KAAK,GAAGV,MAAM,CAAEU,KAAF,EAASS,UAAT,EAAqBA,UAAU,GAAG,CAAlC,CAAd;AACAT,IAAAA,KAAK,GAAGV,MAAM,CAAEU,KAAF,EAASU,QAAT,EAAmBA,QAAQ,GAAG,CAA9B,CAAd;AACAV,IAAAA,KAAK,GAAGT,WAAW,CAAES,KAAF,EAAS;AAAEW,MAAAA,IAAI,EAAEhB;AAAR,KAAT,EAAyBc,UAAzB,EAAqCC,QAArC,CAAnB;AAEA,WAAOV,KAAP;AACA,GAlCkB;;AAmCnBY,EAAAA,IAAI,CAAE;AAAEZ,IAAAA,KAAF;AAASa,IAAAA,QAAT;AAAmBC,IAAAA,OAAnB;AAA4BC,IAAAA;AAA5B,GAAF,EAA2C;AAC9C,aAASC,OAAT,GAAmB;AAClBH,MAAAA,QAAQ,CAAExB,YAAY,CAAEW,KAAF,EAAS;AAAEW,QAAAA,IAAI,EAAEhB,IAAR;AAAcC,QAAAA;AAAd,OAAT,CAAd,CAAR;AACAkB,MAAAA,OAAO;AACP;;AAED,WACC,cAAC,qBAAD;AACC,MAAA,IAAI,EAAGpB,QADR;AAEC,MAAA,KAAK,EAAGE,KAFT;AAGC,MAAA,OAAO,EAAGoB,OAHX;AAIC,MAAA,QAAQ,EAAGD,QAJZ;AAKC,MAAA,IAAI,EAAC;AALN,MADD;AASA;;AAlDkB,CAAb","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { toggleFormat, remove, applyFormat } from '@wordpress/rich-text';\nimport { RichTextToolbarButton } from '@wordpress/block-editor';\nimport { code as codeIcon } from '@wordpress/icons';\n\nconst name = 'core/code';\nconst title = __( 'Inline code' );\n\nexport const code = {\n\tname,\n\ttitle,\n\ttagName: 'code',\n\tclassName: null,\n\t__unstableInputRule( value ) {\n\t\tconst BACKTICK = '`';\n\t\tconst { start, text } = value;\n\t\tconst characterBefore = text.slice( start - 1, start );\n\n\t\t// Quick check the text for the necessary character.\n\t\tif ( characterBefore !== BACKTICK ) {\n\t\t\treturn value;\n\t\t}\n\n\t\tconst textBefore = text.slice( 0, start - 1 );\n\t\tconst indexBefore = textBefore.lastIndexOf( BACKTICK );\n\n\t\tif ( indexBefore === -1 ) {\n\t\t\treturn value;\n\t\t}\n\n\t\tconst startIndex = indexBefore;\n\t\tconst endIndex = start - 2;\n\n\t\tif ( startIndex === endIndex ) {\n\t\t\treturn value;\n\t\t}\n\n\t\tvalue = remove( value, startIndex, startIndex + 1 );\n\t\tvalue = remove( value, endIndex, endIndex + 1 );\n\t\tvalue = applyFormat( value, { type: name }, startIndex, endIndex );\n\n\t\treturn value;\n\t},\n\tedit( { value, onChange, onFocus, isActive } ) {\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={ codeIcon }\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,12 +25,15 @@ export const italic = {
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
 
32
33
  function onClick() {
33
- onToggle();
34
+ onChange(toggleFormat(value, {
35
+ type: name
36
+ }));
34
37
  onFocus();
35
38
  }
36
39
 
@@ -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;A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*/\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,Q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ordpress/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"]}
@@ -7,14 +7,14 @@ import { useState, useRef, createInterpolateElement } from '@wordpress/element';
7
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';
10
+ import { create, insert, isCollapsed, applyFormat, useAnchorRef, removeFormat, slice, replace } from '@wordpress/rich-text';
11
11
  import { __experimentalLinkControl as LinkControl, store as blockEditorStore } from '@wordpress/block-editor';
12
12
  import { useSelect } from '@wordpress/data';
13
13
  /**
14
14
  * Internal dependencies
15
15
  */
16
16
 
17
- import { createLinkFormat, isValidHref } from './utils';
17
+ import { createLinkFormat, isValidHref, getFormatBoundary } from './utils';
18
18
  import { link as settings } from './index';
19
19
 
20
20
  function InlineLinkUI({
@@ -27,6 +27,9 @@ function InlineLinkUI({
27
27
  stopAddingLink,
28
28
  contentRef
29
29
  }) {
30
+ const richLinkTextValue = getRichTextValueFromSelection(value, isActive); // Get the text content minus any HTML tags.
31
+
32
+ const richTextText = richLinkTextValue.text;
30
33
  /**
31
34
  * Pending settings to be applied to the next link. When inserting a new
32
35
  * link, toggle values cannot be applied immediately, because there is not
@@ -35,6 +38,7 @@ function InlineLinkUI({
35
38
  *
36
39
  * @type {[Object|undefined,Function]}
37
40
  */
41
+
38
42
  const [nextLinkValue, setNextLinkValue] = useState();
39
43
  const {
40
44
  createPageEntity,
@@ -56,6 +60,7 @@ function InlineLinkUI({
56
60
  type: activeAttributes.type,
57
61
  id: activeAttributes.id,
58
62
  opensInNewTab: activeAttributes.target === '_blank',
63
+ title: richTextText,
59
64
  ...nextLinkValue
60
65
  };
61
66
 
@@ -88,21 +93,45 @@ function InlineLinkUI({
88
93
  }
89
94
 
90
95
  const newUrl = prependHTTP(nextValue.url);
91
- const format = createLinkFormat({
96
+ const linkFormat = createLinkFormat({
92
97
  url: newUrl,
93
98
  type: nextValue.type,
94
99
  id: nextValue.id !== undefined && nextValue.id !== null ? String(nextValue.id) : undefined,
95
100
  opensInNewWindow: nextValue.opensInNewTab
96
101
  });
102
+ const newText = nextValue.title || newUrl;
97
103
 
98
104
  if (isCollapsed(value) && !isActive) {
99
- const newText = nextValue.title || newUrl;
105
+ // Scenario: we don't have any actively selected text or formats.
100
106
  const toInsert = applyFormat(create({
101
107
  text: newText
102
- }), format, 0, newText.length);
108
+ }), linkFormat, 0, newText.length);
103
109
  onChange(insert(value, toInsert));
104
110
  } else {
105
- const newValue = applyFormat(value, format);
111
+ // Scenario: we have any active text selection or an active format
112
+ let newValue;
113
+
114
+ if (newText === richTextText) {
115
+ // If we're not updating the text then ignore
116
+ newValue = applyFormat(value, linkFormat);
117
+ } else {
118
+ // Create new RichText value for the new text in order that we
119
+ // can apply formats to it.
120
+ newValue = create({
121
+ text: newText
122
+ }); // Apply the new Link format to this new text value.
123
+
124
+ newValue = applyFormat(newValue, linkFormat, 0, newText.length); // Update the original (full) RichTextValue replacing the
125
+ // target text with the *new* RichTextValue containing:
126
+ // 1. The new text content.
127
+ // 2. The new link format.
128
+ // Note original formats will be lost when applying this change.
129
+ // That is expected behaviour.
130
+ // See: https://github.com/WordPress/gutenberg/pull/33849#issuecomment-936134179.
131
+
132
+ newValue = replace(value, richTextText, newValue);
133
+ }
134
+
106
135
  newValue.start = newValue.end;
107
136
  newValue.activeFormats = [];
108
137
  onChange(newValue);
@@ -167,9 +196,31 @@ function InlineLinkUI({
167
196
  hasRichPreviews: true,
168
197
  createSuggestion: createPageEntity && handleCreate,
169
198
  withCreateSuggestion: userCanCreatePages,
170
- createSuggestionButtonText: createButtonText
199
+ createSuggestionButtonText: createButtonText,
200
+ hasTextControl: true
171
201
  }));
172
202
  }
173
203
 
204
+ function getRichTextValueFromSelection(value, isActive) {
205
+ // Default to the selection ranges on the RichTextValue object.
206
+ let textStart = value.start;
207
+ let textEnd = value.end; // If the format is currently active then the rich text value
208
+ // should always be taken from the bounds of the active format
209
+ // and not the selected text.
210
+
211
+ if (isActive) {
212
+ const boundary = getFormatBoundary(value, {
213
+ type: 'core/link'
214
+ });
215
+ textStart = boundary.start; // Text *selection* always extends +1 beyond the edge of the format.
216
+ // We account for that here.
217
+
218
+ textEnd = boundary.end + 1;
219
+ } // Get a RichTextValue containing the selected text content.
220
+
221
+
222
+ return slice(value, textStart, textEnd);
223
+ }
224
+
174
225
  export default withSpokenMessages(InlineLinkUI);
175
226
  //# sourceMappingURL=inline.js.map
@@ -1 +1 @@
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","__experimentalLinkControl","LinkControl","store","blockEditorStore","useSelect","createLinkFormat","isValidHref","link","settings","InlineLinkUI","isActive","activeAttributes","addingLink","value","onChange","speak","stopAddingLink","contentRef","nextLinkValue","setNextLinkValue","createPageEntity","userCanCreatePages","select","getSettings","_settings","__experimentalCreatePageEntity","__experimentalUserCanCreatePages","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","handleCreate","pageTitle","page","status","rendered","kind","createButtonText","searchTerm","mark","current"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,QAAT,EAAmBC,MAAnB,EAA2BC,wBAA3B,QAA2D,oBAA3D;AACA,SAASC,EAAT,EAAaC,OAAb,QAA4B,iBAA5B;AACA,SAASC,kBAAT,EAA6BC,OAA7B,QAA4C,uBAA5C;AACA,SAASC,WAAT,QAA4B,gBAA5B;AACA,SACCC,MADD,EAECC,MAFD,EAGCC,WAHD,EAICC,WAJD,EAKCC,YALD,EAMCC,YAND,QAOO,sBAPP;AAQA,SACCC,yBAAyB,IAAIC,WAD9B,EAECC,KAAK,IAAIC,gBAFV,QAGO,yBAHP;AAIA,SAASC,SAAT,QAA0B,iBAA1B;AAEA;AACA;AACA;;AACA,SAASC,gBAAT,EAA2BC,WAA3B,QAA8C,SAA9C;AACA,SAASC,IAAI,IAAIC,QAAjB,QAAiC,SAAjC;;AAEA,SAASC,YAAT,CAAuB;AACtBC,EAAAA,QADsB;AAEtBC,EAAAA,gBAFsB;AAGtBC,EAAAA,UAHsB;AAItBC,EAAAA,KAJsB;AAKtBC,EAAAA,QALsB;AAMtBC,EAAAA,KANsB;AAOtBC,EAAAA,cAPsB;AAQtBC,EAAAA;AARsB,CAAvB,EASI;AACH;AACD;AACA;AACA;AACA;AACA;AACA;AACA;AACC,QAAM,CAAEC,aAAF,EAAiBC,gBAAjB,IAAsCjC,QAAQ,EAApD;AAEA,QAAM;AAAEkC,IAAAA,gBAAF;AAAoBC,IAA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AAA,SAAS,EAAGX,SADb;AAEC,IAAA,YAAY,EAAGE,YAAY,CAACU,OAF7B;AAGC,IAAA,OAAO,EAAGhD,cAHX;AAIC,IAAA,QAAQ,EAAC;AAJV,KAMC,cAAC,WAAD;AACC,IAAA,KAAK,EAAGW,SADT;AAEC,IAAA,QAAQ,EAAGQ,YAFZ;AAGC,IAAA,QAAQ,EAAGF,UAHZ;AAIC,IAAA,kBAAkB,EAAGrB,UAJtB;AAKC,IAAA,eAAe,MALhB;AAMC,IAAA,gBAAgB,EAAGQ,gBAAgB,IAAImC,YANxC;AAOC,IAAA,oBAAoB,EAAGlC,kBAPxB;AAQC,IAAA,0BAA0B,EAAGwC;AAR9B,IAND,CADD;AAmBA;;AAED,eAAetE,kBAAkB,CAAEkB,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} 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 } 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 { 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\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\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\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/>\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","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","focusOnMount","handleCreate","pageTitle","page","status","rendered","kind","createButtonText","searchTerm","mark","current","textStart","textEnd","boundary"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,QAAT,EAAmBC,MAAnB,EAA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AASuD,SAAT,EAAoBC,OAApB,CAAZ;AACA;;AAED,eAAejF,kBAAkB,CAAEqB,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';\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// 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\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"]}
@@ -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