@wordpress/format-library 3.14.1-next.957ca95e4c.0 → 3.15.1
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.
- package/CHANGELOG.md +2 -0
- package/build/image/index.js +3 -3
- package/build/image/index.js.map +1 -1
- package/build/link/index.native.js +6 -4
- package/build/link/index.native.js.map +1 -1
- package/build/link/inline.js +5 -5
- package/build/link/inline.js.map +1 -1
- package/build/text-color/index.js +1 -7
- package/build/text-color/index.js.map +1 -1
- package/build/text-color/index.native.js +1 -3
- package/build/text-color/index.native.js.map +1 -1
- package/build/text-color/inline.js +8 -12
- package/build/text-color/inline.js.map +1 -1
- package/build-module/image/index.js +4 -4
- package/build-module/image/index.js.map +1 -1
- package/build-module/link/index.native.js +6 -3
- package/build-module/link/index.native.js.map +1 -1
- package/build-module/link/inline.js +6 -6
- package/build-module/link/inline.js.map +1 -1
- package/build-module/text-color/index.js +1 -6
- package/build-module/text-color/index.js.map +1 -1
- package/build-module/text-color/index.native.js +1 -2
- package/build-module/text-color/index.native.js.map +1 -1
- package/build-module/text-color/inline.js +9 -12
- package/build-module/text-color/inline.js.map +1 -1
- package/package.json +13 -14
- package/src/image/index.js +4 -4
- package/src/link/index.native.js +10 -3
- package/src/link/inline.js +9 -5
- package/src/text-color/index.js +1 -6
- package/src/text-color/index.native.js +1 -2
- package/src/text-color/inline.js +11 -12
- package/src/text-color/test/index.native.js +3 -3
- package/src/link/test/inline.js +0 -15
package/CHANGELOG.md
CHANGED
package/build/image/index.js
CHANGED
|
@@ -51,15 +51,15 @@ function InlineUI(_ref) {
|
|
|
51
51
|
style
|
|
52
52
|
} = activeObjectAttributes;
|
|
53
53
|
const [width, setWidth] = (0, _element.useState)(style === null || style === void 0 ? void 0 : style.replace(/\D/g, ''));
|
|
54
|
-
const
|
|
55
|
-
|
|
54
|
+
const popoverAnchor = (0, _richText.useAnchor)({
|
|
55
|
+
editableContentElement: contentRef.current,
|
|
56
56
|
value,
|
|
57
57
|
settings: image
|
|
58
58
|
});
|
|
59
59
|
return (0, _element.createElement)(_components.Popover, {
|
|
60
60
|
position: "bottom center",
|
|
61
61
|
focusOnMount: false,
|
|
62
|
-
|
|
62
|
+
anchor: popoverAnchor,
|
|
63
63
|
className: "block-editor-format-toolbar__image-popover"
|
|
64
64
|
}, (0, _element.createElement)("form", {
|
|
65
65
|
className: "block-editor-format-toolbar__image-container-content",
|
package/build/image/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/format-library/src/image/index.js"],"names":["ALLOWED_MEDIA_TYPES","name","title","image","keywords","object","tagName","className","attributes","style","url","alt","edit","Edit","InlineUI","value","onChange","activeObjectAttributes","contentRef","width","setWidth","replace","
|
|
1
|
+
{"version":3,"sources":["@wordpress/format-library/src/image/index.js"],"names":["ALLOWED_MEDIA_TYPES","name","title","image","keywords","object","tagName","className","attributes","style","url","alt","edit","Edit","InlineUI","value","onChange","activeObjectAttributes","contentRef","width","setWidth","replace","popoverAnchor","editableContentElement","current","settings","event","newReplacements","replacements","slice","start","type","preventDefault","newWidth","keyboardReturn","onFocus","isObjectActive","isModalOpen","setIsModalOpen","openModal","closeModal","id","imgWidth","Math","min","open"],"mappings":";;;;;;;AAKA;;AAFA;;AACA;;AAEA;;AACA;;AAKA;;AAZA;AACA;AACA;AAYA,MAAMA,mBAAmB,GAAG,CAAE,OAAF,CAA5B;AAEA,MAAMC,IAAI,GAAG,YAAb;AACA,MAAMC,KAAK,GAAG,cAAI,cAAJ,CAAd;AAEO,MAAMC,KAAK,GAAG;AACpBF,EAAAA,IADoB;AAEpBC,EAAAA,KAFoB;AAGpBE,EAAAA,QAAQ,EAAE,CAAE,cAAI,OAAJ,CAAF,EAAiB,cAAI,OAAJ,CAAjB,CAHU;AAIpBC,EAAAA,MAAM,EAAE,IAJY;AAKpBC,EAAAA,OAAO,EAAE,KALW;AAMpBC,EAAAA,SAAS,EAAE,IANS;AAOpBC,EAAAA,UAA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EC,IAAA,QAAQ,EAAG,SAAyC;AAAA,UAAvC;AAAEyC,QAAAA,EAAF;AAAM/B,QAAAA,GAAN;AAAWC,QAAAA,GAAX;AAAgBQ,QAAAA,KAAK,EAAEuB;AAAvB,OAAuC;AACnDF,MAAAA,UAAU;AACVxB,MAAAA,QAAQ,CACP,4BAAcD,KAAd,EAAqB;AACpBgB,QAAAA,IAAI,EAAE9B,IADc;AAEpBO,QAAAA,UAAU,EAAE;AACXD,UAAAA,SAAS,EAAG,YAAYkC,EAAI,EADjB;AAEXhC,UAAAA,KAAK,EAAG,UAAUkC,IAAI,CAACC,GAAL,CACjBF,QADiB,EAEjB,GAFiB,CAGf,KALQ;AAMXhC,UAAAA,GANW;AAOXC,UAAAA;AAPW;AAFQ,OAArB,CADO,CAAR;AAcAwB,MAAAA,OAAO;AACP,KAnBF;AAoBC,IAAA,OAAO,EAAGK,UApBX;AAqBC,IAAA,MAAM,EAAG,SAAgB;AAAA,UAAd;AAAEK,QAAAA;AAAF,OAAc;AACxBA,MAAAA,IAAI;AACJ,aAAO,IAAP;AACA;AAxBF,IAZF,EAuCGT,cAAc,IACf,4BAAC,QAAD;AACC,IAAA,KAAK,EAAGrB,KADT;AAEC,IAAA,QAAQ,EAAGC,QAFZ;AAGC,IAAA,sBAAsB,EAAGC,sBAH1B;AAIC,IAAA,UAAU,EAAGC;AAJd,IAxCF,CADD;AAkDA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { Path, SVG, TextControl, Popover, Button } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { useState } from '@wordpress/element';\nimport { insertObject, useAnchor } from '@wordpress/rich-text';\nimport {\n\tMediaUpload,\n\tRichTextToolbarButton,\n\tMediaUploadCheck,\n} from '@wordpress/block-editor';\nimport { keyboardReturn } from '@wordpress/icons';\n\nconst ALLOWED_MEDIA_TYPES = [ 'image' ];\n\nconst name = 'core/image';\nconst title = __( 'Inline image' );\n\nexport const image = {\n\tname,\n\ttitle,\n\tkeywords: [ __( 'photo' ), __( 'media' ) ],\n\tobject: true,\n\ttagName: 'img',\n\tclassName: null,\n\tattributes: {\n\t\tclassName: 'class',\n\t\tstyle: 'style',\n\t\turl: 'src',\n\t\talt: 'alt',\n\t},\n\tedit: Edit,\n};\n\nfunction InlineUI( { value, onChange, activeObjectAttributes, contentRef } ) {\n\tconst { style } = activeObjectAttributes;\n\tconst [ width, setWidth ] = useState( style?.replace( /\\D/g, '' ) );\n\tconst popoverAnchor = useAnchor( {\n\t\teditableContentElement: contentRef.current,\n\t\tvalue,\n\t\tsettings: image,\n\t} );\n\n\treturn (\n\t\t<Popover\n\t\t\tposition=\"bottom center\"\n\t\t\tfocusOnMount={ false }\n\t\t\tanchor={ popoverAnchor }\n\t\t\tclassName=\"block-editor-format-toolbar__image-popover\"\n\t\t>\n\t\t\t<form\n\t\t\t\tclassName=\"block-editor-format-toolbar__image-container-content\"\n\t\t\t\tonSubmit={ ( event ) => {\n\t\t\t\t\tconst newReplacements = value.replacements.slice();\n\n\t\t\t\t\tnewReplacements[ value.start ] = {\n\t\t\t\t\t\ttype: name,\n\t\t\t\t\t\tattributes: {\n\t\t\t\t\t\t\t...activeObjectAttributes,\n\t\t\t\t\t\t\tstyle: width ? `width: ${ width }px;` : '',\n\t\t\t\t\t\t},\n\t\t\t\t\t};\n\n\t\t\t\t\tonChange( {\n\t\t\t\t\t\t...value,\n\t\t\t\t\t\treplacements: newReplacements,\n\t\t\t\t\t} );\n\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t} }\n\t\t\t>\n\t\t\t\t<TextControl\n\t\t\t\t\tclassName=\"block-editor-format-toolbar__image-container-value\"\n\t\t\t\t\ttype=\"number\"\n\t\t\t\t\tlabel={ __( 'Width' ) }\n\t\t\t\t\tvalue={ width }\n\t\t\t\t\tmin={ 1 }\n\t\t\t\t\tonChange={ ( newWidth ) => setWidth( newWidth ) }\n\t\t\t\t/>\n\t\t\t\t<Button\n\t\t\t\t\ticon={ keyboardReturn }\n\t\t\t\t\tlabel={ __( 'Apply' ) }\n\t\t\t\t\ttype=\"submit\"\n\t\t\t\t/>\n\t\t\t</form>\n\t\t</Popover>\n\t);\n}\n\nfunction Edit( {\n\tvalue,\n\tonChange,\n\tonFocus,\n\tisObjectActive,\n\tactiveObjectAttributes,\n\tcontentRef,\n} ) {\n\tconst [ isModalOpen, setIsModalOpen ] = useState( false );\n\n\tfunction openModal() {\n\t\tsetIsModalOpen( true );\n\t}\n\n\tfunction closeModal() {\n\t\tsetIsModalOpen( false );\n\t}\n\n\treturn (\n\t\t<MediaUploadCheck>\n\t\t\t<RichTextToolbarButton\n\t\t\t\ticon={\n\t\t\t\t\t<SVG xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\">\n\t\t\t\t\t\t<Path d=\"M4 18.5h16V17H4v1.5zM16 13v1.5h4V13h-4zM5.1 15h7.8c.6 0 1.1-.5 1.1-1.1V6.1c0-.6-.5-1.1-1.1-1.1H5.1C4.5 5 4 5.5 4 6.1v7.8c0 .6.5 1.1 1.1 1.1zm.4-8.5h7V10l-1-1c-.3-.3-.8-.3-1 0l-1.6 1.5-1.2-.7c-.3-.2-.6-.2-.9 0l-1.3 1V6.5zm0 6.1l1.8-1.3 1.3.8c.3.2.7.2.9-.1l1.5-1.4 1.5 1.4v1.5h-7v-.9z\" />\n\t\t\t\t\t</SVG>\n\t\t\t\t}\n\t\t\t\ttitle={ title }\n\t\t\t\tonClick={ openModal }\n\t\t\t\tisActive={ isObjectActive }\n\t\t\t/>\n\t\t\t{ isModalOpen && (\n\t\t\t\t<MediaUpload\n\t\t\t\t\tallowedTypes={ ALLOWED_MEDIA_TYPES }\n\t\t\t\t\tonSelect={ ( { id, url, alt, width: imgWidth } ) => {\n\t\t\t\t\t\tcloseModal();\n\t\t\t\t\t\tonChange(\n\t\t\t\t\t\t\tinsertObject( value, {\n\t\t\t\t\t\t\t\ttype: name,\n\t\t\t\t\t\t\t\tattributes: {\n\t\t\t\t\t\t\t\t\tclassName: `wp-image-${ id }`,\n\t\t\t\t\t\t\t\t\tstyle: `width: ${ Math.min(\n\t\t\t\t\t\t\t\t\t\timgWidth,\n\t\t\t\t\t\t\t\t\t\t150\n\t\t\t\t\t\t\t\t\t) }px;`,\n\t\t\t\t\t\t\t\t\turl,\n\t\t\t\t\t\t\t\t\talt,\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\tonFocus();\n\t\t\t\t\t} }\n\t\t\t\t\tonClose={ closeModal }\n\t\t\t\t\trender={ ( { open } ) => {\n\t\t\t\t\t\topen();\n\t\t\t\t\t\treturn null;\n\t\t\t\t\t} }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t{ isObjectActive && (\n\t\t\t\t<InlineUI\n\t\t\t\t\tvalue={ value }\n\t\t\t\t\tonChange={ onChange }\n\t\t\t\t\tactiveObjectAttributes={ activeObjectAttributes }\n\t\t\t\t\tcontentRef={ contentRef }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</MediaUploadCheck>\n\t);\n}\n"]}
|
|
@@ -9,8 +9,6 @@ exports.link = void 0;
|
|
|
9
9
|
|
|
10
10
|
var _element = require("@wordpress/element");
|
|
11
11
|
|
|
12
|
-
var _lodash = require("lodash");
|
|
13
|
-
|
|
14
12
|
var _clipboard = _interopRequireDefault(require("@react-native-clipboard/clipboard"));
|
|
15
13
|
|
|
16
14
|
var _i18n = require("@wordpress/i18n");
|
|
@@ -108,13 +106,17 @@ const link = {
|
|
|
108
106
|
let startIndex = value.start;
|
|
109
107
|
let endIndex = value.end;
|
|
110
108
|
|
|
111
|
-
while ((
|
|
109
|
+
while ((_value$formats$startI = value.formats[startIndex]) !== null && _value$formats$startI !== void 0 && _value$formats$startI.find(format => (format === null || format === void 0 ? void 0 : format.type) === startFormat.type)) {
|
|
110
|
+
var _value$formats$startI;
|
|
111
|
+
|
|
112
112
|
startIndex--;
|
|
113
113
|
}
|
|
114
114
|
|
|
115
115
|
endIndex++;
|
|
116
116
|
|
|
117
|
-
while ((
|
|
117
|
+
while ((_value$formats$endInd = value.formats[endIndex]) !== null && _value$formats$endInd !== void 0 && _value$formats$endInd.find(format => (format === null || format === void 0 ? void 0 : format.type) === startFormat.type)) {
|
|
118
|
+
var _value$formats$endInd;
|
|
119
|
+
|
|
118
120
|
endIndex++;
|
|
119
121
|
}
|
|
120
122
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/format-library/src/link/index.native.js"],"names":["name","link","title","tagName","className","attributes","url","target","edit","LinkEdit","Component","constructor","arguments","addLink","bind","stopAddingLink","onRemoveFormat","getURLFromClipboard","state","addingLink","value","onChange","props","text","newValue","type","start","end","activeFormats","needsSelectionUpdate","setState","clipboardURL","undefined","getLinkSelection","isActive","startFormat","startIndex","endIndex","formats","speak","linkSelection","clipboardText","Clipboard","getString","render","activeAttributes","linkIcon"],"mappings":";;;;;;;;;
|
|
1
|
+
{"version":3,"sources":["@wordpress/format-library/src/link/index.native.js"],"names":["name","link","title","tagName","className","attributes","url","target","edit","LinkEdit","Component","constructor","arguments","addLink","bind","stopAddingLink","onRemoveFormat","getURLFromClipboard","state","addingLink","value","onChange","props","text","newValue","type","start","end","activeFormats","needsSelectionUpdate","setState","clipboardURL","undefined","getLinkSelection","isActive","startFormat","startIndex","endIndex","formats","find","format","speak","linkSelection","clipboardText","Clipboard","getString","render","activeAttributes","linkIcon"],"mappings":";;;;;;;;;AASA;;AANA;;AAKA;;AAEA;;AACA;;AACA;;AAQA;;AACA;;AAKA;;AACA;;AA3BA;AACA;AACA;;AAGA;AACA;AACA;;AAgBA;AACA;AACA;AAIA,MAAMA,IAAI,GAAG,WAAb;AAEO,MAAMC,IAAI,GAAG;AACnBD,EAAAA,IADmB;AAEnBE,EAAAA,KAAK,EAAE,cAAI,MAAJ,CAFY;AAGnBC,EAAAA,OAAO,EAAE,GAHU;AAInBC,EAAAA,SAAS,EAAE,IAJQ;AAKnBC,EAAAA,UAAU,EAAE;AAC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C,QAAA,QAAQ,EAAG,KAAKL,cANjB;AAOC,QAAA,KAAK,EAAG0B;AAPT,QADD,EAUC,4BAAC,kCAAD;AACC,QAAA,IAAI,EAAC,MADN;AAEC,QAAA,IAAI,EAAGM,WAFR;AAGC,QAAA,KAAK,EAAG,cAAI,MAAJ,CAHT;AAIC,QAAA,OAAO,EAAG,KAAKnC,OAJhB;AAKC,QAAA,QAAQ,EAAGqB,QALZ;AAMC,QAAA,YAAY,EAAC,SANd;AAOC,QAAA,iBAAiB,EAAC;AAPnB,QAVD,CADD;AAsBA;;AAlI+B,GAD5B;AATa,CAAb","sourcesContent":["/**\n * External dependencies\n */\nimport Clipboard from '@react-native-clipboard/clipboard';\n\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { Component } from '@wordpress/element';\nimport { withSpokenMessages } from '@wordpress/components';\nimport { RichTextToolbarButton } from '@wordpress/block-editor';\nimport {\n\tapplyFormat,\n\tgetActiveFormat,\n\tgetTextContent,\n\tisCollapsed,\n\tremoveFormat,\n\tslice,\n} from '@wordpress/rich-text';\nimport { isURL } from '@wordpress/url';\nimport { link as linkIcon } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport ModalLinkUI from './modal';\nimport { isValidHref } from './utils';\n\nconst name = 'core/link';\n\nexport const link = {\n\tname,\n\ttitle: __( 'Link' ),\n\ttagName: 'a',\n\tclassName: null,\n\tattributes: {\n\t\turl: 'href',\n\t\ttarget: 'target',\n\t},\n\tedit: withSpokenMessages(\n\t\tclass LinkEdit extends Component {\n\t\t\tconstructor() {\n\t\t\t\tsuper( ...arguments );\n\n\t\t\t\tthis.addLink = this.addLink.bind( this );\n\t\t\t\tthis.stopAddingLink = this.stopAddingLink.bind( this );\n\t\t\t\tthis.onRemoveFormat = this.onRemoveFormat.bind( this );\n\t\t\t\tthis.getURLFromClipboard =\n\t\t\t\t\tthis.getURLFromClipboard.bind( this );\n\t\t\t\tthis.state = {\n\t\t\t\t\taddingLink: false,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\taddLink() {\n\t\t\t\tconst { value, onChange } = this.props;\n\t\t\t\tconst text = getTextContent( slice( value ) );\n\n\t\t\t\tif ( text && isURL( text ) && isValidHref( text ) ) {\n\t\t\t\t\tconst newValue = applyFormat( value, {\n\t\t\t\t\t\ttype: name,\n\t\t\t\t\t\tattributes: { url: text },\n\t\t\t\t\t} );\n\t\t\t\t\tnewValue.start = newValue.end;\n\t\t\t\t\tnewValue.activeFormats = [];\n\t\t\t\t\tonChange( { ...newValue, needsSelectionUpdate: true } );\n\t\t\t\t} else {\n\t\t\t\t\tthis.setState( { addingLink: true } );\n\t\t\t\t\tthis.getURLFromClipboard();\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tstopAddingLink() {\n\t\t\t\tthis.setState( { addingLink: false, clipboardURL: undefined } );\n\t\t\t}\n\n\t\t\tgetLinkSelection() {\n\t\t\t\tconst { value, isActive } = this.props;\n\t\t\t\tconst startFormat = getActiveFormat( value, 'core/link' );\n\n\t\t\t\t// If the link isn't selected, get the link manually by looking around the cursor\n\t\t\t\t// TODO: handle partly selected links.\n\t\t\t\tif ( startFormat && isCollapsed( value ) && isActive ) {\n\t\t\t\t\tlet startIndex = value.start;\n\t\t\t\t\tlet endIndex = value.end;\n\n\t\t\t\t\twhile (\n\t\t\t\t\t\tvalue.formats[ startIndex ]?.find(\n\t\t\t\t\t\t\t( format ) => format?.type === startFormat.type\n\t\t\t\t\t\t)\n\t\t\t\t\t) {\n\t\t\t\t\t\tstartIndex--;\n\t\t\t\t\t}\n\n\t\t\t\t\tendIndex++;\n\n\t\t\t\t\twhile (\n\t\t\t\t\t\tvalue.formats[ endIndex ]?.find(\n\t\t\t\t\t\t\t( format ) => format?.type === startFormat.type\n\t\t\t\t\t\t)\n\t\t\t\t\t) {\n\t\t\t\t\t\tendIndex++;\n\t\t\t\t\t}\n\n\t\t\t\t\treturn {\n\t\t\t\t\t\t...value,\n\t\t\t\t\t\tstart: startIndex + 1,\n\t\t\t\t\t\tend: endIndex,\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\treturn value;\n\t\t\t}\n\n\t\t\tonRemoveFormat() {\n\t\t\t\tconst { onChange, speak, value } = this.props;\n\t\t\t\tconst startFormat = getActiveFormat( value, 'core/link' );\n\n\t\t\t\t// Before we try to remove anything we check if there is something at the caret position to remove.\n\t\t\t\tif ( isCollapsed( value ) && startFormat === undefined ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst linkSelection = this.getLinkSelection();\n\n\t\t\t\tonChange( removeFormat( linkSelection, name ) );\n\t\t\t\tspeak( __( 'Link removed.' ), 'assertive' );\n\t\t\t}\n\n\t\t\tasync getURLFromClipboard() {\n\t\t\t\tconst clipboardText = await Clipboard.getString();\n\t\t\t\tif ( ! clipboardText ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\t// Check if pasted text is URL.\n\t\t\t\tif ( ! isURL( clipboardText ) ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tthis.setState( { clipboardURL: clipboardText } );\n\t\t\t}\n\n\t\t\trender() {\n\t\t\t\tconst { isActive, activeAttributes, onChange } = this.props;\n\t\t\t\tconst linkSelection = this.getLinkSelection();\n\t\t\t\t// If no URL is set and we have a clipboard URL let's use it.\n\t\t\t\tif ( ! activeAttributes.url && this.state.clipboardURL ) {\n\t\t\t\t\tactiveAttributes.url = this.state.clipboardURL;\n\t\t\t\t}\n\t\t\t\treturn (\n\t\t\t\t\t<>\n\t\t\t\t\t\t<ModalLinkUI\n\t\t\t\t\t\t\tisVisible={ this.state.addingLink }\n\t\t\t\t\t\t\tisActive={ isActive }\n\t\t\t\t\t\t\tactiveAttributes={ activeAttributes }\n\t\t\t\t\t\t\tonClose={ this.stopAddingLink }\n\t\t\t\t\t\t\tonChange={ onChange }\n\t\t\t\t\t\t\tonRemove={ this.onRemoveFormat }\n\t\t\t\t\t\t\tvalue={ linkSelection }\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<RichTextToolbarButton\n\t\t\t\t\t\t\tname=\"link\"\n\t\t\t\t\t\t\ticon={ linkIcon }\n\t\t\t\t\t\t\ttitle={ __( 'Link' ) }\n\t\t\t\t\t\t\tonClick={ this.addLink }\n\t\t\t\t\t\t\tisActive={ isActive }\n\t\t\t\t\t\t\tshortcutType=\"primary\"\n\t\t\t\t\t\t\tshortcutCharacter=\"k\"\n\t\t\t\t\t\t/>\n\t\t\t\t\t</>\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t),\n};\n"]}
|
package/build/link/inline.js
CHANGED
|
@@ -170,8 +170,8 @@ function InlineLinkUI(_ref) {
|
|
|
170
170
|
}
|
|
171
171
|
}
|
|
172
172
|
|
|
173
|
-
const
|
|
174
|
-
|
|
173
|
+
const popoverAnchor = (0, _richText.useAnchor)({
|
|
174
|
+
editableContentElement: contentRef.current,
|
|
175
175
|
value,
|
|
176
176
|
settings: _index.link
|
|
177
177
|
}); // Generate a string based key that is unique to this anchor reference.
|
|
@@ -179,7 +179,7 @@ function InlineLinkUI(_ref) {
|
|
|
179
179
|
// potential stale state bugs caused by the component not being remounted
|
|
180
180
|
// See https://github.com/WordPress/gutenberg/pull/34742.
|
|
181
181
|
|
|
182
|
-
const forceRemountKey = (0, _useLinkInstanceKey.default)(
|
|
182
|
+
const forceRemountKey = (0, _useLinkInstanceKey.default)(popoverAnchor); // The focusOnMount prop shouldn't evolve during render of a Popover
|
|
183
183
|
// otherwise it causes a render of the content.
|
|
184
184
|
|
|
185
185
|
const focusOnMount = (0, _element.useRef)(addingLink ? 'firstElement' : false);
|
|
@@ -207,11 +207,11 @@ function InlineLinkUI(_ref) {
|
|
|
207
207
|
}
|
|
208
208
|
|
|
209
209
|
return (0, _element.createElement)(_components.Popover, {
|
|
210
|
-
|
|
210
|
+
anchor: popoverAnchor,
|
|
211
211
|
focusOnMount: focusOnMount.current,
|
|
212
212
|
onClose: stopAddingLink,
|
|
213
213
|
position: "bottom center",
|
|
214
|
-
|
|
214
|
+
shift: true
|
|
215
215
|
}, (0, _element.createElement)(_blockEditor.__experimentalLinkControl, {
|
|
216
216
|
key: forceRemountKey,
|
|
217
217
|
value: linkValue,
|
package/build/link/inline.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/format-library/src/link/inline.js"],"names":["InlineLinkUI","isActive","activeAttributes","addingLink","value","onChange","speak","stopAddingLink","contentRef","richLinkTextValue","getRichTextValueFromSelection","richTextText","text","nextLinkValue","setNextLinkValue","createPageEntity","userCanCreatePages","select","getSettings","blockEditorStore","_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","settings","forceRemountKey","focusOnMount","handleCreate","pageTitle","page","status","rendered","link","kind","createButtonText","searchTerm","mark","current","textStart","textEnd","boundary"],"mappings":";;;;;;;;;AAGA;;AACA;;AACA;;AACA;;AACA;;AAUA;;AAIA;;AAKA;;AACA;;AACA;;AA5BA;AACA;AACA;;AAqBA;AACA;AACA;AAKA,SAASA,YAAT,OASI;AAAA,MATmB;AACtBC,IAAAA,QADsB;AAEtBC,IAAAA,gBAFsB;AAGtBC,IAAAA,UAHsB;AAItBC,IAAAA,KAJsB;AAKtBC,IAAAA,QALsB;AAMtBC,IAAAA,KANsB;AAOtBC,IAAAA,cAPsB;AAQtBC,IAAAA;AARsB,GASnB;AACH,QAAMC,iBAAiB,GAAGC,6BAA6B,CAAEN,KAAF,EAASH,QAAT,CAAvD,CADG,CAGH;;AACA,QAAMU,YAAY,GAAGF,iBAAiB,CAACG,IAAvC;AAEA;AACD;AACA;AACA;AACA;AACA;AACA;AACA;;AACC,QAAM,CAAEC,aAAF,EAAiBC,gBAAjB,IAAsC,wBAA5C;AAEA,QAAM;AAAEC,IAAAA,gBA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1B,CAAjB;AAIAsC,IAAAA,SAAS,GAAGE,QAAQ,CAACrB,KAArB,CALe,CAOf;AACA;;AACAoB,IAAAA,OAAO,GAAGC,QAAQ,CAACpB,GAAT,GAAe,CAAzB;AACA,GAlBwD,CAoBzD;;;AACA,SAAO,qBAAOzC,KAAP,EAAc2D,SAAd,EAAyBC,OAAzB,CAAP;AACA;;eAEc,oCAAoBhE,YAApB,C","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useState, useRef, createInterpolateElement } from '@wordpress/element';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { withSpokenMessages, Popover } from '@wordpress/components';\nimport { prependHTTP } from '@wordpress/url';\nimport {\n\tcreate,\n\tinsert,\n\tisCollapsed,\n\tapplyFormat,\n\tuseAnchorRef,\n\tremoveFormat,\n\tslice,\n\treplace,\n} from '@wordpress/rich-text';\nimport {\n\t__experimentalLinkControl as LinkControl,\n\tstore as blockEditorStore,\n} from '@wordpress/block-editor';\nimport { useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { createLinkFormat, isValidHref, getFormatBoundary } from './utils';\nimport { link as settings } from './index';\nimport useLinkInstanceKey from './use-link-instance-key';\n\nfunction InlineLinkUI( {\n\tisActive,\n\tactiveAttributes,\n\taddingLink,\n\tvalue,\n\tonChange,\n\tspeak,\n\tstopAddingLink,\n\tcontentRef,\n} ) {\n\tconst richLinkTextValue = getRichTextValueFromSelection( value, isActive );\n\n\t// Get the text content minus any HTML tags.\n\tconst richTextText = richLinkTextValue.text;\n\n\t/**\n\t * Pending settings to be applied to the next link. When inserting a new\n\t * link, toggle values cannot be applied immediately, because there is not\n\t * yet a link for them to apply to. Thus, they are maintained in a state\n\t * value until the time that the link can be inserted or edited.\n\t *\n\t * @type {[Object|undefined,Function]}\n\t */\n\tconst [ nextLinkValue, setNextLinkValue ] = useState();\n\n\tconst { createPageEntity, userCanCreatePages } = useSelect( ( select ) => {\n\t\tconst { getSettings } = select( blockEditorStore );\n\t\tconst _settings = getSettings();\n\n\t\treturn {\n\t\t\tcreatePageEntity: _settings.__experimentalCreatePageEntity,\n\t\t\tuserCanCreatePages: _settings.__experimentalUserCanCreatePages,\n\t\t};\n\t}, [] );\n\n\tconst linkValue = {\n\t\turl: activeAttributes.url,\n\t\ttype: activeAttributes.type,\n\t\tid: activeAttributes.id,\n\t\topensInNewTab: activeAttributes.target === '_blank',\n\t\ttitle: richTextText,\n\t\t...nextLinkValue,\n\t};\n\n\tfunction removeLink() {\n\t\tconst newValue = removeFormat( value, 'core/link' );\n\t\tonChange( newValue );\n\t\tstopAddingLink();\n\t\tspeak( __( 'Link removed.' ), 'assertive' );\n\t}\n\n\tfunction onChangeLink( nextValue ) {\n\t\t// Merge with values from state, both for the purpose of assigning the\n\t\t// next state value, and for use in constructing the new link format if\n\t\t// the link is ready to be applied.\n\t\tnextValue = {\n\t\t\t...nextLinkValue,\n\t\t\t...nextValue,\n\t\t};\n\n\t\t// LinkControl calls `onChange` immediately upon the toggling a setting.\n\t\tconst didToggleSetting =\n\t\t\tlinkValue.opensInNewTab !== nextValue.opensInNewTab &&\n\t\t\tlinkValue.url === nextValue.url;\n\n\t\t// If change handler was called as a result of a settings change during\n\t\t// link insertion, it must be held in state until the link is ready to\n\t\t// be applied.\n\t\tconst didToggleSettingForNewLink =\n\t\t\tdidToggleSetting && nextValue.url === undefined;\n\n\t\t// If link will be assigned, the state value can be considered flushed.\n\t\t// Otherwise, persist the pending changes.\n\t\tsetNextLinkValue( didToggleSettingForNewLink ? nextValue : undefined );\n\n\t\tif ( didToggleSettingForNewLink ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst newUrl = prependHTTP( nextValue.url );\n\t\tconst linkFormat = createLinkFormat( {\n\t\t\turl: newUrl,\n\t\t\ttype: nextValue.type,\n\t\t\tid:\n\t\t\t\tnextValue.id !== undefined && nextValue.id !== null\n\t\t\t\t\t? String( nextValue.id )\n\t\t\t\t\t: undefined,\n\t\t\topensInNewWindow: nextValue.opensInNewTab,\n\t\t} );\n\n\t\tconst newText = nextValue.title || newUrl;\n\t\tif ( isCollapsed( value ) && ! isActive ) {\n\t\t\t// Scenario: we don't have any actively selected text or formats.\n\t\t\tconst toInsert = applyFormat(\n\t\t\t\tcreate( { text: newText } ),\n\t\t\t\tlinkFormat,\n\t\t\t\t0,\n\t\t\t\tnewText.length\n\t\t\t);\n\t\t\tonChange( insert( value, toInsert ) );\n\t\t} else {\n\t\t\t// Scenario: we have any active text selection or an active format.\n\t\t\tlet newValue;\n\n\t\t\tif ( newText === richTextText ) {\n\t\t\t\t// If we're not updating the text then ignore.\n\t\t\t\tnewValue = applyFormat( value, linkFormat );\n\t\t\t} else {\n\t\t\t\t// Create new RichText value for the new text in order that we\n\t\t\t\t// can apply formats to it.\n\t\t\t\tnewValue = create( { text: newText } );\n\n\t\t\t\t// Apply the new Link format to this new text value.\n\t\t\t\tnewValue = applyFormat(\n\t\t\t\t\tnewValue,\n\t\t\t\t\tlinkFormat,\n\t\t\t\t\t0,\n\t\t\t\t\tnewText.length\n\t\t\t\t);\n\n\t\t\t\t// Update the original (full) RichTextValue replacing the\n\t\t\t\t// target text with the *new* RichTextValue containing:\n\t\t\t\t// 1. The new text content.\n\t\t\t\t// 2. The new link format.\n\t\t\t\t// Note original formats will be lost when applying this change.\n\t\t\t\t// That is expected behaviour.\n\t\t\t\t// See: https://github.com/WordPress/gutenberg/pull/33849#issuecomment-936134179.\n\t\t\t\tnewValue = replace( value, richTextText, newValue );\n\t\t\t}\n\n\t\t\tnewValue.start = newValue.end;\n\t\t\tnewValue.activeFormats = [];\n\t\t\tonChange( newValue );\n\t\t}\n\n\t\t// Focus should only be shifted back to the formatted segment when the\n\t\t// URL is submitted.\n\t\tif ( ! didToggleSetting ) {\n\t\t\tstopAddingLink();\n\t\t}\n\n\t\tif ( ! isValidHref( newUrl ) ) {\n\t\t\tspeak(\n\t\t\t\t__(\n\t\t\t\t\t'Warning: the link has been inserted but may have errors. Please test it.'\n\t\t\t\t),\n\t\t\t\t'assertive'\n\t\t\t);\n\t\t} else if ( isActive ) {\n\t\t\tspeak( __( 'Link edited.' ), 'assertive' );\n\t\t} else {\n\t\t\tspeak( __( 'Link inserted.' ), 'assertive' );\n\t\t}\n\t}\n\n\tconst anchorRef = useAnchorRef( { ref: contentRef, value, settings } );\n\n\t// Generate a string based key that is unique to this anchor reference.\n\t// This is used to force re-mount the LinkControl component to avoid\n\t// potential stale state bugs caused by the component not being remounted\n\t// See https://github.com/WordPress/gutenberg/pull/34742.\n\tconst forceRemountKey = useLinkInstanceKey( anchorRef );\n\n\t// The focusOnMount prop shouldn't evolve during render of a Popover\n\t// otherwise it causes a render of the content.\n\tconst focusOnMount = useRef( addingLink ? 'firstElement' : false );\n\n\tasync function handleCreate( pageTitle ) {\n\t\tconst page = await createPageEntity( {\n\t\t\ttitle: pageTitle,\n\t\t\tstatus: 'draft',\n\t\t} );\n\n\t\treturn {\n\t\t\tid: page.id,\n\t\t\ttype: page.type,\n\t\t\ttitle: page.title.rendered,\n\t\t\turl: page.link,\n\t\t\tkind: 'post-type',\n\t\t};\n\t}\n\n\tfunction createButtonText( searchTerm ) {\n\t\treturn createInterpolateElement(\n\t\t\tsprintf(\n\t\t\t\t/* translators: %s: search term. */\n\t\t\t\t__( 'Create Page: <mark>%s</mark>' ),\n\t\t\t\tsearchTerm\n\t\t\t),\n\t\t\t{ mark: <mark /> }\n\t\t);\n\t}\n\n\treturn (\n\t\t<Popover\n\t\t\tanchorRef={ anchorRef }\n\t\t\tfocusOnMount={ focusOnMount.current }\n\t\t\tonClose={ stopAddingLink }\n\t\t\tposition=\"bottom center\"\n\t\t\t__unstableShift\n\t\t>\n\t\t\t<LinkControl\n\t\t\t\tkey={ forceRemountKey }\n\t\t\t\tvalue={ linkValue }\n\t\t\t\tonChange={ onChangeLink }\n\t\t\t\tonRemove={ removeLink }\n\t\t\t\tforceIsEditingLink={ addingLink }\n\t\t\t\thasRichPreviews\n\t\t\t\tcreateSuggestion={ createPageEntity && handleCreate }\n\t\t\t\twithCreateSuggestion={ userCanCreatePages }\n\t\t\t\tcreateSuggestionButtonText={ createButtonText }\n\t\t\t\thasTextControl\n\t\t\t/>\n\t\t</Popover>\n\t);\n}\n\nfunction getRichTextValueFromSelection( value, isActive ) {\n\t// Default to the selection ranges on the RichTextValue object.\n\tlet textStart = value.start;\n\tlet textEnd = value.end;\n\n\t// If the format is currently active then the rich text value\n\t// should always be taken from the bounds of the active format\n\t// and not the selected text.\n\tif ( isActive ) {\n\t\tconst boundary = getFormatBoundary( value, {\n\t\t\ttype: 'core/link',\n\t\t} );\n\n\t\ttextStart = boundary.start;\n\n\t\t// Text *selection* always extends +1 beyond the edge of the format.\n\t\t// We account for that here.\n\t\ttextEnd = boundary.end + 1;\n\t}\n\n\t// Get a RichTextValue containing the selected text content.\n\treturn slice( value, textStart, textEnd );\n}\n\nexport default withSpokenMessages( InlineLinkUI );\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/format-library/src/link/inline.js"],"names":["InlineLinkUI","isActive","activeAttributes","addingLink","value","onChange","speak","stopAddingLink","contentRef","richLinkTextValue","getRichTextValueFromSelection","richTextText","text","nextLinkValue","setNextLinkValue","createPageEntity","userCanCreatePages","select","getSettings","blockEditorStore","_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","popoverAnchor","editableContentElement","current","settings","forceRemountKey","focusOnMount","handleCreate","pageTitle","page","status","rendered","link","kind","createButtonText","searchTerm","mark","textStart","textEnd","boundary"],"mappings":";;;;;;;;;AAGA;;AACA;;AACA;;AACA;;AACA;;AAUA;;AAIA;;AAKA;;AACA;;AACA;;AA5BA;AACA;AACA;;AAqBA;AACA;AACA;AAKA,SAASA,YAAT,OASI;AAAA,MATmB;AACtBC,IAAAA,QADsB;AAEtBC,IAAAA,gBAFs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IAAA,oBAAoB,EAAGrC,kBARxB;AASC,IAAA,0BAA0B,EAAG4C,gBAT9B;AAUC,IAAA,cAAc;AAVf,IAPD,CADD;AAsBA;;AAED,SAASlD,6BAAT,CAAwCN,KAAxC,EAA+CH,QAA/C,EAA0D;AACzD;AACA,MAAI8D,SAAS,GAAG3D,KAAK,CAACwC,KAAtB;AACA,MAAIoB,OAAO,GAAG5D,KAAK,CAACyC,GAApB,CAHyD,CAKzD;AACA;AACA;;AACA,MAAK5C,QAAL,EAAgB;AACf,UAAMgE,QAAQ,GAAG,8BAAmB7D,KAAnB,EAA0B;AAC1CqB,MAAAA,IAAI,EAAE;AADoC,KAA1B,CAAjB;AAIAsC,IAAAA,SAAS,GAAGE,QAAQ,CAACrB,KAArB,CALe,CAOf;AACA;;AACAoB,IAAAA,OAAO,GAAGC,QAAQ,CAACpB,GAAT,GAAe,CAAzB;AACA,GAlBwD,CAoBzD;;;AACA,SAAO,qBAAOzC,KAAP,EAAc2D,SAAd,EAAyBC,OAAzB,CAAP;AACA;;eAEc,oCAAoBhE,YAApB,C","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\tuseAnchor,\n\tremoveFormat,\n\tslice,\n\treplace,\n} from '@wordpress/rich-text';\nimport {\n\t__experimentalLinkControl as LinkControl,\n\tstore as blockEditorStore,\n} from '@wordpress/block-editor';\nimport { useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { createLinkFormat, isValidHref, getFormatBoundary } from './utils';\nimport { link as settings } from './index';\nimport useLinkInstanceKey from './use-link-instance-key';\n\nfunction InlineLinkUI( {\n\tisActive,\n\tactiveAttributes,\n\taddingLink,\n\tvalue,\n\tonChange,\n\tspeak,\n\tstopAddingLink,\n\tcontentRef,\n} ) {\n\tconst richLinkTextValue = getRichTextValueFromSelection( value, isActive );\n\n\t// Get the text content minus any HTML tags.\n\tconst richTextText = richLinkTextValue.text;\n\n\t/**\n\t * Pending settings to be applied to the next link. When inserting a new\n\t * link, toggle values cannot be applied immediately, because there is not\n\t * yet a link for them to apply to. Thus, they are maintained in a state\n\t * value until the time that the link can be inserted or edited.\n\t *\n\t * @type {[Object|undefined,Function]}\n\t */\n\tconst [ nextLinkValue, setNextLinkValue ] = useState();\n\n\tconst { createPageEntity, userCanCreatePages } = useSelect( ( select ) => {\n\t\tconst { getSettings } = select( blockEditorStore );\n\t\tconst _settings = getSettings();\n\n\t\treturn {\n\t\t\tcreatePageEntity: _settings.__experimentalCreatePageEntity,\n\t\t\tuserCanCreatePages: _settings.__experimentalUserCanCreatePages,\n\t\t};\n\t}, [] );\n\n\tconst linkValue = {\n\t\turl: activeAttributes.url,\n\t\ttype: activeAttributes.type,\n\t\tid: activeAttributes.id,\n\t\topensInNewTab: activeAttributes.target === '_blank',\n\t\ttitle: richTextText,\n\t\t...nextLinkValue,\n\t};\n\n\tfunction removeLink() {\n\t\tconst newValue = removeFormat( value, 'core/link' );\n\t\tonChange( newValue );\n\t\tstopAddingLink();\n\t\tspeak( __( 'Link removed.' ), 'assertive' );\n\t}\n\n\tfunction onChangeLink( nextValue ) {\n\t\t// Merge with values from state, both for the purpose of assigning the\n\t\t// next state value, and for use in constructing the new link format if\n\t\t// the link is ready to be applied.\n\t\tnextValue = {\n\t\t\t...nextLinkValue,\n\t\t\t...nextValue,\n\t\t};\n\n\t\t// LinkControl calls `onChange` immediately upon the toggling a setting.\n\t\tconst didToggleSetting =\n\t\t\tlinkValue.opensInNewTab !== nextValue.opensInNewTab &&\n\t\t\tlinkValue.url === nextValue.url;\n\n\t\t// If change handler was called as a result of a settings change during\n\t\t// link insertion, it must be held in state until the link is ready to\n\t\t// be applied.\n\t\tconst didToggleSettingForNewLink =\n\t\t\tdidToggleSetting && nextValue.url === undefined;\n\n\t\t// If link will be assigned, the state value can be considered flushed.\n\t\t// Otherwise, persist the pending changes.\n\t\tsetNextLinkValue( didToggleSettingForNewLink ? nextValue : undefined );\n\n\t\tif ( didToggleSettingForNewLink ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst newUrl = prependHTTP( nextValue.url );\n\t\tconst linkFormat = createLinkFormat( {\n\t\t\turl: newUrl,\n\t\t\ttype: nextValue.type,\n\t\t\tid:\n\t\t\t\tnextValue.id !== undefined && nextValue.id !== null\n\t\t\t\t\t? String( nextValue.id )\n\t\t\t\t\t: undefined,\n\t\t\topensInNewWindow: nextValue.opensInNewTab,\n\t\t} );\n\n\t\tconst newText = nextValue.title || newUrl;\n\t\tif ( isCollapsed( value ) && ! isActive ) {\n\t\t\t// Scenario: we don't have any actively selected text or formats.\n\t\t\tconst toInsert = applyFormat(\n\t\t\t\tcreate( { text: newText } ),\n\t\t\t\tlinkFormat,\n\t\t\t\t0,\n\t\t\t\tnewText.length\n\t\t\t);\n\t\t\tonChange( insert( value, toInsert ) );\n\t\t} else {\n\t\t\t// Scenario: we have any active text selection or an active format.\n\t\t\tlet newValue;\n\n\t\t\tif ( newText === richTextText ) {\n\t\t\t\t// If we're not updating the text then ignore.\n\t\t\t\tnewValue = applyFormat( value, linkFormat );\n\t\t\t} else {\n\t\t\t\t// Create new RichText value for the new text in order that we\n\t\t\t\t// can apply formats to it.\n\t\t\t\tnewValue = create( { text: newText } );\n\n\t\t\t\t// Apply the new Link format to this new text value.\n\t\t\t\tnewValue = applyFormat(\n\t\t\t\t\tnewValue,\n\t\t\t\t\tlinkFormat,\n\t\t\t\t\t0,\n\t\t\t\t\tnewText.length\n\t\t\t\t);\n\n\t\t\t\t// Update the original (full) RichTextValue replacing the\n\t\t\t\t// target text with the *new* RichTextValue containing:\n\t\t\t\t// 1. The new text content.\n\t\t\t\t// 2. The new link format.\n\t\t\t\t// Note original formats will be lost when applying this change.\n\t\t\t\t// That is expected behaviour.\n\t\t\t\t// See: https://github.com/WordPress/gutenberg/pull/33849#issuecomment-936134179.\n\t\t\t\tnewValue = replace( value, richTextText, newValue );\n\t\t\t}\n\n\t\t\tnewValue.start = newValue.end;\n\t\t\tnewValue.activeFormats = [];\n\t\t\tonChange( newValue );\n\t\t}\n\n\t\t// Focus should only be shifted back to the formatted segment when the\n\t\t// URL is submitted.\n\t\tif ( ! didToggleSetting ) {\n\t\t\tstopAddingLink();\n\t\t}\n\n\t\tif ( ! isValidHref( newUrl ) ) {\n\t\t\tspeak(\n\t\t\t\t__(\n\t\t\t\t\t'Warning: the link has been inserted but may have errors. Please test it.'\n\t\t\t\t),\n\t\t\t\t'assertive'\n\t\t\t);\n\t\t} else if ( isActive ) {\n\t\t\tspeak( __( 'Link edited.' ), 'assertive' );\n\t\t} else {\n\t\t\tspeak( __( 'Link inserted.' ), 'assertive' );\n\t\t}\n\t}\n\n\tconst popoverAnchor = useAnchor( {\n\t\teditableContentElement: contentRef.current,\n\t\tvalue,\n\t\tsettings,\n\t} );\n\n\t// Generate a string based key that is unique to this anchor reference.\n\t// This is used to force re-mount the LinkControl component to avoid\n\t// potential stale state bugs caused by the component not being remounted\n\t// See https://github.com/WordPress/gutenberg/pull/34742.\n\tconst forceRemountKey = useLinkInstanceKey( popoverAnchor );\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\tanchor={ popoverAnchor }\n\t\t\tfocusOnMount={ focusOnMount.current }\n\t\t\tonClose={ stopAddingLink }\n\t\t\tposition=\"bottom center\"\n\t\t\tshift\n\t\t>\n\t\t\t<LinkControl\n\t\t\t\tkey={ forceRemountKey }\n\t\t\t\tvalue={ linkValue }\n\t\t\t\tonChange={ onChangeLink }\n\t\t\t\tonRemove={ removeLink }\n\t\t\t\tforceIsEditingLink={ addingLink }\n\t\t\t\thasRichPreviews\n\t\t\t\tcreateSuggestion={ createPageEntity && handleCreate }\n\t\t\t\twithCreateSuggestion={ userCanCreatePages }\n\t\t\t\tcreateSuggestionButtonText={ createButtonText }\n\t\t\t\thasTextControl\n\t\t\t/>\n\t\t</Popover>\n\t);\n}\n\nfunction getRichTextValueFromSelection( value, isActive ) {\n\t// Default to the selection ranges on the RichTextValue object.\n\tlet textStart = value.start;\n\tlet textEnd = value.end;\n\n\t// If the format is currently active then the rich text value\n\t// should always be taken from the bounds of the active format\n\t// and not the selected text.\n\tif ( isActive ) {\n\t\tconst boundary = getFormatBoundary( value, {\n\t\t\ttype: 'core/link',\n\t\t} );\n\n\t\ttextStart = boundary.start;\n\n\t\t// Text *selection* always extends +1 beyond the edge of the format.\n\t\t// We account for that here.\n\t\ttextEnd = boundary.end + 1;\n\t}\n\n\t// Get a RichTextValue containing the selected text content.\n\treturn slice( value, textStart, textEnd );\n}\n\nexport default withSpokenMessages( InlineLinkUI );\n"]}
|
|
@@ -7,8 +7,6 @@ exports.transparentValue = exports.textColor = void 0;
|
|
|
7
7
|
|
|
8
8
|
var _element = require("@wordpress/element");
|
|
9
9
|
|
|
10
|
-
var _lodash = require("lodash");
|
|
11
|
-
|
|
12
10
|
var _i18n = require("@wordpress/i18n");
|
|
13
11
|
|
|
14
12
|
var _blockEditor = require("@wordpress/block-editor");
|
|
@@ -23,10 +21,6 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
|
|
|
23
21
|
|
|
24
22
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
25
23
|
|
|
26
|
-
/**
|
|
27
|
-
* External dependencies
|
|
28
|
-
*/
|
|
29
|
-
|
|
30
24
|
/**
|
|
31
25
|
* WordPress dependencies
|
|
32
26
|
*/
|
|
@@ -87,7 +81,7 @@ function TextColorEdit(_ref2) {
|
|
|
87
81
|
const enableIsAddingColor = (0, _element.useCallback)(() => setIsAddingColor(true), [setIsAddingColor]);
|
|
88
82
|
const disableIsAddingColor = (0, _element.useCallback)(() => setIsAddingColor(false), [setIsAddingColor]);
|
|
89
83
|
const colorIndicatorStyle = (0, _element.useMemo)(() => fillComputedColors(contentRef.current, (0, _inline.getActiveColors)(value, name, colors)), [value, colors]);
|
|
90
|
-
const hasColorsToChoose =
|
|
84
|
+
const hasColorsToChoose = colors.length || !allowCustomControl;
|
|
91
85
|
|
|
92
86
|
if (!hasColorsToChoose && !isActive) {
|
|
93
87
|
return null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/format-library/src/text-color/index.js"],"names":["transparentValue","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":";;;;;;;
|
|
1
|
+
{"version":3,"sources":["@wordpress/format-library/src/text-color/index.js"],"names":["transparentValue","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","length","textColorIcon","textColor","tagName","className","attributes","class","__unstableFilterAttributeValue","key","includes","addedCSS","join","edit"],"mappings":";;;;;;;AAIA;;AADA;;AAEA;;AACA;;AACA;;AAKA;;;;;;AAZA;AACA;AACA;;AAOA;AACA;AACA;AAGO,MAAMA,gBAAgB,GAAG,kBAAzB;;AAEP,MAAMC,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,gBAAZ,CAA8BL,OAA9B,CAAd;AACA,QAAMM,KAAK,GAAGF,KAAK,CAACG,gBAAN,CAAwBN,QAAxB,CAAd;;AAEA,MACCA,QAAQ,KAAK,kBAAb,IACAK,KAAK,KAAKX,gBADV,IAEAK,OAAO,CAACQ,aAHT,EAIE;AACD,WAAOT,wBAAwB,CAAEC,OAAO,CAACQ,a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AQ,GAAG,CAAE,kBAAF,EAAsBzC,gBAAtB,EAAyC0C,IAAzC,CAA+C,GAA/C,CAAjB,CAJ4C,CAK5C;AACA;;AACA,WAAO/B,KAAK,GAAG,CAAE8B,QAAF,EAAY9B,KAAZ,EAAoB+B,IAApB,CAA0B,GAA1B,CAAH,GAAqCD,QAAjD;AACA,GA1BuB;;AA2BxBE,EAAAA,IAAI,EAAE1B;AA3BkB,CAAlB","sourcesContent":["/**\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\nexport const transparentValue = 'rgba(0, 0, 0, 0)';\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 === transparentValue &&\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 === transparentValue\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(\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.current,\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\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', transparentValue ].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"]}
|
|
@@ -9,8 +9,6 @@ exports.textColor = void 0;
|
|
|
9
9
|
|
|
10
10
|
var _element = require("@wordpress/element");
|
|
11
11
|
|
|
12
|
-
var _lodash = require("lodash");
|
|
13
|
-
|
|
14
12
|
var _reactNative = require("react-native");
|
|
15
13
|
|
|
16
14
|
var _i18n = require("@wordpress/i18n");
|
|
@@ -104,7 +102,7 @@ function TextColorEdit(_ref2) {
|
|
|
104
102
|
const enableIsAddingColor = (0, _element.useCallback)(() => setIsAddingColor(true), [setIsAddingColor]);
|
|
105
103
|
const disableIsAddingColor = (0, _element.useCallback)(() => setIsAddingColor(false), [setIsAddingColor]);
|
|
106
104
|
const colorIndicatorStyle = (0, _element.useMemo)(() => fillComputedColors(contentRef, (0, _inline.getActiveColors)(value, name, colors)), [value, colors]);
|
|
107
|
-
const hasColorsToChoose =
|
|
105
|
+
const hasColorsToChoose = colors.length || !allowCustomControl;
|
|
108
106
|
const onPressButton = (0, _element.useCallback)(() => {
|
|
109
107
|
if (hasColorsToChoose) {
|
|
110
108
|
enableIsAddingColor();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/format-library/src/text-color/index.native.js"],"names":["name","title","getComputedStyleProperty","element","property","props","style","backgroundColor","baseColors","color","background","fillComputedColors","TextColorEdit","value","onChange","isActive","activeAttributes","contentRef","allowCustomControl","colors","isAddingColor","setIsAddingColor","enableIsAddingColor","disableIsAddingColor","colorIndicatorStyle","hasColorsToChoose","onPressButton","outlineStyle","styles","isActiveStyle","customContainerStyles","textColorIcon","textColor","tagName","className","attributes","class","__unstableFilterAttributeValue","key","newValue","replace","includes","addedCSS","transparentValue","join","edit"],"mappings":";;;;;;;;;AAUA;;AAPA;;AACA;;AAKA;;AAEA;;AACA;;AAKA;;AACA;;AACA;;AAKA;;AACA;;AACA;;AACA;;AA3BA;AACA;AACA;;AAIA;AACA;AACA;;AAaA;AACA;AACA;AAMA,MAAMA,IAAI,GAAG,iBAAb;AACA,MAAMC,KAAK,GAAG,cAAI,YAAJ,CAAd;;AAEA,SAASC,wBAAT,CAAmCC,OAAnC,EAA4CC,QAA5C,EAAuD;AACtD,QAAM;AACLC,IAAAA,KAAK,EAAE;AAAEC,MAAAA,KAAK,GAAG;AAAV;AADF,MAEFH,OAFJ;;AAIA,MAAKC,QAAQ,KAAK,kBAAlB,EAAuC;AAAA;;AACtC,UAAM;AAAEG,MAAAA,eAAF;AAAmBC,MAAAA;AAAnB,QAAkCF,KAAxC;;AAEA,QAAKC,eAAe,KAAK,aAAzB,EAAyC;AACxC,aAAOA,eAAP;AACA,KAFD,MAEO,IAAKC,UAAU,IAAIA,UAAJ,aAAIA,UAAJ,oCAAIA,UAAU,CAAEC,KAAhB,8CAAI,kBAAmBC,UAAtC,EAAmD;AAAA;;AACzD,aAAOF,UAAP,aAAOA,UAAP,6CAAOA,UAAU,CAAEC,KAAnB,uDAAO,mBAAmBC,UAA1B;AACA;;AAED,WAAO,aAAP;AACA;AACD;;AAED,SAASC,kBAAT,CAA6BR,OAA7B,QAAmE;AAAA,MAA7B;AAAEM,IAAAA,KAAF;AAASF,IAAAA;AAAT,GAA6B;;AACl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A,KAAK,EAAGH,KAJT;AAKC,IAAA,QAAQ,EAAGC,QALZ;AAMC,IAAA,UAAU,EAAGG;AANd,IA/BF,CADD;AA2CA;;AAEM,MAAMe,SAAS,GAAG;AACxBhC,EAAAA,IADwB;AAExBC,EAAAA,KAFwB;AAGxBgC,EAAAA,OAAO,EAAE,MAHe;AAIxBC,EAAAA,SAAS,EAAE,kBAJa;AAKxBC,EAAAA,UAAU,EAAE;AACX7B,IAAAA,KAAK,EAAE,OADI;AAEX8B,IAAAA,KAAK,EAAE;AAFI,GALY;;AASxB;AACD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACCC,EAAAA,8BAA8B,CAAEC,GAAF,EAAOzB,KAAP,EAAe;AAC5C,QAAKyB,GAAG,KAAK,OAAb,EAAuB,OAAOzB,KAAP,CADqB,CAE5C;;AACA,UAAM0B,QAAQ,GAAG1B,KAAH,aAAGA,KAAH,uBAAGA,KAAK,CAAE2B,OAAP,CAAgB,IAAhB,EAAsB,EAAtB,CAAjB,CAH4C,CAI5C;;AACA,QAAKD,QAAQ,IAAIA,QAAQ,CAACE,QAAT,CAAmB,kBAAnB,CAAjB,EACC,OAAOF,QAAP;AACD,UAAMG,QAAQ,GAAG,CAAE,kBAAF,EAAsBC,uBAAtB,EAAyCC,IAAzC,CAA+C,GAA/C,CAAjB,CAP4C,CAQ5C;AACA;;AACA,WAAOL,QAAQ,GAAG,CAAEG,QAAF,EAAYH,QAAZ,EAAuBK,IAAvB,CAA6B,GAA7B,CAAH,GAAwCF,QAAvD;AACA,GA7BuB;;AA8BxBG,EAAAA,IAAI,EAAEjC;AA9BkB,CAAlB","sourcesContent":["/**\n * External dependencies\n */\nimport { isEmpty } from 'lodash';\nimport { View } from 'react-native';\n\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useCallback, useMemo, useState } from '@wordpress/element';\nimport { BlockControls, useSetting } from '@wordpress/block-editor';\nimport {\n\tToolbarGroup,\n\tToolbarButton,\n\tuseMobileGlobalStylesColors,\n} from '@wordpress/components';\nimport { Icon, textColor as textColorIcon } 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 { transparentValue } from './index.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 {\n\t\tprops: { style = {} },\n\t} = element;\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 = useSetting( '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 = ! isEmpty( colors ) || ! 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 = usePreferredColorSchemeStyle(\n\t\tstyles[ 'components-inline-color__outline' ],\n\t\tstyles[ 'components-inline-color__outline--dark' ]\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={ textColorIcon }\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\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 need to remove the extra spaces within the styles on mobile\n\t\tconst newValue = value?.replace( / /g, '' );\n\t\t// We should not add a background-color if it's already set\n\t\tif ( newValue && newValue.includes( 'background-color' ) )\n\t\t\treturn newValue;\n\t\tconst addedCSS = [ 'background-color', transparentValue ].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 newValue ? [ addedCSS, newValue ].join( ';' ) : addedCSS;\n\t},\n\tedit: TextColorEdit,\n};\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/format-library/src/text-color/index.native.js"],"names":["name","title","getComputedStyleProperty","element","property","props","style","backgroundColor","baseColors","color","background","fillComputedColors","TextColorEdit","value","onChange","isActive","activeAttributes","contentRef","allowCustomControl","colors","isAddingColor","setIsAddingColor","enableIsAddingColor","disableIsAddingColor","colorIndicatorStyle","hasColorsToChoose","length","onPressButton","outlineStyle","styles","isActiveStyle","customContainerStyles","textColorIcon","textColor","tagName","className","attributes","class","__unstableFilterAttributeValue","key","newValue","replace","includes","addedCSS","transparentValue","join","edit"],"mappings":";;;;;;;;;AASA;;AANA;;AAKA;;AAEA;;AACA;;AAKA;;AACA;;AACA;;AAKA;;AACA;;AACA;;AACA;;AA1BA;AACA;AACA;;AAGA;AACA;AACA;;AAaA;AACA;AACA;AAMA,MAAMA,IAAI,GAAG,iBAAb;AACA,MAAMC,KAAK,GAAG,cAAI,YAAJ,CAAd;;AAEA,SAASC,wBAAT,CAAmCC,OAAnC,EAA4CC,QAA5C,EAAuD;AACtD,QAAM;AACLC,IAAAA,KAAK,EAAE;AAAEC,MAAAA,KAAK,GAAG;AAAV;AADF,MAEFH,OAFJ;;AAIA,MAAKC,QAAQ,KAAK,kBAAlB,EAAuC;AAAA;;AACtC,UAAM;AAAEG,MAAAA,eAAF;AAAmBC,MAAAA;AAAnB,QAAkCF,KAAxC;;AAEA,QAAKC,eAAe,KAAK,aAAzB,EAAyC;AACxC,aAAOA,eAAP;AACA,KAFD,MAEO,IAAKC,UAAU,IAAIA,UAAJ,aAAIA,UAAJ,oCAAIA,UAAU,CAAEC,KAAhB,8CAAI,kBAAmBC,UAAtC,EAAmD;AAAA;;AACzD,aAAOF,UAAP,aAAOA,UAAP,6CAAOA,UAAU,CAAEC,KAAnB,uDAAO,mBAAmBC,UAA1B;AACA;;AAED,WAAO,aAAP;AACA;AACD;;AAED,SAASC,kBAAT,CAA6BR,OAA7B,QAAmE;AAAA,MAA7B;AAAEM,IAAAA,KAAF;AAASF,IAAAA;AAAT,GAA6B;;AAClE,MAAK,CAAEE,KAAF,IAAW,CAAEF,eAAlB,EAAoC;AACnC;AACA;;AAED,SAAO;AACNE,IAAAA,KAAK,EAAEA,KAAK,IAAIP,wBAAwB,CAAEC,OAAF,EAAW,OAAX,CADlC;AAENI,IAAAA,eAAe,EAAEL,wBAAwB,CAC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,EAAE,MAHe;AAIxBC,EAAAA,SAAS,EAAE,kBAJa;AAKxBC,EAAAA,UAAU,EAAE;AACX9B,IAAAA,KAAK,EAAE,OADI;AAEX+B,IAAAA,KAAK,EAAE;AAFI,GALY;;AASxB;AACD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACCC,EAAAA,8BAA8B,CAAEC,GAAF,EAAO1B,KAAP,EAAe;AAC5C,QAAK0B,GAAG,KAAK,OAAb,EAAuB,OAAO1B,KAAP,CADqB,CAE5C;;AACA,UAAM2B,QAAQ,GAAG3B,KAAH,aAAGA,KAAH,uBAAGA,KAAK,CAAE4B,OAAP,CAAgB,IAAhB,EAAsB,EAAtB,CAAjB,CAH4C,CAI5C;;AACA,QAAKD,QAAQ,IAAIA,QAAQ,CAACE,QAAT,CAAmB,kBAAnB,CAAjB,EACC,OAAOF,QAAP;AACD,UAAMG,QAAQ,GAAG,CAAE,kBAAF,EAAsBC,uBAAtB,EAAyCC,IAAzC,CAA+C,GAA/C,CAAjB,CAP4C,CAQ5C;AACA;;AACA,WAAOL,QAAQ,GAAG,CAAEG,QAAF,EAAYH,QAAZ,EAAuBK,IAAvB,CAA6B,GAA7B,CAAH,GAAwCF,QAAvD;AACA,GA7BuB;;AA8BxBG,EAAAA,IAAI,EAAElC;AA9BkB,CAAlB","sourcesContent":["/**\n * External dependencies\n */\nimport { View } from 'react-native';\n\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useCallback, useMemo, useState } from '@wordpress/element';\nimport { BlockControls, useSetting } from '@wordpress/block-editor';\nimport {\n\tToolbarGroup,\n\tToolbarButton,\n\tuseMobileGlobalStylesColors,\n} from '@wordpress/components';\nimport { Icon, textColor as textColorIcon } 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 { transparentValue } from './index.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 {\n\t\tprops: { style = {} },\n\t} = element;\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 = useSetting( '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 = usePreferredColorSchemeStyle(\n\t\tstyles[ 'components-inline-color__outline' ],\n\t\tstyles[ 'components-inline-color__outline--dark' ]\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={ textColorIcon }\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\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 need to remove the extra spaces within the styles on mobile\n\t\tconst newValue = value?.replace( / /g, '' );\n\t\t// We should not add a background-color if it's already set\n\t\tif ( newValue && newValue.includes( 'background-color' ) )\n\t\t\treturn newValue;\n\t\tconst addedCSS = [ 'background-color', transparentValue ].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 newValue ? [ addedCSS, newValue ].join( ';' ) : addedCSS;\n\t},\n\tedit: TextColorEdit,\n};\n"]}
|
|
@@ -9,8 +9,6 @@ exports.parseClassName = parseClassName;
|
|
|
9
9
|
|
|
10
10
|
var _element = require("@wordpress/element");
|
|
11
11
|
|
|
12
|
-
var _lodash = require("lodash");
|
|
13
|
-
|
|
14
12
|
var _data = require("@wordpress/data");
|
|
15
13
|
|
|
16
14
|
var _richText = require("@wordpress/rich-text");
|
|
@@ -23,10 +21,6 @@ var _i18n = require("@wordpress/i18n");
|
|
|
23
21
|
|
|
24
22
|
var _index = require("./index");
|
|
25
23
|
|
|
26
|
-
/**
|
|
27
|
-
* External dependencies
|
|
28
|
-
*/
|
|
29
|
-
|
|
30
24
|
/**
|
|
31
25
|
* WordPress dependencies
|
|
32
26
|
*/
|
|
@@ -123,10 +117,12 @@ function ColorPicker(_ref) {
|
|
|
123
117
|
onChange
|
|
124
118
|
} = _ref;
|
|
125
119
|
const colors = (0, _data.useSelect)(select => {
|
|
120
|
+
var _getSettings$colors;
|
|
121
|
+
|
|
126
122
|
const {
|
|
127
123
|
getSettings
|
|
128
124
|
} = select(_blockEditor.store);
|
|
129
|
-
return (
|
|
125
|
+
return (_getSettings$colors = getSettings().colors) !== null && _getSettings$colors !== void 0 ? _getSettings$colors : [];
|
|
130
126
|
}, []);
|
|
131
127
|
const onColorChange = (0, _element.useCallback)(color => {
|
|
132
128
|
onChange(setColors(value, name, colors, {
|
|
@@ -149,22 +145,22 @@ function InlineColorUI(_ref2) {
|
|
|
149
145
|
contentRef
|
|
150
146
|
} = _ref2;
|
|
151
147
|
|
|
152
|
-
/*
|
|
148
|
+
/*
|
|
153
149
|
As you change the text color by typing a HEX value into a field,
|
|
154
150
|
the return value of document.getSelection jumps to the field you're editing,
|
|
155
|
-
not the highlighted text. Given that
|
|
151
|
+
not the highlighted text. Given that useAnchor uses document.getSelection,
|
|
156
152
|
it will return null, since it can't find the <mark> element within the HEX input.
|
|
157
153
|
This caches the last truthy value of the selection anchor reference.
|
|
158
154
|
*/
|
|
159
|
-
const
|
|
160
|
-
|
|
155
|
+
const popoverAnchor = (0, _blockEditor.useCachedTruthy)((0, _richText.useAnchor)({
|
|
156
|
+
editableContentElement: contentRef.current,
|
|
161
157
|
value,
|
|
162
158
|
settings: _index.textColor
|
|
163
159
|
}));
|
|
164
160
|
return (0, _element.createElement)(_components.Popover, {
|
|
165
161
|
onClose: onClose,
|
|
166
162
|
className: "components-inline-color-popover",
|
|
167
|
-
|
|
163
|
+
anchor: popoverAnchor
|
|
168
164
|
}, (0, _element.createElement)(_components.TabPanel, {
|
|
169
165
|
tabs: [{
|
|
170
166
|
name: 'color',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/format-library/src/text-color/inline.js"],"names":["parseCSS","css","split","reduce","accumulator","rule","property","value","color","transparentValue","backgroundColor","parseClassName","className","colorSettings","name","startsWith","endsWith","colorSlug","replace","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","
|
|
1
|
+
{"version":3,"sources":["@wordpress/format-library/src/text-color/inline.js"],"names":["parseCSS","css","split","reduce","accumulator","rule","property","value","color","transparentValue","backgroundColor","parseClassName","className","colorSettings","name","startsWith","endsWith","colorSlug","replace","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","popoverAnchor","editableContentElement","current","settings","title","tab"],"mappings":";;;;;;;;;AAGA;;AACA;;AACA;;AAMA;;AAQA;;AACA;;AAKA;;AAzBA;AACA;AACA;;AAoBA;AACA;AACA;AAGA,SAASA,QAAT,GAA8B;AAAA,MAAXC,GAAW,uEAAL,EAAK;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,kBAAb,IAAmCC,KAAK,KAAKE,uBAAlD,EACCL,WAAW,CAACM,eAAZ,GAA8BH,KAA9B;AACD;;AACD,WAAOH,WAAP;AACA,GARM,EAQJ,EARI,CAAP;AASA;;AAEM,SAASO,cAAT,GAAyD;AAAA,MAAhCC,SAAgC,uEAApB,EAAoB;AAAA,MAAhBC,aAAgB;AAC/D,SAAOD,SAAS,CAACV,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AKN;AACClC,MAAAA,IAAI,EAAE,iBADP;AAECkC,MAAAA,KAAK,EAAE,cAAI,YAAJ;AAFR,KALM;AADR,KAYKC,GAAF,IACD,4BAAC,WAAD;AACC,IAAA,IAAI,EAAGnC,IADR;AAEC,IAAA,QAAQ,EAAGmC,GAAG,CAACnC,IAFhB;AAGC,IAAA,KAAK,EAAGP,KAHT;AAIC,IAAA,QAAQ,EAAG4B;AAJZ,IAbF,CALD,CADD;AA6BA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useCallback, useMemo } from '@wordpress/element';\nimport { useSelect } from '@wordpress/data';\nimport {\n\tapplyFormat,\n\tremoveFormat,\n\tgetActiveFormat,\n\tuseAnchor,\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, transparentValue } 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' && value !== transparentValue )\n\t\t\t\taccumulator.backgroundColor = value;\n\t\t}\n\t\treturn accumulator;\n\t}, {} );\n}\n\nexport function parseClassName( className = '', colorSettings ) {\n\treturn className.split( ' ' ).reduce( ( accumulator, name ) => {\n\t\t// `colorSlug` could contain dashes, so simply match the start and end.\n\t\tif ( name.startsWith( 'has-' ) && name.endsWith( '-color' ) ) {\n\t\t\tconst colorSlug = name\n\t\t\t\t.replace( /^has-/, '' )\n\t\t\t\t.replace( /-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', 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} 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 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 useAnchor 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 popoverAnchor = useCachedTruthy(\n\t\tuseAnchor( {\n\t\t\teditableContentElement: contentRef.current,\n\t\t\tvalue,\n\t\t\tsettings,\n\t\t} )\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\tanchor={ popoverAnchor }\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"]}
|
|
@@ -6,7 +6,7 @@ import { createElement } from "@wordpress/element";
|
|
|
6
6
|
import { Path, SVG, TextControl, Popover, Button } from '@wordpress/components';
|
|
7
7
|
import { __ } from '@wordpress/i18n';
|
|
8
8
|
import { useState } from '@wordpress/element';
|
|
9
|
-
import { insertObject,
|
|
9
|
+
import { insertObject, useAnchor } from '@wordpress/rich-text';
|
|
10
10
|
import { MediaUpload, RichTextToolbarButton, MediaUploadCheck } from '@wordpress/block-editor';
|
|
11
11
|
import { keyboardReturn } from '@wordpress/icons';
|
|
12
12
|
const ALLOWED_MEDIA_TYPES = ['image'];
|
|
@@ -41,15 +41,15 @@ function InlineUI(_ref) {
|
|
|
41
41
|
style
|
|
42
42
|
} = activeObjectAttributes;
|
|
43
43
|
const [width, setWidth] = useState(style === null || style === void 0 ? void 0 : style.replace(/\D/g, ''));
|
|
44
|
-
const
|
|
45
|
-
|
|
44
|
+
const popoverAnchor = useAnchor({
|
|
45
|
+
editableContentElement: contentRef.current,
|
|
46
46
|
value,
|
|
47
47
|
settings: image
|
|
48
48
|
});
|
|
49
49
|
return createElement(Popover, {
|
|
50
50
|
position: "bottom center",
|
|
51
51
|
focusOnMount: false,
|
|
52
|
-
|
|
52
|
+
anchor: popoverAnchor,
|
|
53
53
|
className: "block-editor-format-toolbar__image-popover"
|
|
54
54
|
}, createElement("form", {
|
|
55
55
|
className: "block-editor-format-toolbar__image-container-content",
|