@wordpress/format-library 4.30.0 → 4.32.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/build/default-formats.js +2 -1
  3. package/build/default-formats.js.map +1 -1
  4. package/build/link/index.js +54 -11
  5. package/build/link/index.js.map +1 -1
  6. package/build/link/inline.js +5 -2
  7. package/build/link/inline.js.map +1 -1
  8. package/build/non-breaking-space/index.js +36 -0
  9. package/build/non-breaking-space/index.js.map +1 -0
  10. package/build/text-color/index.native.js +4 -4
  11. package/build/text-color/index.native.js.map +1 -1
  12. package/build/text-color/inline.native.js +17 -38
  13. package/build/text-color/inline.native.js.map +1 -1
  14. package/build/unknown/index.js +12 -7
  15. package/build/unknown/index.js.map +1 -1
  16. package/build-module/default-formats.js +2 -1
  17. package/build-module/default-formats.js.map +1 -1
  18. package/build-module/link/index.js +55 -12
  19. package/build-module/link/index.js.map +1 -1
  20. package/build-module/link/inline.js +5 -2
  21. package/build-module/link/inline.js.map +1 -1
  22. package/build-module/non-breaking-space/index.js +29 -0
  23. package/build-module/non-breaking-space/index.js.map +1 -0
  24. package/build-module/text-color/index.native.js +1 -1
  25. package/build-module/text-color/index.native.js.map +1 -1
  26. package/build-module/text-color/inline.native.js +17 -39
  27. package/build-module/text-color/inline.native.js.map +1 -1
  28. package/build-module/unknown/index.js +13 -8
  29. package/build-module/unknown/index.js.map +1 -1
  30. package/package.json +14 -14
  31. package/src/default-formats.js +2 -0
  32. package/src/link/index.js +55 -11
  33. package/src/link/inline.js +7 -1
  34. package/src/non-breaking-space/index.js +29 -0
  35. package/src/text-color/index.native.js +1 -1
  36. package/src/text-color/inline.native.js +27 -49
  37. package/src/text-color/test/__snapshots__/index.native.js.snap +0 -6
  38. package/src/text-color/test/index.native.js +4 -39
  39. package/src/unknown/index.js +16 -10
@@ -1 +1 @@
1
- {"version":3,"names":["_element","require","_richText","_blockEditor","_components","_index","_inline","parseCSS","css","split","reduce","accumulator","rule","property","value","replace","color","transparentValue","backgroundColor","getActiveColors","name","colorSettings","activeColorFormat","getActiveFormat","attributes","style","parseClassName","class","setColors","colors","removeFormat","styles","classNames","push","join","colorObject","getColorObjectByColorValue","getColorClassName","slug","length","format","type","hasNoSelection","start","end","isAtTheEnd","text","previousCharacter","charAt","applyFormat","newFormat","activeFormats","formats","filter","ColorPicker","onChange","useMobileGlobalStylesColors","useMultipleOriginColorsAndGradients","onColorChange","useCallback","activeColors","useMemo","_react","createElement","ColorSettings","colorValue","defaultSettings","hideNavigation","InlineColorUI","onClose","BottomSheet","isVisible","hideHeader","contentStyle","paddingLeft","paddingRight","hasNavigation","leftButton","testID","NavigationContainer","animate","main","NavigationScreen"],"sources":["@wordpress/format-library/src/text-color/inline.native.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useCallback, useMemo } from '@wordpress/element';\nimport {\n\tapplyFormat,\n\tremoveFormat,\n\tgetActiveFormat,\n} from '@wordpress/rich-text';\nimport {\n\tgetColorClassName,\n\tgetColorObjectByColorValue,\n\tuseMultipleOriginColorsAndGradients,\n} from '@wordpress/block-editor';\nimport {\n\tBottomSheet,\n\tColorSettings,\n\tuseMobileGlobalStylesColors,\n} from '@wordpress/components';\n\n/**\n * Internal dependencies\n */\nimport { transparentValue } from './index.js';\nimport { parseClassName } from './inline.js';\n\nfunction parseCSS( css = '' ) {\n\treturn css.split( ';' ).reduce( ( accumulator, rule ) => {\n\t\tif ( rule ) {\n\t\t\tconst [ property, value ] = rule.replace( / /g, '' ).split( ':' );\n\t\t\tif ( property === 'color' ) accumulator.color = value;\n\t\t\tif ( property === 'background-color' && value !== transparentValue )\n\t\t\t\taccumulator.backgroundColor = value;\n\t\t}\n\t\treturn accumulator;\n\t}, {} );\n}\n\nfunction 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', transparentValue ].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\tstyles.push( [ 'color', colorObject.color ].join( ':' ) );\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\tconst format = { type: name, attributes };\n\tconst hasNoSelection = value.start === value.end;\n\tconst isAtTheEnd = value.end === value.text.length;\n\tconst previousCharacter = value.text.charAt( value.end - 1 );\n\n\t// Force formatting due to limitations in the native implementation\n\tif (\n\t\thasNoSelection &&\n\t\t( value.text.length === 0 ||\n\t\t\t( previousCharacter === ' ' && isAtTheEnd ) )\n\t) {\n\t\t// For cases where there's no text selected, there's a space before\n\t\t// the current caret position and it's at the end of the text.\n\t\treturn applyFormat( value, format, value.start - 1, value.end + 1 );\n\t} else if ( hasNoSelection && isAtTheEnd ) {\n\t\t// If there's no selection and is at the end of the text\n\t\t// manually add the format within the current caret position.\n\t\tconst newFormat = applyFormat( value, format );\n\t\tconst { activeFormats } = newFormat;\n\t\tnewFormat.formats[ value.start ] = [\n\t\t\t...( activeFormats?.filter(\n\t\t\t\t( { type } ) => type !== format.type\n\t\t\t) || [] ),\n\t\t\tformat,\n\t\t];\n\t\treturn newFormat;\n\t} else if ( hasNoSelection ) {\n\t\treturn removeFormat( value, format );\n\t}\n\n\treturn applyFormat( value, format );\n}\n\nfunction ColorPicker( { name, value, onChange } ) {\n\tconst property = 'color';\n\tconst colors = useMobileGlobalStylesColors();\n\tconst colorSettings = useMultipleOriginColorsAndGradients();\n\n\tconst onColorChange = useCallback(\n\t\t( color ) => {\n\t\t\tif ( color !== '' ) {\n\t\t\t\tonChange(\n\t\t\t\t\tsetColors( value, name, colors, { [ property ]: color } )\n\t\t\t\t);\n\t\t\t\t// Remove formatting if the color was reset, there's no\n\t\t\t\t// current selection and the previous character is a space\n\t\t\t} else if (\n\t\t\t\tvalue?.start === value?.end &&\n\t\t\t\tvalue.text?.charAt( value?.end - 1 ) === ' '\n\t\t\t) {\n\t\t\t\tonChange(\n\t\t\t\t\tremoveFormat( value, name, value.end - 1, value.end )\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tonChange( removeFormat( value, name ) );\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<ColorSettings\n\t\t\tcolorValue={ activeColors[ property ] }\n\t\t\tonColorChange={ onColorChange }\n\t\t\tdefaultSettings={ colorSettings }\n\t\t\thideNavigation\n\t\t/>\n\t);\n}\n\nexport default function InlineColorUI( { name, value, onChange, onClose } ) {\n\treturn (\n\t\t<BottomSheet\n\t\t\tisVisible\n\t\t\tonClose={ onClose }\n\t\t\thideHeader\n\t\t\tcontentStyle={ { paddingLeft: 0, paddingRight: 0 } }\n\t\t\thasNavigation\n\t\t\tleftButton={ null }\n\t\t\ttestID=\"inline-text-color-modal\"\n\t\t>\n\t\t\t<BottomSheet.NavigationContainer animate main>\n\t\t\t\t<BottomSheet.NavigationScreen name=\"text-color\">\n\t\t\t\t\t<ColorPicker\n\t\t\t\t\t\tname={ 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</BottomSheet.NavigationScreen>\n\t\t\t</BottomSheet.NavigationContainer>\n\t\t</BottomSheet>\n\t);\n}\n"],"mappings":";;;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;AAKA,IAAAE,YAAA,GAAAF,OAAA;AAKA,IAAAG,WAAA,GAAAH,OAAA;AASA,IAAAI,MAAA,GAAAJ,OAAA;AACA,IAAAK,OAAA,GAAAL,OAAA;AAxBA;AACA;AACA;;AAkBA;AACA;AACA;;AAIA,SAASM,QAAQA,CAAEC,GAAG,GAAG,EAAE,EAAG;EAC7B,OAAOA,GAAG,CAACC,KAAK,CAAE,GAAI,CAAC,CAACC,MAAM,CAAE,CAAEC,WAAW,EAAEC,IAAI,KAAM;IACxD,IAAKA,IAAI,EAAG;MACX,MAAM,CAAEC,QAAQ,EAAEC,KAAK,CAAE,GAAGF,IAAI,CAACG,OAAO,CAAE,IAAI,EAAE,EAAG,CAAC,CAACN,KAAK,CAAE,GAAI,CAAC;MACjE,IAAKI,QAAQ,KAAK,OAAO,EAAGF,WAAW,CAACK,KAAK,GAAGF,KAAK;MACrD,IAAKD,QAAQ,KAAK,kBAAkB,IAAIC,KAAK,KAAKG,uBAAgB,EACjEN,WAAW,CAACO,eAAe,GAAGJ,KAAK;IACrC;IACA,OAAOH,WAAW;EACnB,CAAC,EAAE,CAAC,CAAE,CAAC;AACR;AAEA,SAASQ,eAAeA,CAAEL,KAAK,EAAEM,IAAI,EAAEC,aAAa,EAAG;EACtD,MAAMC,iBAAiB,GAAG,IAAAC,yBAAe,EAAET,KAAK,EAAEM,IAAK,CAAC;EAExD,IAAK,CAAEE,iBAAiB,EAAG;IAC1B,OAAO,CAAC,CAAC;EACV;EAEA,OAAO;IACN,GAA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AM+C,YAAY,GAAG,IAAAC,gBAAO,EAC3B,MAAM1C,eAAe,CAAEL,KAAK,EAAEM,IAAI,EAAES,MAAO,CAAC,EAC5C,CAAET,IAAI,EAAEN,KAAK,EAAEe,MAAM,CACtB,CAAC;EAED,OACC,IAAAiC,MAAA,CAAAC,aAAA,EAAC3D,WAAA,CAAA4D,aAAa;IACbC,UAAU,EAAGL,YAAY,CAAE/C,QAAQ,CAAI;IACvC6C,aAAa,EAAGA,aAAe;IAC/BQ,eAAe,EAAG7C,aAAe;IACjC8C,cAAc;EAAA,CACd,CAAC;AAEJ;AAEe,SAASC,aAAaA,CAAE;EAAEhD,IAAI;EAAEN,KAAK;EAAEyC,QAAQ;EAAEc;AAAQ,CAAC,EAAG;EAC3E,OACC,IAAAP,MAAA,CAAAC,aAAA,EAAC3D,WAAA,CAAAkE,WAAW;IACXC,SAAS;IACTF,OAAO,EAAGA,OAAS;IACnBG,UAAU;IACVC,YAAY,EAAG;MAAEC,WAAW,EAAE,CAAC;MAAEC,YAAY,EAAE;IAAE,CAAG;IACpDC,aAAa;IACbC,UAAU,EAAG,IAAM;IACnBC,MAAM,EAAC;EAAyB,GAEhC,IAAAhB,MAAA,CAAAC,aAAA,EAAC3D,WAAA,CAAAkE,WAAW,CAACS,mBAAmB;IAACC,OAAO;IAACC,IAAI;EAAA,GAC5C,IAAAnB,MAAA,CAAAC,aAAA,EAAC3D,WAAA,CAAAkE,WAAW,CAACY,gBAAgB;IAAC9D,IAAI,EAAC;EAAY,GAC9C,IAAA0C,MAAA,CAAAC,aAAA,EAACT,WAAW;IACXlC,IAAI,EAAGA,IAAM;IACbN,KAAK,EAAGA,KAAO;IACfyC,QAAQ,EAAGA;EAAU,CACrB,CAC4B,CACE,CACrB,CAAC;AAEhB"}
1
+ {"version":3,"names":["_element","require","_richText","_blockEditor","_components","_index","_inline","parseCSS","css","split","reduce","accumulator","rule","property","value","replace","color","transparentValue","backgroundColor","getActiveColors","name","colorSettings","activeColorFormat","getActiveFormat","attributes","style","parseClassName","class","setColors","colors","contentRef","onRemoveMarkFormatting","removeFormat","styles","classNames","push","join","colorObject","getColorObjectByColorValue","getColorClassName","slug","length","format","type","hasNoSelection","start","end","onMarkFormatting","applyFormat","ColorPicker","onChange","useMobileGlobalStylesColors","useMultipleOriginColorsAndGradients","onColorChange","useCallback","activeColors","useMemo","_react","createElement","ColorSettings","colorValue","onColorCleared","defaultSettings","hideNavigation","InlineColorUI","onClose","BottomSheet","isVisible","hideHeader","contentStyle","paddingLeft","paddingRight","hasNavigation","leftButton","testID","NavigationContainer","animate","main","NavigationScreen"],"sources":["@wordpress/format-library/src/text-color/inline.native.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useCallback, useMemo } from '@wordpress/element';\nimport {\n\tapplyFormat,\n\tremoveFormat,\n\tgetActiveFormat,\n} from '@wordpress/rich-text';\nimport {\n\tgetColorClassName,\n\tgetColorObjectByColorValue,\n\tuseMultipleOriginColorsAndGradients,\n} from '@wordpress/block-editor';\nimport {\n\tBottomSheet,\n\tColorSettings,\n\tuseMobileGlobalStylesColors,\n} from '@wordpress/components';\n\n/**\n * Internal dependencies\n */\nimport { transparentValue } from './index.js';\nimport { parseClassName } from './inline.js';\n\nfunction parseCSS( css = '' ) {\n\treturn css.split( ';' ).reduce( ( accumulator, rule ) => {\n\t\tif ( rule ) {\n\t\t\tconst [ property, value ] = rule.replace( / /g, '' ).split( ':' );\n\t\t\tif ( property === 'color' ) accumulator.color = value;\n\t\t\tif ( property === 'background-color' && value !== transparentValue )\n\t\t\t\taccumulator.backgroundColor = value;\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, contentRef ) {\n\tconst { color, backgroundColor } = {\n\t\t...getActiveColors( value, name, colorSettings ),\n\t\t...colors,\n\t};\n\n\tif ( ! color ) {\n\t\tcontentRef?.onRemoveMarkFormatting();\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', transparentValue ].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\tstyles.push( [ 'color', colorObject.color ].join( ':' ) );\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\tconst format = { type: name, attributes };\n\tconst hasNoSelection = value.start === value.end;\n\n\tif ( hasNoSelection ) {\n\t\tcontentRef?.onMarkFormatting( color );\n\t}\n\treturn applyFormat( value, format );\n}\n\nfunction ColorPicker( { name, value, onChange, contentRef } ) {\n\tconst property = 'color';\n\tconst colors = useMobileGlobalStylesColors();\n\tconst colorSettings = useMultipleOriginColorsAndGradients();\n\n\tconst onColorChange = useCallback(\n\t\t( color ) => {\n\t\t\tonChange(\n\t\t\t\tsetColors(\n\t\t\t\t\tvalue,\n\t\t\t\t\tname,\n\t\t\t\t\tcolors,\n\t\t\t\t\t{ [ property ]: color },\n\t\t\t\t\tcontentRef\n\t\t\t\t)\n\t\t\t);\n\t\t},\n\t\t[ colors, contentRef, name, onChange, value ]\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<ColorSettings\n\t\t\tcolorValue={ activeColors[ property ] }\n\t\t\tonColorChange={ onColorChange }\n\t\t\tonColorCleared={ onColorChange }\n\t\t\tdefaultSettings={ colorSettings }\n\t\t\thideNavigation\n\t\t/>\n\t);\n}\n\nexport default function InlineColorUI( {\n\tname,\n\tvalue,\n\tonChange,\n\tonClose,\n\tcontentRef,\n} ) {\n\treturn (\n\t\t<BottomSheet\n\t\t\tisVisible\n\t\t\tonClose={ onClose }\n\t\t\thideHeader\n\t\t\tcontentStyle={ { paddingLeft: 0, paddingRight: 0 } }\n\t\t\thasNavigation\n\t\t\tleftButton={ null }\n\t\t\ttestID=\"inline-text-color-modal\"\n\t\t>\n\t\t\t<BottomSheet.NavigationContainer animate main>\n\t\t\t\t<BottomSheet.NavigationScreen name=\"text-color\">\n\t\t\t\t\t<ColorPicker\n\t\t\t\t\t\tname={ name }\n\t\t\t\t\t\tvalue={ value }\n\t\t\t\t\t\tonChange={ onChange }\n\t\t\t\t\t\tcontentRef={ contentRef }\n\t\t\t\t\t/>\n\t\t\t\t</BottomSheet.NavigationScreen>\n\t\t\t</BottomSheet.NavigationContainer>\n\t\t</BottomSheet>\n\t);\n}\n"],"mappings":";;;;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;AAKA,IAAAE,YAAA,GAAAF,OAAA;AAKA,IAAAG,WAAA,GAAAH,OAAA;AASA,IAAAI,MAAA,GAAAJ,OAAA;AACA,IAAAK,OAAA,GAAAL,OAAA;AAxBA;AACA;AACA;;AAkBA;AACA;AACA;;AAIA,SAASM,QAAQA,CAAEC,GAAG,GAAG,EAAE,EAAG;EAC7B,OAAOA,GAAG,CAACC,KAAK,CAAE,GAAI,CAAC,CAACC,MAAM,CAAE,CAAEC,WAAW,EAAEC,IAAI,KAAM;IACxD,IAAKA,IAAI,EAAG;MACX,MAAM,CAAEC,QAAQ,EAAEC,KAAK,CAAE,GAAGF,IAAI,CAACG,OAAO,CAAE,IAAI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EAACtD,WAAA,CAAA8D,WAAW,CAACS,mBAAmB;IAACC,OAAO;IAACC,IAAI;EAAA,GAC5C,IAAApB,MAAA,CAAAC,aAAA,EAACtD,WAAA,CAAA8D,WAAW,CAACY,gBAAgB;IAAC1D,IAAI,EAAC;EAAY,GAC9C,IAAAqC,MAAA,CAAAC,aAAA,EAACT,WAAW;IACX7B,IAAI,EAAGA,IAAM;IACbN,KAAK,EAAGA,KAAO;IACfoC,QAAQ,EAAGA,QAAU;IACrBpB,UAAU,EAAGA;EAAY,CACzB,CAC4B,CACE,CACrB,CAAC;AAEhB"}
@@ -15,6 +15,15 @@ var _icons = require("@wordpress/icons");
15
15
 
16
16
  const name = 'core/unknown';
17
17
  const title = (0, _i18n.__)('Clear Unknown Formatting');
18
+ function selectionContainsUnknownFormats(value) {
19
+ if ((0, _richText.isCollapsed)(value)) {
20
+ return false;
21
+ }
22
+ const selectedValue = (0, _richText.slice)(value);
23
+ return selectedValue.formats.some(formats => {
24
+ return formats.some(format => format.type === name);
25
+ });
26
+ }
18
27
  const unknown = exports.unknown = {
19
28
  name,
20
29
  title,
@@ -26,17 +35,13 @@ const unknown = exports.unknown = {
26
35
  onChange,
27
36
  onFocus
28
37
  }) {
38
+ if (!isActive && !selectionContainsUnknownFormats(value)) {
39
+ return null;
40
+ }
29
41
  function onClick() {
30
42
  onChange((0, _richText.removeFormat)(value, name));
31
43
  onFocus();
32
44
  }
33
- const selectedValue = (0, _richText.slice)(value);
34
- const hasUnknownFormats = selectedValue.formats.some(formats => {
35
- return formats.some(format => format.type === name);
36
- });
37
- if (!isActive && !hasUnknownFormats) {
38
- return null;
39
- }
40
45
  return (0, _react.createElement)(_blockEditor.RichTextToolbarButton, {
41
46
  name: "unknown",
42
47
  icon: _icons.help,
@@ -1 +1 @@
1
- {"version":3,"names":["_i18n","require","_richText","_blockEditor","_icons","name","title","__","unknown","exports","tagName","className","edit","isActive","value","onChange","onFocus","onClick","removeFormat","selectedValue","slice","hasUnknownFormats","formats","some","format","type","_react","createElement","RichTextToolbarButton","icon","help"],"sources":["@wordpress/format-library/src/unknown/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { removeFormat, slice } from '@wordpress/rich-text';\nimport { RichTextToolbarButton } from '@wordpress/block-editor';\nimport { help } from '@wordpress/icons';\n\nconst name = 'core/unknown';\nconst title = __( 'Clear Unknown Formatting' );\n\nexport const unknown = {\n\tname,\n\ttitle,\n\ttagName: '*',\n\tclassName: null,\n\tedit( { isActive, value, onChange, onFocus } ) {\n\t\tfunction onClick() {\n\t\t\tonChange( removeFormat( value, name ) );\n\t\t\tonFocus();\n\t\t}\n\n\t\tconst selectedValue = slice( value );\n\t\tconst hasUnknownFormats = selectedValue.formats.some( ( formats ) => {\n\t\t\treturn formats.some( ( format ) => format.type === name );\n\t\t} );\n\n\t\tif ( ! isActive && ! hasUnknownFormats ) {\n\t\t\treturn null;\n\t\t}\n\n\t\treturn (\n\t\t\t<RichTextToolbarButton\n\t\t\t\tname=\"unknown\"\n\t\t\t\ticon={ help }\n\t\t\t\ttitle={ title }\n\t\t\t\tonClick={ onClick }\n\t\t\t\tisActive\n\t\t\t/>\n\t\t);\n\t},\n};\n"],"mappings":";;;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;AACA,IAAAE,YAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AANA;AACA;AACA;;AAMA,MAAMI,IAAI,GAAG,cAAc;AAC3B,MAAMC,KAAK,GAAG,IAAAC,QAAE,EAAE,0BAA2B,CAAC;AAEvC,MAAMC,OAAO,GAAAC,OAAA,CAAAD,OAAA,GAAG;EACtBH,IAAI;EACJC,KAAK;EACLI,OAAO,EAAE,GAAG;EACZC,SAAS,EAAE,IAAI;EACfC,IAAIA,CAAE;IAAEC,QAAQ;IAAEC,KAAK;IAAEC,QAAQ;IAAEC;EAAQ,CAAC,EAAG;IAC9C,SAASC,OAAOA,CAAA,EAAG;MAClBF,QAAQ,CAAE,IAAAG,sBAAY,EAAEJ,KAAK,EAAET,IAAK,CAAE,CAAC;MACvCW,OAAO,CAAC,CAAC;IACV;IAEA,MAAMG,aAAa,GAAG,IAAAC,eAAK,EAAEN,KAAM,CAAC;IACpC,MAAMO,iBAAiB,GAAGF,aAAa,CAACG,OAAO,CAACC,IAAI,CAAID,OAAO,IAAM;MACpE,OAAOA,OAAO,CAACC,IAAI,CAAIC,MAAM,IAAMA,MAAM,CAACC,IAAI,KAAKpB,IAAK,CAAC;IAC1D,CAAE,CAAC;IAEH,IAAK,CAAEQ,QAAQ,IAAI,CAAEQ,iBAAiB,EAAG;MACxC,OAAO,IAAI;IACZ;IAEA,OACC,IAAAK,MAAA,CAAAC,aAAA,EAACxB,YAAA,CAAAyB,qBAAqB;MACrBvB,IAAI,EAAC,SAAS;MACdwB,IAAI,EAAGC,WAAM;MACbxB,KAAK,EAAGA,KAAO;MACfW,OAAO,EAAGA,OAAS;MACnBJ,QAAQ;IAAA,CACR,CAAC;EAEJ;AACD,CAAC"}
1
+ {"version":3,"names":["_i18n","require","_richText","_blockEditor","_icons","name","title","__","selectionContainsUnknownFormats","value","isCollapsed","selectedValue","slice","formats","some","format","type","unknown","exports","tagName","className","edit","isActive","onChange","onFocus","onClick","removeFormat","_react","createElement","RichTextToolbarButton","icon","help"],"sources":["@wordpress/format-library/src/unknown/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { removeFormat, slice, isCollapsed } from '@wordpress/rich-text';\nimport { RichTextToolbarButton } from '@wordpress/block-editor';\nimport { help } from '@wordpress/icons';\n\nconst name = 'core/unknown';\nconst title = __( 'Clear Unknown Formatting' );\n\nfunction selectionContainsUnknownFormats( value ) {\n\tif ( isCollapsed( value ) ) {\n\t\treturn false;\n\t}\n\n\tconst selectedValue = slice( value );\n\treturn selectedValue.formats.some( ( formats ) => {\n\t\treturn formats.some( ( format ) => format.type === name );\n\t} );\n}\n\nexport const unknown = {\n\tname,\n\ttitle,\n\ttagName: '*',\n\tclassName: null,\n\tedit( { isActive, value, onChange, onFocus } ) {\n\t\tif ( ! isActive && ! selectionContainsUnknownFormats( value ) ) {\n\t\t\treturn null;\n\t\t}\n\n\t\tfunction onClick() {\n\t\t\tonChange( removeFormat( value, name ) );\n\t\t\tonFocus();\n\t\t}\n\n\t\treturn (\n\t\t\t<RichTextToolbarButton\n\t\t\t\tname=\"unknown\"\n\t\t\t\ticon={ help }\n\t\t\t\ttitle={ title }\n\t\t\t\tonClick={ onClick }\n\t\t\t\tisActive\n\t\t\t/>\n\t\t);\n\t},\n};\n"],"mappings":";;;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;AACA,IAAAE,YAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AANA;AACA;AACA;;AAMA,MAAMI,IAAI,GAAG,cAAc;AAC3B,MAAMC,KAAK,GAAG,IAAAC,QAAE,EAAE,0BAA2B,CAAC;AAE9C,SAASC,+BAA+BA,CAAEC,KAAK,EAAG;EACjD,IAAK,IAAAC,qBAAW,EAAED,KAAM,CAAC,EAAG;IAC3B,OAAO,KAAK;EACb;EAEA,MAAME,aAAa,GAAG,IAAAC,eAAK,EAAEH,KAAM,CAAC;EACpC,OAAOE,aAAa,CAACE,OAAO,CAACC,IAAI,CAAID,OAAO,IAAM;IACjD,OAAOA,OAAO,CAACC,IAAI,CAAIC,MAAM,IAAMA,MAAM,CAACC,IAAI,KAAKX,IAAK,CAAC;EAC1D,CAAE,CAAC;AACJ;AAEO,MAAMY,OAAO,GAAAC,OAAA,CAAAD,OAAA,GAAG;EACtBZ,IAAI;EACJC,KAAK;EACLa,OAAO,EAAE,GAAG;EACZC,SAAS,EAAE,IAAI;EACfC,IAAIA,CAAE;IAAEC,QAAQ;IAAEb,KAAK;IAAEc,QAAQ;IAAEC;EAAQ,CAAC,EAAG;IAC9C,IAAK,CAAEF,QAAQ,IAAI,CAAEd,+BAA+B,CAAEC,KAAM,CAAC,EAAG;MAC/D,OAAO,IAAI;IACZ;IAEA,SAASgB,OAAOA,CAAA,EAAG;MAClBF,QAAQ,CAAE,IAAAG,sBAAY,EAAEjB,KAAK,EAAEJ,IAAK,CAAE,CAAC;MACvCmB,OAAO,CAAC,CAAC;IACV;IAEA,OACC,IAAAG,MAAA,CAAAC,aAAA,EAACzB,YAAA,CAAA0B,qBAAqB;MACrBxB,IAAI,EAAC,SAAS;MACdyB,IAAI,EAAGC,WAAM;MACbzB,KAAK,EAAGA,KAAO;MACfmB,OAAO,EAAGA,OAAS;MACnBH,QAAQ;IAAA,CACR,CAAC;EAEJ;AACD,CAAC"}
@@ -14,5 +14,6 @@ import { superscript } from './superscript';
14
14
  import { keyboard } from './keyboard';
15
15
  import { unknown } from './unknown';
16
16
  import { language } from './language';
17
- export default [bold, code, image, italic, link, strikethrough, underline, textColor, subscript, superscript, keyboard, unknown, language];
17
+ import { nonBreakingSpace } from './non-breaking-space';
18
+ export default [bold, code, image, italic, link, strikethrough, underline, textColor, subscript, superscript, keyboard, unknown, language, nonBreakingSpace];
18
19
  //# sourceMappingURL=default-formats.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["bold","code","image","italic","link","strikethrough","underline","textColor","subscript","superscript","keyboard","unknown","language"],"sources":["@wordpress/format-library/src/default-formats.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport { bold } from './bold';\nimport { code } from './code';\nimport { image } from './image';\nimport { italic } from './italic';\nimport { link } from './link';\nimport { strikethrough } from './strikethrough';\nimport { underline } from './underline';\nimport { textColor } from './text-color';\nimport { subscript } from './subscript';\nimport { superscript } from './superscript';\nimport { keyboard } from './keyboard';\nimport { unknown } from './unknown';\nimport { language } from './language';\n\nexport default [\n\tbold,\n\tcode,\n\timage,\n\titalic,\n\tlink,\n\tstrikethrough,\n\tunderline,\n\ttextColor,\n\tsubscript,\n\tsuperscript,\n\tkeyboard,\n\tunknown,\n\tlanguage,\n];\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,IAAI,QAAQ,QAAQ;AAC7B,SAASC,IAAI,QAAQ,QAAQ;AAC7B,SAASC,KAAK,QAAQ,SAAS;AAC/B,SAASC,MAAM,QAAQ,UAAU;AACjC,SAASC,IAAI,QAAQ,QAAQ;AAC7B,SAASC,aAAa,QAAQ,iBAAiB;AAC/C,SAASC,SAAS,QAAQ,aAAa;AACvC,SAASC,SAAS,QAAQ,cAAc;AACxC,SAASC,SAAS,QAAQ,aAAa;AACvC,SAASC,WAAW,QAAQ,eAAe;AAC3C,SAASC,QAAQ,QAAQ,YAAY;AACrC,SAASC,OAAO,QAAQ,WAAW;AACnC,SAASC,QAAQ,QAAQ,YAAY;AAErC,eAAe,CACdZ,IAAI,EACJC,IAAI,EACJC,KAAK,EACLC,MAAM,EACNC,IAAI,EACJC,aAAa,EACbC,SAAS,EACTC,SAAS,EACTC,SAAS,EACTC,WAAW,EACXC,QAAQ,EACRC,OAAO,EACPC,QAAQ,CACR"}
1
+ {"version":3,"names":["bold","code","image","italic","link","strikethrough","underline","textColor","subscript","superscript","keyboard","unknown","language","nonBreakingSpace"],"sources":["@wordpress/format-library/src/default-formats.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport { bold } from './bold';\nimport { code } from './code';\nimport { image } from './image';\nimport { italic } from './italic';\nimport { link } from './link';\nimport { strikethrough } from './strikethrough';\nimport { underline } from './underline';\nimport { textColor } from './text-color';\nimport { subscript } from './subscript';\nimport { superscript } from './superscript';\nimport { keyboard } from './keyboard';\nimport { unknown } from './unknown';\nimport { language } from './language';\nimport { nonBreakingSpace } from './non-breaking-space';\n\nexport default [\n\tbold,\n\tcode,\n\timage,\n\titalic,\n\tlink,\n\tstrikethrough,\n\tunderline,\n\ttextColor,\n\tsubscript,\n\tsuperscript,\n\tkeyboard,\n\tunknown,\n\tlanguage,\n\tnonBreakingSpace,\n];\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,IAAI,QAAQ,QAAQ;AAC7B,SAASC,IAAI,QAAQ,QAAQ;AAC7B,SAASC,KAAK,QAAQ,SAAS;AAC/B,SAASC,MAAM,QAAQ,UAAU;AACjC,SAASC,IAAI,QAAQ,QAAQ;AAC7B,SAASC,aAAa,QAAQ,iBAAiB;AAC/C,SAASC,SAAS,QAAQ,aAAa;AACvC,SAASC,SAAS,QAAQ,cAAc;AACxC,SAASC,SAAS,QAAQ,aAAa;AACvC,SAASC,WAAW,QAAQ,eAAe;AAC3C,SAASC,QAAQ,QAAQ,YAAY;AACrC,SAASC,OAAO,QAAQ,WAAW;AACnC,SAASC,QAAQ,QAAQ,YAAY;AACrC,SAASC,gBAAgB,QAAQ,sBAAsB;AAEvD,eAAe,CACdb,IAAI,EACJC,IAAI,EACJC,KAAK,EACLC,MAAM,EACNC,IAAI,EACJC,aAAa,EACbC,SAAS,EACTC,SAAS,EACTC,SAAS,EACTC,WAAW,EACXC,QAAQ,EACRC,OAAO,EACPC,QAAQ,EACRC,gBAAgB,CAChB"}
@@ -3,7 +3,7 @@ import { createElement, Fragment } from "react";
3
3
  * WordPress dependencies
4
4
  */
5
5
  import { __ } from '@wordpress/i18n';
6
- import { useState, useLayoutEffect } from '@wordpress/element';
6
+ import { useState, useLayoutEffect, useEffect } from '@wordpress/element';
7
7
  import { getTextContent, applyFormat, removeFormat, slice, isCollapsed, insert, create } from '@wordpress/rich-text';
8
8
  import { isURL, isEmail } from '@wordpress/url';
9
9
  import { RichTextToolbarButton, RichTextShortcut } from '@wordpress/block-editor';
@@ -26,9 +26,37 @@ function Edit({
26
26
  onFocus,
27
27
  contentRef
28
28
  }) {
29
- const [addingLink, setAddingLink] = useState(false);
29
+ const [editingLink, setEditingLink] = useState(false);
30
+ const [creatingLink, setCreatingLink] = useState(false);
31
+
30
32
  // We only need to store the button element that opened the popover. We can ignore the other states, as they will be handled by the onFocus prop to return to the rich text field.
31
33
  const [openedBy, setOpenedBy] = useState(null);
34
+
35
+ // Manages whether the Link UI popover should autofocus when shown.
36
+ const [shouldAutoFocus, setShouldAutoFocus] = useState(true);
37
+ function setIsEditingLink(isEditing, {
38
+ autoFocus = true
39
+ } = {}) {
40
+ setEditingLink(isEditing);
41
+ setShouldAutoFocus(autoFocus);
42
+ }
43
+ function setIsCreatingLink(isCreating) {
44
+ // Don't add a new link if there is already an active link.
45
+ // The two states are mutually exclusive.
46
+ if (isCreating === true && isActive) {
47
+ return;
48
+ }
49
+ setCreatingLink(isCreating);
50
+ }
51
+ useEffect(() => {
52
+ // When the link becomes inactive (i.e. isActive is false), reset the editingLink state
53
+ // and the creatingLink state. This means that if the Link UI is displayed and the link
54
+ // becomes inactive (e.g. used arrow keys to move cursor outside of link bounds), the UI will close.
55
+ if (!isActive) {
56
+ setEditingLink(false);
57
+ setCreatingLink(false);
58
+ }
59
+ }, [isActive]);
32
60
  useLayoutEffect(() => {
33
61
  const editableContentElement = contentRef.current;
34
62
  if (!editableContentElement) {
@@ -38,13 +66,18 @@ function Edit({
38
66
  // There is a situation whereby there is an existing link in the rich text
39
67
  // and the user clicks on the leftmost edge of that link and fails to activate
40
68
  // the link format, but the click event still fires on the `<a>` element.
41
- // This causes the `addingLink` state to be set to `true` and the link UI
69
+ // This causes the `editingLink` state to be set to `true` and the link UI
42
70
  // to be rendered in "creating" mode. We need to check isActive to see if
43
71
  // we have an active link format.
44
- if (event.target.tagName !== 'A' || !isActive) {
72
+ if (!event.target.closest('[contenteditable] a') ||
73
+ // other formats (e.g. bold) may be nested within the link.
74
+ !isActive) {
75
+ setIsEditingLink(false);
45
76
  return;
46
77
  }
47
- setAddingLink(true);
78
+ setIsEditingLink(true, {
79
+ autoFocus: false
80
+ });
48
81
  }
49
82
  editableContentElement.addEventListener('click', handleClick);
50
83
  return () => {
@@ -52,6 +85,7 @@ function Edit({
52
85
  };
53
86
  }, [contentRef, isActive]);
54
87
  function addLink(target) {
88
+ setShouldAutoFocus(true);
55
89
  const text = getTextContent(slice(value));
56
90
  if (!isActive && text && isURL(text) && isValidHref(text)) {
57
91
  onChange(applyFormat(value, {
@@ -71,7 +105,11 @@ function Edit({
71
105
  if (target) {
72
106
  setOpenedBy(target);
73
107
  }
74
- setAddingLink(true);
108
+ if (!isActive) {
109
+ setIsCreatingLink(true);
110
+ } else {
111
+ setIsEditingLink(true);
112
+ }
75
113
  }
76
114
  }
77
115
 
@@ -90,7 +128,9 @@ function Edit({
90
128
  // Otherwise, we rely on the passed in onFocus to return focus to the rich text field.
91
129
 
92
130
  // Close the popover
93
- setAddingLink(false);
131
+ setIsEditingLink(false);
132
+ setIsCreatingLink(false);
133
+
94
134
  // Return focus to the toolbar button or the rich text field
95
135
  if (openedBy?.tagName === 'BUTTON') {
96
136
  openedBy.focus();
@@ -108,13 +148,15 @@ function Edit({
108
148
  // 4. Press Escape
109
149
  // 5. Focus should be on the Options button
110
150
  function onFocusOutside() {
111
- setAddingLink(false);
151
+ setIsEditingLink(false);
152
+ setIsCreatingLink(false);
112
153
  setOpenedBy(null);
113
154
  }
114
155
  function onRemoveFormat() {
115
156
  onChange(removeFormat(value, name));
116
157
  speak(__('Link removed.'), 'assertive');
117
158
  }
159
+ const isEditingActiveLink = editingLink && isActive;
118
160
  return createElement(Fragment, null, createElement(RichTextShortcut, {
119
161
  type: "primary",
120
162
  character: "k",
@@ -130,19 +172,20 @@ function Edit({
130
172
  onClick: event => {
131
173
  addLink(event.currentTarget);
132
174
  },
133
- isActive: isActive || addingLink,
175
+ isActive: isActive || editingLink,
134
176
  shortcutType: "primary",
135
177
  shortcutCharacter: "k",
136
178
  "aria-haspopup": "true",
137
- "aria-expanded": addingLink
138
- }), addingLink && createElement(InlineLinkUI, {
179
+ "aria-expanded": editingLink
180
+ }), (isEditingActiveLink || creatingLink) && createElement(InlineLinkUI, {
139
181
  stopAddingLink: stopAddingLink,
140
182
  onFocusOutside: onFocusOutside,
141
183
  isActive: isActive,
142
184
  activeAttributes: activeAttributes,
143
185
  value: value,
144
186
  onChange: onChange,
145
- contentRef: contentRef
187
+ contentRef: contentRef,
188
+ focusOnMount: shouldAutoFocus ? 'firstElement' : false
146
189
  }));
147
190
  }
148
191
  export const link = {
@@ -1 +1 @@
1
- {"version":3,"names":["__","useState","useLayoutEffect","getTextContent","applyFormat","removeFormat","slice","isCollapsed","insert","create","isURL","isEmail","RichTextToolbarButton","RichTextShortcut","decodeEntities","link","linkIcon","speak","InlineLinkUI","isValidHref","name","title","Edit","isActive","activeAttributes","value","onChange","onFocus","contentRef","addingLink","setAddingLink","openedBy","setOpenedBy","editableContentElement","current","handleClick","event","target","tagName","addEventListener","removeEventListener","addLink","text","type","attributes","url","stopAddingLink","focus","onFocusOutside","onRemoveFormat","createElement","Fragment","character","onUse","icon","onClick","currentTarget","shortcutType","shortcutCharacter","className","id","_id","rel","__unstablePasteRule","html","plainText","pastedText","replace","trim","test","window","console","log","format","length","edit"],"sources":["@wordpress/format-library/src/link/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useState, useLayoutEffect } from '@wordpress/element';\nimport {\n\tgetTextContent,\n\tapplyFormat,\n\tremoveFormat,\n\tslice,\n\tisCollapsed,\n\tinsert,\n\tcreate,\n} from '@wordpress/rich-text';\nimport { isURL, isEmail } from '@wordpress/url';\nimport {\n\tRichTextToolbarButton,\n\tRichTextShortcut,\n} from '@wordpress/block-editor';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { link as linkIcon } from '@wordpress/icons';\nimport { speak } from '@wordpress/a11y';\n\n/**\n * Internal dependencies\n */\nimport InlineLinkUI from './inline';\nimport { isValidHref } from './utils';\n\nconst name = 'core/link';\nconst title = __( 'Link' );\n\nfunction Edit( {\n\tisActive,\n\tactiveAttributes,\n\tvalue,\n\tonChange,\n\tonFocus,\n\tcontentRef,\n} ) {\n\tconst [ addingLink, setAddingLink ] = useState( false );\n\t// We only need to store the button element that opened the popover. We can ignore the other states, as they will be handled by the onFocus prop to return to the rich text field.\n\tconst [ openedBy, setOpenedBy ] = useState( null );\n\n\tuseLayoutEffect( () => {\n\t\tconst editableContentElement = contentRef.current;\n\t\tif ( ! editableContentElement ) {\n\t\t\treturn;\n\t\t}\n\n\t\tfunction handleClick( event ) {\n\t\t\t// There is a situation whereby there is an existing link in the rich text\n\t\t\t// and the user clicks on the leftmost edge of that link and fails to activate\n\t\t\t// the link format, but the click event still fires on the `<a>` element.\n\t\t\t// This causes the `addingLink` state to be set to `true` and the link UI\n\t\t\t// to be rendered in \"creating\" mode. We need to check isActive to see if\n\t\t\t// we have an active link format.\n\t\t\tif ( event.target.tagName !== 'A' || ! isActive ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tsetAddingLink( true );\n\t\t}\n\n\t\teditableContentElement.addEventListener( 'click', handleClick );\n\n\t\treturn () => {\n\t\t\teditableContentElement.removeEventListener( 'click', handleClick );\n\t\t};\n\t}, [ contentRef, isActive ] );\n\n\tfunction addLink( target ) {\n\t\tconst text = getTextContent( slice( value ) );\n\n\t\tif ( ! isActive && text && isURL( text ) && isValidHref( text ) ) {\n\t\t\tonChange(\n\t\t\t\tapplyFormat( value, {\n\t\t\t\t\ttype: name,\n\t\t\t\t\tattributes: { url: text },\n\t\t\t\t} )\n\t\t\t);\n\t\t} else if ( ! isActive && text && isEmail( text ) ) {\n\t\t\tonChange(\n\t\t\t\tapplyFormat( value, {\n\t\t\t\t\ttype: name,\n\t\t\t\t\tattributes: { url: `mailto:${ text }` },\n\t\t\t\t} )\n\t\t\t);\n\t\t} else {\n\t\t\tif ( target ) {\n\t\t\t\tsetOpenedBy( target );\n\t\t\t}\n\t\t\tsetAddingLink( true );\n\t\t}\n\t}\n\n\t/**\n\t * Runs when the popover is closed via escape keypress, unlinking the selected text,\n\t * but _not_ on a click outside the popover. onFocusOutside handles that.\n\t */\n\tfunction stopAddingLink() {\n\t\t// Don't let the click handler on the toolbar button trigger again.\n\n\t\t// There are two places for us to return focus to on Escape keypress:\n\t\t// 1. The rich text field.\n\t\t// 2. The toolbar button.\n\n\t\t// The toolbar button is the only one we need to handle returning focus to.\n\t\t// Otherwise, we rely on the passed in onFocus to return focus to the rich text field.\n\n\t\t// Close the popover\n\t\tsetAddingLink( false );\n\t\t// Return focus to the toolbar button or the rich text field\n\t\tif ( openedBy?.tagName === 'BUTTON' ) {\n\t\t\topenedBy.focus();\n\t\t} else {\n\t\t\tonFocus();\n\t\t}\n\t\t// Remove the openedBy state\n\t\tsetOpenedBy( null );\n\t}\n\n\t// Test for this:\n\t// 1. Click on the link button\n\t// 2. Click the Options button in the top right of header\n\t// 3. Focus should be in the dropdown of the Options button\n\t// 4. Press Escape\n\t// 5. Focus should be on the Options button\n\tfunction onFocusOutside() {\n\t\tsetAddingLink( false );\n\t\tsetOpenedBy( null );\n\t}\n\n\tfunction onRemoveFormat() {\n\t\tonChange( removeFormat( value, name ) );\n\t\tspeak( __( 'Link removed.' ), 'assertive' );\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t<RichTextShortcut type=\"primary\" character=\"k\" onUse={ addLink } />\n\t\t\t<RichTextShortcut\n\t\t\t\ttype=\"primaryShift\"\n\t\t\t\tcharacter=\"k\"\n\t\t\t\tonUse={ onRemoveFormat }\n\t\t\t/>\n\t\t\t<RichTextToolbarButton\n\t\t\t\tname=\"link\"\n\t\t\t\ticon={ linkIcon }\n\t\t\t\ttitle={ isActive ? __( 'Link' ) : title }\n\t\t\t\tonClick={ ( event ) => {\n\t\t\t\t\taddLink( event.currentTarget );\n\t\t\t\t} }\n\t\t\t\tisActive={ isActive || addingLink }\n\t\t\t\tshortcutType=\"primary\"\n\t\t\t\tshortcutCharacter=\"k\"\n\t\t\t\taria-haspopup=\"true\"\n\t\t\t\taria-expanded={ addingLink }\n\t\t\t/>\n\t\t\t{ addingLink && (\n\t\t\t\t<InlineLinkUI\n\t\t\t\t\tstopAddingLink={ stopAddingLink }\n\t\t\t\t\tonFocusOutside={ onFocusOutside }\n\t\t\t\t\tisActive={ isActive }\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 link = {\n\tname,\n\ttitle,\n\ttagName: 'a',\n\tclassName: null,\n\tattributes: {\n\t\turl: 'href',\n\t\ttype: 'data-type',\n\t\tid: 'data-id',\n\t\t_id: 'id',\n\t\ttarget: 'target',\n\t\trel: 'rel',\n\t},\n\t__unstablePasteRule( value, { html, plainText } ) {\n\t\tconst pastedText = ( html || plainText )\n\t\t\t.replace( /<[^>]+>/g, '' )\n\t\t\t.trim();\n\n\t\t// A URL was pasted, turn the selection into a link.\n\t\t// For the link pasting feature, allow only http(s) protocols.\n\t\tif ( ! isURL( pastedText ) || ! /^https?:/.test( pastedText ) ) {\n\t\t\treturn value;\n\t\t}\n\n\t\t// Allows us to ask for this information when we get a report.\n\t\twindow.console.log( 'Created link:\\n\\n', pastedText );\n\n\t\tconst format = {\n\t\t\ttype: name,\n\t\t\tattributes: {\n\t\t\t\turl: decodeEntities( pastedText ),\n\t\t\t},\n\t\t};\n\n\t\tif ( isCollapsed( value ) ) {\n\t\t\treturn insert(\n\t\t\t\tvalue,\n\t\t\t\tapplyFormat(\n\t\t\t\t\tcreate( { text: plainText } ),\n\t\t\t\t\tformat,\n\t\t\t\t\t0,\n\t\t\t\t\tplainText.length\n\t\t\t\t)\n\t\t\t);\n\t\t}\n\n\t\treturn applyFormat( value, format );\n\t},\n\tedit: Edit,\n};\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,EAAE,QAAQ,iBAAiB;AACpC,SAASC,QAAQ,EAAEC,eAAe,QAAQ,oBAAoB;AAC9D,SACCC,cAAc,EACdC,WAAW,EACXC,YAAY,EACZC,KAAK,EACLC,WAAW,EACXC,MAAM,EACNC,MAAM,QACA,sBAAsB;AAC7B,SAASC,KAAK,EAAEC,OAAO,QAAQ,gBAAgB;AAC/C,SACCC,qBAAqB,EACrBC,gBA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AEtC,KAAK,EAAE;IAAEuC,IAAI;IAAEC;EAAU,CAAC,EAAG;IACjD,MAAMC,UAAU,GAAG,CAAEF,IAAI,IAAIC,SAAS,EACpCE,OAAO,CAAE,UAAU,EAAE,EAAG,CAAC,CACzBC,IAAI,CAAC,CAAC;;IAER;IACA;IACA,IAAK,CAAE1D,KAAK,CAAEwD,UAAW,CAAC,IAAI,CAAE,UAAU,CAACG,IAAI,CAAEH,UAAW,CAAC,EAAG;MAC/D,OAAOzC,KAAK;IACb;;IAEA;IACA6C,MAAM,CAACC,OAAO,CAACC,GAAG,CAAE,mBAAmB,EAAEN,UAAW,CAAC;IAErD,MAAMO,MAAM,GAAG;MACd9B,IAAI,EAAEvB,IAAI;MACVwB,UAAU,EAAE;QACXC,GAAG,EAAE/B,cAAc,CAAEoD,UAAW;MACjC;IACD,CAAC;IAED,IAAK3D,WAAW,CAAEkB,KAAM,CAAC,EAAG;MAC3B,OAAOjB,MAAM,CACZiB,KAAK,EACLrB,WAAW,CACVK,MAAM,CAAE;QAAEiC,IAAI,EAAEuB;MAAU,CAAE,CAAC,EAC7BQ,MAAM,EACN,CAAC,EACDR,SAAS,CAACS,MACX,CACD,CAAC;IACF;IAEA,OAAOtE,WAAW,CAAEqB,KAAK,EAAEgD,MAAO,CAAC;EACpC,CAAC;EACDE,IAAI,EAAErD;AACP,CAAC"}
1
+ {"version":3,"names":["__","useState","useLayoutEffect","useEffect","getTextContent","applyFormat","removeFormat","slice","isCollapsed","insert","create","isURL","isEmail","RichTextToolbarButton","RichTextShortcut","decodeEntities","link","linkIcon","speak","InlineLinkUI","isValidHref","name","title","Edit","isActive","activeAttributes","value","onChange","onFocus","contentRef","editingLink","setEditingLink","creatingLink","setCreatingLink","openedBy","setOpenedBy","shouldAutoFocus","setShouldAutoFocus","setIsEditingLink","isEditing","autoFocus","setIsCreatingLink","isCreating","editableContentElement","current","handleClick","event","target","closest","addEventListener","removeEventListener","addLink","text","type","attributes","url","stopAddingLink","tagName","focus","onFocusOutside","onRemoveFormat","isEditingActiveLink","createElement","Fragment","character","onUse","icon","onClick","currentTarget","shortcutType","shortcutCharacter","focusOnMount","className","id","_id","rel","__unstablePasteRule","html","plainText","pastedText","replace","trim","test","window","console","log","format","length","edit"],"sources":["@wordpress/format-library/src/link/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useState, useLayoutEffect, useEffect } from '@wordpress/element';\nimport {\n\tgetTextContent,\n\tapplyFormat,\n\tremoveFormat,\n\tslice,\n\tisCollapsed,\n\tinsert,\n\tcreate,\n} from '@wordpress/rich-text';\nimport { isURL, isEmail } from '@wordpress/url';\nimport {\n\tRichTextToolbarButton,\n\tRichTextShortcut,\n} from '@wordpress/block-editor';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { link as linkIcon } from '@wordpress/icons';\nimport { speak } from '@wordpress/a11y';\n\n/**\n * Internal dependencies\n */\nimport InlineLinkUI from './inline';\nimport { isValidHref } from './utils';\n\nconst name = 'core/link';\nconst title = __( 'Link' );\n\nfunction Edit( {\n\tisActive,\n\tactiveAttributes,\n\tvalue,\n\tonChange,\n\tonFocus,\n\tcontentRef,\n} ) {\n\tconst [ editingLink, setEditingLink ] = useState( false );\n\tconst [ creatingLink, setCreatingLink ] = useState( false );\n\n\t// We only need to store the button element that opened the popover. We can ignore the other states, as they will be handled by the onFocus prop to return to the rich text field.\n\tconst [ openedBy, setOpenedBy ] = useState( null );\n\n\t// Manages whether the Link UI popover should autofocus when shown.\n\tconst [ shouldAutoFocus, setShouldAutoFocus ] = useState( true );\n\n\tfunction setIsEditingLink( isEditing, { autoFocus = true } = {} ) {\n\t\tsetEditingLink( isEditing );\n\t\tsetShouldAutoFocus( autoFocus );\n\t}\n\n\tfunction setIsCreatingLink( isCreating ) {\n\t\t// Don't add a new link if there is already an active link.\n\t\t// The two states are mutually exclusive.\n\t\tif ( isCreating === true && isActive ) {\n\t\t\treturn;\n\t\t}\n\t\tsetCreatingLink( isCreating );\n\t}\n\n\tuseEffect( () => {\n\t\t// When the link becomes inactive (i.e. isActive is false), reset the editingLink state\n\t\t// and the creatingLink state. This means that if the Link UI is displayed and the link\n\t\t// becomes inactive (e.g. used arrow keys to move cursor outside of link bounds), the UI will close.\n\t\tif ( ! isActive ) {\n\t\t\tsetEditingLink( false );\n\t\t\tsetCreatingLink( false );\n\t\t}\n\t}, [ isActive ] );\n\n\tuseLayoutEffect( () => {\n\t\tconst editableContentElement = contentRef.current;\n\t\tif ( ! editableContentElement ) {\n\t\t\treturn;\n\t\t}\n\n\t\tfunction handleClick( event ) {\n\t\t\t// There is a situation whereby there is an existing link in the rich text\n\t\t\t// and the user clicks on the leftmost edge of that link and fails to activate\n\t\t\t// the link format, but the click event still fires on the `<a>` element.\n\t\t\t// This causes the `editingLink` state to be set to `true` and the link UI\n\t\t\t// to be rendered in \"creating\" mode. We need to check isActive to see if\n\t\t\t// we have an active link format.\n\t\t\tif (\n\t\t\t\t! event.target.closest( '[contenteditable] a' ) || // other formats (e.g. bold) may be nested within the link.\n\t\t\t\t! isActive\n\t\t\t) {\n\t\t\t\tsetIsEditingLink( false );\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tsetIsEditingLink( true, { autoFocus: false } );\n\t\t}\n\n\t\teditableContentElement.addEventListener( 'click', handleClick );\n\n\t\treturn () => {\n\t\t\teditableContentElement.removeEventListener( 'click', handleClick );\n\t\t};\n\t}, [ contentRef, isActive ] );\n\n\tfunction addLink( target ) {\n\t\tsetShouldAutoFocus( true );\n\t\tconst text = getTextContent( slice( value ) );\n\n\t\tif ( ! isActive && text && isURL( text ) && isValidHref( text ) ) {\n\t\t\tonChange(\n\t\t\t\tapplyFormat( value, {\n\t\t\t\t\ttype: name,\n\t\t\t\t\tattributes: { url: text },\n\t\t\t\t} )\n\t\t\t);\n\t\t} else if ( ! isActive && text && isEmail( text ) ) {\n\t\t\tonChange(\n\t\t\t\tapplyFormat( value, {\n\t\t\t\t\ttype: name,\n\t\t\t\t\tattributes: { url: `mailto:${ text }` },\n\t\t\t\t} )\n\t\t\t);\n\t\t} else {\n\t\t\tif ( target ) {\n\t\t\t\tsetOpenedBy( target );\n\t\t\t}\n\t\t\tif ( ! isActive ) {\n\t\t\t\tsetIsCreatingLink( true );\n\t\t\t} else {\n\t\t\t\tsetIsEditingLink( true );\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Runs when the popover is closed via escape keypress, unlinking the selected text,\n\t * but _not_ on a click outside the popover. onFocusOutside handles that.\n\t */\n\tfunction stopAddingLink() {\n\t\t// Don't let the click handler on the toolbar button trigger again.\n\n\t\t// There are two places for us to return focus to on Escape keypress:\n\t\t// 1. The rich text field.\n\t\t// 2. The toolbar button.\n\n\t\t// The toolbar button is the only one we need to handle returning focus to.\n\t\t// Otherwise, we rely on the passed in onFocus to return focus to the rich text field.\n\n\t\t// Close the popover\n\t\tsetIsEditingLink( false );\n\t\tsetIsCreatingLink( false );\n\n\t\t// Return focus to the toolbar button or the rich text field\n\t\tif ( openedBy?.tagName === 'BUTTON' ) {\n\t\t\topenedBy.focus();\n\t\t} else {\n\t\t\tonFocus();\n\t\t}\n\t\t// Remove the openedBy state\n\t\tsetOpenedBy( null );\n\t}\n\n\t// Test for this:\n\t// 1. Click on the link button\n\t// 2. Click the Options button in the top right of header\n\t// 3. Focus should be in the dropdown of the Options button\n\t// 4. Press Escape\n\t// 5. Focus should be on the Options button\n\tfunction onFocusOutside() {\n\t\tsetIsEditingLink( false );\n\t\tsetIsCreatingLink( false );\n\t\tsetOpenedBy( null );\n\t}\n\n\tfunction onRemoveFormat() {\n\t\tonChange( removeFormat( value, name ) );\n\t\tspeak( __( 'Link removed.' ), 'assertive' );\n\t}\n\n\tconst isEditingActiveLink = editingLink && isActive;\n\n\treturn (\n\t\t<>\n\t\t\t<RichTextShortcut type=\"primary\" character=\"k\" onUse={ addLink } />\n\t\t\t<RichTextShortcut\n\t\t\t\ttype=\"primaryShift\"\n\t\t\t\tcharacter=\"k\"\n\t\t\t\tonUse={ onRemoveFormat }\n\t\t\t/>\n\t\t\t<RichTextToolbarButton\n\t\t\t\tname=\"link\"\n\t\t\t\ticon={ linkIcon }\n\t\t\t\ttitle={ isActive ? __( 'Link' ) : title }\n\t\t\t\tonClick={ ( event ) => {\n\t\t\t\t\taddLink( event.currentTarget );\n\t\t\t\t} }\n\t\t\t\tisActive={ isActive || editingLink }\n\t\t\t\tshortcutType=\"primary\"\n\t\t\t\tshortcutCharacter=\"k\"\n\t\t\t\taria-haspopup=\"true\"\n\t\t\t\taria-expanded={ editingLink }\n\t\t\t/>\n\t\t\t{ ( isEditingActiveLink || creatingLink ) && (\n\t\t\t\t<InlineLinkUI\n\t\t\t\t\tstopAddingLink={ stopAddingLink }\n\t\t\t\t\tonFocusOutside={ onFocusOutside }\n\t\t\t\t\tisActive={ isActive }\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\tfocusOnMount={ shouldAutoFocus ? 'firstElement' : false }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nexport const link = {\n\tname,\n\ttitle,\n\ttagName: 'a',\n\tclassName: null,\n\tattributes: {\n\t\turl: 'href',\n\t\ttype: 'data-type',\n\t\tid: 'data-id',\n\t\t_id: 'id',\n\t\ttarget: 'target',\n\t\trel: 'rel',\n\t},\n\t__unstablePasteRule( value, { html, plainText } ) {\n\t\tconst pastedText = ( html || plainText )\n\t\t\t.replace( /<[^>]+>/g, '' )\n\t\t\t.trim();\n\n\t\t// A URL was pasted, turn the selection into a link.\n\t\t// For the link pasting feature, allow only http(s) protocols.\n\t\tif ( ! isURL( pastedText ) || ! /^https?:/.test( pastedText ) ) {\n\t\t\treturn value;\n\t\t}\n\n\t\t// Allows us to ask for this information when we get a report.\n\t\twindow.console.log( 'Created link:\\n\\n', pastedText );\n\n\t\tconst format = {\n\t\t\ttype: name,\n\t\t\tattributes: {\n\t\t\t\turl: decodeEntities( pastedText ),\n\t\t\t},\n\t\t};\n\n\t\tif ( isCollapsed( value ) ) {\n\t\t\treturn insert(\n\t\t\t\tvalue,\n\t\t\t\tapplyFormat(\n\t\t\t\t\tcreate( { text: plainText } ),\n\t\t\t\t\tformat,\n\t\t\t\t\t0,\n\t\t\t\t\tplainText.length\n\t\t\t\t)\n\t\t\t);\n\t\t}\n\n\t\treturn applyFormat( value, format );\n\t},\n\tedit: Edit,\n};\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,EAAE,QAAQ,iBAAiB;AACpC,SAASC,QAAQ,EAAEC,eAAe,EAAEC,SAAS,QAAQ,oBAAoB;AACzE,SACCC,cAAc,EACdC,WAAW,EACXC,YAAY,EACZC,KAAK,EACLC,WAAW,EACXC,MAAM,EACNC,MAAM,QACA,sBAAsB;AAC7B,SAASC,KAAK,EAAEC,OAAO,QAAQ,gBAAgB;AAC/C,SACCC,qBAAqB,EACrBC,gBAAgB,QACV,yBAAyB;AAChC,SAASC,cAAc,QAAQ,0BAA0B;AACzD,SAASC,IAAI,IAAIC,QAAQ,QAAQ,kBAAkB;AACnD,SAASC,KAAK,QAAQ,iBAAiB;;AAEvC;AACA;AACA;AACA,OAAOC,YAAY,MAAM,UAAU;AACnC,SAASC,WAAW,QAAQ,SAAS;AAErC,MAAMC,IAAI,GAAG,WAAW;AACxB,MAAMC,KAAK,GAAGtB,EAAE,CAAE,MAAO,CAAC;AAE1B,SAASuB,IAAIA,CAAE;EACdC,QAAQ;EACRC,gBAAgB;EAChBC,KAAK;EACLC,QAAQ;EACRC,OAAO;EACPC;AACD,CAAC,EAAG;EACH,MAAM,CAAEC,WAAW,EAAEC,cAAc,CAAE,GAAG9B,QAAQ,CAAE,KAAM,CAAC;EACzD,MAAM,CAAE+B,YAAY,EAAEC,eAAe,CAAE,GAAGhC,QAAQ,CAAE,KAAM,CAAC;;EAE3D;EACA,MAAM,CAAEiC,QAAQ,EAAEC,WAA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;IACF;IAEA,OAAOlF,WAAW,CAAEqB,KAAK,EAAE4D,MAAO,CAAC;EACpC,CAAC;EACDE,IAAI,EAAEjE;AACP,CAAC"}
@@ -27,7 +27,8 @@ function InlineLinkUI({
27
27
  onChange,
28
28
  onFocusOutside,
29
29
  stopAddingLink,
30
- contentRef
30
+ contentRef,
31
+ focusOnMount
31
32
  }) {
32
33
  const richLinkTextValue = getRichTextValueFromSelection(value, isActive);
33
34
 
@@ -193,7 +194,9 @@ function InlineLinkUI({
193
194
  onFocusOutside: onFocusOutside,
194
195
  placement: "bottom",
195
196
  offset: 10,
196
- shift: true
197
+ shift: true,
198
+ focusOnMount: focusOnMount,
199
+ constrainTabbing: true
197
200
  }, createElement(LinkControl, {
198
201
  value: linkValue,
199
202
  onChange: onChangeLink,
@@ -1 +1 @@
1
- {"version":3,"names":["useMemo","createInterpolateElement","__","sprintf","speak","Popover","prependHTTP","create","insert","isCollapsed","applyFormat","removeFormat","slice","replace","split","concat","useAnchor","__experimentalLinkControl","LinkControl","store","blockEditorStore","useDispatch","useSelect","createLinkFormat","isValidHref","getFormatBoundary","link","settings","LINK_SETTINGS","DEFAULT_LINK_SETTINGS","id","title","InlineLinkUI","isActive","activeAttributes","value","onChange","onFocusOutside","stopAddingLink","contentRef","richLinkTextValue","getRichTextValueFromSelection","richTextText","text","selectionChange","createPageEntity","userCanCreatePages","selectionStart","select","getSettings","getSelectionStart","_settings","__experimentalCreatePageEntity","__experimentalUserCanCreatePages","linkValue","url","type","opensInNewTab","target","nofollow","rel","includes","removeLink","newValue","onChangeLink","nextValue","hasLink","isNewLink","newUrl","linkFormat","undefined","String","opensInNewWindow","newText","inserted","start","length","clientId","identifier","attributeKey","boundary","valBefore","valAfter","newValAfter","popoverAnchor","editableContentElement","current","handleCreate","pageTitle","page","status","rendered","kind","createButtonText","searchTerm","mark","createElement","anchor","onClose","placement","offset","shift","onRemove","hasRichPreviews","createSuggestion","withCreateSuggestion","createSuggestionButtonText","hasTextControl","showInitialSuggestions","suggestionsQuery","initialSuggestionsSearchOptions","subtype","perPage","textStart","textEnd","end"],"sources":["@wordpress/format-library/src/link/inline.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useMemo, createInterpolateElement } from '@wordpress/element';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { speak } from '@wordpress/a11y';\nimport { Popover } from '@wordpress/components';\nimport { prependHTTP } from '@wordpress/url';\nimport {\n\tcreate,\n\tinsert,\n\tisCollapsed,\n\tapplyFormat,\n\tremoveFormat,\n\tslice,\n\treplace,\n\tsplit,\n\tconcat,\n\tuseAnchor,\n} from '@wordpress/rich-text';\nimport {\n\t__experimentalLinkControl as LinkControl,\n\tstore as blockEditorStore,\n} from '@wordpress/block-editor';\nimport { useDispatch, useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { createLinkFormat, isValidHref, getFormatBoundary } from './utils';\nimport { link as settings } from './index';\n\nconst LINK_SETTINGS = [\n\t...LinkControl.DEFAULT_LINK_SETTINGS,\n\t{\n\t\tid: 'nofollow',\n\t\ttitle: __( 'Mark as nofollow' ),\n\t},\n];\n\nfunction InlineLinkUI( {\n\tisActive,\n\tactiveAttributes,\n\tvalue,\n\tonChange,\n\tonFocusOutside,\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\tconst { selectionChange } = useDispatch( blockEditorStore );\n\n\tconst { createPageEntity, userCanCreatePages, selectionStart } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getSettings, getSelectionStart } =\n\t\t\t\tselect( blockEditorStore );\n\t\t\tconst _settings = getSettings();\n\n\t\t\treturn {\n\t\t\t\tcreatePageEntity: _settings.__experimentalCreatePageEntity,\n\t\t\t\tuserCanCreatePages: _settings.__experimentalUserCanCreatePages,\n\t\t\t\tselectionStart: getSelectionStart(),\n\t\t\t};\n\t\t},\n\t\t[]\n\t);\n\n\tconst linkValue = useMemo(\n\t\t() => ( {\n\t\t\turl: activeAttributes.url,\n\t\t\ttype: activeAttributes.type,\n\t\t\tid: activeAttributes.id,\n\t\t\topensInNewTab: activeAttributes.target === '_blank',\n\t\t\tnofollow: activeAttributes.rel?.includes( 'nofollow' ),\n\t\t\ttitle: richTextText,\n\t\t} ),\n\t\t[\n\t\t\tactiveAttributes.id,\n\t\t\tactiveAttributes.rel,\n\t\t\tactiveAttributes.target,\n\t\t\tactiveAttributes.type,\n\t\t\tactiveAttributes.url,\n\t\t\trichTextText,\n\t\t]\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\tconst hasLink = linkValue?.url;\n\t\tconst isNewLink = ! hasLink;\n\n\t\t// Merge the next value with the current link value.\n\t\tnextValue = {\n\t\t\t...linkValue,\n\t\t\t...nextValue,\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\tnofollow: nextValue.nofollow,\n\t\t} );\n\n\t\tconst newText = nextValue.title || newUrl;\n\n\t\t// Scenario: we have any active text selection or an active format.\n\t\tlet newValue;\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 inserted = insert( value, newText );\n\n\t\t\tnewValue = applyFormat(\n\t\t\t\tinserted,\n\t\t\t\tlinkFormat,\n\t\t\t\tvalue.start,\n\t\t\t\tvalue.start + newText.length\n\t\t\t);\n\n\t\t\tonChange( newValue );\n\n\t\t\t// Close the Link UI.\n\t\t\tstopAddingLink();\n\n\t\t\t// Move the selection to the end of the inserted link outside of the format boundary\n\t\t\t// so the user can continue typing after the link.\n\t\t\tselectionChange( {\n\t\t\t\tclientId: selectionStart.clientId,\n\t\t\t\tidentifier: selectionStart.attributeKey,\n\t\t\t\tstart: value.start + newText.length + 1,\n\t\t\t} );\n\n\t\t\treturn;\n\t\t} else if ( newText === richTextText ) {\n\t\t\tnewValue = applyFormat( value, linkFormat );\n\t\t} else {\n\t\t\t// Scenario: Editing an existing link.\n\n\t\t\t// Create new RichText value for the new text in order that we\n\t\t\t// can apply formats to it.\n\t\t\tnewValue = create( { text: newText } );\n\t\t\t// Apply the new Link format to this new text value.\n\t\t\tnewValue = applyFormat( newValue, linkFormat, 0, newText.length );\n\n\t\t\t// Get the boundaries of the active link format.\n\t\t\tconst boundary = getFormatBoundary( value, {\n\t\t\t\ttype: 'core/link',\n\t\t\t} );\n\n\t\t\t// Split the value at the start of the active link format.\n\t\t\t// Passing \"start\" as the 3rd parameter is required to ensure\n\t\t\t// the second half of the split value is split at the format's\n\t\t\t// start boundary and avoids relying on the value's \"end\" property\n\t\t\t// which may not correspond correctly.\n\t\t\tconst [ valBefore, valAfter ] = split(\n\t\t\t\tvalue,\n\t\t\t\tboundary.start,\n\t\t\t\tboundary.start\n\t\t\t);\n\n\t\t\t// Update the original (full) RichTextValue replacing the\n\t\t\t// target text with the *new* RichTextValue containing:\n\t\t\t// 1. The new text content.\n\t\t\t// 2. The new link format.\n\t\t\t// As \"replace\" will operate on the first match only, it is\n\t\t\t// run only against the second half of the value which was\n\t\t\t// split at the active format's boundary. This avoids a bug\n\t\t\t// with incorrectly targetted replacements.\n\t\t\t// See: https://github.com/WordPress/gutenberg/issues/41771.\n\t\t\t// Note original formats will be lost when applying this change.\n\t\t\t// That is expected behaviour.\n\t\t\t// See: https://github.com/WordPress/gutenberg/pull/33849#issuecomment-936134179.\n\t\t\tconst newValAfter = replace( valAfter, richTextText, newValue );\n\n\t\t\tnewValue = concat( valBefore, newValAfter );\n\t\t}\n\n\t\tonChange( newValue );\n\n\t\t// Focus should only be returned to the rich text on submit if this link is not\n\t\t// being created for the first time. If it is then focus should remain within the\n\t\t// Link UI because it should remain open for the user to modify the link they have\n\t\t// just created.\n\t\tif ( ! isNewLink ) {\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 popoverAnchor = useAnchor( {\n\t\teditableContentElement: contentRef.current,\n\t\tsettings: { ...settings, isActive },\n\t} );\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\tanchor={ popoverAnchor }\n\t\t\tonClose={ stopAddingLink }\n\t\t\tonFocusOutside={ onFocusOutside }\n\t\t\tplacement=\"bottom\"\n\t\t\toffset={ 10 }\n\t\t\tshift\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\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\tsettings={ LINK_SETTINGS }\n\t\t\t\tshowInitialSuggestions\n\t\t\t\tsuggestionsQuery={ {\n\t\t\t\t\t// always show Pages as initial suggestions\n\t\t\t\t\tinitialSuggestionsSearchOptions: {\n\t\t\t\t\t\ttype: 'post',\n\t\t\t\t\t\tsubtype: 'page',\n\t\t\t\t\t\tperPage: 20,\n\t\t\t\t\t},\n\t\t\t\t} }\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 InlineLinkUI;\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,OAAO,EAAEC,wBAAwB,QAAQ,oBAAoB;AACtE,SAASC,EAAE,EAAEC,OAAO,QAAQ,iBAAiB;AAC7C,SAASC,KAAK,QAAQ,iBAAiB;AACvC,SAASC,OAAO,QAAQ,uBAAuB;AAC/C,SAASC,WAAW,QAAQ,gBAAgB;AAC5C,SACCC,MAAM,EACNC,MAAM,EACNC,WAAW,EACXC,WAAW,EACXC,YAAY,EACZC,KAAK,EACLC,OAAO,EACPC,KAAK,EACLC,MAAM,EACNC,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OAAO,GAAGlC,QAAQ,CAACmC,GAAG,GAAG,CAAC;EAC3B;;EAEA;EACA,OAAOvG,KAAK,CAAEuB,KAAK,EAAE8E,SAAS,EAAEC,OAAQ,CAAC;AAC1C;AAEA,eAAelF,YAAY"}
1
+ {"version":3,"names":["useMemo","createInterpolateElement","__","sprintf","speak","Popover","prependHTTP","create","insert","isCollapsed","applyFormat","removeFormat","slice","replace","split","concat","useAnchor","__experimentalLinkControl","LinkControl","store","blockEditorStore","useDispatch","useSelect","createLinkFormat","isValidHref","getFormatBoundary","link","settings","LINK_SETTINGS","DEFAULT_LINK_SETTINGS","id","title","InlineLinkUI","isActive","activeAttributes","value","onChange","onFocusOutside","stopAddingLink","contentRef","focusOnMount","richLinkTextValue","getRichTextValueFromSelection","richTextText","text","selectionChange","createPageEntity","userCanCreatePages","selectionStart","select","getSettings","getSelectionStart","_settings","__experimentalCreatePageEntity","__experimentalUserCanCreatePages","linkValue","url","type","opensInNewTab","target","nofollow","rel","includes","removeLink","newValue","onChangeLink","nextValue","hasLink","isNewLink","newUrl","linkFormat","undefined","String","opensInNewWindow","newText","inserted","start","length","clientId","identifier","attributeKey","boundary","valBefore","valAfter","newValAfter","popoverAnchor","editableContentElement","current","handleCreate","pageTitle","page","status","rendered","kind","createButtonText","searchTerm","mark","createElement","anchor","onClose","placement","offset","shift","constrainTabbing","onRemove","hasRichPreviews","createSuggestion","withCreateSuggestion","createSuggestionButtonText","hasTextControl","showInitialSuggestions","suggestionsQuery","initialSuggestionsSearchOptions","subtype","perPage","textStart","textEnd","end"],"sources":["@wordpress/format-library/src/link/inline.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useMemo, createInterpolateElement } from '@wordpress/element';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { speak } from '@wordpress/a11y';\nimport { Popover } from '@wordpress/components';\nimport { prependHTTP } from '@wordpress/url';\nimport {\n\tcreate,\n\tinsert,\n\tisCollapsed,\n\tapplyFormat,\n\tremoveFormat,\n\tslice,\n\treplace,\n\tsplit,\n\tconcat,\n\tuseAnchor,\n} from '@wordpress/rich-text';\nimport {\n\t__experimentalLinkControl as LinkControl,\n\tstore as blockEditorStore,\n} from '@wordpress/block-editor';\nimport { useDispatch, useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { createLinkFormat, isValidHref, getFormatBoundary } from './utils';\nimport { link as settings } from './index';\n\nconst LINK_SETTINGS = [\n\t...LinkControl.DEFAULT_LINK_SETTINGS,\n\t{\n\t\tid: 'nofollow',\n\t\ttitle: __( 'Mark as nofollow' ),\n\t},\n];\n\nfunction InlineLinkUI( {\n\tisActive,\n\tactiveAttributes,\n\tvalue,\n\tonChange,\n\tonFocusOutside,\n\tstopAddingLink,\n\tcontentRef,\n\tfocusOnMount,\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\tconst { selectionChange } = useDispatch( blockEditorStore );\n\n\tconst { createPageEntity, userCanCreatePages, selectionStart } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getSettings, getSelectionStart } =\n\t\t\t\tselect( blockEditorStore );\n\t\t\tconst _settings = getSettings();\n\n\t\t\treturn {\n\t\t\t\tcreatePageEntity: _settings.__experimentalCreatePageEntity,\n\t\t\t\tuserCanCreatePages: _settings.__experimentalUserCanCreatePages,\n\t\t\t\tselectionStart: getSelectionStart(),\n\t\t\t};\n\t\t},\n\t\t[]\n\t);\n\n\tconst linkValue = useMemo(\n\t\t() => ( {\n\t\t\turl: activeAttributes.url,\n\t\t\ttype: activeAttributes.type,\n\t\t\tid: activeAttributes.id,\n\t\t\topensInNewTab: activeAttributes.target === '_blank',\n\t\t\tnofollow: activeAttributes.rel?.includes( 'nofollow' ),\n\t\t\ttitle: richTextText,\n\t\t} ),\n\t\t[\n\t\t\tactiveAttributes.id,\n\t\t\tactiveAttributes.rel,\n\t\t\tactiveAttributes.target,\n\t\t\tactiveAttributes.type,\n\t\t\tactiveAttributes.url,\n\t\t\trichTextText,\n\t\t]\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\tconst hasLink = linkValue?.url;\n\t\tconst isNewLink = ! hasLink;\n\n\t\t// Merge the next value with the current link value.\n\t\tnextValue = {\n\t\t\t...linkValue,\n\t\t\t...nextValue,\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\tnofollow: nextValue.nofollow,\n\t\t} );\n\n\t\tconst newText = nextValue.title || newUrl;\n\n\t\t// Scenario: we have any active text selection or an active format.\n\t\tlet newValue;\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 inserted = insert( value, newText );\n\n\t\t\tnewValue = applyFormat(\n\t\t\t\tinserted,\n\t\t\t\tlinkFormat,\n\t\t\t\tvalue.start,\n\t\t\t\tvalue.start + newText.length\n\t\t\t);\n\n\t\t\tonChange( newValue );\n\n\t\t\t// Close the Link UI.\n\t\t\tstopAddingLink();\n\n\t\t\t// Move the selection to the end of the inserted link outside of the format boundary\n\t\t\t// so the user can continue typing after the link.\n\t\t\tselectionChange( {\n\t\t\t\tclientId: selectionStart.clientId,\n\t\t\t\tidentifier: selectionStart.attributeKey,\n\t\t\t\tstart: value.start + newText.length + 1,\n\t\t\t} );\n\n\t\t\treturn;\n\t\t} else if ( newText === richTextText ) {\n\t\t\tnewValue = applyFormat( value, linkFormat );\n\t\t} else {\n\t\t\t// Scenario: Editing an existing link.\n\n\t\t\t// Create new RichText value for the new text in order that we\n\t\t\t// can apply formats to it.\n\t\t\tnewValue = create( { text: newText } );\n\t\t\t// Apply the new Link format to this new text value.\n\t\t\tnewValue = applyFormat( newValue, linkFormat, 0, newText.length );\n\n\t\t\t// Get the boundaries of the active link format.\n\t\t\tconst boundary = getFormatBoundary( value, {\n\t\t\t\ttype: 'core/link',\n\t\t\t} );\n\n\t\t\t// Split the value at the start of the active link format.\n\t\t\t// Passing \"start\" as the 3rd parameter is required to ensure\n\t\t\t// the second half of the split value is split at the format's\n\t\t\t// start boundary and avoids relying on the value's \"end\" property\n\t\t\t// which may not correspond correctly.\n\t\t\tconst [ valBefore, valAfter ] = split(\n\t\t\t\tvalue,\n\t\t\t\tboundary.start,\n\t\t\t\tboundary.start\n\t\t\t);\n\n\t\t\t// Update the original (full) RichTextValue replacing the\n\t\t\t// target text with the *new* RichTextValue containing:\n\t\t\t// 1. The new text content.\n\t\t\t// 2. The new link format.\n\t\t\t// As \"replace\" will operate on the first match only, it is\n\t\t\t// run only against the second half of the value which was\n\t\t\t// split at the active format's boundary. This avoids a bug\n\t\t\t// with incorrectly targetted replacements.\n\t\t\t// See: https://github.com/WordPress/gutenberg/issues/41771.\n\t\t\t// Note original formats will be lost when applying this change.\n\t\t\t// That is expected behaviour.\n\t\t\t// See: https://github.com/WordPress/gutenberg/pull/33849#issuecomment-936134179.\n\t\t\tconst newValAfter = replace( valAfter, richTextText, newValue );\n\n\t\t\tnewValue = concat( valBefore, newValAfter );\n\t\t}\n\n\t\tonChange( newValue );\n\n\t\t// Focus should only be returned to the rich text on submit if this link is not\n\t\t// being created for the first time. If it is then focus should remain within the\n\t\t// Link UI because it should remain open for the user to modify the link they have\n\t\t// just created.\n\t\tif ( ! isNewLink ) {\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 popoverAnchor = useAnchor( {\n\t\teditableContentElement: contentRef.current,\n\t\tsettings: {\n\t\t\t...settings,\n\t\t\tisActive,\n\t\t},\n\t} );\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\tanchor={ popoverAnchor }\n\t\t\tonClose={ stopAddingLink }\n\t\t\tonFocusOutside={ onFocusOutside }\n\t\t\tplacement=\"bottom\"\n\t\t\toffset={ 10 }\n\t\t\tshift\n\t\t\tfocusOnMount={ focusOnMount }\n\t\t\tconstrainTabbing\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\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\tsettings={ LINK_SETTINGS }\n\t\t\t\tshowInitialSuggestions\n\t\t\t\tsuggestionsQuery={ {\n\t\t\t\t\t// always show Pages as initial suggestions\n\t\t\t\t\tinitialSuggestionsSearchOptions: {\n\t\t\t\t\t\ttype: 'post',\n\t\t\t\t\t\tsubtype: 'page',\n\t\t\t\t\t\tperPage: 20,\n\t\t\t\t\t},\n\t\t\t\t} }\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 InlineLinkUI;\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,OAAO,EAAEC,wBAAwB,QAAQ,oBAAoB;AACtE,SAASC,EAAE,EAAEC,OAAO,QAAQ,iBAAiB;AAC7C,SAASC,KAAK,QAAQ,iBAAiB;AACvC,SAASC,OAAO,QAAQ,uBAAuB;AAC/C,SAASC,WAAW,QAAQ,gBAAgB;AAC5C,SACCC,MAAM,EACNC,MAAM,EACNC,WAAW,EACXC,WAAW,EACXC,YAAY,EACZC,KAAK,EACLC,OAAO,EACPC,KAAK,EACLC,MAAM,EACNC,SAAS,QACH,sBAAsB;AAC7B,SACCC,yBAAyB,IAAIC,WAAW,EACxCC,KAAK,IAAIC,gBAAgB,QACnB,yBAAyB;AAChC,SAASC,WAAW,EAAEC,SAAS,QAAQ,iBAAiB;;AAExD;AACA;AACA;AACA,SAASC,gBAAgB,EAAEC,WAAW,EAAEC,iBAAiB,QAAQ,SAAS;AAC1E,SAASC,IA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{ createElement } from "react";
2
+ /**
3
+ * WordPress dependencies
4
+ */
5
+ import { __ } from '@wordpress/i18n';
6
+ import { insert } from '@wordpress/rich-text';
7
+ import { RichTextShortcut } from '@wordpress/block-editor';
8
+ const name = 'core/non-breaking-space';
9
+ const title = __('Non breaking space');
10
+ export const nonBreakingSpace = {
11
+ name,
12
+ title,
13
+ tagName: 'nbsp',
14
+ className: null,
15
+ edit({
16
+ value,
17
+ onChange
18
+ }) {
19
+ function addNonBreakingSpace() {
20
+ onChange(insert(value, '\u00a0'));
21
+ }
22
+ return createElement(RichTextShortcut, {
23
+ type: "primaryShift",
24
+ character: " ",
25
+ onUse: addNonBreakingSpace
26
+ });
27
+ }
28
+ };
29
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["__","insert","RichTextShortcut","name","title","nonBreakingSpace","tagName","className","edit","value","onChange","addNonBreakingSpace","createElement","type","character","onUse"],"sources":["@wordpress/format-library/src/non-breaking-space/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { insert } from '@wordpress/rich-text';\nimport { RichTextShortcut } from '@wordpress/block-editor';\n\nconst name = 'core/non-breaking-space';\nconst title = __( 'Non breaking space' );\n\nexport const nonBreakingSpace = {\n\tname,\n\ttitle,\n\ttagName: 'nbsp',\n\tclassName: null,\n\tedit( { value, onChange } ) {\n\t\tfunction addNonBreakingSpace() {\n\t\t\tonChange( insert( value, '\\u00a0' ) );\n\t\t}\n\n\t\treturn (\n\t\t\t<RichTextShortcut\n\t\t\t\ttype=\"primaryShift\"\n\t\t\t\tcharacter=\" \"\n\t\t\t\tonUse={ addNonBreakingSpace }\n\t\t\t/>\n\t\t);\n\t},\n};\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,EAAE,QAAQ,iBAAiB;AACpC,SAASC,MAAM,QAAQ,sBAAsB;AAC7C,SAASC,gBAAgB,QAAQ,yBAAyB;AAE1D,MAAMC,IAAI,GAAG,yBAAyB;AACtC,MAAMC,KAAK,GAAGJ,EAAE,CAAE,oBAAqB,CAAC;AAExC,OAAO,MAAMK,gBAAgB,GAAG;EAC/BF,IAAI;EACJC,KAAK;EACLE,OAAO,EAAE,MAAM;EACfC,SAAS,EAAE,IAAI;EACfC,IAAIA,CAAE;IAAEC,KAAK;IAAEC;EAAS,CAAC,EAAG;IAC3B,SAASC,mBAAmBA,CAAA,EAAG;MAC9BD,QAAQ,CAAET,MAAM,CAAEQ,KAAK,EAAE,QAAS,CAAE,CAAC;IACtC;IAEA,OACCG,aAAA,CAACV,gBAAgB;MAChBW,IAAI,EAAC,cAAc;MACnBC,SAAS,EAAC,GAAG;MACbC,KAAK,EAAGJ;IAAqB,CAC7B,CAAC;EAEJ;AACD,CAAC"}
@@ -18,7 +18,7 @@ import { usePreferredColorSchemeStyle } from '@wordpress/compose';
18
18
  /**
19
19
  * Internal dependencies
20
20
  */
21
- import { getActiveColors } from './inline.js';
21
+ import { getActiveColors } from './inline.native.js';
22
22
  import { default as InlineColorUI } from './inline';
23
23
  import styles from './style.scss';
24
24
  const name = 'core/text-color';
@@ -1 +1 @@
1
- {"version":3,"names":["StyleSheet","View","__","useCallback","useMemo","useState","BlockControls","useSettings","ToolbarGroup","ToolbarButton","useMobileGlobalStylesColors","Icon","color","colorIcon","textColor","textColorIcon","removeFormat","usePreferredColorSchemeStyle","getActiveColors","default","InlineColorUI","styles","name","title","getComputedStyleProperty","element","property","_element$props$style","style","props","backgroundColor","baseColors","background","fillComputedColors","TextColorEdit","value","onChange","isActive","activeAttributes","contentRef","allowCustomControl","colors","isAddingColor","setIsAddingColor","enableIsAddingColor","disableIsAddingColor","colorIndicatorStyle","hasColorsToChoose","length","onPressButton","outlineStyle","borderWidth","hairlineWidth","isActiveStyle","customContainerStyles","createElement","Fragment","pointerEvents","icon","Object","keys","extraProps","onClick","onClose","tagName","className","attributes","class","edit"],"sources":["@wordpress/format-library/src/text-color/index.native.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport { StyleSheet, View } from 'react-native';\n\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useCallback, useMemo, useState } from '@wordpress/element';\nimport { BlockControls, useSettings } from '@wordpress/block-editor';\nimport {\n\tToolbarGroup,\n\tToolbarButton,\n\tuseMobileGlobalStylesColors,\n} from '@wordpress/components';\nimport {\n\tIcon,\n\tcolor as colorIcon,\n\ttextColor as textColorIcon,\n} from '@wordpress/icons';\nimport { removeFormat } from '@wordpress/rich-text';\nimport { usePreferredColorSchemeStyle } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { getActiveColors } from './inline.js';\nimport { default as InlineColorUI } from './inline';\nimport styles from './style.scss';\n\nconst name = 'core/text-color';\nconst title = __( 'Text color' );\n\nfunction getComputedStyleProperty( element, property ) {\n\tconst style = element?.props?.style ?? {};\n\n\tif ( property === 'background-color' ) {\n\t\tconst { backgroundColor, baseColors } = style;\n\n\t\tif ( backgroundColor !== 'transparent' ) {\n\t\t\treturn backgroundColor;\n\t\t} else if ( baseColors && baseColors?.color?.background ) {\n\t\t\treturn baseColors?.color?.background;\n\t\t}\n\n\t\treturn 'transparent';\n\t}\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: getComputedStyleProperty(\n\t\t\telement,\n\t\t\t'background-color'\n\t\t),\n\t};\n}\n\nfunction TextColorEdit( {\n\tvalue,\n\tonChange,\n\tisActive,\n\tactiveAttributes,\n\tcontentRef,\n} ) {\n\tconst [ allowCustomControl ] = useSettings( 'color.custom' );\n\tconst colors = useMobileGlobalStylesColors();\n\tconst [ isAddingColor, setIsAddingColor ] = useState( false );\n\tconst enableIsAddingColor = useCallback(\n\t\t() => setIsAddingColor( true ),\n\t\t[ setIsAddingColor ]\n\t);\n\tconst disableIsAddingColor = useCallback(\n\t\t() => setIsAddingColor( false ),\n\t\t[ setIsAddingColor ]\n\t);\n\tconst colorIndicatorStyle = useMemo(\n\t\t() =>\n\t\t\tfillComputedColors(\n\t\t\t\tcontentRef,\n\t\t\t\tgetActiveColors( value, name, colors )\n\t\t\t),\n\t\t[ value, colors ]\n\t);\n\n\tconst hasColorsToChoose = colors.length || ! allowCustomControl;\n\n\tconst onPressButton = useCallback( () => {\n\t\tif ( hasColorsToChoose ) {\n\t\t\tenableIsAddingColor();\n\t\t} else {\n\t\t\tonChange( removeFormat( value, name ) );\n\t\t}\n\t}, [ hasColorsToChoose, value ] );\n\n\tconst outlineStyle = [\n\t\tusePreferredColorSchemeStyle(\n\t\t\tstyles[ 'components-inline-color__outline' ],\n\t\t\tstyles[ 'components-inline-color__outline--dark' ]\n\t\t),\n\t\t{ borderWidth: StyleSheet.hairlineWidth },\n\t];\n\n\tif ( ! hasColorsToChoose && ! isActive ) {\n\t\treturn null;\n\t}\n\n\tconst isActiveStyle = {\n\t\t...colorIndicatorStyle,\n\t\t...( ! colorIndicatorStyle?.backgroundColor\n\t\t\t? { backgroundColor: 'transparent' }\n\t\t\t: {} ),\n\t\t...styles[ 'components-inline-color--is-active' ],\n\t};\n\n\tconst customContainerStyles =\n\t\tstyles[ 'components-inline-color__button-container' ];\n\n\treturn (\n\t\t<>\n\t\t\t<BlockControls>\n\t\t\t\t<ToolbarGroup>\n\t\t\t\t\t{ isActive && (\n\t\t\t\t\t\t<View style={ outlineStyle } pointerEvents=\"none\" />\n\t\t\t\t\t) }\n\n\t\t\t\t\t<ToolbarButton\n\t\t\t\t\t\tname=\"text-color\"\n\t\t\t\t\t\tisActive={ isActive }\n\t\t\t\t\t\ticon={\n\t\t\t\t\t\t\t<Icon\n\t\t\t\t\t\t\t\ticon={\n\t\t\t\t\t\t\t\t\tObject.keys( activeAttributes ).length\n\t\t\t\t\t\t\t\t\t\t? textColorIcon\n\t\t\t\t\t\t\t\t\t\t: colorIcon\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tstyle={\n\t\t\t\t\t\t\t\t\tcolorIndicatorStyle?.color && {\n\t\t\t\t\t\t\t\t\t\tcolor: colorIndicatorStyle.color,\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t}\n\t\t\t\t\t\ttitle={ title }\n\t\t\t\t\t\textraProps={ {\n\t\t\t\t\t\t\tisActiveStyle,\n\t\t\t\t\t\t\tcustomContainerStyles,\n\t\t\t\t\t\t} }\n\t\t\t\t\t\t// If has no colors to choose but a color is active remove the color onClick\n\t\t\t\t\t\tonClick={ onPressButton }\n\t\t\t\t\t/>\n\t\t\t\t</ToolbarGroup>\n\t\t\t</BlockControls>\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\tedit: TextColorEdit,\n};\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,UAAU,EAAEC,IAAI,QAAQ,cAAc;;AAE/C;AACA;AACA;AACA,SAASC,EAAE,QAAQ,iBAAiB;AACpC,SAASC,WAAW,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,oBAAoB;AACnE,SAASC,aAAa,EAAEC,WAAW,QAAQ,yBAAyB;AACpE,SACCC,YAAY,EACZC,aAAa,EACbC,2BAA2B,QACrB,uBAAuB;AAC9B,SACCC,IAAI,EACJC,KAAK,IAAIC,SAAS,EAClBC,SAAS,IAAIC,aAAa,QACpB,kBAAkB;AACzB,SAASC,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;AACP,CAAC"}
1
+ {"version":3,"names":["StyleSheet","View","__","useCallback","useMemo","useState","BlockControls","useSettings","ToolbarGroup","ToolbarButton","useMobileGlobalStylesColors","Icon","color","colorIcon","textColor","textColorIcon","removeFormat","usePreferredColorSchemeStyle","getActiveColors","default","InlineColorUI","styles","name","title","getComputedStyleProperty","element","property","_element$props$style","style","props","backgroundColor","baseColors","background","fillComputedColors","TextColorEdit","value","onChange","isActive","activeAttributes","contentRef","allowCustomControl","colors","isAddingColor","setIsAddingColor","enableIsAddingColor","disableIsAddingColor","colorIndicatorStyle","hasColorsToChoose","length","onPressButton","outlineStyle","borderWidth","hairlineWidth","isActiveStyle","customContainerStyles","createElement","Fragment","pointerEvents","icon","Object","keys","extraProps","onClick","onClose","tagName","className","attributes","class","edit"],"sources":["@wordpress/format-library/src/text-color/index.native.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport { StyleSheet, View } from 'react-native';\n\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useCallback, useMemo, useState } from '@wordpress/element';\nimport { BlockControls, useSettings } from '@wordpress/block-editor';\nimport {\n\tToolbarGroup,\n\tToolbarButton,\n\tuseMobileGlobalStylesColors,\n} from '@wordpress/components';\nimport {\n\tIcon,\n\tcolor as colorIcon,\n\ttextColor as textColorIcon,\n} from '@wordpress/icons';\nimport { removeFormat } from '@wordpress/rich-text';\nimport { usePreferredColorSchemeStyle } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { getActiveColors } from './inline.native.js';\nimport { default as InlineColorUI } from './inline';\nimport styles from './style.scss';\n\nconst name = 'core/text-color';\nconst title = __( 'Text color' );\n\nfunction getComputedStyleProperty( element, property ) {\n\tconst style = element?.props?.style ?? {};\n\n\tif ( property === 'background-color' ) {\n\t\tconst { backgroundColor, baseColors } = style;\n\n\t\tif ( backgroundColor !== 'transparent' ) {\n\t\t\treturn backgroundColor;\n\t\t} else if ( baseColors && baseColors?.color?.background ) {\n\t\t\treturn baseColors?.color?.background;\n\t\t}\n\n\t\treturn 'transparent';\n\t}\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: getComputedStyleProperty(\n\t\t\telement,\n\t\t\t'background-color'\n\t\t),\n\t};\n}\n\nfunction TextColorEdit( {\n\tvalue,\n\tonChange,\n\tisActive,\n\tactiveAttributes,\n\tcontentRef,\n} ) {\n\tconst [ allowCustomControl ] = useSettings( 'color.custom' );\n\tconst colors = useMobileGlobalStylesColors();\n\tconst [ isAddingColor, setIsAddingColor ] = useState( false );\n\tconst enableIsAddingColor = useCallback(\n\t\t() => setIsAddingColor( true ),\n\t\t[ setIsAddingColor ]\n\t);\n\tconst disableIsAddingColor = useCallback(\n\t\t() => setIsAddingColor( false ),\n\t\t[ setIsAddingColor ]\n\t);\n\tconst colorIndicatorStyle = useMemo(\n\t\t() =>\n\t\t\tfillComputedColors(\n\t\t\t\tcontentRef,\n\t\t\t\tgetActiveColors( value, name, colors )\n\t\t\t),\n\t\t[ value, colors ]\n\t);\n\n\tconst hasColorsToChoose = colors.length || ! allowCustomControl;\n\n\tconst onPressButton = useCallback( () => {\n\t\tif ( hasColorsToChoose ) {\n\t\t\tenableIsAddingColor();\n\t\t} else {\n\t\t\tonChange( removeFormat( value, name ) );\n\t\t}\n\t}, [ hasColorsToChoose, value ] );\n\n\tconst outlineStyle = [\n\t\tusePreferredColorSchemeStyle(\n\t\t\tstyles[ 'components-inline-color__outline' ],\n\t\t\tstyles[ 'components-inline-color__outline--dark' ]\n\t\t),\n\t\t{ borderWidth: StyleSheet.hairlineWidth },\n\t];\n\n\tif ( ! hasColorsToChoose && ! isActive ) {\n\t\treturn null;\n\t}\n\n\tconst isActiveStyle = {\n\t\t...colorIndicatorStyle,\n\t\t...( ! colorIndicatorStyle?.backgroundColor\n\t\t\t? { backgroundColor: 'transparent' }\n\t\t\t: {} ),\n\t\t...styles[ 'components-inline-color--is-active' ],\n\t};\n\n\tconst customContainerStyles =\n\t\tstyles[ 'components-inline-color__button-container' ];\n\n\treturn (\n\t\t<>\n\t\t\t<BlockControls>\n\t\t\t\t<ToolbarGroup>\n\t\t\t\t\t{ isActive && (\n\t\t\t\t\t\t<View style={ outlineStyle } pointerEvents=\"none\" />\n\t\t\t\t\t) }\n\n\t\t\t\t\t<ToolbarButton\n\t\t\t\t\t\tname=\"text-color\"\n\t\t\t\t\t\tisActive={ isActive }\n\t\t\t\t\t\ticon={\n\t\t\t\t\t\t\t<Icon\n\t\t\t\t\t\t\t\ticon={\n\t\t\t\t\t\t\t\t\tObject.keys( activeAttributes ).length\n\t\t\t\t\t\t\t\t\t\t? textColorIcon\n\t\t\t\t\t\t\t\t\t\t: colorIcon\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tstyle={\n\t\t\t\t\t\t\t\t\tcolorIndicatorStyle?.color && {\n\t\t\t\t\t\t\t\t\t\tcolor: colorIndicatorStyle.color,\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t}\n\t\t\t\t\t\ttitle={ title }\n\t\t\t\t\t\textraProps={ {\n\t\t\t\t\t\t\tisActiveStyle,\n\t\t\t\t\t\t\tcustomContainerStyles,\n\t\t\t\t\t\t} }\n\t\t\t\t\t\t// If has no colors to choose but a color is active remove the color onClick\n\t\t\t\t\t\tonClick={ onPressButton }\n\t\t\t\t\t/>\n\t\t\t\t</ToolbarGroup>\n\t\t\t</BlockControls>\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\tedit: TextColorEdit,\n};\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,UAAU,EAAEC,IAAI,QAAQ,cAAc;;AAE/C;AACA;AACA;AACA,SAASC,EAAE,QAAQ,iBAAiB;AACpC,SAASC,WAAW,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,oBAAoB;AACnE,SAASC,aAAa,EAAEC,WAAW,QAAQ,yBAAyB;AACpE,SACCC,YAAY,EACZC,aAAa,EACbC,2BAA2B,QACrB,uBAAuB;AAC9B,SACCC,IAAI,EACJC,KAAK,IAAIC,SAAS,EAClBC,SAAS,IAAIC,aAAa,QACpB,kBAAkB;AACzB,SAASC,YAAY,QAAQ,sBAAsB;AACnD,SAASC,4BAA4B,QAAQ,oBAAoB;;AAEjE;AACA;AACA;AACA,SAASC,eAAe,QAAQ,oBAAoB;AACpD,SAASC,OAAO,IAAIC,aAAa,QAAQ,UAAU;AACnD,OAAOC,MAAM,MAAM,cAAc;AAEjC,MAAMC,IAAI,GAAG,iBAAiB;AAC9B,MAAMC,KAAK,GAAGrB,EAAE,CAAE,YAAa,CAAC;AAEhC,SAASsB,wBAAwBA,CAAEC,OAAO,EAAEC,QAAQ,EAAG;EAAA,IAAAC,oBAAA;EACtD,MAAMC,KAAK,IAAAD,oBAAA,GAAGF,OAAO,EAAEI,KAAK,EAAED,KAAK,cAAAD,oBAAA,cAAAA,oBAAA,GAAI,CAAC,CAAC;EAEzC,IAAKD,QAAQ,KAAK,kBAAkB,EAAG;IACtC,MAAM;MAAEI,eAAe;MAAEC;IAAW,CAAC,GAAGH,KAAK;IAE7C,IAAKE,eAAe,KAAK,aAAa,EAAG;MACxC,OAAOA,eAAe;IACvB,CAAC,MAAM,IAAKC,UAAU,IAAIA,UAAU,EAAEnB,K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