@wordpress/format-library 4.31.0 → 4.32.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -0
- package/build/text-color/index.native.js +4 -4
- package/build/text-color/index.native.js.map +1 -1
- package/build/text-color/inline.native.js +17 -38
- package/build/text-color/inline.native.js.map +1 -1
- package/build/unknown/index.js +12 -7
- package/build/unknown/index.js.map +1 -1
- package/build-module/text-color/index.native.js +1 -1
- package/build-module/text-color/index.native.js.map +1 -1
- package/build-module/text-color/inline.native.js +17 -39
- package/build-module/text-color/inline.native.js.map +1 -1
- package/build-module/unknown/index.js +13 -8
- package/build-module/unknown/index.js.map +1 -1
- package/package.json +14 -14
- package/src/text-color/index.native.js +1 -1
- package/src/text-color/inline.native.js +27 -49
- package/src/text-color/test/__snapshots__/index.native.js.snap +0 -6
- package/src/text-color/test/index.native.js +4 -39
- package/src/unknown/index.js +16 -10
package/CHANGELOG.md
CHANGED
|
@@ -14,8 +14,8 @@ var _components = require("@wordpress/components");
|
|
|
14
14
|
var _icons = require("@wordpress/icons");
|
|
15
15
|
var _richText = require("@wordpress/rich-text");
|
|
16
16
|
var _compose = require("@wordpress/compose");
|
|
17
|
-
var
|
|
18
|
-
var
|
|
17
|
+
var _inlineNative = require("./inline.native.js");
|
|
18
|
+
var _inline = _interopRequireDefault(require("./inline"));
|
|
19
19
|
var _style = _interopRequireDefault(require("./style.scss"));
|
|
20
20
|
/**
|
|
21
21
|
* External dependencies
|
|
@@ -71,7 +71,7 @@ function TextColorEdit({
|
|
|
71
71
|
const [isAddingColor, setIsAddingColor] = (0, _element.useState)(false);
|
|
72
72
|
const enableIsAddingColor = (0, _element.useCallback)(() => setIsAddingColor(true), [setIsAddingColor]);
|
|
73
73
|
const disableIsAddingColor = (0, _element.useCallback)(() => setIsAddingColor(false), [setIsAddingColor]);
|
|
74
|
-
const colorIndicatorStyle = (0, _element.useMemo)(() => fillComputedColors(contentRef, (0,
|
|
74
|
+
const colorIndicatorStyle = (0, _element.useMemo)(() => fillComputedColors(contentRef, (0, _inlineNative.getActiveColors)(value, name, colors)), [value, colors]);
|
|
75
75
|
const hasColorsToChoose = colors.length || !allowCustomControl;
|
|
76
76
|
const onPressButton = (0, _element.useCallback)(() => {
|
|
77
77
|
if (hasColorsToChoose) {
|
|
@@ -114,7 +114,7 @@ function TextColorEdit({
|
|
|
114
114
|
// If has no colors to choose but a color is active remove the color onClick
|
|
115
115
|
,
|
|
116
116
|
onClick: onPressButton
|
|
117
|
-
}))), isAddingColor && (0, _react.createElement)(
|
|
117
|
+
}))), isAddingColor && (0, _react.createElement)(_inline.default, {
|
|
118
118
|
name: name,
|
|
119
119
|
onClose: disableIsAddingColor,
|
|
120
120
|
activeAttributes: activeAttributes,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_reactNative","require","_i18n","_element","_blockEditor","_components","_icons","_richText","_compose","
|
|
1
|
+
{"version":3,"names":["_reactNative","require","_i18n","_element","_blockEditor","_components","_icons","_richText","_compose","_inlineNative","_inline","_interopRequireDefault","_style","name","title","__","getComputedStyleProperty","element","property","_element$props$style","style","props","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","exports","tagName","className","attributes","class","edit"],"sources":["@wordpress/format-library/src/text-color/index.native.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport { StyleSheet, View } from 'react-native';\n\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useCallback, useMemo, useState } from '@wordpress/element';\nimport { BlockControls, useSettings } from '@wordpress/block-editor';\nimport {\n\tToolbarGroup,\n\tToolbarButton,\n\tuseMobileGlobalStylesColors,\n} from '@wordpress/components';\nimport {\n\tIcon,\n\tcolor as colorIcon,\n\ttextColor as textColorIcon,\n} from '@wordpress/icons';\nimport { removeFormat } from '@wordpress/rich-text';\nimport { usePreferredColorSchemeStyle } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { getActiveColors } from './inline.native.js';\nimport { default as InlineColorUI } from './inline';\nimport styles from './style.scss';\n\nconst name = 'core/text-color';\nconst title = __( 'Text color' );\n\nfunction getComputedStyleProperty( element, property ) {\n\tconst style = element?.props?.style ?? {};\n\n\tif ( property === 'background-color' ) {\n\t\tconst { backgroundColor, baseColors } = style;\n\n\t\tif ( backgroundColor !== 'transparent' ) {\n\t\t\treturn backgroundColor;\n\t\t} else if ( baseColors && baseColors?.color?.background ) {\n\t\t\treturn baseColors?.color?.background;\n\t\t}\n\n\t\treturn 'transparent';\n\t}\n}\n\nfunction fillComputedColors( element, { color, backgroundColor } ) {\n\tif ( ! color && ! backgroundColor ) {\n\t\treturn;\n\t}\n\n\treturn {\n\t\tcolor: color || getComputedStyleProperty( element, 'color' ),\n\t\tbackgroundColor: getComputedStyleProperty(\n\t\t\telement,\n\t\t\t'background-color'\n\t\t),\n\t};\n}\n\nfunction TextColorEdit( {\n\tvalue,\n\tonChange,\n\tisActive,\n\tactiveAttributes,\n\tcontentRef,\n} ) {\n\tconst [ allowCustomControl ] = useSettings( 'color.custom' );\n\tconst colors = useMobileGlobalStylesColors();\n\tconst [ isAddingColor, setIsAddingColor ] = useState( false );\n\tconst enableIsAddingColor = useCallback(\n\t\t() => setIsAddingColor( true ),\n\t\t[ setIsAddingColor ]\n\t);\n\tconst disableIsAddingColor = useCallback(\n\t\t() => setIsAddingColor( false ),\n\t\t[ setIsAddingColor ]\n\t);\n\tconst colorIndicatorStyle = useMemo(\n\t\t() =>\n\t\t\tfillComputedColors(\n\t\t\t\tcontentRef,\n\t\t\t\tgetActiveColors( value, name, colors )\n\t\t\t),\n\t\t[ value, colors ]\n\t);\n\n\tconst hasColorsToChoose = colors.length || ! allowCustomControl;\n\n\tconst onPressButton = useCallback( () => {\n\t\tif ( hasColorsToChoose ) {\n\t\t\tenableIsAddingColor();\n\t\t} else {\n\t\t\tonChange( removeFormat( value, name ) );\n\t\t}\n\t}, [ hasColorsToChoose, value ] );\n\n\tconst outlineStyle = [\n\t\tusePreferredColorSchemeStyle(\n\t\t\tstyles[ 'components-inline-color__outline' ],\n\t\t\tstyles[ 'components-inline-color__outline--dark' ]\n\t\t),\n\t\t{ borderWidth: StyleSheet.hairlineWidth },\n\t];\n\n\tif ( ! hasColorsToChoose && ! isActive ) {\n\t\treturn null;\n\t}\n\n\tconst isActiveStyle = {\n\t\t...colorIndicatorStyle,\n\t\t...( ! colorIndicatorStyle?.backgroundColor\n\t\t\t? { backgroundColor: 'transparent' }\n\t\t\t: {} ),\n\t\t...styles[ 'components-inline-color--is-active' ],\n\t};\n\n\tconst customContainerStyles =\n\t\tstyles[ 'components-inline-color__button-container' ];\n\n\treturn (\n\t\t<>\n\t\t\t<BlockControls>\n\t\t\t\t<ToolbarGroup>\n\t\t\t\t\t{ isActive && (\n\t\t\t\t\t\t<View style={ outlineStyle } pointerEvents=\"none\" />\n\t\t\t\t\t) }\n\n\t\t\t\t\t<ToolbarButton\n\t\t\t\t\t\tname=\"text-color\"\n\t\t\t\t\t\tisActive={ isActive }\n\t\t\t\t\t\ticon={\n\t\t\t\t\t\t\t<Icon\n\t\t\t\t\t\t\t\ticon={\n\t\t\t\t\t\t\t\t\tObject.keys( activeAttributes ).length\n\t\t\t\t\t\t\t\t\t\t? textColorIcon\n\t\t\t\t\t\t\t\t\t\t: colorIcon\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tstyle={\n\t\t\t\t\t\t\t\t\tcolorIndicatorStyle?.color && {\n\t\t\t\t\t\t\t\t\t\tcolor: colorIndicatorStyle.color,\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t}\n\t\t\t\t\t\ttitle={ title }\n\t\t\t\t\t\textraProps={ {\n\t\t\t\t\t\t\tisActiveStyle,\n\t\t\t\t\t\t\tcustomContainerStyles,\n\t\t\t\t\t\t} }\n\t\t\t\t\t\t// If has no colors to choose but a color is active remove the color onClick\n\t\t\t\t\t\tonClick={ onPressButton }\n\t\t\t\t\t/>\n\t\t\t\t</ToolbarGroup>\n\t\t\t</BlockControls>\n\t\t\t{ isAddingColor && (\n\t\t\t\t<InlineColorUI\n\t\t\t\t\tname={ name }\n\t\t\t\t\tonClose={ disableIsAddingColor }\n\t\t\t\t\tactiveAttributes={ activeAttributes }\n\t\t\t\t\tvalue={ value }\n\t\t\t\t\tonChange={ onChange }\n\t\t\t\t\tcontentRef={ contentRef }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nexport const textColor = {\n\tname,\n\ttitle,\n\ttagName: 'mark',\n\tclassName: 'has-inline-color',\n\tattributes: {\n\t\tstyle: 'style',\n\t\tclass: 'class',\n\t},\n\tedit: TextColorEdit,\n};\n"],"mappings":";;;;;;;;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,aAAA,GAAAR,OAAA;AACA,IAAAS,OAAA,GAAAC,sBAAA,CAAAV,OAAA;AACA,IAAAW,MAAA,GAAAD,sBAAA,CAAAV,OAAA;AA7BA;AACA;AACA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EACJC,KAAK;EACLgE,OAAO,EAAE,MAAM;EACfC,SAAS,EAAE,kBAAkB;EAC7BC,UAAU,EAAE;IACX5D,KAAK,EAAE,OAAO;IACd6D,KAAK,EAAE;EACR,CAAC;EACDC,IAAI,EAAEvD;AACP,CAAC"}
|
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = InlineColorUI;
|
|
7
|
+
exports.getActiveColors = getActiveColors;
|
|
7
8
|
var _react = require("react");
|
|
8
9
|
var _element = require("@wordpress/element");
|
|
9
10
|
var _richText = require("@wordpress/rich-text");
|
|
@@ -39,7 +40,7 @@ function getActiveColors(value, name, colorSettings) {
|
|
|
39
40
|
...(0, _inline.parseClassName)(activeColorFormat.attributes.class, colorSettings)
|
|
40
41
|
};
|
|
41
42
|
}
|
|
42
|
-
function setColors(value, name, colorSettings, colors) {
|
|
43
|
+
function setColors(value, name, colorSettings, colors, contentRef) {
|
|
43
44
|
const {
|
|
44
45
|
color,
|
|
45
46
|
backgroundColor
|
|
@@ -47,7 +48,8 @@ function setColors(value, name, colorSettings, colors) {
|
|
|
47
48
|
...getActiveColors(value, name, colorSettings),
|
|
48
49
|
...colors
|
|
49
50
|
};
|
|
50
|
-
if (!color
|
|
51
|
+
if (!color) {
|
|
52
|
+
contentRef?.onRemoveMarkFormatting();
|
|
51
53
|
return (0, _richText.removeFormat)(value, name);
|
|
52
54
|
}
|
|
53
55
|
const styles = [];
|
|
@@ -75,55 +77,30 @@ function setColors(value, name, colorSettings, colors) {
|
|
|
75
77
|
attributes
|
|
76
78
|
};
|
|
77
79
|
const hasNoSelection = value.start === value.end;
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
// Force formatting due to limitations in the native implementation
|
|
82
|
-
if (hasNoSelection && (value.text.length === 0 || previousCharacter === ' ' && isAtTheEnd)) {
|
|
83
|
-
// For cases where there's no text selected, there's a space before
|
|
84
|
-
// the current caret position and it's at the end of the text.
|
|
85
|
-
return (0, _richText.applyFormat)(value, format, value.start - 1, value.end + 1);
|
|
86
|
-
} else if (hasNoSelection && isAtTheEnd) {
|
|
87
|
-
// If there's no selection and is at the end of the text
|
|
88
|
-
// manually add the format within the current caret position.
|
|
89
|
-
const newFormat = (0, _richText.applyFormat)(value, format);
|
|
90
|
-
const {
|
|
91
|
-
activeFormats
|
|
92
|
-
} = newFormat;
|
|
93
|
-
newFormat.formats[value.start] = [...(activeFormats?.filter(({
|
|
94
|
-
type
|
|
95
|
-
}) => type !== format.type) || []), format];
|
|
96
|
-
return newFormat;
|
|
97
|
-
} else if (hasNoSelection) {
|
|
98
|
-
return (0, _richText.removeFormat)(value, format);
|
|
80
|
+
if (hasNoSelection) {
|
|
81
|
+
contentRef?.onMarkFormatting(color);
|
|
99
82
|
}
|
|
100
83
|
return (0, _richText.applyFormat)(value, format);
|
|
101
84
|
}
|
|
102
85
|
function ColorPicker({
|
|
103
86
|
name,
|
|
104
87
|
value,
|
|
105
|
-
onChange
|
|
88
|
+
onChange,
|
|
89
|
+
contentRef
|
|
106
90
|
}) {
|
|
107
91
|
const property = 'color';
|
|
108
92
|
const colors = (0, _components.useMobileGlobalStylesColors)();
|
|
109
93
|
const colorSettings = (0, _blockEditor.useMultipleOriginColorsAndGradients)();
|
|
110
94
|
const onColorChange = (0, _element.useCallback)(color => {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
// Remove formatting if the color was reset, there's no
|
|
116
|
-
// current selection and the previous character is a space
|
|
117
|
-
} else if (value?.start === value?.end && value.text?.charAt(value?.end - 1) === ' ') {
|
|
118
|
-
onChange((0, _richText.removeFormat)(value, name, value.end - 1, value.end));
|
|
119
|
-
} else {
|
|
120
|
-
onChange((0, _richText.removeFormat)(value, name));
|
|
121
|
-
}
|
|
122
|
-
}, [colors, onChange, property]);
|
|
95
|
+
onChange(setColors(value, name, colors, {
|
|
96
|
+
[property]: color
|
|
97
|
+
}, contentRef));
|
|
98
|
+
}, [colors, contentRef, name, onChange, value]);
|
|
123
99
|
const activeColors = (0, _element.useMemo)(() => getActiveColors(value, name, colors), [name, value, colors]);
|
|
124
100
|
return (0, _react.createElement)(_components.ColorSettings, {
|
|
125
101
|
colorValue: activeColors[property],
|
|
126
102
|
onColorChange: onColorChange,
|
|
103
|
+
onColorCleared: onColorChange,
|
|
127
104
|
defaultSettings: colorSettings,
|
|
128
105
|
hideNavigation: true
|
|
129
106
|
});
|
|
@@ -132,7 +109,8 @@ function InlineColorUI({
|
|
|
132
109
|
name,
|
|
133
110
|
value,
|
|
134
111
|
onChange,
|
|
135
|
-
onClose
|
|
112
|
+
onClose,
|
|
113
|
+
contentRef
|
|
136
114
|
}) {
|
|
137
115
|
return (0, _react.createElement)(_components.BottomSheet, {
|
|
138
116
|
isVisible: true,
|
|
@@ -153,7 +131,8 @@ function InlineColorUI({
|
|
|
153
131
|
}, (0, _react.createElement)(ColorPicker, {
|
|
154
132
|
name: name,
|
|
155
133
|
value: value,
|
|
156
|
-
onChange: onChange
|
|
134
|
+
onChange: onChange,
|
|
135
|
+
contentRef: contentRef
|
|
157
136
|
}))));
|
|
158
137
|
}
|
|
159
138
|
//# sourceMappingURL=inline.native.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_element","require","_richText","_blockEditor","_components","_index","_inline","parseCSS","css","split","reduce","accumulator","rule","property","value","replace","color","transparentValue","backgroundColor","getActiveColors","name","colorSettings","activeColorFormat","getActiveFormat","attributes","style","parseClassName","class","setColors","colors","removeFormat","styles","classNames","push","join","colorObject","getColorObjectByColorValue","getColorClassName","slug","length","format","type","hasNoSelection","start","end","isAtTheEnd","text","previousCharacter","charAt","applyFormat","newFormat","activeFormats","formats","filter","ColorPicker","onChange","useMobileGlobalStylesColors","useMultipleOriginColorsAndGradients","onColorChange","useCallback","activeColors","useMemo","_react","createElement","ColorSettings","colorValue","defaultSettings","hideNavigation","InlineColorUI","onClose","BottomSheet","isVisible","hideHeader","contentStyle","paddingLeft","paddingRight","hasNavigation","leftButton","testID","NavigationContainer","animate","main","NavigationScreen"],"sources":["@wordpress/format-library/src/text-color/inline.native.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useCallback, useMemo } from '@wordpress/element';\nimport {\n\tapplyFormat,\n\tremoveFormat,\n\tgetActiveFormat,\n} from '@wordpress/rich-text';\nimport {\n\tgetColorClassName,\n\tgetColorObjectByColorValue,\n\tuseMultipleOriginColorsAndGradients,\n} from '@wordpress/block-editor';\nimport {\n\tBottomSheet,\n\tColorSettings,\n\tuseMobileGlobalStylesColors,\n} from '@wordpress/components';\n\n/**\n * Internal dependencies\n */\nimport { transparentValue } from './index.js';\nimport { parseClassName } from './inline.js';\n\nfunction parseCSS( css = '' ) {\n\treturn css.split( ';' ).reduce( ( accumulator, rule ) => {\n\t\tif ( rule ) {\n\t\t\tconst [ property, value ] = rule.replace( / /g, '' ).split( ':' );\n\t\t\tif ( property === 'color' ) accumulator.color = value;\n\t\t\tif ( property === 'background-color' && value !== transparentValue )\n\t\t\t\taccumulator.backgroundColor = value;\n\t\t}\n\t\treturn accumulator;\n\t}, {} );\n}\n\nfunction getActiveColors( value, name, colorSettings ) {\n\tconst activeColorFormat = getActiveFormat( value, name );\n\n\tif ( ! activeColorFormat ) {\n\t\treturn {};\n\t}\n\n\treturn {\n\t\t...parseCSS( activeColorFormat.attributes.style ),\n\t\t...parseClassName( activeColorFormat.attributes.class, colorSettings ),\n\t};\n}\n\nfunction setColors( value, name, colorSettings, colors ) {\n\tconst { color, backgroundColor } = {\n\t\t...getActiveColors( value, name, colorSettings ),\n\t\t...colors,\n\t};\n\n\tif ( ! color && ! backgroundColor ) {\n\t\treturn removeFormat( value, name );\n\t}\n\n\tconst styles = [];\n\tconst classNames = [];\n\tconst attributes = {};\n\n\tif ( backgroundColor ) {\n\t\tstyles.push( [ 'background-color', backgroundColor ].join( ':' ) );\n\t} else {\n\t\t// Override default browser color for mark element.\n\t\tstyles.push( [ 'background-color', transparentValue ].join( ':' ) );\n\t}\n\n\tif ( color ) {\n\t\tconst colorObject = getColorObjectByColorValue( colorSettings, color );\n\n\t\tif ( colorObject ) {\n\t\t\tclassNames.push( getColorClassName( 'color', colorObject.slug ) );\n\t\t\tstyles.push( [ 'color', colorObject.color ].join( ':' ) );\n\t\t} else {\n\t\t\tstyles.push( [ 'color', color ].join( ':' ) );\n\t\t}\n\t}\n\n\tif ( styles.length ) attributes.style = styles.join( ';' );\n\tif ( classNames.length ) attributes.class = classNames.join( ' ' );\n\n\tconst format = { type: name, attributes };\n\tconst hasNoSelection = value.start === value.end;\n\tconst isAtTheEnd = value.end === value.text.length;\n\tconst previousCharacter = value.text.charAt( value.end - 1 );\n\n\t// Force formatting due to limitations in the native implementation\n\tif (\n\t\thasNoSelection &&\n\t\t( value.text.length === 0 ||\n\t\t\t( previousCharacter === ' ' && isAtTheEnd ) )\n\t) {\n\t\t// For cases where there's no text selected, there's a space before\n\t\t// the current caret position and it's at the end of the text.\n\t\treturn applyFormat( value, format, value.start - 1, value.end + 1 );\n\t} else if ( hasNoSelection && isAtTheEnd ) {\n\t\t// If there's no selection and is at the end of the text\n\t\t// manually add the format within the current caret position.\n\t\tconst newFormat = applyFormat( value, format );\n\t\tconst { activeFormats } = newFormat;\n\t\tnewFormat.formats[ value.start ] = [\n\t\t\t...( activeFormats?.filter(\n\t\t\t\t( { type } ) => type !== format.type\n\t\t\t) || [] ),\n\t\t\tformat,\n\t\t];\n\t\treturn newFormat;\n\t} else if ( hasNoSelection ) {\n\t\treturn removeFormat( value, format );\n\t}\n\n\treturn applyFormat( value, format );\n}\n\nfunction ColorPicker( { name, value, onChange } ) {\n\tconst property = 'color';\n\tconst colors = useMobileGlobalStylesColors();\n\tconst colorSettings = useMultipleOriginColorsAndGradients();\n\n\tconst onColorChange = useCallback(\n\t\t( color ) => {\n\t\t\tif ( color !== '' ) {\n\t\t\t\tonChange(\n\t\t\t\t\tsetColors( value, name, colors, { [ property ]: color } )\n\t\t\t\t);\n\t\t\t\t// Remove formatting if the color was reset, there's no\n\t\t\t\t// current selection and the previous character is a space\n\t\t\t} else if (\n\t\t\t\tvalue?.start === value?.end &&\n\t\t\t\tvalue.text?.charAt( value?.end - 1 ) === ' '\n\t\t\t) {\n\t\t\t\tonChange(\n\t\t\t\t\tremoveFormat( value, name, value.end - 1, value.end )\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tonChange( removeFormat( value, name ) );\n\t\t\t}\n\t\t},\n\t\t[ colors, onChange, property ]\n\t);\n\tconst activeColors = useMemo(\n\t\t() => getActiveColors( value, name, colors ),\n\t\t[ name, value, colors ]\n\t);\n\n\treturn (\n\t\t<ColorSettings\n\t\t\tcolorValue={ activeColors[ property ] }\n\t\t\tonColorChange={ onColorChange }\n\t\t\tdefaultSettings={ colorSettings }\n\t\t\thideNavigation\n\t\t/>\n\t);\n}\n\nexport default function InlineColorUI( { name, value, onChange, onClose } ) {\n\treturn (\n\t\t<BottomSheet\n\t\t\tisVisible\n\t\t\tonClose={ onClose }\n\t\t\thideHeader\n\t\t\tcontentStyle={ { paddingLeft: 0, paddingRight: 0 } }\n\t\t\thasNavigation\n\t\t\tleftButton={ null }\n\t\t\ttestID=\"inline-text-color-modal\"\n\t\t>\n\t\t\t<BottomSheet.NavigationContainer animate main>\n\t\t\t\t<BottomSheet.NavigationScreen name=\"text-color\">\n\t\t\t\t\t<ColorPicker\n\t\t\t\t\t\tname={ name }\n\t\t\t\t\t\tvalue={ value }\n\t\t\t\t\t\tonChange={ onChange }\n\t\t\t\t\t/>\n\t\t\t\t</BottomSheet.NavigationScreen>\n\t\t\t</BottomSheet.NavigationContainer>\n\t\t</BottomSheet>\n\t);\n}\n"],"mappings":";;;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;AAKA,IAAAE,YAAA,GAAAF,OAAA;AAKA,IAAAG,WAAA,GAAAH,OAAA;AASA,IAAAI,MAAA,GA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A,CAAE;EAAEhD,IAAI;EAAEN,KAAK;EAAEyC,QAAQ;EAAEc;AAAQ,CAAC,EAAG;EAC3E,OACC,IAAAP,MAAA,CAAAC,aAAA,EAAC3D,WAAA,CAAAkE,WAAW;IACXC,SAAS;IACTF,OAAO,EAAGA,OAAS;IACnBG,UAAU;IACVC,YAAY,EAAG;MAAEC,WAAW,EAAE,CAAC;MAAEC,YAAY,EAAE;IAAE,CAAG;IACpDC,aAAa;IACbC,UAAU,EAAG,IAAM;IACnBC,MAAM,EAAC;EAAyB,GAEhC,IAAAhB,MAAA,CAAAC,aAAA,EAAC3D,WAAA,CAAAkE,WAAW,CAACS,mBAAmB;IAACC,OAAO;IAACC,IAAI;EAAA,GAC5C,IAAAnB,MAAA,CAAAC,aAAA,EAAC3D,WAAA,CAAAkE,WAAW,CAACY,gBAAgB;IAAC9D,IAAI,EAAC;EAAY,GAC9C,IAAA0C,MAAA,CAAAC,aAAA,EAACT,WAAW;IACXlC,IAAI,EAAGA,IAAM;IACbN,KAAK,EAAGA,KAAO;IACfyC,QAAQ,EAAGA;EAAU,CACrB,CAC4B,CACE,CACrB,CAAC;AAEhB"}
|
|
1
|
+
{"version":3,"names":["_element","require","_richText","_blockEditor","_components","_index","_inline","parseCSS","css","split","reduce","accumulator","rule","property","value","replace","color","transparentValue","backgroundColor","getActiveColors","name","colorSettings","activeColorFormat","getActiveFormat","attributes","style","parseClassName","class","setColors","colors","contentRef","onRemoveMarkFormatting","removeFormat","styles","classNames","push","join","colorObject","getColorObjectByColorValue","getColorClassName","slug","length","format","type","hasNoSelection","start","end","onMarkFormatting","applyFormat","ColorPicker","onChange","useMobileGlobalStylesColors","useMultipleOriginColorsAndGradients","onColorChange","useCallback","activeColors","useMemo","_react","createElement","ColorSettings","colorValue","onColorCleared","defaultSettings","hideNavigation","InlineColorUI","onClose","BottomSheet","isVisible","hideHeader","contentStyle","paddingLeft","paddingRight","hasNavigation","leftButton","testID","NavigationContainer","animate","main","NavigationScreen"],"sources":["@wordpress/format-library/src/text-color/inline.native.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useCallback, useMemo } from '@wordpress/element';\nimport {\n\tapplyFormat,\n\tremoveFormat,\n\tgetActiveFormat,\n} from '@wordpress/rich-text';\nimport {\n\tgetColorClassName,\n\tgetColorObjectByColorValue,\n\tuseMultipleOriginColorsAndGradients,\n} from '@wordpress/block-editor';\nimport {\n\tBottomSheet,\n\tColorSettings,\n\tuseMobileGlobalStylesColors,\n} from '@wordpress/components';\n\n/**\n * Internal dependencies\n */\nimport { transparentValue } from './index.js';\nimport { parseClassName } from './inline.js';\n\nfunction parseCSS( css = '' ) {\n\treturn css.split( ';' ).reduce( ( accumulator, rule ) => {\n\t\tif ( rule ) {\n\t\t\tconst [ property, value ] = rule.replace( / /g, '' ).split( ':' );\n\t\t\tif ( property === 'color' ) accumulator.color = value;\n\t\t\tif ( property === 'background-color' && value !== transparentValue )\n\t\t\t\taccumulator.backgroundColor = value;\n\t\t}\n\t\treturn accumulator;\n\t}, {} );\n}\n\nexport function getActiveColors( value, name, colorSettings ) {\n\tconst activeColorFormat = getActiveFormat( value, name );\n\n\tif ( ! activeColorFormat ) {\n\t\treturn {};\n\t}\n\n\treturn {\n\t\t...parseCSS( activeColorFormat.attributes.style ),\n\t\t...parseClassName( activeColorFormat.attributes.class, colorSettings ),\n\t};\n}\n\nfunction setColors( value, name, colorSettings, colors, contentRef ) {\n\tconst { color, backgroundColor } = {\n\t\t...getActiveColors( value, name, colorSettings ),\n\t\t...colors,\n\t};\n\n\tif ( ! color ) {\n\t\tcontentRef?.onRemoveMarkFormatting();\n\t\treturn removeFormat( value, name );\n\t}\n\n\tconst styles = [];\n\tconst classNames = [];\n\tconst attributes = {};\n\n\tif ( backgroundColor ) {\n\t\tstyles.push( [ 'background-color', backgroundColor ].join( ':' ) );\n\t} else {\n\t\t// Override default browser color for mark element.\n\t\tstyles.push( [ 'background-color', transparentValue ].join( ':' ) );\n\t}\n\n\tif ( color ) {\n\t\tconst colorObject = getColorObjectByColorValue( colorSettings, color );\n\n\t\tif ( colorObject ) {\n\t\t\tclassNames.push( getColorClassName( 'color', colorObject.slug ) );\n\t\t\tstyles.push( [ 'color', colorObject.color ].join( ':' ) );\n\t\t} else {\n\t\t\tstyles.push( [ 'color', color ].join( ':' ) );\n\t\t}\n\t}\n\n\tif ( styles.length ) attributes.style = styles.join( ';' );\n\tif ( classNames.length ) attributes.class = classNames.join( ' ' );\n\n\tconst format = { type: name, attributes };\n\tconst hasNoSelection = value.start === value.end;\n\n\tif ( hasNoSelection ) {\n\t\tcontentRef?.onMarkFormatting( color );\n\t}\n\treturn applyFormat( value, format );\n}\n\nfunction ColorPicker( { name, value, onChange, contentRef } ) {\n\tconst property = 'color';\n\tconst colors = useMobileGlobalStylesColors();\n\tconst colorSettings = useMultipleOriginColorsAndGradients();\n\n\tconst onColorChange = useCallback(\n\t\t( color ) => {\n\t\t\tonChange(\n\t\t\t\tsetColors(\n\t\t\t\t\tvalue,\n\t\t\t\t\tname,\n\t\t\t\t\tcolors,\n\t\t\t\t\t{ [ property ]: color },\n\t\t\t\t\tcontentRef\n\t\t\t\t)\n\t\t\t);\n\t\t},\n\t\t[ colors, contentRef, name, onChange, value ]\n\t);\n\tconst activeColors = useMemo(\n\t\t() => getActiveColors( value, name, colors ),\n\t\t[ name, value, colors ]\n\t);\n\n\treturn (\n\t\t<ColorSettings\n\t\t\tcolorValue={ activeColors[ property ] }\n\t\t\tonColorChange={ onColorChange }\n\t\t\tonColorCleared={ onColorChange }\n\t\t\tdefaultSettings={ colorSettings }\n\t\t\thideNavigation\n\t\t/>\n\t);\n}\n\nexport default function InlineColorUI( {\n\tname,\n\tvalue,\n\tonChange,\n\tonClose,\n\tcontentRef,\n} ) {\n\treturn (\n\t\t<BottomSheet\n\t\t\tisVisible\n\t\t\tonClose={ onClose }\n\t\t\thideHeader\n\t\t\tcontentStyle={ { paddingLeft: 0, paddingRight: 0 } }\n\t\t\thasNavigation\n\t\t\tleftButton={ null }\n\t\t\ttestID=\"inline-text-color-modal\"\n\t\t>\n\t\t\t<BottomSheet.NavigationContainer animate main>\n\t\t\t\t<BottomSheet.NavigationScreen name=\"text-color\">\n\t\t\t\t\t<ColorPicker\n\t\t\t\t\t\tname={ name }\n\t\t\t\t\t\tvalue={ value }\n\t\t\t\t\t\tonChange={ onChange }\n\t\t\t\t\t\tcontentRef={ contentRef }\n\t\t\t\t\t/>\n\t\t\t\t</BottomSheet.NavigationScreen>\n\t\t\t</BottomSheet.NavigationContainer>\n\t\t</BottomSheet>\n\t);\n}\n"],"mappings":";;;;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;AAKA,IAAAE,YAAA,GAAAF,OAAA;AAKA,IAAAG,WAAA,GAAAH,OAAA;AASA,IAAAI,MAAA,GAAAJ,OAAA;AACA,IAAAK,OAAA,GAAAL,OAAA;AAxBA;AACA;AACA;;AAkBA;AACA;AACA;;AAIA,SAASM,QAAQA,CAAEC,GAAG,GAAG,EAAE,EAAG;EAC7B,OAAOA,GAAG,CAACC,KAAK,CAAE,GAAI,CAAC,CAACC,MAAM,CAAE,CAAEC,WAAW,EAAEC,IAAI,KAAM;IACxD,IAAKA,IAAI,EAAG;MACX,MAAM,CAAEC,QAAQ,EAAEC,KAAK,CAAE,GAAGF,IAAI,CAACG,OAAO,CAAE,IAAI,EAAE,EAAG,CAAC,CAACN,KAAK,CAAE,GAAI,CAAC;MACjE,IAAKI,QAAQ,KAAK,OAAO,EAAGF,WAAW,CAACK,KAAK,GAAGF,KAAK;MACrD,IAAKD,QAAQ,KAAK,kBAAkB,IAAIC,KAAK,KAAKG,uBAAgB,EACjEN,WAAW,CAACO,eAAe,GAAGJ,KAAK;IACrC;IACA,OAAOH,WAAW;EACnB,CAAC,EAAE,CAAC,CAAE,CAAC;AACR;AAEO,SAASQ,eAAeA,CAAEL,KAAK,EAAEM,IAAI,EAAEC,aAAa,EAAG;EAC7D,MAAMC,iBAAi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unknown/index.js
CHANGED
|
@@ -15,6 +15,15 @@ var _icons = require("@wordpress/icons");
|
|
|
15
15
|
|
|
16
16
|
const name = 'core/unknown';
|
|
17
17
|
const title = (0, _i18n.__)('Clear Unknown Formatting');
|
|
18
|
+
function selectionContainsUnknownFormats(value) {
|
|
19
|
+
if ((0, _richText.isCollapsed)(value)) {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
const selectedValue = (0, _richText.slice)(value);
|
|
23
|
+
return selectedValue.formats.some(formats => {
|
|
24
|
+
return formats.some(format => format.type === name);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
18
27
|
const unknown = exports.unknown = {
|
|
19
28
|
name,
|
|
20
29
|
title,
|
|
@@ -26,17 +35,13 @@ const unknown = exports.unknown = {
|
|
|
26
35
|
onChange,
|
|
27
36
|
onFocus
|
|
28
37
|
}) {
|
|
38
|
+
if (!isActive && !selectionContainsUnknownFormats(value)) {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
29
41
|
function onClick() {
|
|
30
42
|
onChange((0, _richText.removeFormat)(value, name));
|
|
31
43
|
onFocus();
|
|
32
44
|
}
|
|
33
|
-
const selectedValue = (0, _richText.slice)(value);
|
|
34
|
-
const hasUnknownFormats = selectedValue.formats.some(formats => {
|
|
35
|
-
return formats.some(format => format.type === name);
|
|
36
|
-
});
|
|
37
|
-
if (!isActive && !hasUnknownFormats) {
|
|
38
|
-
return null;
|
|
39
|
-
}
|
|
40
45
|
return (0, _react.createElement)(_blockEditor.RichTextToolbarButton, {
|
|
41
46
|
name: "unknown",
|
|
42
47
|
icon: _icons.help,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_i18n","require","_richText","_blockEditor","_icons","name","title","__","
|
|
1
|
+
{"version":3,"names":["_i18n","require","_richText","_blockEditor","_icons","name","title","__","selectionContainsUnknownFormats","value","isCollapsed","selectedValue","slice","formats","some","format","type","unknown","exports","tagName","className","edit","isActive","onChange","onFocus","onClick","removeFormat","_react","createElement","RichTextToolbarButton","icon","help"],"sources":["@wordpress/format-library/src/unknown/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { removeFormat, slice, isCollapsed } from '@wordpress/rich-text';\nimport { RichTextToolbarButton } from '@wordpress/block-editor';\nimport { help } from '@wordpress/icons';\n\nconst name = 'core/unknown';\nconst title = __( 'Clear Unknown Formatting' );\n\nfunction selectionContainsUnknownFormats( value ) {\n\tif ( isCollapsed( value ) ) {\n\t\treturn false;\n\t}\n\n\tconst selectedValue = slice( value );\n\treturn selectedValue.formats.some( ( formats ) => {\n\t\treturn formats.some( ( format ) => format.type === name );\n\t} );\n}\n\nexport const unknown = {\n\tname,\n\ttitle,\n\ttagName: '*',\n\tclassName: null,\n\tedit( { isActive, value, onChange, onFocus } ) {\n\t\tif ( ! isActive && ! selectionContainsUnknownFormats( value ) ) {\n\t\t\treturn null;\n\t\t}\n\n\t\tfunction onClick() {\n\t\t\tonChange( removeFormat( value, name ) );\n\t\t\tonFocus();\n\t\t}\n\n\t\treturn (\n\t\t\t<RichTextToolbarButton\n\t\t\t\tname=\"unknown\"\n\t\t\t\ticon={ help }\n\t\t\t\ttitle={ title }\n\t\t\t\tonClick={ onClick }\n\t\t\t\tisActive\n\t\t\t/>\n\t\t);\n\t},\n};\n"],"mappings":";;;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;AACA,IAAAE,YAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AANA;AACA;AACA;;AAMA,MAAMI,IAAI,GAAG,cAAc;AAC3B,MAAMC,KAAK,GAAG,IAAAC,QAAE,EAAE,0BAA2B,CAAC;AAE9C,SAASC,+BAA+BA,CAAEC,KAAK,EAAG;EACjD,IAAK,IAAAC,qBAAW,EAAED,KAAM,CAAC,EAAG;IAC3B,OAAO,KAAK;EACb;EAEA,MAAME,aAAa,GAAG,IAAAC,eAAK,EAAEH,KAAM,CAAC;EACpC,OAAOE,aAAa,CAACE,OAAO,CAACC,IAAI,CAAID,OAAO,IAAM;IACjD,OAAOA,OAAO,CAACC,IAAI,CAAIC,MAAM,IAAMA,MAAM,CAACC,IAAI,KAAKX,IAAK,CAAC;EAC1D,CAAE,CAAC;AACJ;AAEO,MAAMY,OAAO,GAAAC,OAAA,CAAAD,OAAA,GAAG;EACtBZ,IAAI;EACJC,KAAK;EACLa,OAAO,EAAE,GAAG;EACZC,SAAS,EAAE,IAAI;EACfC,IAAIA,CAAE;IAAEC,QAAQ;IAAEb,KAAK;IAAEc,QAAQ;IAAEC;EAAQ,CAAC,EAAG;IAC9C,IAAK,CAAEF,QAAQ,IAAI,CAAEd,+BAA+B,CAAEC,KAAM,CAAC,EAAG;MAC/D,OAAO,IAAI;IACZ;IAEA,SAASgB,OAAOA,CAAA,EAAG;MAClBF,QAAQ,CAAE,IAAAG,sBAAY,EAAEjB,KAAK,EAAEJ,IAAK,CAAE,CAAC;MACvCmB,OAAO,CAAC,CAAC;IACV;IAEA,OACC,IAAAG,MAAA,CAAAC,aAAA,EAACzB,YAAA,CAAA0B,qBAAqB;MACrBxB,IAAI,EAAC,SAAS;MACdyB,IAAI,EAAGC,WAAM;MACbzB,KAAK,EAAGA,KAAO;MACfmB,OAAO,EAAGA,OAAS;MACnBH,QAAQ;IAAA,CACR,CAAC;EAEJ;AACD,CAAC"}
|
|
@@ -18,7 +18,7 @@ import { usePreferredColorSchemeStyle } from '@wordpress/compose';
|
|
|
18
18
|
/**
|
|
19
19
|
* Internal dependencies
|
|
20
20
|
*/
|
|
21
|
-
import { getActiveColors } from './inline.js';
|
|
21
|
+
import { getActiveColors } from './inline.native.js';
|
|
22
22
|
import { default as InlineColorUI } from './inline';
|
|
23
23
|
import styles from './style.scss';
|
|
24
24
|
const name = 'core/text-color';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["StyleSheet","View","__","useCallback","useMemo","useState","BlockControls","useSettings","ToolbarGroup","ToolbarButton","useMobileGlobalStylesColors","Icon","color","colorIcon","textColor","textColorIcon","removeFormat","usePreferredColorSchemeStyle","getActiveColors","default","InlineColorUI","styles","name","title","getComputedStyleProperty","element","property","_element$props$style","style","props","backgroundColor","baseColors","background","fillComputedColors","TextColorEdit","value","onChange","isActive","activeAttributes","contentRef","allowCustomControl","colors","isAddingColor","setIsAddingColor","enableIsAddingColor","disableIsAddingColor","colorIndicatorStyle","hasColorsToChoose","length","onPressButton","outlineStyle","borderWidth","hairlineWidth","isActiveStyle","customContainerStyles","createElement","Fragment","pointerEvents","icon","Object","keys","extraProps","onClick","onClose","tagName","className","attributes","class","edit"],"sources":["@wordpress/format-library/src/text-color/index.native.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport { StyleSheet, View } from 'react-native';\n\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useCallback, useMemo, useState } from '@wordpress/element';\nimport { BlockControls, useSettings } from '@wordpress/block-editor';\nimport {\n\tToolbarGroup,\n\tToolbarButton,\n\tuseMobileGlobalStylesColors,\n} from '@wordpress/components';\nimport {\n\tIcon,\n\tcolor as colorIcon,\n\ttextColor as textColorIcon,\n} from '@wordpress/icons';\nimport { removeFormat } from '@wordpress/rich-text';\nimport { usePreferredColorSchemeStyle } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { getActiveColors } from './inline.js';\nimport { default as InlineColorUI } from './inline';\nimport styles from './style.scss';\n\nconst name = 'core/text-color';\nconst title = __( 'Text color' );\n\nfunction getComputedStyleProperty( element, property ) {\n\tconst style = element?.props?.style ?? {};\n\n\tif ( property === 'background-color' ) {\n\t\tconst { backgroundColor, baseColors } = style;\n\n\t\tif ( backgroundColor !== 'transparent' ) {\n\t\t\treturn backgroundColor;\n\t\t} else if ( baseColors && baseColors?.color?.background ) {\n\t\t\treturn baseColors?.color?.background;\n\t\t}\n\n\t\treturn 'transparent';\n\t}\n}\n\nfunction fillComputedColors( element, { color, backgroundColor } ) {\n\tif ( ! color && ! backgroundColor ) {\n\t\treturn;\n\t}\n\n\treturn {\n\t\tcolor: color || getComputedStyleProperty( element, 'color' ),\n\t\tbackgroundColor: getComputedStyleProperty(\n\t\t\telement,\n\t\t\t'background-color'\n\t\t),\n\t};\n}\n\nfunction TextColorEdit( {\n\tvalue,\n\tonChange,\n\tisActive,\n\tactiveAttributes,\n\tcontentRef,\n} ) {\n\tconst [ allowCustomControl ] = useSettings( 'color.custom' );\n\tconst colors = useMobileGlobalStylesColors();\n\tconst [ isAddingColor, setIsAddingColor ] = useState( false );\n\tconst enableIsAddingColor = useCallback(\n\t\t() => setIsAddingColor( true ),\n\t\t[ setIsAddingColor ]\n\t);\n\tconst disableIsAddingColor = useCallback(\n\t\t() => setIsAddingColor( false ),\n\t\t[ setIsAddingColor ]\n\t);\n\tconst colorIndicatorStyle = useMemo(\n\t\t() =>\n\t\t\tfillComputedColors(\n\t\t\t\tcontentRef,\n\t\t\t\tgetActiveColors( value, name, colors )\n\t\t\t),\n\t\t[ value, colors ]\n\t);\n\n\tconst hasColorsToChoose = colors.length || ! allowCustomControl;\n\n\tconst onPressButton = useCallback( () => {\n\t\tif ( hasColorsToChoose ) {\n\t\t\tenableIsAddingColor();\n\t\t} else {\n\t\t\tonChange( removeFormat( value, name ) );\n\t\t}\n\t}, [ hasColorsToChoose, value ] );\n\n\tconst outlineStyle = [\n\t\tusePreferredColorSchemeStyle(\n\t\t\tstyles[ 'components-inline-color__outline' ],\n\t\t\tstyles[ 'components-inline-color__outline--dark' ]\n\t\t),\n\t\t{ borderWidth: StyleSheet.hairlineWidth },\n\t];\n\n\tif ( ! hasColorsToChoose && ! isActive ) {\n\t\treturn null;\n\t}\n\n\tconst isActiveStyle = {\n\t\t...colorIndicatorStyle,\n\t\t...( ! colorIndicatorStyle?.backgroundColor\n\t\t\t? { backgroundColor: 'transparent' }\n\t\t\t: {} ),\n\t\t...styles[ 'components-inline-color--is-active' ],\n\t};\n\n\tconst customContainerStyles =\n\t\tstyles[ 'components-inline-color__button-container' ];\n\n\treturn (\n\t\t<>\n\t\t\t<BlockControls>\n\t\t\t\t<ToolbarGroup>\n\t\t\t\t\t{ isActive && (\n\t\t\t\t\t\t<View style={ outlineStyle } pointerEvents=\"none\" />\n\t\t\t\t\t) }\n\n\t\t\t\t\t<ToolbarButton\n\t\t\t\t\t\tname=\"text-color\"\n\t\t\t\t\t\tisActive={ isActive }\n\t\t\t\t\t\ticon={\n\t\t\t\t\t\t\t<Icon\n\t\t\t\t\t\t\t\ticon={\n\t\t\t\t\t\t\t\t\tObject.keys( activeAttributes ).length\n\t\t\t\t\t\t\t\t\t\t? textColorIcon\n\t\t\t\t\t\t\t\t\t\t: colorIcon\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tstyle={\n\t\t\t\t\t\t\t\t\tcolorIndicatorStyle?.color && {\n\t\t\t\t\t\t\t\t\t\tcolor: colorIndicatorStyle.color,\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t}\n\t\t\t\t\t\ttitle={ title }\n\t\t\t\t\t\textraProps={ {\n\t\t\t\t\t\t\tisActiveStyle,\n\t\t\t\t\t\t\tcustomContainerStyles,\n\t\t\t\t\t\t} }\n\t\t\t\t\t\t// If has no colors to choose but a color is active remove the color onClick\n\t\t\t\t\t\tonClick={ onPressButton }\n\t\t\t\t\t/>\n\t\t\t\t</ToolbarGroup>\n\t\t\t</BlockControls>\n\t\t\t{ isAddingColor && (\n\t\t\t\t<InlineColorUI\n\t\t\t\t\tname={ name }\n\t\t\t\t\tonClose={ disableIsAddingColor }\n\t\t\t\t\tactiveAttributes={ activeAttributes }\n\t\t\t\t\tvalue={ value }\n\t\t\t\t\tonChange={ onChange }\n\t\t\t\t\tcontentRef={ contentRef }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nexport const textColor = {\n\tname,\n\ttitle,\n\ttagName: 'mark',\n\tclassName: 'has-inline-color',\n\tattributes: {\n\t\tstyle: 'style',\n\t\tclass: 'class',\n\t},\n\tedit: TextColorEdit,\n};\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,UAAU,EAAEC,IAAI,QAAQ,cAAc;;AAE/C;AACA;AACA;AACA,SAASC,EAAE,QAAQ,iBAAiB;AACpC,SAASC,WAAW,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,oBAAoB;AACnE,SAASC,aAAa,EAAEC,WAAW,QAAQ,yBAAyB;AACpE,SACCC,YAAY,EACZC,aAAa,EACbC,2BAA2B,QACrB,uBAAuB;AAC9B,SACCC,IAAI,EACJC,KAAK,IAAIC,SAAS,EAClBC,SAAS,IAAIC,aAAa,QACpB,kBAAkB;AACzB,SAASC,YAAY,QAAQ,sBAAsB;AACnD,SAASC,4BAA4B,QAAQ,oBAAoB;;AAEjE;AACA;AACA;AACA,SAASC,eAAe,QAAQ,
|
|
1
|
+
{"version":3,"names":["StyleSheet","View","__","useCallback","useMemo","useState","BlockControls","useSettings","ToolbarGroup","ToolbarButton","useMobileGlobalStylesColors","Icon","color","colorIcon","textColor","textColorIcon","removeFormat","usePreferredColorSchemeStyle","getActiveColors","default","InlineColorUI","styles","name","title","getComputedStyleProperty","element","property","_element$props$style","style","props","backgroundColor","baseColors","background","fillComputedColors","TextColorEdit","value","onChange","isActive","activeAttributes","contentRef","allowCustomControl","colors","isAddingColor","setIsAddingColor","enableIsAddingColor","disableIsAddingColor","colorIndicatorStyle","hasColorsToChoose","length","onPressButton","outlineStyle","borderWidth","hairlineWidth","isActiveStyle","customContainerStyles","createElement","Fragment","pointerEvents","icon","Object","keys","extraProps","onClick","onClose","tagName","className","attributes","class","edit"],"sources":["@wordpress/format-library/src/text-color/index.native.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport { StyleSheet, View } from 'react-native';\n\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useCallback, useMemo, useState } from '@wordpress/element';\nimport { BlockControls, useSettings } from '@wordpress/block-editor';\nimport {\n\tToolbarGroup,\n\tToolbarButton,\n\tuseMobileGlobalStylesColors,\n} from '@wordpress/components';\nimport {\n\tIcon,\n\tcolor as colorIcon,\n\ttextColor as textColorIcon,\n} from '@wordpress/icons';\nimport { removeFormat } from '@wordpress/rich-text';\nimport { usePreferredColorSchemeStyle } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { getActiveColors } from './inline.native.js';\nimport { default as InlineColorUI } from './inline';\nimport styles from './style.scss';\n\nconst name = 'core/text-color';\nconst title = __( 'Text color' );\n\nfunction getComputedStyleProperty( element, property ) {\n\tconst style = element?.props?.style ?? {};\n\n\tif ( property === 'background-color' ) {\n\t\tconst { backgroundColor, baseColors } = style;\n\n\t\tif ( backgroundColor !== 'transparent' ) {\n\t\t\treturn backgroundColor;\n\t\t} else if ( baseColors && baseColors?.color?.background ) {\n\t\t\treturn baseColors?.color?.background;\n\t\t}\n\n\t\treturn 'transparent';\n\t}\n}\n\nfunction fillComputedColors( element, { color, backgroundColor } ) {\n\tif ( ! color && ! backgroundColor ) {\n\t\treturn;\n\t}\n\n\treturn {\n\t\tcolor: color || getComputedStyleProperty( element, 'color' ),\n\t\tbackgroundColor: getComputedStyleProperty(\n\t\t\telement,\n\t\t\t'background-color'\n\t\t),\n\t};\n}\n\nfunction TextColorEdit( {\n\tvalue,\n\tonChange,\n\tisActive,\n\tactiveAttributes,\n\tcontentRef,\n} ) {\n\tconst [ allowCustomControl ] = useSettings( 'color.custom' );\n\tconst colors = useMobileGlobalStylesColors();\n\tconst [ isAddingColor, setIsAddingColor ] = useState( false );\n\tconst enableIsAddingColor = useCallback(\n\t\t() => setIsAddingColor( true ),\n\t\t[ setIsAddingColor ]\n\t);\n\tconst disableIsAddingColor = useCallback(\n\t\t() => setIsAddingColor( false ),\n\t\t[ setIsAddingColor ]\n\t);\n\tconst colorIndicatorStyle = useMemo(\n\t\t() =>\n\t\t\tfillComputedColors(\n\t\t\t\tcontentRef,\n\t\t\t\tgetActiveColors( value, name, colors )\n\t\t\t),\n\t\t[ value, colors ]\n\t);\n\n\tconst hasColorsToChoose = colors.length || ! allowCustomControl;\n\n\tconst onPressButton = useCallback( () => {\n\t\tif ( hasColorsToChoose ) {\n\t\t\tenableIsAddingColor();\n\t\t} else {\n\t\t\tonChange( removeFormat( value, name ) );\n\t\t}\n\t}, [ hasColorsToChoose, value ] );\n\n\tconst outlineStyle = [\n\t\tusePreferredColorSchemeStyle(\n\t\t\tstyles[ 'components-inline-color__outline' ],\n\t\t\tstyles[ 'components-inline-color__outline--dark' ]\n\t\t),\n\t\t{ borderWidth: StyleSheet.hairlineWidth },\n\t];\n\n\tif ( ! hasColorsToChoose && ! isActive ) {\n\t\treturn null;\n\t}\n\n\tconst isActiveStyle = {\n\t\t...colorIndicatorStyle,\n\t\t...( ! colorIndicatorStyle?.backgroundColor\n\t\t\t? { backgroundColor: 'transparent' }\n\t\t\t: {} ),\n\t\t...styles[ 'components-inline-color--is-active' ],\n\t};\n\n\tconst customContainerStyles =\n\t\tstyles[ 'components-inline-color__button-container' ];\n\n\treturn (\n\t\t<>\n\t\t\t<BlockControls>\n\t\t\t\t<ToolbarGroup>\n\t\t\t\t\t{ isActive && (\n\t\t\t\t\t\t<View style={ outlineStyle } pointerEvents=\"none\" />\n\t\t\t\t\t) }\n\n\t\t\t\t\t<ToolbarButton\n\t\t\t\t\t\tname=\"text-color\"\n\t\t\t\t\t\tisActive={ isActive }\n\t\t\t\t\t\ticon={\n\t\t\t\t\t\t\t<Icon\n\t\t\t\t\t\t\t\ticon={\n\t\t\t\t\t\t\t\t\tObject.keys( activeAttributes ).length\n\t\t\t\t\t\t\t\t\t\t? textColorIcon\n\t\t\t\t\t\t\t\t\t\t: colorIcon\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tstyle={\n\t\t\t\t\t\t\t\t\tcolorIndicatorStyle?.color && {\n\t\t\t\t\t\t\t\t\t\tcolor: colorIndicatorStyle.color,\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t}\n\t\t\t\t\t\ttitle={ title }\n\t\t\t\t\t\textraProps={ {\n\t\t\t\t\t\t\tisActiveStyle,\n\t\t\t\t\t\t\tcustomContainerStyles,\n\t\t\t\t\t\t} }\n\t\t\t\t\t\t// If has no colors to choose but a color is active remove the color onClick\n\t\t\t\t\t\tonClick={ onPressButton }\n\t\t\t\t\t/>\n\t\t\t\t</ToolbarGroup>\n\t\t\t</BlockControls>\n\t\t\t{ isAddingColor && (\n\t\t\t\t<InlineColorUI\n\t\t\t\t\tname={ name }\n\t\t\t\t\tonClose={ disableIsAddingColor }\n\t\t\t\t\tactiveAttributes={ activeAttributes }\n\t\t\t\t\tvalue={ value }\n\t\t\t\t\tonChange={ onChange }\n\t\t\t\t\tcontentRef={ contentRef }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nexport const textColor = {\n\tname,\n\ttitle,\n\ttagName: 'mark',\n\tclassName: 'has-inline-color',\n\tattributes: {\n\t\tstyle: 'style',\n\t\tclass: 'class',\n\t},\n\tedit: TextColorEdit,\n};\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,UAAU,EAAEC,IAAI,QAAQ,cAAc;;AAE/C;AACA;AACA;AACA,SAASC,EAAE,QAAQ,iBAAiB;AACpC,SAASC,WAAW,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,oBAAoB;AACnE,SAASC,aAAa,EAAEC,WAAW,QAAQ,yBAAyB;AACpE,SACCC,YAAY,EACZC,aAAa,EACbC,2BAA2B,QACrB,uBAAuB;AAC9B,SACCC,IAAI,EACJC,KAAK,IAAIC,SAAS,EAClBC,SAAS,IAAIC,aAAa,QACpB,kBAAkB;AACzB,SAASC,YAAY,QAAQ,sBAAsB;AACnD,SAASC,4BAA4B,QAAQ,oBAAoB;;AAEjE;AACA;AACA;AACA,SAASC,eAAe,QAAQ,oBAAoB;AACpD,SAASC,OAAO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GAC1BjC,MAAM,CAAE,2CAA2C,CAAE;EAEtD,OACCkC,aAAA,CAAAC,QAAA,QACCD,aAAA,CAACjD,aAAa,QACbiD,aAAA,CAAC/C,YAAY,QACV6B,QAAQ,IACTkB,aAAA,CAACtD,IAAI;IAAC2B,KAAK,EAAGsB,YAAc;IAACO,aAAa,EAAC;EAAM,CAAE,CACnD,EAEDF,aAAA,CAAC9C,aAAa;IACba,IAAI,EAAC,YAAY;IACjBe,QAAQ,EAAGA,QAAU;IACrBqB,IAAI,EACHH,aAAA,CAAC5C,IAAI;MACJ+C,IAAI,EACHC,MAAM,CAACC,IAAI,CAAEtB,gBAAiB,CAAC,CAACU,MAAM,GACnCjC,aAAa,GACbF,SACH;MACDe,KAAK,EACJkB,mBAAmB,EAAElC,KAAK,IAAI;QAC7BA,KAAK,EAAEkC,mBAAmB,CAAClC;MAC5B;IACA,CACD,CACD;IACDW,KAAK,EAAGA,KAAO;IACfsC,UAAU,EAAG;MACZR,aAAa;MACbC;IACD;IACA;IAAA;IACAQ,OAAO,EAAGb;EAAe,CACzB,CACY,CACA,CAAC,EACdP,aAAa,IACda,aAAA,CAACnC,aAAa;IACbE,IAAI,EAAGA,IAAM;IACbyC,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;EACxBQ,IAAI;EACJC,KAAK;EACLyC,OAAO,EAAE,MAAM;EACfC,SAAS,EAAE,kBAAkB;EAC7BC,UAAU,EAAE;IACXtC,KAAK,EAAE,OAAO;IACduC,KAAK,EAAE;EACR,CAAC;EACDC,IAAI,EAAElC;AACP,CAAC"}
|
|
@@ -22,7 +22,7 @@ function parseCSS(css = '') {
|
|
|
22
22
|
return accumulator;
|
|
23
23
|
}, {});
|
|
24
24
|
}
|
|
25
|
-
function getActiveColors(value, name, colorSettings) {
|
|
25
|
+
export function getActiveColors(value, name, colorSettings) {
|
|
26
26
|
const activeColorFormat = getActiveFormat(value, name);
|
|
27
27
|
if (!activeColorFormat) {
|
|
28
28
|
return {};
|
|
@@ -32,7 +32,7 @@ function getActiveColors(value, name, colorSettings) {
|
|
|
32
32
|
...parseClassName(activeColorFormat.attributes.class, colorSettings)
|
|
33
33
|
};
|
|
34
34
|
}
|
|
35
|
-
function setColors(value, name, colorSettings, colors) {
|
|
35
|
+
function setColors(value, name, colorSettings, colors, contentRef) {
|
|
36
36
|
const {
|
|
37
37
|
color,
|
|
38
38
|
backgroundColor
|
|
@@ -40,7 +40,8 @@ function setColors(value, name, colorSettings, colors) {
|
|
|
40
40
|
...getActiveColors(value, name, colorSettings),
|
|
41
41
|
...colors
|
|
42
42
|
};
|
|
43
|
-
if (!color
|
|
43
|
+
if (!color) {
|
|
44
|
+
contentRef?.onRemoveMarkFormatting();
|
|
44
45
|
return removeFormat(value, name);
|
|
45
46
|
}
|
|
46
47
|
const styles = [];
|
|
@@ -68,55 +69,30 @@ function setColors(value, name, colorSettings, colors) {
|
|
|
68
69
|
attributes
|
|
69
70
|
};
|
|
70
71
|
const hasNoSelection = value.start === value.end;
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
// Force formatting due to limitations in the native implementation
|
|
75
|
-
if (hasNoSelection && (value.text.length === 0 || previousCharacter === ' ' && isAtTheEnd)) {
|
|
76
|
-
// For cases where there's no text selected, there's a space before
|
|
77
|
-
// the current caret position and it's at the end of the text.
|
|
78
|
-
return applyFormat(value, format, value.start - 1, value.end + 1);
|
|
79
|
-
} else if (hasNoSelection && isAtTheEnd) {
|
|
80
|
-
// If there's no selection and is at the end of the text
|
|
81
|
-
// manually add the format within the current caret position.
|
|
82
|
-
const newFormat = applyFormat(value, format);
|
|
83
|
-
const {
|
|
84
|
-
activeFormats
|
|
85
|
-
} = newFormat;
|
|
86
|
-
newFormat.formats[value.start] = [...(activeFormats?.filter(({
|
|
87
|
-
type
|
|
88
|
-
}) => type !== format.type) || []), format];
|
|
89
|
-
return newFormat;
|
|
90
|
-
} else if (hasNoSelection) {
|
|
91
|
-
return removeFormat(value, format);
|
|
72
|
+
if (hasNoSelection) {
|
|
73
|
+
contentRef?.onMarkFormatting(color);
|
|
92
74
|
}
|
|
93
75
|
return applyFormat(value, format);
|
|
94
76
|
}
|
|
95
77
|
function ColorPicker({
|
|
96
78
|
name,
|
|
97
79
|
value,
|
|
98
|
-
onChange
|
|
80
|
+
onChange,
|
|
81
|
+
contentRef
|
|
99
82
|
}) {
|
|
100
83
|
const property = 'color';
|
|
101
84
|
const colors = useMobileGlobalStylesColors();
|
|
102
85
|
const colorSettings = useMultipleOriginColorsAndGradients();
|
|
103
86
|
const onColorChange = useCallback(color => {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
// Remove formatting if the color was reset, there's no
|
|
109
|
-
// current selection and the previous character is a space
|
|
110
|
-
} else if (value?.start === value?.end && value.text?.charAt(value?.end - 1) === ' ') {
|
|
111
|
-
onChange(removeFormat(value, name, value.end - 1, value.end));
|
|
112
|
-
} else {
|
|
113
|
-
onChange(removeFormat(value, name));
|
|
114
|
-
}
|
|
115
|
-
}, [colors, onChange, property]);
|
|
87
|
+
onChange(setColors(value, name, colors, {
|
|
88
|
+
[property]: color
|
|
89
|
+
}, contentRef));
|
|
90
|
+
}, [colors, contentRef, name, onChange, value]);
|
|
116
91
|
const activeColors = useMemo(() => getActiveColors(value, name, colors), [name, value, colors]);
|
|
117
92
|
return createElement(ColorSettings, {
|
|
118
93
|
colorValue: activeColors[property],
|
|
119
94
|
onColorChange: onColorChange,
|
|
95
|
+
onColorCleared: onColorChange,
|
|
120
96
|
defaultSettings: colorSettings,
|
|
121
97
|
hideNavigation: true
|
|
122
98
|
});
|
|
@@ -125,7 +101,8 @@ export default function InlineColorUI({
|
|
|
125
101
|
name,
|
|
126
102
|
value,
|
|
127
103
|
onChange,
|
|
128
|
-
onClose
|
|
104
|
+
onClose,
|
|
105
|
+
contentRef
|
|
129
106
|
}) {
|
|
130
107
|
return createElement(BottomSheet, {
|
|
131
108
|
isVisible: true,
|
|
@@ -146,7 +123,8 @@ export default function InlineColorUI({
|
|
|
146
123
|
}, createElement(ColorPicker, {
|
|
147
124
|
name: name,
|
|
148
125
|
value: value,
|
|
149
|
-
onChange: onChange
|
|
126
|
+
onChange: onChange,
|
|
127
|
+
contentRef: contentRef
|
|
150
128
|
}))));
|
|
151
129
|
}
|
|
152
130
|
//# sourceMappingURL=inline.native.js.map
|
|
@@ -1 +1 @@
|
|
|
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\t</BottomSheet>\n\t);\n}\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,WAAW,EAAEC,OAAO,QAAQ,oBAAoB;AACzD,SACCC,WAAW,EACXC,YAAY,EACZC,eAAe,QACT,sBAAsB;AAC7B,SACCC,iBAAiB,EACjBC,0BAA0B,EAC1BC,mCAAmC,QAC7B,yBAAyB;AAChC,SACCC,WAAW,EACXC,aAAa,EACbC,2BAA2B,QACrB,uBAAuB;;AAE9B;AACA;AACA;AACA,SAASC,gBAAgB,QAAQ,YAAY;AAC7C,SAASC,cAAc,QAAQ,aAAa;AAE5C,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,CAACG,OAAO,CAAE,IAAI,EAAE,E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IACX5B,IAAI,EAAGA,IAAM;IACbL,KAAK,EAAGA,KAAO;IACfkC,QAAQ,EAAGA;EAAU,CACrB,CAC4B,CACE,CACrB,CAAC;AAEhB"}
|
|
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","contentRef","onRemoveMarkFormatting","styles","classNames","push","join","colorObject","slug","length","format","type","hasNoSelection","start","end","onMarkFormatting","ColorPicker","onChange","onColorChange","activeColors","createElement","colorValue","onColorCleared","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\nexport function getActiveColors( value, name, colorSettings ) {\n\tconst activeColorFormat = getActiveFormat( value, name );\n\n\tif ( ! activeColorFormat ) {\n\t\treturn {};\n\t}\n\n\treturn {\n\t\t...parseCSS( activeColorFormat.attributes.style ),\n\t\t...parseClassName( activeColorFormat.attributes.class, colorSettings ),\n\t};\n}\n\nfunction setColors( value, name, colorSettings, colors, contentRef ) {\n\tconst { color, backgroundColor } = {\n\t\t...getActiveColors( value, name, colorSettings ),\n\t\t...colors,\n\t};\n\n\tif ( ! color ) {\n\t\tcontentRef?.onRemoveMarkFormatting();\n\t\treturn removeFormat( value, name );\n\t}\n\n\tconst styles = [];\n\tconst classNames = [];\n\tconst attributes = {};\n\n\tif ( backgroundColor ) {\n\t\tstyles.push( [ 'background-color', backgroundColor ].join( ':' ) );\n\t} else {\n\t\t// Override default browser color for mark element.\n\t\tstyles.push( [ 'background-color', transparentValue ].join( ':' ) );\n\t}\n\n\tif ( color ) {\n\t\tconst colorObject = getColorObjectByColorValue( colorSettings, color );\n\n\t\tif ( colorObject ) {\n\t\t\tclassNames.push( getColorClassName( 'color', colorObject.slug ) );\n\t\t\tstyles.push( [ 'color', colorObject.color ].join( ':' ) );\n\t\t} else {\n\t\t\tstyles.push( [ 'color', color ].join( ':' ) );\n\t\t}\n\t}\n\n\tif ( styles.length ) attributes.style = styles.join( ';' );\n\tif ( classNames.length ) attributes.class = classNames.join( ' ' );\n\n\tconst format = { type: name, attributes };\n\tconst hasNoSelection = value.start === value.end;\n\n\tif ( hasNoSelection ) {\n\t\tcontentRef?.onMarkFormatting( color );\n\t}\n\treturn applyFormat( value, format );\n}\n\nfunction ColorPicker( { name, value, onChange, contentRef } ) {\n\tconst property = 'color';\n\tconst colors = useMobileGlobalStylesColors();\n\tconst colorSettings = useMultipleOriginColorsAndGradients();\n\n\tconst onColorChange = useCallback(\n\t\t( color ) => {\n\t\t\tonChange(\n\t\t\t\tsetColors(\n\t\t\t\t\tvalue,\n\t\t\t\t\tname,\n\t\t\t\t\tcolors,\n\t\t\t\t\t{ [ property ]: color },\n\t\t\t\t\tcontentRef\n\t\t\t\t)\n\t\t\t);\n\t\t},\n\t\t[ colors, contentRef, name, onChange, value ]\n\t);\n\tconst activeColors = useMemo(\n\t\t() => getActiveColors( value, name, colors ),\n\t\t[ name, value, colors ]\n\t);\n\n\treturn (\n\t\t<ColorSettings\n\t\t\tcolorValue={ activeColors[ property ] }\n\t\t\tonColorChange={ onColorChange }\n\t\t\tonColorCleared={ onColorChange }\n\t\t\tdefaultSettings={ colorSettings }\n\t\t\thideNavigation\n\t\t/>\n\t);\n}\n\nexport default function InlineColorUI( {\n\tname,\n\tvalue,\n\tonChange,\n\tonClose,\n\tcontentRef,\n} ) {\n\treturn (\n\t\t<BottomSheet\n\t\t\tisVisible\n\t\t\tonClose={ onClose }\n\t\t\thideHeader\n\t\t\tcontentStyle={ { paddingLeft: 0, paddingRight: 0 } }\n\t\t\thasNavigation\n\t\t\tleftButton={ null }\n\t\t\ttestID=\"inline-text-color-modal\"\n\t\t>\n\t\t\t<BottomSheet.NavigationContainer animate main>\n\t\t\t\t<BottomSheet.NavigationScreen name=\"text-color\">\n\t\t\t\t\t<ColorPicker\n\t\t\t\t\t\tname={ name }\n\t\t\t\t\t\tvalue={ value }\n\t\t\t\t\t\tonChange={ onChange }\n\t\t\t\t\t\tcontentRef={ contentRef }\n\t\t\t\t\t/>\n\t\t\t\t</BottomSheet.NavigationScreen>\n\t\t\t</BottomSheet.NavigationContainer>\n\t\t</BottomSheet>\n\t);\n}\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,WAAW,EAAEC,OAAO,QAAQ,oBAAoB;AACzD,SACCC,WAAW,EACXC,YAAY,EACZC,eAAe,QACT,sBAAsB;AAC7B,SACCC,iBAAiB,EACjBC,0BAA0B,EAC1BC,mCAAmC,QAC7B,yBAAyB;AAChC,SACCC,WAAW,EACXC,aAAa,EACbC,2BAA2B,QACrB,uBAAuB;;AAE9B;AACA;AACA;AACA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,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,GAEhCd,aAAA,CAAC5C,WAAW,CAAC2D,mBAAmB;IAACC,OAAO;IAACC,IAAI;EAAA,GAC5CjB,aAAA,CAAC5C,WAAW,CAAC8D,gBAAgB;IAAC7C,IAAI,EAAC;EAAY,GAC9C2B,aAAA,CAACJ,WAAW;IACXvB,IAAI,EAAGA,IAAM;IACbL,KAAK,EAAGA,KAAO;IACf6B,QAAQ,EAAGA,QAAU;IACrBhB,UAAU,EAAGA;EAAY,CACzB,CAC4B,CACE,CACrB,CAAC;AAEhB"}
|
|
@@ -3,11 +3,20 @@ import { createElement } from "react";
|
|
|
3
3
|
* WordPress dependencies
|
|
4
4
|
*/
|
|
5
5
|
import { __ } from '@wordpress/i18n';
|
|
6
|
-
import { removeFormat, slice } from '@wordpress/rich-text';
|
|
6
|
+
import { removeFormat, slice, isCollapsed } from '@wordpress/rich-text';
|
|
7
7
|
import { RichTextToolbarButton } from '@wordpress/block-editor';
|
|
8
8
|
import { help } from '@wordpress/icons';
|
|
9
9
|
const name = 'core/unknown';
|
|
10
10
|
const title = __('Clear Unknown Formatting');
|
|
11
|
+
function selectionContainsUnknownFormats(value) {
|
|
12
|
+
if (isCollapsed(value)) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
const selectedValue = slice(value);
|
|
16
|
+
return selectedValue.formats.some(formats => {
|
|
17
|
+
return formats.some(format => format.type === name);
|
|
18
|
+
});
|
|
19
|
+
}
|
|
11
20
|
export const unknown = {
|
|
12
21
|
name,
|
|
13
22
|
title,
|
|
@@ -19,17 +28,13 @@ export const unknown = {
|
|
|
19
28
|
onChange,
|
|
20
29
|
onFocus
|
|
21
30
|
}) {
|
|
31
|
+
if (!isActive && !selectionContainsUnknownFormats(value)) {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
22
34
|
function onClick() {
|
|
23
35
|
onChange(removeFormat(value, name));
|
|
24
36
|
onFocus();
|
|
25
37
|
}
|
|
26
|
-
const selectedValue = slice(value);
|
|
27
|
-
const hasUnknownFormats = selectedValue.formats.some(formats => {
|
|
28
|
-
return formats.some(format => format.type === name);
|
|
29
|
-
});
|
|
30
|
-
if (!isActive && !hasUnknownFormats) {
|
|
31
|
-
return null;
|
|
32
|
-
}
|
|
33
38
|
return createElement(RichTextToolbarButton, {
|
|
34
39
|
name: "unknown",
|
|
35
40
|
icon: help,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["__","removeFormat","slice","RichTextToolbarButton","help","name","title","
|
|
1
|
+
{"version":3,"names":["__","removeFormat","slice","isCollapsed","RichTextToolbarButton","help","name","title","selectionContainsUnknownFormats","value","selectedValue","formats","some","format","type","unknown","tagName","className","edit","isActive","onChange","onFocus","onClick","createElement","icon"],"sources":["@wordpress/format-library/src/unknown/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { removeFormat, slice, isCollapsed } from '@wordpress/rich-text';\nimport { RichTextToolbarButton } from '@wordpress/block-editor';\nimport { help } from '@wordpress/icons';\n\nconst name = 'core/unknown';\nconst title = __( 'Clear Unknown Formatting' );\n\nfunction selectionContainsUnknownFormats( value ) {\n\tif ( isCollapsed( value ) ) {\n\t\treturn false;\n\t}\n\n\tconst selectedValue = slice( value );\n\treturn selectedValue.formats.some( ( formats ) => {\n\t\treturn formats.some( ( format ) => format.type === name );\n\t} );\n}\n\nexport const unknown = {\n\tname,\n\ttitle,\n\ttagName: '*',\n\tclassName: null,\n\tedit( { isActive, value, onChange, onFocus } ) {\n\t\tif ( ! isActive && ! selectionContainsUnknownFormats( value ) ) {\n\t\t\treturn null;\n\t\t}\n\n\t\tfunction onClick() {\n\t\t\tonChange( removeFormat( value, name ) );\n\t\t\tonFocus();\n\t\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B,qBAAqB;MACrBE,IAAI,EAAC,SAAS;MACdkB,IAAI,EAAGnB,IAAM;MACbE,KAAK,EAAGA,KAAO;MACfe,OAAO,EAAGA,OAAS;MACnBH,QAAQ;IAAA,CACR,CAAC;EAEJ;AACD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/format-library",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.32.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,18 +26,18 @@
|
|
|
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": "^27.
|
|
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/private-apis": "^0.
|
|
39
|
-
"@wordpress/rich-text": "^6.
|
|
40
|
-
"@wordpress/url": "^3.
|
|
29
|
+
"@wordpress/a11y": "^3.55.0",
|
|
30
|
+
"@wordpress/block-editor": "^12.23.0",
|
|
31
|
+
"@wordpress/components": "^27.3.0",
|
|
32
|
+
"@wordpress/compose": "^6.32.0",
|
|
33
|
+
"@wordpress/data": "^9.25.0",
|
|
34
|
+
"@wordpress/element": "^5.32.0",
|
|
35
|
+
"@wordpress/html-entities": "^3.55.0",
|
|
36
|
+
"@wordpress/i18n": "^4.55.0",
|
|
37
|
+
"@wordpress/icons": "^9.46.0",
|
|
38
|
+
"@wordpress/private-apis": "^0.37.0",
|
|
39
|
+
"@wordpress/rich-text": "^6.32.0",
|
|
40
|
+
"@wordpress/url": "^3.56.0"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
43
|
"react": "^18.0.0",
|
|
@@ -46,5 +46,5 @@
|
|
|
46
46
|
"publishConfig": {
|
|
47
47
|
"access": "public"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "ac2b13783c28f959770cf029a797a712f59e1958"
|
|
50
50
|
}
|
|
@@ -25,7 +25,7 @@ import { usePreferredColorSchemeStyle } from '@wordpress/compose';
|
|
|
25
25
|
/**
|
|
26
26
|
* Internal dependencies
|
|
27
27
|
*/
|
|
28
|
-
import { getActiveColors } from './inline.js';
|
|
28
|
+
import { getActiveColors } from './inline.native.js';
|
|
29
29
|
import { default as InlineColorUI } from './inline';
|
|
30
30
|
import styles from './style.scss';
|
|
31
31
|
|
|
@@ -36,7 +36,7 @@ function parseCSS( css = '' ) {
|
|
|
36
36
|
}, {} );
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
function getActiveColors( value, name, colorSettings ) {
|
|
39
|
+
export function getActiveColors( value, name, colorSettings ) {
|
|
40
40
|
const activeColorFormat = getActiveFormat( value, name );
|
|
41
41
|
|
|
42
42
|
if ( ! activeColorFormat ) {
|
|
@@ -49,13 +49,14 @@ function getActiveColors( value, name, colorSettings ) {
|
|
|
49
49
|
};
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
function setColors( value, name, colorSettings, colors ) {
|
|
52
|
+
function setColors( value, name, colorSettings, colors, contentRef ) {
|
|
53
53
|
const { color, backgroundColor } = {
|
|
54
54
|
...getActiveColors( value, name, colorSettings ),
|
|
55
55
|
...colors,
|
|
56
56
|
};
|
|
57
57
|
|
|
58
|
-
if ( ! color
|
|
58
|
+
if ( ! color ) {
|
|
59
|
+
contentRef?.onRemoveMarkFormatting();
|
|
59
60
|
return removeFormat( value, name );
|
|
60
61
|
}
|
|
61
62
|
|
|
@@ -86,62 +87,31 @@ function setColors( value, name, colorSettings, colors ) {
|
|
|
86
87
|
|
|
87
88
|
const format = { type: name, attributes };
|
|
88
89
|
const hasNoSelection = value.start === value.end;
|
|
89
|
-
const isAtTheEnd = value.end === value.text.length;
|
|
90
|
-
const previousCharacter = value.text.charAt( value.end - 1 );
|
|
91
|
-
|
|
92
|
-
// Force formatting due to limitations in the native implementation
|
|
93
|
-
if (
|
|
94
|
-
hasNoSelection &&
|
|
95
|
-
( value.text.length === 0 ||
|
|
96
|
-
( previousCharacter === ' ' && isAtTheEnd ) )
|
|
97
|
-
) {
|
|
98
|
-
// For cases where there's no text selected, there's a space before
|
|
99
|
-
// the current caret position and it's at the end of the text.
|
|
100
|
-
return applyFormat( value, format, value.start - 1, value.end + 1 );
|
|
101
|
-
} else if ( hasNoSelection && isAtTheEnd ) {
|
|
102
|
-
// If there's no selection and is at the end of the text
|
|
103
|
-
// manually add the format within the current caret position.
|
|
104
|
-
const newFormat = applyFormat( value, format );
|
|
105
|
-
const { activeFormats } = newFormat;
|
|
106
|
-
newFormat.formats[ value.start ] = [
|
|
107
|
-
...( activeFormats?.filter(
|
|
108
|
-
( { type } ) => type !== format.type
|
|
109
|
-
) || [] ),
|
|
110
|
-
format,
|
|
111
|
-
];
|
|
112
|
-
return newFormat;
|
|
113
|
-
} else if ( hasNoSelection ) {
|
|
114
|
-
return removeFormat( value, format );
|
|
115
|
-
}
|
|
116
90
|
|
|
91
|
+
if ( hasNoSelection ) {
|
|
92
|
+
contentRef?.onMarkFormatting( color );
|
|
93
|
+
}
|
|
117
94
|
return applyFormat( value, format );
|
|
118
95
|
}
|
|
119
96
|
|
|
120
|
-
function ColorPicker( { name, value, onChange } ) {
|
|
97
|
+
function ColorPicker( { name, value, onChange, contentRef } ) {
|
|
121
98
|
const property = 'color';
|
|
122
99
|
const colors = useMobileGlobalStylesColors();
|
|
123
100
|
const colorSettings = useMultipleOriginColorsAndGradients();
|
|
124
101
|
|
|
125
102
|
const onColorChange = useCallback(
|
|
126
103
|
( color ) => {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
) {
|
|
137
|
-
onChange(
|
|
138
|
-
removeFormat( value, name, value.end - 1, value.end )
|
|
139
|
-
);
|
|
140
|
-
} else {
|
|
141
|
-
onChange( removeFormat( value, name ) );
|
|
142
|
-
}
|
|
104
|
+
onChange(
|
|
105
|
+
setColors(
|
|
106
|
+
value,
|
|
107
|
+
name,
|
|
108
|
+
colors,
|
|
109
|
+
{ [ property ]: color },
|
|
110
|
+
contentRef
|
|
111
|
+
)
|
|
112
|
+
);
|
|
143
113
|
},
|
|
144
|
-
[ colors, onChange,
|
|
114
|
+
[ colors, contentRef, name, onChange, value ]
|
|
145
115
|
);
|
|
146
116
|
const activeColors = useMemo(
|
|
147
117
|
() => getActiveColors( value, name, colors ),
|
|
@@ -152,13 +122,20 @@ function ColorPicker( { name, value, onChange } ) {
|
|
|
152
122
|
<ColorSettings
|
|
153
123
|
colorValue={ activeColors[ property ] }
|
|
154
124
|
onColorChange={ onColorChange }
|
|
125
|
+
onColorCleared={ onColorChange }
|
|
155
126
|
defaultSettings={ colorSettings }
|
|
156
127
|
hideNavigation
|
|
157
128
|
/>
|
|
158
129
|
);
|
|
159
130
|
}
|
|
160
131
|
|
|
161
|
-
export default function InlineColorUI( {
|
|
132
|
+
export default function InlineColorUI( {
|
|
133
|
+
name,
|
|
134
|
+
value,
|
|
135
|
+
onChange,
|
|
136
|
+
onClose,
|
|
137
|
+
contentRef,
|
|
138
|
+
} ) {
|
|
162
139
|
return (
|
|
163
140
|
<BottomSheet
|
|
164
141
|
isVisible
|
|
@@ -175,6 +152,7 @@ export default function InlineColorUI( { name, value, onChange, onClose } ) {
|
|
|
175
152
|
name={ name }
|
|
176
153
|
value={ value }
|
|
177
154
|
onChange={ onChange }
|
|
155
|
+
contentRef={ contentRef }
|
|
178
156
|
/>
|
|
179
157
|
</BottomSheet.NavigationScreen>
|
|
180
158
|
</BottomSheet.NavigationContainer>
|
|
@@ -6,12 +6,6 @@ exports[`Text color allows toggling the highlight color feature to selected text
|
|
|
6
6
|
<!-- /wp:paragraph -->"
|
|
7
7
|
`;
|
|
8
8
|
|
|
9
|
-
exports[`Text color allows toggling the highlight color feature to type new text 1`] = `
|
|
10
|
-
"<!-- wp:paragraph -->
|
|
11
|
-
<p><mark style="background-color:rgba(0, 0, 0, 0);color:#f78da7" class="has-inline-color has-pale-pink-color"></mark></p>
|
|
12
|
-
<!-- /wp:paragraph -->"
|
|
13
|
-
`;
|
|
14
|
-
|
|
15
9
|
exports[`Text color creates a paragraph block with the text color format 1`] = `
|
|
16
10
|
"<!-- wp:paragraph -->
|
|
17
11
|
<p>Hello <mark style="background-color:rgba(0,0,0,0);color:#cf2e2e" class="has-inline-color has-vivid-red-color">this is a test</mark></p>
|
|
@@ -64,45 +64,6 @@ describe( 'Text color', () => {
|
|
|
64
64
|
expect( textColorButton ).toBeDefined();
|
|
65
65
|
} );
|
|
66
66
|
|
|
67
|
-
it( 'allows toggling the highlight color feature to type new text', async () => {
|
|
68
|
-
const screen = await initializeEditor();
|
|
69
|
-
|
|
70
|
-
// Wait for the editor placeholder
|
|
71
|
-
const paragraphPlaceholder = await screen.findByLabelText(
|
|
72
|
-
'Add paragraph block'
|
|
73
|
-
);
|
|
74
|
-
expect( paragraphPlaceholder ).toBeDefined();
|
|
75
|
-
fireEvent.press( paragraphPlaceholder );
|
|
76
|
-
|
|
77
|
-
// Wait for the block to be created
|
|
78
|
-
const [ paragraphBlock ] = await screen.findAllByLabelText(
|
|
79
|
-
/Paragraph Block\. Row 1/
|
|
80
|
-
);
|
|
81
|
-
expect( paragraphBlock ).toBeDefined();
|
|
82
|
-
|
|
83
|
-
// Look for the highlight text color button
|
|
84
|
-
const textColorButton = await screen.findByLabelText( 'Text color' );
|
|
85
|
-
expect( textColorButton ).toBeDefined();
|
|
86
|
-
fireEvent.press( textColorButton );
|
|
87
|
-
|
|
88
|
-
// Wait for Inline color modal to be visible
|
|
89
|
-
const inlineTextColorModal = screen.getByTestId(
|
|
90
|
-
'inline-text-color-modal'
|
|
91
|
-
);
|
|
92
|
-
await waitFor( () => inlineTextColorModal.props.isVisible );
|
|
93
|
-
|
|
94
|
-
// Look for the pink color button
|
|
95
|
-
const pinkColorButton = await screen.findByA11yHint( COLOR_PINK );
|
|
96
|
-
expect( pinkColorButton ).toBeDefined();
|
|
97
|
-
fireEvent.press( pinkColorButton );
|
|
98
|
-
// TODO(jest-console): Fix the warning and remove the expect below.
|
|
99
|
-
expect( console ).toHaveWarnedWith(
|
|
100
|
-
`Non-serializable values were found in the navigation state. Check:\n\ntext-color > Palette > params.onColorChange (Function)\n\nThis can break usage such as persisting and restoring state. This might happen if you passed non-serializable values such as function, class instances etc. in params. If you need to use components with callbacks in your options, you can use 'navigation.setOptions' instead. See https://reactnavigation.org/docs/troubleshooting#i-get-the-warning-non-serializable-values-were-found-in-the-navigation-state for more details.`
|
|
101
|
-
);
|
|
102
|
-
|
|
103
|
-
expect( getEditorHtml() ).toMatchSnapshot();
|
|
104
|
-
} );
|
|
105
|
-
|
|
106
67
|
it( 'allows toggling the highlight color feature to selected text', async () => {
|
|
107
68
|
const screen = await initializeEditor();
|
|
108
69
|
const text = 'Hello this is a test';
|
|
@@ -145,6 +106,10 @@ describe( 'Text color', () => {
|
|
|
145
106
|
const pinkColorButton = await screen.findByA11yHint( COLOR_PINK );
|
|
146
107
|
expect( pinkColorButton ).toBeDefined();
|
|
147
108
|
fireEvent.press( pinkColorButton );
|
|
109
|
+
// TODO(jest-console): Fix the warning and remove the expect below.
|
|
110
|
+
expect( console ).toHaveWarnedWith(
|
|
111
|
+
`Non-serializable values were found in the navigation state. Check:\n\ntext-color > Palette > params.onColorChange (Function)\n\nThis can break usage such as persisting and restoring state. This might happen if you passed non-serializable values such as function, class instances etc. in params. If you need to use components with callbacks in your options, you can use 'navigation.setOptions' instead. See https://reactnavigation.org/docs/troubleshooting#i-get-the-warning-non-serializable-values-were-found-in-the-navigation-state for more details.`
|
|
112
|
+
);
|
|
148
113
|
|
|
149
114
|
expect( getEditorHtml() ).toMatchSnapshot();
|
|
150
115
|
} );
|
package/src/unknown/index.js
CHANGED
|
@@ -2,33 +2,39 @@
|
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
4
|
import { __ } from '@wordpress/i18n';
|
|
5
|
-
import { removeFormat, slice } from '@wordpress/rich-text';
|
|
5
|
+
import { removeFormat, slice, isCollapsed } from '@wordpress/rich-text';
|
|
6
6
|
import { RichTextToolbarButton } from '@wordpress/block-editor';
|
|
7
7
|
import { help } from '@wordpress/icons';
|
|
8
8
|
|
|
9
9
|
const name = 'core/unknown';
|
|
10
10
|
const title = __( 'Clear Unknown Formatting' );
|
|
11
11
|
|
|
12
|
+
function selectionContainsUnknownFormats( value ) {
|
|
13
|
+
if ( isCollapsed( value ) ) {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const selectedValue = slice( value );
|
|
18
|
+
return selectedValue.formats.some( ( formats ) => {
|
|
19
|
+
return formats.some( ( format ) => format.type === name );
|
|
20
|
+
} );
|
|
21
|
+
}
|
|
22
|
+
|
|
12
23
|
export const unknown = {
|
|
13
24
|
name,
|
|
14
25
|
title,
|
|
15
26
|
tagName: '*',
|
|
16
27
|
className: null,
|
|
17
28
|
edit( { isActive, value, onChange, onFocus } ) {
|
|
29
|
+
if ( ! isActive && ! selectionContainsUnknownFormats( value ) ) {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
|
|
18
33
|
function onClick() {
|
|
19
34
|
onChange( removeFormat( value, name ) );
|
|
20
35
|
onFocus();
|
|
21
36
|
}
|
|
22
37
|
|
|
23
|
-
const selectedValue = slice( value );
|
|
24
|
-
const hasUnknownFormats = selectedValue.formats.some( ( formats ) => {
|
|
25
|
-
return formats.some( ( format ) => format.type === name );
|
|
26
|
-
} );
|
|
27
|
-
|
|
28
|
-
if ( ! isActive && ! hasUnknownFormats ) {
|
|
29
|
-
return null;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
38
|
return (
|
|
33
39
|
<RichTextToolbarButton
|
|
34
40
|
name="unknown"
|