@wordpress/format-library 4.20.1 → 4.21.1-next.f8d8eceb.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.
- package/CHANGELOG.md +2 -0
- package/build/link/index.js +10 -6
- package/build/link/index.js.map +1 -1
- package/build/text-color/index.js +1 -2
- package/build/text-color/index.js.map +1 -1
- package/build/text-color/index.native.js +1 -1
- package/build/text-color/index.native.js.map +1 -1
- package/build-module/link/index.js +11 -7
- package/build-module/link/index.js.map +1 -1
- package/build-module/text-color/index.js +2 -3
- package/build-module/text-color/index.js.map +1 -1
- package/build-module/text-color/index.native.js +2 -2
- package/build-module/text-color/index.native.js.map +1 -1
- package/package.json +13 -13
- package/src/link/index.js +20 -7
- package/src/text-color/index.js +5 -3
- package/src/text-color/index.native.js +2 -2
package/CHANGELOG.md
CHANGED
package/build/link/index.js
CHANGED
|
@@ -120,24 +120,28 @@ const link = {
|
|
|
120
120
|
html,
|
|
121
121
|
plainText
|
|
122
122
|
}) {
|
|
123
|
-
if ((0, _richText.isCollapsed)(value)) {
|
|
124
|
-
return value;
|
|
125
|
-
}
|
|
126
123
|
const pastedText = (html || plainText).replace(/<[^>]+>/g, '').trim();
|
|
127
124
|
|
|
128
125
|
// A URL was pasted, turn the selection into a link.
|
|
129
|
-
|
|
126
|
+
// For the link pasting feature, allow only http(s) protocols.
|
|
127
|
+
if (!(0, _url.isURL)(pastedText) || !/^https?:/.test(pastedText)) {
|
|
130
128
|
return value;
|
|
131
129
|
}
|
|
132
130
|
|
|
133
131
|
// Allows us to ask for this information when we get a report.
|
|
134
132
|
window.console.log('Created link:\n\n', pastedText);
|
|
135
|
-
|
|
133
|
+
const format = {
|
|
136
134
|
type: name,
|
|
137
135
|
attributes: {
|
|
138
136
|
url: (0, _htmlEntities.decodeEntities)(pastedText)
|
|
139
137
|
}
|
|
140
|
-
}
|
|
138
|
+
};
|
|
139
|
+
if ((0, _richText.isCollapsed)(value)) {
|
|
140
|
+
return (0, _richText.insert)(value, (0, _richText.applyFormat)((0, _richText.create)({
|
|
141
|
+
text: plainText
|
|
142
|
+
}), format, 0, plainText.length));
|
|
143
|
+
}
|
|
144
|
+
return (0, _richText.applyFormat)(value, format);
|
|
141
145
|
},
|
|
142
146
|
edit: Edit
|
|
143
147
|
};
|
package/build/link/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_i18n","require","_element","_richText","_url","_blockEditor","_htmlEntities","_icons","_a11y","_inline","_interopRequireDefault","_utils","name","title","__","Edit","isActive","activeAttributes","value","onChange","onFocus","contentRef","addingLink","setAddingLink","useState","addLink","text","getTextContent","slice","isURL","isValidHref","applyFormat","type","attributes","url","isEmail","stopAddingLink","returnFocus","onRemoveFormat","removeFormat","speak","_react","createElement","Fragment","RichTextShortcut","character","onUse","RichTextToolbarButton","icon","linkOff","onClick","shortcutType","shortcutCharacter","linkIcon","default","link","tagName","className","id","_id","target","rel","__unstablePasteRule","html","plainText","
|
|
1
|
+
{"version":3,"names":["_i18n","require","_element","_richText","_url","_blockEditor","_htmlEntities","_icons","_a11y","_inline","_interopRequireDefault","_utils","name","title","__","Edit","isActive","activeAttributes","value","onChange","onFocus","contentRef","addingLink","setAddingLink","useState","addLink","text","getTextContent","slice","isURL","isValidHref","applyFormat","type","attributes","url","isEmail","stopAddingLink","returnFocus","onRemoveFormat","removeFormat","speak","_react","createElement","Fragment","RichTextShortcut","character","onUse","RichTextToolbarButton","icon","linkOff","onClick","shortcutType","shortcutCharacter","linkIcon","default","link","tagName","className","id","_id","target","rel","__unstablePasteRule","html","plainText","pastedText","replace","trim","test","window","console","log","format","decodeEntities","isCollapsed","insert","create","length","edit","exports"],"sources":["@wordpress/format-library/src/link/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useState } 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, linkOff } 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\n\tfunction addLink() {\n\t\tconst text = getTextContent( slice( value ) );\n\n\t\tif ( 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 ( 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\tsetAddingLink( true );\n\t\t}\n\t}\n\n\tfunction stopAddingLink( returnFocus = true ) {\n\t\tsetAddingLink( false );\n\t\tif ( returnFocus ) {\n\t\t\tonFocus();\n\t\t}\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{ isActive && (\n\t\t\t\t<RichTextToolbarButton\n\t\t\t\t\tname=\"link\"\n\t\t\t\t\ticon={ linkOff }\n\t\t\t\t\ttitle={ __( 'Unlink' ) }\n\t\t\t\t\tonClick={ onRemoveFormat }\n\t\t\t\t\tisActive={ isActive }\n\t\t\t\t\tshortcutType=\"primaryShift\"\n\t\t\t\t\tshortcutCharacter=\"k\"\n\t\t\t\t\taria-haspopup=\"true\"\n\t\t\t\t\taria-expanded={ addingLink || isActive }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t{ ! isActive && (\n\t\t\t\t<RichTextToolbarButton\n\t\t\t\t\tname=\"link\"\n\t\t\t\t\ticon={ linkIcon }\n\t\t\t\t\ttitle={ title }\n\t\t\t\t\tonClick={ addLink }\n\t\t\t\t\tisActive={ isActive }\n\t\t\t\t\tshortcutType=\"primary\"\n\t\t\t\t\tshortcutCharacter=\"k\"\n\t\t\t\t\taria-haspopup=\"true\"\n\t\t\t\t\taria-expanded={ addingLink || isActive }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t{ ( addingLink || isActive ) && (\n\t\t\t\t<InlineLinkUI\n\t\t\t\t\taddingLink={ addingLink }\n\t\t\t\t\tstopAddingLink={ stopAddingLink }\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":";;;;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,SAAA,GAAAF,OAAA;AASA,IAAAG,IAAA,GAAAH,OAAA;AACA,IAAAI,YAAA,GAAAJ,OAAA;AAIA,IAAAK,aAAA,GAAAL,OAAA;AACA,IAAAM,MAAA,GAAAN,OAAA;AACA,IAAAO,KAAA,GAAAP,OAAA;AAKA,IAAAQ,OAAA,GAAAC,sBAAA,CAAAT,OAAA;AACA,IAAAU,MAAA,GAAAV,OAAA;AA3BA;AACA;AACA;;AAqBA;AACA;AACA;;AAIA,MAAMW,IAAI,GAAG,WAAW;AACxB,MAAMC,KAAK,GAAG,IAAAC,QAAE,EAAE,MAAO,CAAC;AAE1B,SAASC,IAAIA,CAAE;EACdC,QAAQ;EACRC,gBAAgB;EAChBC,KAAK;EACLC,QAAQ;EACRC,OAAO;EACPC;AACD,CAAC,EAAG;EACH,MAAM,CAAEC,UAAU,EAAEC,aAAa,CAAE,GAAG,IAAAC,iBAAQ,EAAE,KAAM,CAAC;EAEvD,SAASC,OAAOA,CAAA,EAAG;IAClB,MAAMC,IAAI,GAAG,IA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AAM;IACXF,IAAI,EAAE,WAAW;IACjB0B,EAAE,EAAE,SAAS;IACbC,GAAG,EAAE,IAAI;IACTC,MAAM,EAAE,QAAQ;IAChBC,GAAG,EAAE;EACN,CAAC;EACDC,mBAAmBA,CAAE5C,KAAK,EAAE;IAAE6C,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,CAAE,IAAAtC,UAAK,EAAEoC,UAAW,CAAC,IAAI,CAAE,UAAU,CAACG,IAAI,CAAEH,UAAW,CAAC,EAAG;MAC/D,OAAO/C,KAAK;IACb;;IAEA;IACAmD,MAAM,CAACC,OAAO,CAACC,GAAG,CAAE,mBAAmB,EAAEN,UAAW,CAAC;IAErD,MAAMO,MAAM,GAAG;MACdxC,IAAI,EAAEpB,IAAI;MACVqB,UAAU,EAAE;QACXC,GAAG,EAAE,IAAAuC,4BAAc,EAAER,UAAW;MACjC;IACD,CAAC;IAED,IAAK,IAAAS,qBAAW,EAAExD,KAAM,CAAC,EAAG;MAC3B,OAAO,IAAAyD,gBAAM,EACZzD,KAAK,EACL,IAAAa,qBAAW,EACV,IAAA6C,gBAAM,EAAE;QAAElD,IAAI,EAAEsC;MAAU,CAAE,CAAC,EAC7BQ,MAAM,EACN,CAAC,EACDR,SAAS,CAACa,MACX,CACD,CAAC;IACF;IAEA,OAAO,IAAA9C,qBAAW,EAAEb,KAAK,EAAEsD,MAAO,CAAC;EACpC,CAAC;EACDM,IAAI,EAAE/D;AACP,CAAC;AAACgE,OAAA,CAAAxB,IAAA,GAAAA,IAAA"}
|
|
@@ -59,8 +59,7 @@ function TextColorEdit({
|
|
|
59
59
|
activeAttributes,
|
|
60
60
|
contentRef
|
|
61
61
|
}) {
|
|
62
|
-
const allowCustomControl = (0, _blockEditor.
|
|
63
|
-
const colors = (0, _blockEditor.useSetting)('color.palette') || EMPTY_ARRAY;
|
|
62
|
+
const [allowCustomControl, colors = EMPTY_ARRAY] = (0, _blockEditor.useSettings)('color.custom', 'color.palette');
|
|
64
63
|
const [isAddingColor, setIsAddingColor] = (0, _element.useState)(false);
|
|
65
64
|
const enableIsAddingColor = (0, _element.useCallback)(() => setIsAddingColor(true), [setIsAddingColor]);
|
|
66
65
|
const disableIsAddingColor = (0, _element.useCallback)(() => setIsAddingColor(false), [setIsAddingColor]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_i18n","require","_element","_blockEditor","_icons","_richText","_inline","_interopRequireWildcard","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","transparentValue","exports","name","title","__","EMPTY_ARRAY","getComputedStyleProperty","element","property","ownerDocument","defaultView","style","getComputedStyle","value","getPropertyValue","parentElement","fillComputedColors","color","backgroundColor","TextColorEdit","onChange","isActive","activeAttributes","contentRef","allowCustomControl","
|
|
1
|
+
{"version":3,"names":["_i18n","require","_element","_blockEditor","_icons","_richText","_inline","_interopRequireWildcard","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","transparentValue","exports","name","title","__","EMPTY_ARRAY","getComputedStyleProperty","element","property","ownerDocument","defaultView","style","getComputedStyle","value","getPropertyValue","parentElement","fillComputedColors","color","backgroundColor","TextColorEdit","onChange","isActive","activeAttributes","contentRef","allowCustomControl","colors","useSettings","isAddingColor","setIsAddingColor","useState","enableIsAddingColor","useCallback","disableIsAddingColor","colorIndicatorStyle","useMemo","current","getActiveColors","hasColorsToChoose","length","_react","createElement","Fragment","RichTextToolbarButton","className","icon","Icon","keys","textColorIcon","colorIcon","onClick","removeFormat","role","onClose","textColor","tagName","attributes","class","__unstableFilterAttributeValue","includes","addedCSS","join","edit"],"sources":["@wordpress/format-library/src/text-color/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useCallback, useMemo, useState } from '@wordpress/element';\nimport { RichTextToolbarButton, useSettings } from '@wordpress/block-editor';\nimport {\n\tIcon,\n\tcolor as colorIcon,\n\ttextColor as textColorIcon,\n} 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, colors = EMPTY_ARRAY ] = useSettings(\n\t\t'color.custom',\n\t\t'color.palette'\n\t);\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={\n\t\t\t\t\t\t\tObject.keys( activeAttributes ).length\n\t\t\t\t\t\t\t\t? textColorIcon\n\t\t\t\t\t\t\t\t: colorIcon\n\t\t\t\t\t\t}\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"],"mappings":";;;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,YAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AAKA,IAAAI,SAAA,GAAAJ,OAAA;AAKA,IAAAK,OAAA,GAAAC,uBAAA,CAAAN,OAAA;AAAqE,SAAAO,yBAAAC,WAAA,eAAAC,OAAA,kCAAAC,iBAAA,OAAAD,OAAA,QAAAE,gBAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,WAAA,WAAAA,WAAA,GAAAG,gBAAA,GAAAD,iBAAA,KAAAF,WAAA;AAAA,SAAAF,wBAAAM,GAAA,EAAAJ,WAAA,SAAAA,WAAA,IAAAI,GAAA,IAAAA,GAAA,CAAAC,UAAA,WAAAD,GAAA,QAAAA,GAAA,oBAAAA,GAAA,wBAAAA,GAAA,4BAAAE,OAAA,EAAAF,GAAA,UAAAG,KAAA,GAAAR,wBAAA,CAAAC,WAAA,OAAAO,KAAA,IAAAA,KAAA,CAAAC,GAAA,CAAAJ,GAAA,YAAAG,KAAA,CAAAE,GAAA,CAAAL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EAAG,OAAOmB,KAAK;IACnC;IACA,IAAKA,KAAK,IAAIA,KAAK,CAAC6C,QAAQ,CAAE,kBAAmB,CAAC,EAAG,OAAO7C,KAAK;IACjE,MAAM8C,QAAQ,GAAG,CAAE,kBAAkB,EAAE3D,gBAAgB,CAAE,CAAC4D,IAAI,CAAE,GAAI,CAAC;IACrE;IACA;IACA,OAAO/C,KAAK,GAAG,CAAE8C,QAAQ,EAAE9C,KAAK,CAAE,CAAC+C,IAAI,CAAE,GAAI,CAAC,GAAGD,QAAQ;EAC1D,CAAC;EACDE,IAAI,EAAE1C;AACP,CAAC;AAAClB,OAAA,CAAAoD,SAAA,GAAAA,SAAA"}
|
|
@@ -70,7 +70,7 @@ function TextColorEdit({
|
|
|
70
70
|
activeAttributes,
|
|
71
71
|
contentRef
|
|
72
72
|
}) {
|
|
73
|
-
const allowCustomControl = (0, _blockEditor.
|
|
73
|
+
const [allowCustomControl] = (0, _blockEditor.useSettings)('color.custom');
|
|
74
74
|
const colors = (0, _components.useMobileGlobalStylesColors)();
|
|
75
75
|
const [isAddingColor, setIsAddingColor] = (0, _element.useState)(false);
|
|
76
76
|
const enableIsAddingColor = (0, _element.useCallback)(() => setIsAddingColor(true), [setIsAddingColor]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_reactNative","require","_i18n","_element","_blockEditor","_components","_icons","_richText","_compose","_inline","_index","_inline2","_interopRequireDefault","_style","name","title","__","getComputedStyleProperty","element","property","props","style","backgroundColor","baseColors","color","background","fillComputedColors","TextColorEdit","value","onChange","isActive","activeAttributes","contentRef","allowCustomControl","useSetting","colors","useMobileGlobalStylesColors","isAddingColor","setIsAddingColor","useState","enableIsAddingColor","useCallback","disableIsAddingColor","colorIndicatorStyle","useMemo","getActiveColors","hasColorsToChoose","length","onPressButton","removeFormat","outlineStyle","usePreferredColorSchemeStyle","styles","borderWidth","StyleSheet","hairlineWidth","isActiveStyle","customContainerStyles","_react","createElement","Fragment","BlockControls","ToolbarGroup","View","pointerEvents","ToolbarButton","icon","Icon","Object","keys","textColorIcon","colorIcon","extraProps","onClick","default","onClose","textColor","tagName","className","attributes","class","__unstableFilterAttributeValue","key","newValue","replace","includes","addedCSS","transparentValue","join","edit","exports"],"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, useSetting } 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 { 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 = [\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\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"],"mappings":";;;;;;;;AAGA,IAAAA,YAAA,GAAAC,OAAA;AAKA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AACA,IAAAG,YAAA,GAAAH,OAAA;AACA,IAAAI,WAAA,GAAAJ,OAAA;AAKA,IAAAK,MAAA,GAAAL,OAAA;AAKA,IAAAM,SAAA,GAAAN,OAAA;AACA,IAAAO,QAAA,GAAAP,OAAA;AAKA,IAAAQ,OAAA,GAAAR,OAAA;AACA,IAAAS,MAAA,GAAAT,OAAA;AACA,IAAAU,QAAA,GAAAC,sBAAA,CAAAX,OAAA;AACA,IAAAY,MAAA,GAAAD,sBAAA,CAAAX,OAAA;AA9BA;AACA;AACA;;AAGA;AACA;AACA;;AAiBA;AACA;AACA;;AAMA,MAAMa,IAAI,GAAG,iBAAiB;AAC9B,MAAMC,KAAK,GAAG,IAAAC,QAAE,EAAE,YAAa,CAAC;AAEhC,SAASC,wBAAwBA,CAAEC,OAAO,EAAEC,QAAQ,EAAG;EACtD,MAAM;IACLC,KAAK,EAAE;MAAEC,KAAK,GAAG,CAAC;IAAE;EACrB,CAAC,GAAGH,OAAO;EAEX,IAAKC,QAAQ,KAAK,kBAAkB,EAAG;IACtC,MAAM;MAAEG,eAAe;MAAEC;IAAW,CAAC,GAAGF,KAAK;IAE7C,IAAKC,eAAe,KAAK,aAAa,EA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kBAAkB,EAAEC,uBAAgB,CAAE,CAACC,IAAI,CAAE,GAAI,CAAC;IACrE;IACA;IACA,OAAOL,QAAQ,GAAG,CAAEG,QAAQ,EAAEH,QAAQ,CAAE,CAACK,IAAI,CAAE,GAAI,CAAC,GAAGF,QAAQ;EAChE,CAAC;EACDG,IAAI,EAAE9D;AACP,CAAC;AAAC+D,OAAA,CAAAd,SAAA,GAAAA,SAAA"}
|
|
1
|
+
{"version":3,"names":["_reactNative","require","_i18n","_element","_blockEditor","_components","_icons","_richText","_compose","_inline","_index","_inline2","_interopRequireDefault","_style","name","title","__","getComputedStyleProperty","element","property","props","style","backgroundColor","baseColors","color","background","fillComputedColors","TextColorEdit","value","onChange","isActive","activeAttributes","contentRef","allowCustomControl","useSettings","colors","useMobileGlobalStylesColors","isAddingColor","setIsAddingColor","useState","enableIsAddingColor","useCallback","disableIsAddingColor","colorIndicatorStyle","useMemo","getActiveColors","hasColorsToChoose","length","onPressButton","removeFormat","outlineStyle","usePreferredColorSchemeStyle","styles","borderWidth","StyleSheet","hairlineWidth","isActiveStyle","customContainerStyles","_react","createElement","Fragment","BlockControls","ToolbarGroup","View","pointerEvents","ToolbarButton","icon","Icon","Object","keys","textColorIcon","colorIcon","extraProps","onClick","default","onClose","textColor","tagName","className","attributes","class","__unstableFilterAttributeValue","key","newValue","replace","includes","addedCSS","transparentValue","join","edit","exports"],"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 { 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 ] = 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\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"],"mappings":";;;;;;;;AAGA,IAAAA,YAAA,GAAAC,OAAA;AAKA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AACA,IAAAG,YAAA,GAAAH,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D,IAAI,EAAGA,IAAM;IACb6D,OAAO,EAAGjC,oBAAsB;IAChCX,gBAAgB,EAAGA,gBAAkB;IACrCH,KAAK,EAAGA,KAAO;IACfC,QAAQ,EAAGA,QAAU;IACrBG,UAAU,EAAGA;EAAY,CACzB,CAED,CAAC;AAEL;AAEO,MAAM4C,SAAS,GAAG;EACxB9D,IAAI;EACJC,KAAK;EACL8D,OAAO,EAAE,MAAM;EACfC,SAAS,EAAE,kBAAkB;EAC7BC,UAAU,EAAE;IACX1D,KAAK,EAAE,OAAO;IACd2D,KAAK,EAAE;EACR,CAAC;EACD;AACD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACCC,8BAA8BA,CAAEC,GAAG,EAAEtD,KAAK,EAAG;IAC5C,IAAKsD,GAAG,KAAK,OAAO,EAAG,OAAOtD,KAAK;IACnC;IACA,MAAMuD,QAAQ,GAAGvD,KAAK,EAAEwD,OAAO,CAAE,IAAI,EAAE,EAAG,CAAC;IAC3C;IACA,IAAKD,QAAQ,IAAIA,QAAQ,CAACE,QAAQ,CAAE,kBAAmB,CAAC,EACvD,OAAOF,QAAQ;IAChB,MAAMG,QAAQ,GAAG,CAAE,kBAAkB,EAAEC,uBAAgB,CAAE,CAACC,IAAI,CAAE,GAAI,CAAC;IACrE;IACA;IACA,OAAOL,QAAQ,GAAG,CAAEG,QAAQ,EAAEH,QAAQ,CAAE,CAACK,IAAI,CAAE,GAAI,CAAC,GAAGF,QAAQ;EAChE,CAAC;EACDG,IAAI,EAAE9D;AACP,CAAC;AAAC+D,OAAA,CAAAd,SAAA,GAAAA,SAAA"}
|
|
@@ -4,7 +4,7 @@ import { createElement, Fragment } from "react";
|
|
|
4
4
|
*/
|
|
5
5
|
import { __ } from '@wordpress/i18n';
|
|
6
6
|
import { useState } from '@wordpress/element';
|
|
7
|
-
import { getTextContent, applyFormat, removeFormat, slice, isCollapsed } from '@wordpress/rich-text';
|
|
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';
|
|
10
10
|
import { decodeEntities } from '@wordpress/html-entities';
|
|
@@ -112,24 +112,28 @@ export const link = {
|
|
|
112
112
|
html,
|
|
113
113
|
plainText
|
|
114
114
|
}) {
|
|
115
|
-
if (isCollapsed(value)) {
|
|
116
|
-
return value;
|
|
117
|
-
}
|
|
118
115
|
const pastedText = (html || plainText).replace(/<[^>]+>/g, '').trim();
|
|
119
116
|
|
|
120
117
|
// A URL was pasted, turn the selection into a link.
|
|
121
|
-
|
|
118
|
+
// For the link pasting feature, allow only http(s) protocols.
|
|
119
|
+
if (!isURL(pastedText) || !/^https?:/.test(pastedText)) {
|
|
122
120
|
return value;
|
|
123
121
|
}
|
|
124
122
|
|
|
125
123
|
// Allows us to ask for this information when we get a report.
|
|
126
124
|
window.console.log('Created link:\n\n', pastedText);
|
|
127
|
-
|
|
125
|
+
const format = {
|
|
128
126
|
type: name,
|
|
129
127
|
attributes: {
|
|
130
128
|
url: decodeEntities(pastedText)
|
|
131
129
|
}
|
|
132
|
-
}
|
|
130
|
+
};
|
|
131
|
+
if (isCollapsed(value)) {
|
|
132
|
+
return insert(value, applyFormat(create({
|
|
133
|
+
text: plainText
|
|
134
|
+
}), format, 0, plainText.length));
|
|
135
|
+
}
|
|
136
|
+
return applyFormat(value, format);
|
|
133
137
|
},
|
|
134
138
|
edit: Edit
|
|
135
139
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["__","useState","getTextContent","applyFormat","removeFormat","slice","isCollapsed","isURL","isEmail","RichTextToolbarButton","RichTextShortcut","decodeEntities","link","linkIcon","linkOff","speak","InlineLinkUI","isValidHref","name","title","Edit","isActive","activeAttributes","value","onChange","onFocus","contentRef","addingLink","setAddingLink","addLink","text","type","attributes","url","stopAddingLink","returnFocus","onRemoveFormat","createElement","Fragment","character","onUse","icon","onClick","shortcutType","shortcutCharacter","tagName","className","id","_id","target","rel","__unstablePasteRule","html","plainText","pastedText","replace","trim","window","console","log","edit"],"sources":["@wordpress/format-library/src/link/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useState } from '@wordpress/element';\nimport {\n\tgetTextContent,\n\tapplyFormat,\n\tremoveFormat,\n\tslice,\n\tisCollapsed,\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, linkOff } 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\n\tfunction addLink() {\n\t\tconst text = getTextContent( slice( value ) );\n\n\t\tif ( 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 ( 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\tsetAddingLink( true );\n\t\t}\n\t}\n\n\tfunction stopAddingLink( returnFocus = true ) {\n\t\tsetAddingLink( false );\n\t\tif ( returnFocus ) {\n\t\t\tonFocus();\n\t\t}\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{ isActive && (\n\t\t\t\t<RichTextToolbarButton\n\t\t\t\t\tname=\"link\"\n\t\t\t\t\ticon={ linkOff }\n\t\t\t\t\ttitle={ __( 'Unlink' ) }\n\t\t\t\t\tonClick={ onRemoveFormat }\n\t\t\t\t\tisActive={ isActive }\n\t\t\t\t\tshortcutType=\"primaryShift\"\n\t\t\t\t\tshortcutCharacter=\"k\"\n\t\t\t\t\taria-haspopup=\"true\"\n\t\t\t\t\taria-expanded={ addingLink || isActive }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t{ ! isActive && (\n\t\t\t\t<RichTextToolbarButton\n\t\t\t\t\tname=\"link\"\n\t\t\t\t\ticon={ linkIcon }\n\t\t\t\t\ttitle={ title }\n\t\t\t\t\tonClick={ addLink }\n\t\t\t\t\tisActive={ isActive }\n\t\t\t\t\tshortcutType=\"primary\"\n\t\t\t\t\tshortcutCharacter=\"k\"\n\t\t\t\t\taria-haspopup=\"true\"\n\t\t\t\t\taria-expanded={ addingLink || isActive }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t{ ( addingLink || isActive ) && (\n\t\t\t\t<InlineLinkUI\n\t\t\t\t\taddingLink={ addingLink }\n\t\t\t\t\tstopAddingLink={ stopAddingLink }\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\
|
|
1
|
+
{"version":3,"names":["__","useState","getTextContent","applyFormat","removeFormat","slice","isCollapsed","insert","create","isURL","isEmail","RichTextToolbarButton","RichTextShortcut","decodeEntities","link","linkIcon","linkOff","speak","InlineLinkUI","isValidHref","name","title","Edit","isActive","activeAttributes","value","onChange","onFocus","contentRef","addingLink","setAddingLink","addLink","text","type","attributes","url","stopAddingLink","returnFocus","onRemoveFormat","createElement","Fragment","character","onUse","icon","onClick","shortcutType","shortcutCharacter","tagName","className","id","_id","target","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 } 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, linkOff } 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\n\tfunction addLink() {\n\t\tconst text = getTextContent( slice( value ) );\n\n\t\tif ( 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 ( 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\tsetAddingLink( true );\n\t\t}\n\t}\n\n\tfunction stopAddingLink( returnFocus = true ) {\n\t\tsetAddingLink( false );\n\t\tif ( returnFocus ) {\n\t\t\tonFocus();\n\t\t}\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{ isActive && (\n\t\t\t\t<RichTextToolbarButton\n\t\t\t\t\tname=\"link\"\n\t\t\t\t\ticon={ linkOff }\n\t\t\t\t\ttitle={ __( 'Unlink' ) }\n\t\t\t\t\tonClick={ onRemoveFormat }\n\t\t\t\t\tisActive={ isActive }\n\t\t\t\t\tshortcutType=\"primaryShift\"\n\t\t\t\t\tshortcutCharacter=\"k\"\n\t\t\t\t\taria-haspopup=\"true\"\n\t\t\t\t\taria-expanded={ addingLink || isActive }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t{ ! isActive && (\n\t\t\t\t<RichTextToolbarButton\n\t\t\t\t\tname=\"link\"\n\t\t\t\t\ticon={ linkIcon }\n\t\t\t\t\ttitle={ title }\n\t\t\t\t\tonClick={ addLink }\n\t\t\t\t\tisActive={ isActive }\n\t\t\t\t\tshortcutType=\"primary\"\n\t\t\t\t\tshortcutCharacter=\"k\"\n\t\t\t\t\taria-haspopup=\"true\"\n\t\t\t\t\taria-expanded={ addingLink || isActive }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t{ ( addingLink || isActive ) && (\n\t\t\t\t<InlineLinkUI\n\t\t\t\t\taddingLink={ addingLink }\n\t\t\t\t\tstopAddingLink={ stopAddingLink }\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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AAC,EAAG;MAC3B,OAAOlB,MAAM,CACZkB,KAAK,EACLtB,WAAW,CACVK,MAAM,CAAE;QAAEwB,IAAI,EAAEuB;MAAU,CAAE,CAAC,EAC7BQ,MAAM,EACN,CAAC,EACDR,SAAS,CAACS,MACX,CACD,CAAC;IACF;IAEA,OAAO7D,WAAW,CAAEsB,KAAK,EAAEsC,MAAO,CAAC;EACpC,CAAC;EACDE,IAAI,EAAE3C;AACP,CAAC"}
|
|
@@ -4,7 +4,7 @@ import { createElement, Fragment } from "react";
|
|
|
4
4
|
*/
|
|
5
5
|
import { __ } from '@wordpress/i18n';
|
|
6
6
|
import { useCallback, useMemo, useState } from '@wordpress/element';
|
|
7
|
-
import { RichTextToolbarButton,
|
|
7
|
+
import { RichTextToolbarButton, useSettings } from '@wordpress/block-editor';
|
|
8
8
|
import { Icon, color as colorIcon, textColor as textColorIcon } from '@wordpress/icons';
|
|
9
9
|
import { removeFormat } from '@wordpress/rich-text';
|
|
10
10
|
|
|
@@ -49,8 +49,7 @@ function TextColorEdit({
|
|
|
49
49
|
activeAttributes,
|
|
50
50
|
contentRef
|
|
51
51
|
}) {
|
|
52
|
-
const allowCustomControl =
|
|
53
|
-
const colors = useSetting('color.palette') || EMPTY_ARRAY;
|
|
52
|
+
const [allowCustomControl, colors = EMPTY_ARRAY] = useSettings('color.custom', 'color.palette');
|
|
54
53
|
const [isAddingColor, setIsAddingColor] = useState(false);
|
|
55
54
|
const enableIsAddingColor = useCallback(() => setIsAddingColor(true), [setIsAddingColor]);
|
|
56
55
|
const disableIsAddingColor = useCallback(() => setIsAddingColor(false), [setIsAddingColor]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["__","useCallback","useMemo","useState","RichTextToolbarButton","
|
|
1
|
+
{"version":3,"names":["__","useCallback","useMemo","useState","RichTextToolbarButton","useSettings","Icon","color","colorIcon","textColor","textColorIcon","removeFormat","default","InlineColorUI","getActiveColors","transparentValue","name","title","EMPTY_ARRAY","getComputedStyleProperty","element","property","ownerDocument","defaultView","style","getComputedStyle","value","getPropertyValue","parentElement","fillComputedColors","backgroundColor","TextColorEdit","onChange","isActive","activeAttributes","contentRef","allowCustomControl","colors","isAddingColor","setIsAddingColor","enableIsAddingColor","disableIsAddingColor","colorIndicatorStyle","current","hasColorsToChoose","length","createElement","Fragment","className","icon","Object","keys","onClick","role","onClose","tagName","attributes","class","__unstableFilterAttributeValue","key","includes","addedCSS","join","edit"],"sources":["@wordpress/format-library/src/text-color/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useCallback, useMemo, useState } from '@wordpress/element';\nimport { RichTextToolbarButton, useSettings } from '@wordpress/block-editor';\nimport {\n\tIcon,\n\tcolor as colorIcon,\n\ttextColor as textColorIcon,\n} 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, colors = EMPTY_ARRAY ] = useSettings(\n\t\t'color.custom',\n\t\t'color.palette'\n\t);\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={\n\t\t\t\t\t\t\tObject.keys( activeAttributes ).length\n\t\t\t\t\t\t\t\t? textColorIcon\n\t\t\t\t\t\t\t\t: colorIcon\n\t\t\t\t\t\t}\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"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,EAAE,QAAQ,iBAAiB;AACpC,SAASC,WAAW,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,oBAAoB;AACnE,SAASC,qBAAqB,EAAEC,WAAW,QAAQ,yBAAyB;AAC5E,SACCC,IAAI,EACJC,KAAK,IAAIC,SAAS,EAClBC,SAAS,IAAIC,aAAa,QACpB,kBAAkB;AACzB,SAASC,YAAY,QAAQ,sBAAsB;;AAEnD;AACA;AACA;AACA,SAASC,OAAO,IAAIC,aAAa,EAAEC,eAAe,QAAQ,UAAU;AAEpE,OAAO,MAAMC,gBAAgB,GAAG,kBAAkB;AAElD,MAAMC,IAAI,GAAG,iBAAiB;AAC9B,MAAMC,KAAK,GAAGjB,EAAE,CAAE,WAAY,CAAC;AAE/B,MAAMkB,WAAW,GAAG,EAAE;AAE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P,SAAS,EAAE,kBAAkB;EAC7BQ,UAAU,EAAE;IACXhC,KAAK,EAAE,OAAO;IACdiC,KAAK,EAAE;EACR,CAAC;EACD;AACD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACCC,8BAA8BA,CAAEC,GAAG,EAAEjC,KAAK,EAAG;IAC5C,IAAKiC,GAAG,KAAK,OAAO,EAAG,OAAOjC,KAAK;IACnC;IACA,IAAKA,KAAK,IAAIA,KAAK,CAACkC,QAAQ,CAAE,kBAAmB,CAAC,EAAG,OAAOlC,KAAK;IACjE,MAAMmC,QAAQ,GAAG,CAAE,kBAAkB,EAAE9C,gBAAgB,CAAE,CAAC+C,IAAI,CAAE,GAAI,CAAC;IACrE;IACA;IACA,OAAOpC,KAAK,GAAG,CAAEmC,QAAQ,EAAEnC,KAAK,CAAE,CAACoC,IAAI,CAAE,GAAI,CAAC,GAAGD,QAAQ;EAC1D,CAAC;EACDE,IAAI,EAAEhC;AACP,CAAC"}
|
|
@@ -9,7 +9,7 @@ import { StyleSheet, View } from 'react-native';
|
|
|
9
9
|
*/
|
|
10
10
|
import { __ } from '@wordpress/i18n';
|
|
11
11
|
import { useCallback, useMemo, useState } from '@wordpress/element';
|
|
12
|
-
import { BlockControls,
|
|
12
|
+
import { BlockControls, useSettings } from '@wordpress/block-editor';
|
|
13
13
|
import { ToolbarGroup, ToolbarButton, useMobileGlobalStylesColors } from '@wordpress/components';
|
|
14
14
|
import { Icon, color as colorIcon, textColor as textColorIcon } from '@wordpress/icons';
|
|
15
15
|
import { removeFormat } from '@wordpress/rich-text';
|
|
@@ -62,7 +62,7 @@ function TextColorEdit({
|
|
|
62
62
|
activeAttributes,
|
|
63
63
|
contentRef
|
|
64
64
|
}) {
|
|
65
|
-
const allowCustomControl =
|
|
65
|
+
const [allowCustomControl] = useSettings('color.custom');
|
|
66
66
|
const colors = useMobileGlobalStylesColors();
|
|
67
67
|
const [isAddingColor, setIsAddingColor] = useState(false);
|
|
68
68
|
const enableIsAddingColor = useCallback(() => setIsAddingColor(true), [setIsAddingColor]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["StyleSheet","View","__","useCallback","useMemo","useState","BlockControls","useSetting","ToolbarGroup","ToolbarButton","useMobileGlobalStylesColors","Icon","color","colorIcon","textColor","textColorIcon","removeFormat","usePreferredColorSchemeStyle","getActiveColors","transparentValue","default","InlineColorUI","styles","name","title","getComputedStyleProperty","element","property","props","style","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","__unstableFilterAttributeValue","key","newValue","replace","includes","addedCSS","join","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, useSetting } 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 { 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 = [\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\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"],"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,UAAU,QAAQ,yBAAyB;AACnE,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,4BAA4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K,EAAG;IAC5C,IAAKkC,GAAG,KAAK,OAAO,EAAG,OAAOlC,KAAK;IACnC;IACA,MAAMmC,QAAQ,GAAGnC,KAAK,EAAEoC,OAAO,CAAE,IAAI,EAAE,EAAG,CAAC;IAC3C;IACA,IAAKD,QAAQ,IAAIA,QAAQ,CAACE,QAAQ,CAAE,kBAAmB,CAAC,EACvD,OAAOF,QAAQ;IAChB,MAAMG,QAAQ,GAAG,CAAE,kBAAkB,EAAEtD,gBAAgB,CAAE,CAACuD,IAAI,CAAE,GAAI,CAAC;IACrE;IACA;IACA,OAAOJ,QAAQ,GAAG,CAAEG,QAAQ,EAAEH,QAAQ,CAAE,CAACI,IAAI,CAAE,GAAI,CAAC,GAAGD,QAAQ;EAChE,CAAC;EACDE,IAAI,EAAEzC;AACP,CAAC"}
|
|
1
|
+
{"version":3,"names":["StyleSheet","View","__","useCallback","useMemo","useState","BlockControls","useSettings","ToolbarGroup","ToolbarButton","useMobileGlobalStylesColors","Icon","color","colorIcon","textColor","textColorIcon","removeFormat","usePreferredColorSchemeStyle","getActiveColors","transparentValue","default","InlineColorUI","styles","name","title","getComputedStyleProperty","element","property","props","style","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","__unstableFilterAttributeValue","key","newValue","replace","includes","addedCSS","join","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 { 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 ] = 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\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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AAa;IACbE,IAAI,EAAGA,IAAM;IACbwC,OAAO,EAAGlB,oBAAsB;IAChCP,gBAAgB,EAAGA,gBAAkB;IACrCH,KAAK,EAAGA,KAAO;IACfC,QAAQ,EAAGA,QAAU;IACrBG,UAAU,EAAGA;EAAY,CACzB,CAED,CAAC;AAEL;AAEA,OAAO,MAAMzB,SAAS,GAAG;EACxBS,IAAI;EACJC,KAAK;EACLwC,OAAO,EAAE,MAAM;EACfC,SAAS,EAAE,kBAAkB;EAC7BC,UAAU,EAAE;IACXrC,KAAK,EAAE,OAAO;IACdsC,KAAK,EAAE;EACR,CAAC;EACD;AACD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACCC,8BAA8BA,CAAEC,GAAG,EAAElC,KAAK,EAAG;IAC5C,IAAKkC,GAAG,KAAK,OAAO,EAAG,OAAOlC,KAAK;IACnC;IACA,MAAMmC,QAAQ,GAAGnC,KAAK,EAAEoC,OAAO,CAAE,IAAI,EAAE,EAAG,CAAC;IAC3C;IACA,IAAKD,QAAQ,IAAIA,QAAQ,CAACE,QAAQ,CAAE,kBAAmB,CAAC,EACvD,OAAOF,QAAQ;IAChB,MAAMG,QAAQ,GAAG,CAAE,kBAAkB,EAAEtD,gBAAgB,CAAE,CAACuD,IAAI,CAAE,GAAI,CAAC;IACrE;IACA;IACA,OAAOJ,QAAQ,GAAG,CAAEG,QAAQ,EAAEH,QAAQ,CAAE,CAACI,IAAI,CAAE,GAAI,CAAC,GAAGD,QAAQ;EAChE,CAAC;EACDE,IAAI,EAAEzC;AACP,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/format-library",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.21.1-next.f8d8eceb.0",
|
|
4
4
|
"description": "Format library for the WordPress editor.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -26,17 +26,17 @@
|
|
|
26
26
|
"react-native": "src/index",
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@babel/runtime": "^7.16.0",
|
|
29
|
-
"@wordpress/a11y": "^3.
|
|
30
|
-
"@wordpress/block-editor": "^12.
|
|
31
|
-
"@wordpress/components": "^25.
|
|
32
|
-
"@wordpress/compose": "^6.
|
|
33
|
-
"@wordpress/data": "^9.
|
|
34
|
-
"@wordpress/element": "^5.
|
|
35
|
-
"@wordpress/html-entities": "^3.
|
|
36
|
-
"@wordpress/i18n": "^4.
|
|
37
|
-
"@wordpress/icons": "^9.
|
|
38
|
-
"@wordpress/rich-text": "^6.
|
|
39
|
-
"@wordpress/url": "^3.
|
|
29
|
+
"@wordpress/a11y": "^3.44.1-next.f8d8eceb.0",
|
|
30
|
+
"@wordpress/block-editor": "^12.12.2-next.f8d8eceb.0",
|
|
31
|
+
"@wordpress/components": "^25.11.1-next.f8d8eceb.0",
|
|
32
|
+
"@wordpress/compose": "^6.21.1-next.f8d8eceb.0",
|
|
33
|
+
"@wordpress/data": "^9.14.1-next.f8d8eceb.0",
|
|
34
|
+
"@wordpress/element": "^5.21.1-next.f8d8eceb.0",
|
|
35
|
+
"@wordpress/html-entities": "^3.44.1-next.f8d8eceb.0",
|
|
36
|
+
"@wordpress/i18n": "^4.44.1-next.f8d8eceb.0",
|
|
37
|
+
"@wordpress/icons": "^9.35.1-next.f8d8eceb.0",
|
|
38
|
+
"@wordpress/rich-text": "^6.21.1-next.f8d8eceb.0",
|
|
39
|
+
"@wordpress/url": "^3.45.1-next.f8d8eceb.0"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
42
|
"react": "^18.0.0",
|
|
@@ -45,5 +45,5 @@
|
|
|
45
45
|
"publishConfig": {
|
|
46
46
|
"access": "public"
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "8d8fd197e202b8104ffb1cb83048efd0a6c3faf4"
|
|
49
49
|
}
|
package/src/link/index.js
CHANGED
|
@@ -9,6 +9,8 @@ import {
|
|
|
9
9
|
removeFormat,
|
|
10
10
|
slice,
|
|
11
11
|
isCollapsed,
|
|
12
|
+
insert,
|
|
13
|
+
create,
|
|
12
14
|
} from '@wordpress/rich-text';
|
|
13
15
|
import { isURL, isEmail } from '@wordpress/url';
|
|
14
16
|
import {
|
|
@@ -135,28 +137,39 @@ export const link = {
|
|
|
135
137
|
rel: 'rel',
|
|
136
138
|
},
|
|
137
139
|
__unstablePasteRule( value, { html, plainText } ) {
|
|
138
|
-
if ( isCollapsed( value ) ) {
|
|
139
|
-
return value;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
140
|
const pastedText = ( html || plainText )
|
|
143
141
|
.replace( /<[^>]+>/g, '' )
|
|
144
142
|
.trim();
|
|
145
143
|
|
|
146
144
|
// A URL was pasted, turn the selection into a link.
|
|
147
|
-
|
|
145
|
+
// For the link pasting feature, allow only http(s) protocols.
|
|
146
|
+
if ( ! isURL( pastedText ) || ! /^https?:/.test( pastedText ) ) {
|
|
148
147
|
return value;
|
|
149
148
|
}
|
|
150
149
|
|
|
151
150
|
// Allows us to ask for this information when we get a report.
|
|
152
151
|
window.console.log( 'Created link:\n\n', pastedText );
|
|
153
152
|
|
|
154
|
-
|
|
153
|
+
const format = {
|
|
155
154
|
type: name,
|
|
156
155
|
attributes: {
|
|
157
156
|
url: decodeEntities( pastedText ),
|
|
158
157
|
},
|
|
159
|
-
}
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
if ( isCollapsed( value ) ) {
|
|
161
|
+
return insert(
|
|
162
|
+
value,
|
|
163
|
+
applyFormat(
|
|
164
|
+
create( { text: plainText } ),
|
|
165
|
+
format,
|
|
166
|
+
0,
|
|
167
|
+
plainText.length
|
|
168
|
+
)
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
return applyFormat( value, format );
|
|
160
173
|
},
|
|
161
174
|
edit: Edit,
|
|
162
175
|
};
|
package/src/text-color/index.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { __ } from '@wordpress/i18n';
|
|
5
5
|
import { useCallback, useMemo, useState } from '@wordpress/element';
|
|
6
|
-
import { RichTextToolbarButton,
|
|
6
|
+
import { RichTextToolbarButton, useSettings } from '@wordpress/block-editor';
|
|
7
7
|
import {
|
|
8
8
|
Icon,
|
|
9
9
|
color as colorIcon,
|
|
@@ -61,8 +61,10 @@ function TextColorEdit( {
|
|
|
61
61
|
activeAttributes,
|
|
62
62
|
contentRef,
|
|
63
63
|
} ) {
|
|
64
|
-
const allowCustomControl =
|
|
65
|
-
|
|
64
|
+
const [ allowCustomControl, colors = EMPTY_ARRAY ] = useSettings(
|
|
65
|
+
'color.custom',
|
|
66
|
+
'color.palette'
|
|
67
|
+
);
|
|
66
68
|
const [ isAddingColor, setIsAddingColor ] = useState( false );
|
|
67
69
|
const enableIsAddingColor = useCallback(
|
|
68
70
|
() => setIsAddingColor( true ),
|
|
@@ -8,7 +8,7 @@ import { StyleSheet, View } from 'react-native';
|
|
|
8
8
|
*/
|
|
9
9
|
import { __ } from '@wordpress/i18n';
|
|
10
10
|
import { useCallback, useMemo, useState } from '@wordpress/element';
|
|
11
|
-
import { BlockControls,
|
|
11
|
+
import { BlockControls, useSettings } from '@wordpress/block-editor';
|
|
12
12
|
import {
|
|
13
13
|
ToolbarGroup,
|
|
14
14
|
ToolbarButton,
|
|
@@ -72,7 +72,7 @@ function TextColorEdit( {
|
|
|
72
72
|
activeAttributes,
|
|
73
73
|
contentRef,
|
|
74
74
|
} ) {
|
|
75
|
-
const allowCustomControl =
|
|
75
|
+
const [ allowCustomControl ] = useSettings( 'color.custom' );
|
|
76
76
|
const colors = useMobileGlobalStylesColors();
|
|
77
77
|
const [ isAddingColor, setIsAddingColor ] = useState( false );
|
|
78
78
|
const enableIsAddingColor = useCallback(
|