@wordpress/format-library 4.16.0 → 4.17.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/bold/index.js +1 -10
- package/build/bold/index.js.map +1 -1
- package/build/code/index.js +3 -17
- package/build/code/index.js.map +1 -1
- package/build/default-formats.js +0 -14
- package/build/default-formats.js.map +1 -1
- package/build/default-formats.native.js +0 -6
- package/build/default-formats.native.js.map +1 -1
- package/build/image/index.js +5 -14
- package/build/image/index.js.map +1 -1
- package/build/index.js +1 -3
- package/build/index.js.map +1 -1
- package/build/italic/index.js +1 -10
- package/build/italic/index.js.map +1 -1
- package/build/keyboard/index.js +1 -10
- package/build/keyboard/index.js.map +1 -1
- package/build/language/index.js +1 -11
- package/build/language/index.js.map +1 -1
- package/build/link/index.js +5 -26
- package/build/link/index.js.map +1 -1
- package/build/link/index.native.js +14 -39
- package/build/link/index.native.js.map +1 -1
- package/build/link/inline.js +41 -78
- package/build/link/inline.js.map +1 -1
- package/build/link/modal-screens/link-picker-screen.native.js +1 -13
- package/build/link/modal-screens/link-picker-screen.native.js.map +1 -1
- package/build/link/modal-screens/link-settings-screen.native.js +9 -36
- package/build/link/modal-screens/link-settings-screen.native.js.map +1 -1
- package/build/link/modal-screens/screens.native.js.map +1 -1
- package/build/link/modal.native.js +1 -9
- package/build/link/modal.native.js.map +1 -1
- package/build/link/use-link-instance-key.js +3 -7
- package/build/link/use-link-instance-key.js.map +1 -1
- package/build/link/utils.js +23 -47
- package/build/link/utils.js.map +1 -1
- package/build/strikethrough/index.js +1 -9
- package/build/strikethrough/index.js.map +1 -1
- package/build/subscript/index.js +1 -10
- package/build/subscript/index.js.map +1 -1
- package/build/superscript/index.js +1 -10
- package/build/superscript/index.js.map +1 -1
- package/build/text-color/index.js +7 -25
- package/build/text-color/index.js.map +1 -1
- package/build/text-color/index.native.js +11 -34
- package/build/text-color/index.native.js.map +1 -1
- package/build/text-color/inline.js +5 -26
- package/build/text-color/inline.js.map +1 -1
- package/build/text-color/inline.native.js +9 -25
- package/build/text-color/inline.native.js.map +1 -1
- package/build/underline/index.js +1 -8
- package/build/underline/index.js.map +1 -1
- package/build/unknown/index.js +1 -11
- package/build/unknown/index.js.map +1 -1
- package/build-module/bold/index.js +0 -7
- package/build-module/bold/index.js.map +1 -1
- package/build-module/code/index.js +2 -14
- package/build-module/code/index.js.map +1 -1
- package/build-module/default-formats.js.map +1 -1
- package/build-module/default-formats.native.js.map +1 -1
- package/build-module/image/index.js +4 -10
- package/build-module/image/index.js.map +1 -1
- package/build-module/index.js +1 -1
- package/build-module/index.js.map +1 -1
- package/build-module/italic/index.js +0 -7
- package/build-module/italic/index.js.map +1 -1
- package/build-module/keyboard/index.js +0 -7
- package/build-module/keyboard/index.js.map +1 -1
- package/build-module/language/index.js +1 -8
- package/build-module/language/index.js.map +1 -1
- package/build-module/link/index.js +5 -17
- package/build-module/link/index.js.map +1 -1
- package/build-module/link/index.native.js +15 -30
- package/build-module/link/index.native.js.map +1 -1
- package/build-module/link/inline.js +42 -69
- package/build-module/link/inline.js.map +1 -1
- package/build-module/link/modal-screens/link-picker-screen.native.js +2 -8
- package/build-module/link/modal-screens/link-picker-screen.native.js.map +1 -1
- package/build-module/link/modal-screens/link-settings-screen.native.js +10 -28
- package/build-module/link/modal-screens/link-settings-screen.native.js.map +1 -1
- package/build-module/link/modal-screens/screens.native.js.map +1 -1
- package/build-module/link/modal.native.js +1 -4
- package/build-module/link/modal.native.js.map +1 -1
- package/build-module/link/use-link-instance-key.js +3 -7
- package/build-module/link/use-link-instance-key.js.map +1 -1
- package/build-module/link/utils.js +24 -43
- package/build-module/link/utils.js.map +1 -1
- package/build-module/strikethrough/index.js +0 -6
- package/build-module/strikethrough/index.js.map +1 -1
- package/build-module/subscript/index.js +0 -7
- package/build-module/subscript/index.js.map +1 -1
- package/build-module/superscript/index.js +0 -7
- package/build-module/superscript/index.js.map +1 -1
- package/build-module/text-color/index.js +7 -20
- package/build-module/text-color/index.js.map +1 -1
- package/build-module/text-color/index.native.js +12 -24
- package/build-module/text-color/index.native.js.map +1 -1
- package/build-module/text-color/inline.js +5 -20
- package/build-module/text-color/inline.js.map +1 -1
- package/build-module/text-color/inline.native.js +9 -21
- package/build-module/text-color/inline.native.js.map +1 -1
- package/build-module/underline/index.js +0 -6
- package/build-module/underline/index.js.map +1 -1
- package/build-module/unknown/index.js +0 -8
- package/build-module/unknown/index.js.map +1 -1
- package/package.json +13 -13
- package/src/link/inline.js +11 -34
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { createElement, Fragment } from "@wordpress/element";
|
|
2
|
-
|
|
3
2
|
/**
|
|
4
3
|
* External dependencies
|
|
5
4
|
*/
|
|
6
5
|
import { StyleSheet, View } from 'react-native';
|
|
6
|
+
|
|
7
7
|
/**
|
|
8
8
|
* WordPress dependencies
|
|
9
9
|
*/
|
|
10
|
-
|
|
11
10
|
import { __ } from '@wordpress/i18n';
|
|
12
11
|
import { useCallback, useMemo, useState } from '@wordpress/element';
|
|
13
12
|
import { BlockControls, useSetting } from '@wordpress/block-editor';
|
|
@@ -15,41 +14,35 @@ import { ToolbarGroup, ToolbarButton, useMobileGlobalStylesColors } from '@wordp
|
|
|
15
14
|
import { Icon, color as colorIcon, textColor as textColorIcon } from '@wordpress/icons';
|
|
16
15
|
import { removeFormat } from '@wordpress/rich-text';
|
|
17
16
|
import { usePreferredColorSchemeStyle } from '@wordpress/compose';
|
|
17
|
+
|
|
18
18
|
/**
|
|
19
19
|
* Internal dependencies
|
|
20
20
|
*/
|
|
21
|
-
|
|
22
21
|
import { getActiveColors } from './inline.js';
|
|
23
22
|
import { transparentValue } from './index.js';
|
|
24
23
|
import { default as InlineColorUI } from './inline';
|
|
25
24
|
import styles from './style.scss';
|
|
26
25
|
const name = 'core/text-color';
|
|
27
|
-
|
|
28
26
|
const title = __('Text color');
|
|
29
|
-
|
|
30
27
|
function getComputedStyleProperty(element, property) {
|
|
31
28
|
const {
|
|
32
29
|
props: {
|
|
33
30
|
style = {}
|
|
34
31
|
}
|
|
35
32
|
} = element;
|
|
36
|
-
|
|
37
33
|
if (property === 'background-color') {
|
|
38
34
|
const {
|
|
39
35
|
backgroundColor,
|
|
40
36
|
baseColors
|
|
41
37
|
} = style;
|
|
42
|
-
|
|
43
38
|
if (backgroundColor !== 'transparent') {
|
|
44
39
|
return backgroundColor;
|
|
45
40
|
} else if (baseColors && baseColors?.color?.background) {
|
|
46
41
|
return baseColors?.color?.background;
|
|
47
42
|
}
|
|
48
|
-
|
|
49
43
|
return 'transparent';
|
|
50
44
|
}
|
|
51
45
|
}
|
|
52
|
-
|
|
53
46
|
function fillComputedColors(element, {
|
|
54
47
|
color,
|
|
55
48
|
backgroundColor
|
|
@@ -57,13 +50,11 @@ function fillComputedColors(element, {
|
|
|
57
50
|
if (!color && !backgroundColor) {
|
|
58
51
|
return;
|
|
59
52
|
}
|
|
60
|
-
|
|
61
53
|
return {
|
|
62
54
|
color: color || getComputedStyleProperty(element, 'color'),
|
|
63
55
|
backgroundColor: getComputedStyleProperty(element, 'background-color')
|
|
64
56
|
};
|
|
65
57
|
}
|
|
66
|
-
|
|
67
58
|
function TextColorEdit({
|
|
68
59
|
value,
|
|
69
60
|
onChange,
|
|
@@ -88,12 +79,11 @@ function TextColorEdit({
|
|
|
88
79
|
const outlineStyle = [usePreferredColorSchemeStyle(styles['components-inline-color__outline'], styles['components-inline-color__outline--dark']), {
|
|
89
80
|
borderWidth: StyleSheet.hairlineWidth
|
|
90
81
|
}];
|
|
91
|
-
|
|
92
82
|
if (!hasColorsToChoose && !isActive) {
|
|
93
83
|
return null;
|
|
94
84
|
}
|
|
95
|
-
|
|
96
|
-
|
|
85
|
+
const isActiveStyle = {
|
|
86
|
+
...colorIndicatorStyle,
|
|
97
87
|
...(!colorIndicatorStyle?.backgroundColor ? {
|
|
98
88
|
backgroundColor: 'transparent'
|
|
99
89
|
} : {}),
|
|
@@ -116,7 +106,8 @@ function TextColorEdit({
|
|
|
116
106
|
extraProps: {
|
|
117
107
|
isActiveStyle,
|
|
118
108
|
customContainerStyles
|
|
119
|
-
}
|
|
109
|
+
}
|
|
110
|
+
// If has no colors to choose but a color is active remove the color onClick
|
|
120
111
|
,
|
|
121
112
|
onClick: onPressButton
|
|
122
113
|
}))), isAddingColor && createElement(InlineColorUI, {
|
|
@@ -128,7 +119,6 @@ function TextColorEdit({
|
|
|
128
119
|
contentRef: contentRef
|
|
129
120
|
}));
|
|
130
121
|
}
|
|
131
|
-
|
|
132
122
|
export const textColor = {
|
|
133
123
|
name,
|
|
134
124
|
title,
|
|
@@ -138,7 +128,6 @@ export const textColor = {
|
|
|
138
128
|
style: 'style',
|
|
139
129
|
class: 'class'
|
|
140
130
|
},
|
|
141
|
-
|
|
142
131
|
/*
|
|
143
132
|
* Since this format relies on the <mark> tag, it's important to
|
|
144
133
|
* prevent the default yellow background color applied by most
|
|
@@ -149,17 +138,16 @@ export const textColor = {
|
|
|
149
138
|
* @see https://github.com/WordPress/gutenberg/pull/35516
|
|
150
139
|
*/
|
|
151
140
|
__unstableFilterAttributeValue(key, value) {
|
|
152
|
-
if (key !== 'style') return value;
|
|
153
|
-
|
|
154
|
-
const newValue = value?.replace(/ /g, '');
|
|
155
|
-
|
|
141
|
+
if (key !== 'style') return value;
|
|
142
|
+
// We need to remove the extra spaces within the styles on mobile
|
|
143
|
+
const newValue = value?.replace(/ /g, '');
|
|
144
|
+
// We should not add a background-color if it's already set
|
|
156
145
|
if (newValue && newValue.includes('background-color')) return newValue;
|
|
157
|
-
const addedCSS = ['background-color', transparentValue].join(':');
|
|
146
|
+
const addedCSS = ['background-color', transparentValue].join(':');
|
|
147
|
+
// Prepend `addedCSS` to avoid a double `;;` as any the existing CSS
|
|
158
148
|
// rules will already include a `;`.
|
|
159
|
-
|
|
160
149
|
return newValue ? [addedCSS, newValue].join(';') : addedCSS;
|
|
161
150
|
},
|
|
162
|
-
|
|
163
151
|
edit: TextColorEdit
|
|
164
152
|
};
|
|
165
153
|
//# sourceMappingURL=index.native.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/format-library/src/text-color/index.native.js"],"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","Object","keys","tagName","className","attributes","class","__unstableFilterAttributeValue","key","newValue","replace","includes","addedCSS","join","edit"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,UAAT,EAAqBC,IAArB,QAAiC,cAAjC;AAEA;AACA;AACA;;AACA,SAASC,EAAT,QAAmB,iBAAnB;AACA,SAASC,WAAT,EAAsBC,OAAtB,EAA+BC,QAA/B,QAA+C,oBAA/C;AACA,SAASC,aAAT,EAAwBC,UAAxB,QAA0C,yBAA1C;AACA,SACCC,YADD,EAECC,aAFD,EAGCC,2BAHD,QAIO,uBAJP;AAKA,SACCC,IADD,EAECC,KAAK,IAAIC,SAFV,EAGCC,SAAS,IAAIC,aAHd,QAIO,kBAJP;AAKA,SAASC,YAAT,QAA6B,sBAA7B;AACA,SAASC,4BAAT,QAA6C,oBAA7C;AAEA;AACA;AACA;;AACA,SAASC,eAAT,QAAgC,aAAhC;AACA,SAASC,gBAAT,QAAiC,YAAjC;AACA,SAASC,OAAO,IAAIC,aAApB,QAAyC,UAAzC;AACA,OAAOC,MAAP,MAAmB,cAAnB;AAEA,MAAMC,IAAI,GAAG,iBAAb;;AACA,MAAMC,KAAK,GAAGtB,EAA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EAAuB,OAAO3B,KAAP,CADqB,CAE5C;;AACA,UAAM4B,QAAQ,GAAG5B,KAAK,EAAE6B,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,EAAsB/C,gBAAtB,EAAyCgD,IAAzC,CAA+C,GAA/C,CAAjB,CAP4C,CAQ5C;AACA;;AACA,WAAOJ,QAAQ,GAAG,CAAEG,QAAF,EAAYH,QAAZ,EAAuBI,IAAvB,CAA6B,GAA7B,CAAH,GAAwCD,QAAvD;AACA,GA7BuB;;AA8BxBE,EAAAA,IAAI,EAAElC;AA9BkB,CAAlB","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"]}
|
|
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,4BAA4B,QAAQ,oBAAoB;;AAEjE;AACA;AACA;AACA,SAASC,eAAe,QAAQ,aAAa;AAC7C,SAASC,gBAAgB,QAAQ,YAAY;AAC7C,SAASC,OAAO,IAAIC,aAAa,QAAQ,UAAU;AACnD,OAAOC,MAAM,MAAM,cAAc;AAEjC,MAAMC,IAAI,GAAG,iBAAiB;AAC9B,MAAMC,KAAK,GAAGtB,EAAE,CAAE,YAAa,CAAC;AAEhC,SAASuB,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,EAAG;MACxC,OAAOA,eAAe;IACvB,CAAC,M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
|
/**
|
|
4
3
|
* WordPress dependencies
|
|
5
4
|
*/
|
|
@@ -9,12 +8,11 @@ import { applyFormat, removeFormat, getActiveFormat, useAnchor } from '@wordpres
|
|
|
9
8
|
import { ColorPalette, getColorClassName, getColorObjectByColorValue, getColorObjectByAttributeValues, store as blockEditorStore, useCachedTruthy } from '@wordpress/block-editor';
|
|
10
9
|
import { Popover, TabPanel } from '@wordpress/components';
|
|
11
10
|
import { __ } from '@wordpress/i18n';
|
|
11
|
+
|
|
12
12
|
/**
|
|
13
13
|
* Internal dependencies
|
|
14
14
|
*/
|
|
15
|
-
|
|
16
15
|
import { textColor as settings, transparentValue } from './index';
|
|
17
|
-
|
|
18
16
|
function parseCSS(css = '') {
|
|
19
17
|
return css.split(';').reduce((accumulator, rule) => {
|
|
20
18
|
if (rule) {
|
|
@@ -22,11 +20,9 @@ function parseCSS(css = '') {
|
|
|
22
20
|
if (property === 'color') accumulator.color = value;
|
|
23
21
|
if (property === 'background-color' && value !== transparentValue) accumulator.backgroundColor = value;
|
|
24
22
|
}
|
|
25
|
-
|
|
26
23
|
return accumulator;
|
|
27
24
|
}, {});
|
|
28
25
|
}
|
|
29
|
-
|
|
30
26
|
export function parseClassName(className = '', colorSettings) {
|
|
31
27
|
return className.split(' ').reduce((accumulator, name) => {
|
|
32
28
|
// `colorSlug` could contain dashes, so simply match the start and end.
|
|
@@ -35,55 +31,47 @@ export function parseClassName(className = '', colorSettings) {
|
|
|
35
31
|
const colorObject = getColorObjectByAttributeValues(colorSettings, colorSlug);
|
|
36
32
|
accumulator.color = colorObject.color;
|
|
37
33
|
}
|
|
38
|
-
|
|
39
34
|
return accumulator;
|
|
40
35
|
}, {});
|
|
41
36
|
}
|
|
42
37
|
export function getActiveColors(value, name, colorSettings) {
|
|
43
38
|
const activeColorFormat = getActiveFormat(value, name);
|
|
44
|
-
|
|
45
39
|
if (!activeColorFormat) {
|
|
46
40
|
return {};
|
|
47
41
|
}
|
|
48
|
-
|
|
49
|
-
|
|
42
|
+
return {
|
|
43
|
+
...parseCSS(activeColorFormat.attributes.style),
|
|
50
44
|
...parseClassName(activeColorFormat.attributes.class, colorSettings)
|
|
51
45
|
};
|
|
52
46
|
}
|
|
53
|
-
|
|
54
47
|
function setColors(value, name, colorSettings, colors) {
|
|
55
48
|
const {
|
|
56
49
|
color,
|
|
57
50
|
backgroundColor
|
|
58
|
-
} = {
|
|
51
|
+
} = {
|
|
52
|
+
...getActiveColors(value, name, colorSettings),
|
|
59
53
|
...colors
|
|
60
54
|
};
|
|
61
|
-
|
|
62
55
|
if (!color && !backgroundColor) {
|
|
63
56
|
return removeFormat(value, name);
|
|
64
57
|
}
|
|
65
|
-
|
|
66
58
|
const styles = [];
|
|
67
59
|
const classNames = [];
|
|
68
60
|
const attributes = {};
|
|
69
|
-
|
|
70
61
|
if (backgroundColor) {
|
|
71
62
|
styles.push(['background-color', backgroundColor].join(':'));
|
|
72
63
|
} else {
|
|
73
64
|
// Override default browser color for mark element.
|
|
74
65
|
styles.push(['background-color', transparentValue].join(':'));
|
|
75
66
|
}
|
|
76
|
-
|
|
77
67
|
if (color) {
|
|
78
68
|
const colorObject = getColorObjectByColorValue(colorSettings, color);
|
|
79
|
-
|
|
80
69
|
if (colorObject) {
|
|
81
70
|
classNames.push(getColorClassName('color', colorObject.slug));
|
|
82
71
|
} else {
|
|
83
72
|
styles.push(['color', color].join(':'));
|
|
84
73
|
}
|
|
85
74
|
}
|
|
86
|
-
|
|
87
75
|
if (styles.length) attributes.style = styles.join(';');
|
|
88
76
|
if (classNames.length) attributes.class = classNames.join(' ');
|
|
89
77
|
return applyFormat(value, {
|
|
@@ -91,7 +79,6 @@ function setColors(value, name, colorSettings, colors) {
|
|
|
91
79
|
attributes
|
|
92
80
|
});
|
|
93
81
|
}
|
|
94
|
-
|
|
95
82
|
function ColorPicker({
|
|
96
83
|
name,
|
|
97
84
|
property,
|
|
@@ -100,7 +87,6 @@ function ColorPicker({
|
|
|
100
87
|
}) {
|
|
101
88
|
const colors = useSelect(select => {
|
|
102
89
|
var _getSettings$colors;
|
|
103
|
-
|
|
104
90
|
const {
|
|
105
91
|
getSettings
|
|
106
92
|
} = select(blockEditorStore);
|
|
@@ -117,7 +103,6 @@ function ColorPicker({
|
|
|
117
103
|
onChange: onColorChange
|
|
118
104
|
});
|
|
119
105
|
}
|
|
120
|
-
|
|
121
106
|
export default function InlineColorUI({
|
|
122
107
|
name,
|
|
123
108
|
value,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/format-library/src/text-color/inline.js"],"names":["useCallback","useMemo","useSelect","applyFormat","removeFormat","getActiveFormat","useAnchor","ColorPalette","getColorClassName","getColorObjectByColorValue","getColorObjectByAttributeValues","store","blockEditorStore","useCachedTruthy","Popover","TabPanel","__","textColor","settings","transparentValue","parseCSS","css","split","reduce","accumulator","rule","property","value","color","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","onColorChange","activeColors","InlineColorUI","onClose","contentRef","popoverAnchor","editableContentElement","current","title","tab"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,WAAT,EAAsBC,OAAtB,QAAqC,oBAArC;AACA,SAASC,SAAT,QAA0B,iBAA1B;AACA,SACCC,WADD,EAECC,YAFD,EAGCC,eAHD,EAICC,SAJD,QAKO,sBALP;AAMA,SACCC,YADD,EAECC,iBAFD,EAGCC,0BAHD,EAICC,+BAJD,EAKCC,KAAK,IAAIC,gBALV,EAMCC,eAND,QAOO,yBAPP;AAQA,SAASC,OAAT,EAAkBC,QAAlB,QAAkC,uBAAlC;AACA,SAASC,EAAT,QAAmB,iBAAnB;AAEA;AACA;AACA;;AACA,SAASC,SAAS,IAAIC,QAAtB,EAAgCC,gBAAhC,QAAwD,SAAxD;;AAEA,SAASC,QAAT,CAAmBC,GAAG,GAAG,EAAzB,EAA8B;AAC7B,S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AG+B;AAFZ,IADD;AAMA;;AAED,eAAe,SAASE,aAAT,CAAwB;AACtC1B,EAAAA,IADsC;AAEtCN,EAAAA,KAFsC;AAGtC2B,EAAAA,QAHsC;AAItCM,EAAAA,OAJsC;AAKtCC,EAAAA;AALsC,CAAxB,EAMX;AACH;AACD;AACA;AACA;AACA;AACA;AACA;AACC,QAAMC,aAAa,GAAGjD,eAAe,CACpCP,SAAS,CAAE;AACVyD,IAAAA,sBAAsB,EAAEF,UAAU,CAACG,OADzB;AAEV9C,IAAAA;AAFU,GAAF,CAD2B,CAArC;AAOA,SACC,cAAC,OAAD;AACC,IAAA,OAAO,EAAG0C,OADX;AAEC,IAAA,SAAS,EAAC,iCAFX;AAGC,IAAA,MAAM,EAAGE;AAHV,KAKC,cAAC,QAAD;AACC,IAAA,IAAI,EAAG,CACN;AACC7B,MAAAA,IAAI,EAAE,OADP;AAECgC,MAAAA,KAAK,EAAEjD,EAAE,CAAE,MAAF;AAFV,KADM,EAKN;AACCiB,MAAAA,IAAI,EAAE,iBADP;AAECgC,MAAAA,KAAK,EAAEjD,EAAE,CAAE,YAAF;AAFV,KALM;AADR,KAYKkD,GAAF,IACD,cAAC,WAAD;AACC,IAAA,IAAI,EAAGjC,IADR;AAEC,IAAA,QAAQ,EAAGiC,GAAG,CAACjC,IAFhB;AAGC,IAAA,KAAK,EAAGN,KAHT;AAIC,IAAA,QAAQ,EAAG2B;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\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"]}
|
|
1
|
+
{"version":3,"names":["useCallback","useMemo","useSelect","applyFormat","removeFormat","getActiveFormat","useAnchor","ColorPalette","getColorClassName","getColorObjectByColorValue","getColorObjectByAttributeValues","store","blockEditorStore","useCachedTruthy","Popover","TabPanel","__","textColor","settings","transparentValue","parseCSS","css","split","reduce","accumulator","rule","property","value","color","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$colors","getSettings","onColorChange","activeColors","createElement","InlineColorUI","onClose","contentRef","popoverAnchor","editableContentElement","current","anchor","tabs","title","tab"],"sources":["@wordpress/format-library/src/text-color/inline.js"],"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\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"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,WAAW,EAAEC,OAAO,QAAQ,oBAAoB;AACzD,SAASC,SAAS,QAAQ,iBAAiB;AAC3C,SACCC,WAAW,EACXC,YAAY,EACZC,eAAe,EACfC,SAAS,QACH,sBAAsB;AAC7B,SACCC,YAAY,EACZC,iBAAiB,EACjBC,0BAA0B,EAC1BC,+BAA+B,EAC/BC,KAAK,IAAIC,gBAAgB,EACzBC,eAAe,QACT,yBAAyB;AAChC,SAASC,OAAO,EAAEC,QAAQ,QAAQ,uBAAuB;AACzD,SAASC,EAAE,QAAQ,iBAAiB;;AAEpC;AACA;AACA;AACA,SAASC,SAAS,IAAIC,QAAQ,EAAEC,gBAAgB,QAAQ,SAAS;AAEjE,SAASC,QAAQA,CAAEC,GAAG,GAAG,EAAE,EAAG;EAC7B,OAAOA,GAAG,CAACC,KAAK,CAAE,GAAI,CAAC,CAACC,MAAM,CAAE,CAAEC,WAAW,EAAEC,IAAI,KAAM;IACxD,IAAKA,IAAI,EAAG;MACX,MAAM,CAAEC,QAAQ,EAAEC,KAAK,CAAE,GAAGF,IAAI,CAACH,KAAK,CAAE,GAAI,CAAC;MAC7C,IAAKI,QAAQ,KAAK,OAAO,EAAGF,WAAW,CAACI,KAAK,GAAGD,KAAK;MACrD,IAAKD,QAAQ,KAAK,kBAAkB,IAAIC,K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C3CoC,MAAM,EAAGH;EAAe,GAExBJ,aAAA,CAAC7C,QAAQ;IACRqD,IAAI,EAAG,CACN;MACCnC,IAAI,EAAE,OAAO;MACboC,KAAK,EAAErD,EAAE,CAAE,MAAO;IACnB,CAAC,EACD;MACCiB,IAAI,EAAE,iBAAiB;MACvBoC,KAAK,EAAErD,EAAE,CAAE,YAAa;IACzB,CAAC;EACC,GAECsD,GAAG,IACNV,aAAA,CAACP,WAAW;IACXpB,IAAI,EAAGA,IAAM;IACbP,QAAQ,EAAG4C,GAAG,CAACrC,IAAM;IACrBN,KAAK,EAAGA,KAAO;IACf2B,QAAQ,EAAGA;EAAU,CACrB,CAEO,CACF,CAAC;AAEZ"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { createElement } from "@wordpress/element";
|
|
2
|
-
|
|
3
2
|
/**
|
|
4
3
|
* WordPress dependencies
|
|
5
4
|
*/
|
|
@@ -7,13 +6,12 @@ import { useCallback, useMemo } from '@wordpress/element';
|
|
|
7
6
|
import { applyFormat, removeFormat, getActiveFormat } from '@wordpress/rich-text';
|
|
8
7
|
import { getColorClassName, getColorObjectByColorValue, useMultipleOriginColorsAndGradients } from '@wordpress/block-editor';
|
|
9
8
|
import { BottomSheet, ColorSettings, useMobileGlobalStylesColors } from '@wordpress/components';
|
|
9
|
+
|
|
10
10
|
/**
|
|
11
11
|
* Internal dependencies
|
|
12
12
|
*/
|
|
13
|
-
|
|
14
13
|
import { transparentValue } from './index.js';
|
|
15
14
|
import { parseClassName } from './inline.js';
|
|
16
|
-
|
|
17
15
|
function parseCSS(css = '') {
|
|
18
16
|
return css.split(';').reduce((accumulator, rule) => {
|
|
19
17
|
if (rule) {
|
|
@@ -21,49 +19,41 @@ function parseCSS(css = '') {
|
|
|
21
19
|
if (property === 'color') accumulator.color = value;
|
|
22
20
|
if (property === 'background-color' && value !== transparentValue) accumulator.backgroundColor = value;
|
|
23
21
|
}
|
|
24
|
-
|
|
25
22
|
return accumulator;
|
|
26
23
|
}, {});
|
|
27
24
|
}
|
|
28
|
-
|
|
29
25
|
function getActiveColors(value, name, colorSettings) {
|
|
30
26
|
const activeColorFormat = getActiveFormat(value, name);
|
|
31
|
-
|
|
32
27
|
if (!activeColorFormat) {
|
|
33
28
|
return {};
|
|
34
29
|
}
|
|
35
|
-
|
|
36
|
-
|
|
30
|
+
return {
|
|
31
|
+
...parseCSS(activeColorFormat.attributes.style),
|
|
37
32
|
...parseClassName(activeColorFormat.attributes.class, colorSettings)
|
|
38
33
|
};
|
|
39
34
|
}
|
|
40
|
-
|
|
41
35
|
function setColors(value, name, colorSettings, colors) {
|
|
42
36
|
const {
|
|
43
37
|
color,
|
|
44
38
|
backgroundColor
|
|
45
|
-
} = {
|
|
39
|
+
} = {
|
|
40
|
+
...getActiveColors(value, name, colorSettings),
|
|
46
41
|
...colors
|
|
47
42
|
};
|
|
48
|
-
|
|
49
43
|
if (!color && !backgroundColor) {
|
|
50
44
|
return removeFormat(value, name);
|
|
51
45
|
}
|
|
52
|
-
|
|
53
46
|
const styles = [];
|
|
54
47
|
const classNames = [];
|
|
55
48
|
const attributes = {};
|
|
56
|
-
|
|
57
49
|
if (backgroundColor) {
|
|
58
50
|
styles.push(['background-color', backgroundColor].join(':'));
|
|
59
51
|
} else {
|
|
60
52
|
// Override default browser color for mark element.
|
|
61
53
|
styles.push(['background-color', transparentValue].join(':'));
|
|
62
54
|
}
|
|
63
|
-
|
|
64
55
|
if (color) {
|
|
65
56
|
const colorObject = getColorObjectByColorValue(colorSettings, color);
|
|
66
|
-
|
|
67
57
|
if (colorObject) {
|
|
68
58
|
classNames.push(getColorClassName('color', colorObject.slug));
|
|
69
59
|
styles.push(['color', colorObject.color].join(':'));
|
|
@@ -71,7 +61,6 @@ function setColors(value, name, colorSettings, colors) {
|
|
|
71
61
|
styles.push(['color', color].join(':'));
|
|
72
62
|
}
|
|
73
63
|
}
|
|
74
|
-
|
|
75
64
|
if (styles.length) attributes.style = styles.join(';');
|
|
76
65
|
if (classNames.length) attributes.class = classNames.join(' ');
|
|
77
66
|
const format = {
|
|
@@ -80,8 +69,9 @@ function setColors(value, name, colorSettings, colors) {
|
|
|
80
69
|
};
|
|
81
70
|
const hasNoSelection = value.start === value.end;
|
|
82
71
|
const isAtTheEnd = value.end === value.text.length;
|
|
83
|
-
const previousCharacter = value.text.charAt(value.end - 1);
|
|
72
|
+
const previousCharacter = value.text.charAt(value.end - 1);
|
|
84
73
|
|
|
74
|
+
// Force formatting due to limitations in the native implementation
|
|
85
75
|
if (hasNoSelection && (value.text.length === 0 || previousCharacter === ' ' && isAtTheEnd)) {
|
|
86
76
|
// For cases where there's no text selected, there's a space before
|
|
87
77
|
// the current caret position and it's at the end of the text.
|
|
@@ -100,10 +90,8 @@ function setColors(value, name, colorSettings, colors) {
|
|
|
100
90
|
} else if (hasNoSelection) {
|
|
101
91
|
return removeFormat(value, format);
|
|
102
92
|
}
|
|
103
|
-
|
|
104
93
|
return applyFormat(value, format);
|
|
105
94
|
}
|
|
106
|
-
|
|
107
95
|
function ColorPicker({
|
|
108
96
|
name,
|
|
109
97
|
value,
|
|
@@ -116,7 +104,8 @@ function ColorPicker({
|
|
|
116
104
|
if (color !== '') {
|
|
117
105
|
onChange(setColors(value, name, colors, {
|
|
118
106
|
[property]: color
|
|
119
|
-
}));
|
|
107
|
+
}));
|
|
108
|
+
// Remove formatting if the color was reset, there's no
|
|
120
109
|
// current selection and the previous character is a space
|
|
121
110
|
} else if (value?.start === value?.end && value.text?.charAt(value?.end - 1) === ' ') {
|
|
122
111
|
onChange(removeFormat(value, name, value.end - 1, value.end));
|
|
@@ -132,7 +121,6 @@ function ColorPicker({
|
|
|
132
121
|
hideNavigation: true
|
|
133
122
|
});
|
|
134
123
|
}
|
|
135
|
-
|
|
136
124
|
export default function InlineColorUI({
|
|
137
125
|
name,
|
|
138
126
|
value,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/format-library/src/text-color/inline.native.js"],"names":["useCallback","useMemo","applyFormat","removeFormat","getActiveFormat","getColorClassName","getColorObjectByColorValue","useMultipleOriginColorsAndGradients","BottomSheet","ColorSettings","useMobileGlobalStylesColors","transparentValue","parseClassName","parseCSS","css","split","reduce","accumulator","rule","property","value","replace","color","backgroundColor","getActiveColors","name","colorSettings","activeColorFormat","attributes","style","class","setColors","colors","styles","classNames","push","join","colorObject","slug","length","format","type","hasNoSelection","start","end","isAtTheEnd","text","previousCharacter","charAt","newFormat","activeFormats","formats","filter","ColorPicker","onChange","onColorChange","activeColors","InlineColorUI","onClose","paddingLeft","paddingRight"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,WAAT,EAAsBC,OAAtB,QAAqC,oBAArC;AACA,SACCC,WADD,EAECC,YAFD,EAGCC,eAHD,QAIO,sBAJP;AAKA,SACCC,iBADD,EAECC,0BAFD,EAGCC,mCAHD,QAIO,yBAJP;AAKA,SACCC,WADD,EAECC,aAFD,EAGCC,2BAHD,QAIO,uBAJP;AAMA;AACA;AACA;;AACA,SAASC,gBAAT,QAAiC,YAAjC;AACA,SAASC,cAAT,QAA+B,aAA/B;;AAEA,SAASC,QAAT,CAAmBC,GAAG,GAAG,EAAzB,EAA8B;AAC7B,SAAOA,GAAG,CAACC,KAAJ,CAAW,GAAX,EAAiBC,MAAjB,CAAyB,CAAEC,WAAF,EAAeC,IAAf,KAAyB;AACxD,QAAKA,IAAL,EAAY;AACX,YAAM,CAAEC,QAAF,EAAYC,KAAZ,IAAsBF,IAAI,CAACG,OAAL,CAAc,IAAd,EAAoB,EAApB,EAAyBN,KAAzB,CAAgC,GAAhC,CAA5B;AACA,UAAKI,QAAQ,KAAK,OAAlB,EAA4BF,WAAW,CAACK,KAAZ,GAAoBF,KAApB;AAC5B,UAAKD,QAAQ,KAAK,kBAAb,IAAmCC,KAAK,KAAKT,gBAAlD,EACCM,WAAW,CAACM,eAAZ,GAA8BH,KAA9B;AACD;;AACD,WAAOH,WAAP;AACA,GARM,EAQJ,EARI,CAAP;AASA;;AAED,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AAGL,KAFT;AAGC,IAAA,QAAQ,EAAGkC;AAHZ,IADD,CADD,CATD,CADD;AAqBA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useCallback, useMemo } from '@wordpress/element';\nimport {\n\tapplyFormat,\n\tremoveFormat,\n\tgetActiveFormat,\n} from '@wordpress/rich-text';\nimport {\n\tgetColorClassName,\n\tgetColorObjectByColorValue,\n\tuseMultipleOriginColorsAndGradients,\n} from '@wordpress/block-editor';\nimport {\n\tBottomSheet,\n\tColorSettings,\n\tuseMobileGlobalStylesColors,\n} from '@wordpress/components';\n\n/**\n * Internal dependencies\n */\nimport { transparentValue } from './index.js';\nimport { parseClassName } from './inline.js';\n\nfunction parseCSS( css = '' ) {\n\treturn css.split( ';' ).reduce( ( accumulator, rule ) => {\n\t\tif ( rule ) {\n\t\t\tconst [ property, value ] = rule.replace( / /g, '' ).split( ':' );\n\t\t\tif ( property === 'color' ) accumulator.color = value;\n\t\t\tif ( property === 'background-color' && value !== transparentValue )\n\t\t\t\taccumulator.backgroundColor = value;\n\t\t}\n\t\treturn accumulator;\n\t}, {} );\n}\n\nfunction getActiveColors( value, name, colorSettings ) {\n\tconst activeColorFormat = getActiveFormat( value, name );\n\n\tif ( ! activeColorFormat ) {\n\t\treturn {};\n\t}\n\n\treturn {\n\t\t...parseCSS( activeColorFormat.attributes.style ),\n\t\t...parseClassName( activeColorFormat.attributes.class, colorSettings ),\n\t};\n}\n\nfunction setColors( value, name, colorSettings, colors ) {\n\tconst { color, backgroundColor } = {\n\t\t...getActiveColors( value, name, colorSettings ),\n\t\t...colors,\n\t};\n\n\tif ( ! color && ! backgroundColor ) {\n\t\treturn removeFormat( value, name );\n\t}\n\n\tconst styles = [];\n\tconst classNames = [];\n\tconst attributes = {};\n\n\tif ( backgroundColor ) {\n\t\tstyles.push( [ 'background-color', backgroundColor ].join( ':' ) );\n\t} else {\n\t\t// Override default browser color for mark element.\n\t\tstyles.push( [ 'background-color', transparentValue ].join( ':' ) );\n\t}\n\n\tif ( color ) {\n\t\tconst colorObject = getColorObjectByColorValue( colorSettings, color );\n\n\t\tif ( colorObject ) {\n\t\t\tclassNames.push( getColorClassName( 'color', colorObject.slug ) );\n\t\t\tstyles.push( [ 'color', colorObject.color ].join( ':' ) );\n\t\t} else {\n\t\t\tstyles.push( [ 'color', color ].join( ':' ) );\n\t\t}\n\t}\n\n\tif ( styles.length ) attributes.style = styles.join( ';' );\n\tif ( classNames.length ) attributes.class = classNames.join( ' ' );\n\n\tconst format = { type: name, attributes };\n\tconst hasNoSelection = value.start === value.end;\n\tconst isAtTheEnd = value.end === value.text.length;\n\tconst previousCharacter = value.text.charAt( value.end - 1 );\n\n\t// Force formatting due to limitations in the native implementation\n\tif (\n\t\thasNoSelection &&\n\t\t( value.text.length === 0 ||\n\t\t\t( previousCharacter === ' ' && isAtTheEnd ) )\n\t) {\n\t\t// For cases where there's no text selected, there's a space before\n\t\t// the current caret position and it's at the end of the text.\n\t\treturn applyFormat( value, format, value.start - 1, value.end + 1 );\n\t} else if ( hasNoSelection && isAtTheEnd ) {\n\t\t// If there's no selection and is at the end of the text\n\t\t// manually add the format within the current caret position.\n\t\tconst newFormat = applyFormat( value, format );\n\t\tconst { activeFormats } = newFormat;\n\t\tnewFormat.formats[ value.start ] = [\n\t\t\t...( activeFormats?.filter(\n\t\t\t\t( { type } ) => type !== format.type\n\t\t\t) || [] ),\n\t\t\tformat,\n\t\t];\n\t\treturn newFormat;\n\t} else if ( hasNoSelection ) {\n\t\treturn removeFormat( value, format );\n\t}\n\n\treturn applyFormat( value, format );\n}\n\nfunction ColorPicker( { name, value, onChange } ) {\n\tconst property = 'color';\n\tconst colors = useMobileGlobalStylesColors();\n\tconst colorSettings = useMultipleOriginColorsAndGradients();\n\n\tconst onColorChange = useCallback(\n\t\t( color ) => {\n\t\t\tif ( color !== '' ) {\n\t\t\t\tonChange(\n\t\t\t\t\tsetColors( value, name, colors, { [ property ]: color } )\n\t\t\t\t);\n\t\t\t\t// Remove formatting if the color was reset, there's no\n\t\t\t\t// current selection and the previous character is a space\n\t\t\t} else if (\n\t\t\t\tvalue?.start === value?.end &&\n\t\t\t\tvalue.text?.charAt( value?.end - 1 ) === ' '\n\t\t\t) {\n\t\t\t\tonChange(\n\t\t\t\t\tremoveFormat( value, name, value.end - 1, value.end )\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tonChange( removeFormat( value, name ) );\n\t\t\t}\n\t\t},\n\t\t[ colors, onChange, property ]\n\t);\n\tconst activeColors = useMemo(\n\t\t() => getActiveColors( value, name, colors ),\n\t\t[ name, value, colors ]\n\t);\n\n\treturn (\n\t\t<ColorSettings\n\t\t\tcolorValue={ activeColors[ property ] }\n\t\t\tonColorChange={ onColorChange }\n\t\t\tdefaultSettings={ colorSettings }\n\t\t\thideNavigation\n\t\t/>\n\t);\n}\n\nexport default function InlineColorUI( { name, value, onChange, onClose } ) {\n\treturn (\n\t\t<BottomSheet\n\t\t\tisVisible\n\t\t\tonClose={ onClose }\n\t\t\thideHeader\n\t\t\tcontentStyle={ { paddingLeft: 0, paddingRight: 0 } }\n\t\t\thasNavigation\n\t\t\tleftButton={ null }\n\t\t\ttestID=\"inline-text-color-modal\"\n\t\t>\n\t\t\t<BottomSheet.NavigationContainer animate main>\n\t\t\t\t<BottomSheet.NavigationScreen name=\"text-color\">\n\t\t\t\t\t<ColorPicker\n\t\t\t\t\t\tname={ name }\n\t\t\t\t\t\tvalue={ value }\n\t\t\t\t\t\tonChange={ onChange }\n\t\t\t\t\t/>\n\t\t\t\t</BottomSheet.NavigationScreen>\n\t\t\t</BottomSheet.NavigationContainer>\n\t\t</BottomSheet>\n\t);\n}\n"]}
|
|
1
|
+
{"version":3,"names":["useCallback","useMemo","applyFormat","removeFormat","getActiveFormat","getColorClassName","getColorObjectByColorValue","useMultipleOriginColorsAndGradients","BottomSheet","ColorSettings","useMobileGlobalStylesColors","transparentValue","parseClassName","parseCSS","css","split","reduce","accumulator","rule","property","value","replace","color","backgroundColor","getActiveColors","name","colorSettings","activeColorFormat","attributes","style","class","setColors","colors","styles","classNames","push","join","colorObject","slug","length","format","type","hasNoSelection","start","end","isAtTheEnd","text","previousCharacter","charAt","newFormat","activeFormats","formats","filter","ColorPicker","onChange","onColorChange","activeColors","createElement","colorValue","defaultSettings","hideNavigation","InlineColorUI","onClose","isVisible","hideHeader","contentStyle","paddingLeft","paddingRight","hasNavigation","leftButton","testID","NavigationContainer","animate","main","NavigationScreen"],"sources":["@wordpress/format-library/src/text-color/inline.native.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useCallback, useMemo } from '@wordpress/element';\nimport {\n\tapplyFormat,\n\tremoveFormat,\n\tgetActiveFormat,\n} from '@wordpress/rich-text';\nimport {\n\tgetColorClassName,\n\tgetColorObjectByColorValue,\n\tuseMultipleOriginColorsAndGradients,\n} from '@wordpress/block-editor';\nimport {\n\tBottomSheet,\n\tColorSettings,\n\tuseMobileGlobalStylesColors,\n} from '@wordpress/components';\n\n/**\n * Internal dependencies\n */\nimport { transparentValue } from './index.js';\nimport { parseClassName } from './inline.js';\n\nfunction parseCSS( css = '' ) {\n\treturn css.split( ';' ).reduce( ( accumulator, rule ) => {\n\t\tif ( rule ) {\n\t\t\tconst [ property, value ] = rule.replace( / /g, '' ).split( ':' );\n\t\t\tif ( property === 'color' ) accumulator.color = value;\n\t\t\tif ( property === 'background-color' && value !== transparentValue )\n\t\t\t\taccumulator.backgroundColor = value;\n\t\t}\n\t\treturn accumulator;\n\t}, {} );\n}\n\nfunction getActiveColors( value, name, colorSettings ) {\n\tconst activeColorFormat = getActiveFormat( value, name );\n\n\tif ( ! activeColorFormat ) {\n\t\treturn {};\n\t}\n\n\treturn {\n\t\t...parseCSS( activeColorFormat.attributes.style ),\n\t\t...parseClassName( activeColorFormat.attributes.class, colorSettings ),\n\t};\n}\n\nfunction setColors( value, name, colorSettings, colors ) {\n\tconst { color, backgroundColor } = {\n\t\t...getActiveColors( value, name, colorSettings ),\n\t\t...colors,\n\t};\n\n\tif ( ! color && ! backgroundColor ) {\n\t\treturn removeFormat( value, name );\n\t}\n\n\tconst styles = [];\n\tconst classNames = [];\n\tconst attributes = {};\n\n\tif ( backgroundColor ) {\n\t\tstyles.push( [ 'background-color', backgroundColor ].join( ':' ) );\n\t} else {\n\t\t// Override default browser color for mark element.\n\t\tstyles.push( [ 'background-color', transparentValue ].join( ':' ) );\n\t}\n\n\tif ( color ) {\n\t\tconst colorObject = getColorObjectByColorValue( colorSettings, color );\n\n\t\tif ( colorObject ) {\n\t\t\tclassNames.push( getColorClassName( 'color', colorObject.slug ) );\n\t\t\tstyles.push( [ 'color', colorObject.color ].join( ':' ) );\n\t\t} else {\n\t\t\tstyles.push( [ 'color', color ].join( ':' ) );\n\t\t}\n\t}\n\n\tif ( styles.length ) attributes.style = styles.join( ';' );\n\tif ( classNames.length ) attributes.class = classNames.join( ' ' );\n\n\tconst format = { type: name, attributes };\n\tconst hasNoSelection = value.start === value.end;\n\tconst isAtTheEnd = value.end === value.text.length;\n\tconst previousCharacter = value.text.charAt( value.end - 1 );\n\n\t// Force formatting due to limitations in the native implementation\n\tif (\n\t\thasNoSelection &&\n\t\t( value.text.length === 0 ||\n\t\t\t( previousCharacter === ' ' && isAtTheEnd ) )\n\t) {\n\t\t// For cases where there's no text selected, there's a space before\n\t\t// the current caret position and it's at the end of the text.\n\t\treturn applyFormat( value, format, value.start - 1, value.end + 1 );\n\t} else if ( hasNoSelection && isAtTheEnd ) {\n\t\t// If there's no selection and is at the end of the text\n\t\t// manually add the format within the current caret position.\n\t\tconst newFormat = applyFormat( value, format );\n\t\tconst { activeFormats } = newFormat;\n\t\tnewFormat.formats[ value.start ] = [\n\t\t\t...( activeFormats?.filter(\n\t\t\t\t( { type } ) => type !== format.type\n\t\t\t) || [] ),\n\t\t\tformat,\n\t\t];\n\t\treturn newFormat;\n\t} else if ( hasNoSelection ) {\n\t\treturn removeFormat( value, format );\n\t}\n\n\treturn applyFormat( value, format );\n}\n\nfunction ColorPicker( { name, value, onChange } ) {\n\tconst property = 'color';\n\tconst colors = useMobileGlobalStylesColors();\n\tconst colorSettings = useMultipleOriginColorsAndGradients();\n\n\tconst onColorChange = useCallback(\n\t\t( color ) => {\n\t\t\tif ( color !== '' ) {\n\t\t\t\tonChange(\n\t\t\t\t\tsetColors( value, name, colors, { [ property ]: color } )\n\t\t\t\t);\n\t\t\t\t// Remove formatting if the color was reset, there's no\n\t\t\t\t// current selection and the previous character is a space\n\t\t\t} else if (\n\t\t\t\tvalue?.start === value?.end &&\n\t\t\t\tvalue.text?.charAt( value?.end - 1 ) === ' '\n\t\t\t) {\n\t\t\t\tonChange(\n\t\t\t\t\tremoveFormat( value, name, value.end - 1, value.end )\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tonChange( removeFormat( value, name ) );\n\t\t\t}\n\t\t},\n\t\t[ colors, onChange, property ]\n\t);\n\tconst activeColors = useMemo(\n\t\t() => getActiveColors( value, name, colors ),\n\t\t[ name, value, colors ]\n\t);\n\n\treturn (\n\t\t<ColorSettings\n\t\t\tcolorValue={ activeColors[ property ] }\n\t\t\tonColorChange={ onColorChange }\n\t\t\tdefaultSettings={ colorSettings }\n\t\t\thideNavigation\n\t\t/>\n\t);\n}\n\nexport default function InlineColorUI( { name, value, onChange, onClose } ) {\n\treturn (\n\t\t<BottomSheet\n\t\t\tisVisible\n\t\t\tonClose={ onClose }\n\t\t\thideHeader\n\t\t\tcontentStyle={ { paddingLeft: 0, paddingRight: 0 } }\n\t\t\thasNavigation\n\t\t\tleftButton={ null }\n\t\t\ttestID=\"inline-text-color-modal\"\n\t\t>\n\t\t\t<BottomSheet.NavigationContainer animate main>\n\t\t\t\t<BottomSheet.NavigationScreen name=\"text-color\">\n\t\t\t\t\t<ColorPicker\n\t\t\t\t\t\tname={ name }\n\t\t\t\t\t\tvalue={ value }\n\t\t\t\t\t\tonChange={ onChange }\n\t\t\t\t\t/>\n\t\t\t\t</BottomSheet.NavigationScreen>\n\t\t\t</BottomSheet.NavigationContainer>\n\t\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,EAAGF,YAAY,CAAErC,QAAQ,CAAI;IACvCoC,aAAa,EAAGA,aAAe;IAC/BI,eAAe,EAAGjC,aAAe;IACjCkC,cAAc;EAAA,CACd,CAAC;AAEJ;AAEA,eAAe,SAASC,aAAaA,CAAE;EAAEpC,IAAI;EAAEL,KAAK;EAAEkC,QAAQ;EAAEQ;AAAQ,CAAC,EAAG;EAC3E,OACCL,aAAA,CAACjD,WAAW;IACXuD,SAAS;IACTD,OAAO,EAAGA,OAAS;IACnBE,UAAU;IACVC,YAAY,EAAG;MAAEC,WAAW,EAAE,CAAC;MAAEC,YAAY,EAAE;IAAE,CAAG;IACpDC,aAAa;IACbC,UAAU,EAAG,IAAM;IACnBC,MAAM,EAAC;EAAyB,GAEhCb,aAAA,CAACjD,WAAW,CAAC+D,mBAAmB;IAACC,OAAO;IAACC,IAAI;EAAA,GAC5ChB,aAAA,CAACjD,WAAW,CAACkE,gBAAgB;IAACjD,IAAI,EAAC;EAAY,GAC9CgC,aAAA,CAACJ,WAAW;IACX5B,IAAI,EAAGA,IAAM;IACbL,KAAK,EAAGA,KAAO;IACfkC,QAAQ,EAAGA;EAAU,CACrB,CAC4B,CACE,CACrB,CAAC;AAEhB"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { createElement, Fragment } from "@wordpress/element";
|
|
2
|
-
|
|
3
2
|
/**
|
|
4
3
|
* WordPress dependencies
|
|
5
4
|
*/
|
|
@@ -7,9 +6,7 @@ import { __ } from '@wordpress/i18n';
|
|
|
7
6
|
import { toggleFormat } from '@wordpress/rich-text';
|
|
8
7
|
import { RichTextShortcut, __unstableRichTextInputEvent } from '@wordpress/block-editor';
|
|
9
8
|
const name = 'core/underline';
|
|
10
|
-
|
|
11
9
|
const title = __('Underline');
|
|
12
|
-
|
|
13
10
|
export const underline = {
|
|
14
11
|
name,
|
|
15
12
|
title,
|
|
@@ -18,7 +15,6 @@ export const underline = {
|
|
|
18
15
|
attributes: {
|
|
19
16
|
style: 'style'
|
|
20
17
|
},
|
|
21
|
-
|
|
22
18
|
edit({
|
|
23
19
|
value,
|
|
24
20
|
onChange
|
|
@@ -32,7 +28,6 @@ export const underline = {
|
|
|
32
28
|
title
|
|
33
29
|
}));
|
|
34
30
|
};
|
|
35
|
-
|
|
36
31
|
return createElement(Fragment, null, createElement(RichTextShortcut, {
|
|
37
32
|
type: "primary",
|
|
38
33
|
character: "u",
|
|
@@ -42,6 +37,5 @@ export const underline = {
|
|
|
42
37
|
onInput: onToggle
|
|
43
38
|
}));
|
|
44
39
|
}
|
|
45
|
-
|
|
46
40
|
};
|
|
47
41
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["__","toggleFormat","RichTextShortcut","__unstableRichTextInputEvent","name","title","underline","tagName","className","attributes","style","edit","value","onChange","onToggle","type","createElement","Fragment","character","onUse","inputType","onInput"],"sources":["@wordpress/format-library/src/underline/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { toggleFormat } from '@wordpress/rich-text';\nimport {\n\tRichTextShortcut,\n\t__unstableRichTextInputEvent,\n} from '@wordpress/block-editor';\n\nconst name = 'core/underline';\nconst title = __( 'Underline' );\n\nexport const underline = {\n\tname,\n\ttitle,\n\ttagName: 'span',\n\tclassName: null,\n\tattributes: {\n\t\tstyle: 'style',\n\t},\n\tedit( { value, onChange } ) {\n\t\tconst onToggle = () => {\n\t\t\tonChange(\n\t\t\t\ttoggleFormat( value, {\n\t\t\t\t\ttype: name,\n\t\t\t\t\tattributes: {\n\t\t\t\t\t\tstyle: 'text-decoration: underline;',\n\t\t\t\t\t},\n\t\t\t\t\ttitle,\n\t\t\t\t} )\n\t\t\t);\n\t\t};\n\n\t\treturn (\n\t\t\t<>\n\t\t\t\t<RichTextShortcut\n\t\t\t\t\ttype=\"primary\"\n\t\t\t\t\tcharacter=\"u\"\n\t\t\t\t\tonUse={ onToggle }\n\t\t\t\t/>\n\t\t\t\t<__unstableRichTextInputEvent\n\t\t\t\t\tinputType=\"formatUnderline\"\n\t\t\t\t\tonInput={ onToggle }\n\t\t\t\t/>\n\t\t\t</>\n\t\t);\n\t},\n};\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,EAAE,QAAQ,iBAAiB;AACpC,SAASC,YAAY,QAAQ,sBAAsB;AACnD,SACCC,gBAAgB,EAChBC,4BAA4B,QACtB,yBAAyB;AAEhC,MAAMC,IAAI,GAAG,gBAAgB;AAC7B,MAAMC,KAAK,GAAGL,EAAE,CAAE,WAAY,CAAC;AAE/B,OAAO,MAAMM,SAAS,GAAG;EACxBF,IAAI;EACJC,KAAK;EACLE,OAAO,EAAE,MAAM;EACfC,SAAS,EAAE,IAAI;EACfC,UAAU,EAAE;IACXC,KAAK,EAAE;EACR,CAAC;EACDC,IAAIA,CAAE;IAAEC,KAAK;IAAEC;EAAS,CAAC,EAAG;IAC3B,MAAMC,QAAQ,GAAGA,CAAA,KAAM;MACtBD,QAAQ,CACPZ,YAAY,CAAEW,KAAK,EAAE;QACpBG,IAAI,EAAEX,IAAI;QACVK,UAAU,EAAE;UACXC,KAAK,EAAE;QACR,CAAC;QACDL;MACD,CAAE,CACH,CAAC;IACF,CAAC;IAED,OACCW,aAAA,CAAAC,QAAA,QACCD,aAAA,CAACd,gBAAgB;MAChBa,IAAI,EAAC,SAAS;MACdG,SAAS,EAAC,GAAG;MACbC,KAAK,EAAGL;IAAU,CAClB,CAAC,EACFE,aAAA,CAACb,4BAA4B;MAC5BiB,SAAS,EAAC,iBAAiB;MAC3BC,OAAO,EAAGP;IAAU,CACpB,CACA,CAAC;EAEL;AACD,CAAC"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { createElement } from "@wordpress/element";
|
|
2
|
-
|
|
3
2
|
/**
|
|
4
3
|
* WordPress dependencies
|
|
5
4
|
*/
|
|
@@ -8,15 +7,12 @@ import { removeFormat, slice } from '@wordpress/rich-text';
|
|
|
8
7
|
import { RichTextToolbarButton } from '@wordpress/block-editor';
|
|
9
8
|
import { help } from '@wordpress/icons';
|
|
10
9
|
const name = 'core/unknown';
|
|
11
|
-
|
|
12
10
|
const title = __('Clear Unknown Formatting');
|
|
13
|
-
|
|
14
11
|
export const unknown = {
|
|
15
12
|
name,
|
|
16
13
|
title,
|
|
17
14
|
tagName: '*',
|
|
18
15
|
className: null,
|
|
19
|
-
|
|
20
16
|
edit({
|
|
21
17
|
isActive,
|
|
22
18
|
value,
|
|
@@ -27,16 +23,13 @@ export const unknown = {
|
|
|
27
23
|
onChange(removeFormat(value, name));
|
|
28
24
|
onFocus();
|
|
29
25
|
}
|
|
30
|
-
|
|
31
26
|
const selectedValue = slice(value);
|
|
32
27
|
const hasUnknownFormats = selectedValue.formats.some(formats => {
|
|
33
28
|
return formats.some(format => format.type === name);
|
|
34
29
|
});
|
|
35
|
-
|
|
36
30
|
if (!isActive && !hasUnknownFormats) {
|
|
37
31
|
return null;
|
|
38
32
|
}
|
|
39
|
-
|
|
40
33
|
return createElement(RichTextToolbarButton, {
|
|
41
34
|
name: "unknown",
|
|
42
35
|
icon: help,
|
|
@@ -45,6 +38,5 @@ export const unknown = {
|
|
|
45
38
|
isActive: true
|
|
46
39
|
});
|
|
47
40
|
}
|
|
48
|
-
|
|
49
41
|
};
|
|
50
42
|
//# sourceMappingURL=index.js.map
|