@wordpress/format-library 3.0.19 → 3.1.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/LICENSE.md +1 -1
- package/build/default-formats.native.js +3 -1
- package/build/default-formats.native.js.map +1 -1
- package/build/link/index.native.js +2 -2
- package/build/link/index.native.js.map +1 -1
- package/build/link/modal-screens/link-picker-screen.native.js +12 -25
- package/build/link/modal-screens/link-picker-screen.native.js.map +1 -1
- package/build/link/modal-screens/link-settings-screen.native.js +50 -19
- package/build/link/modal-screens/link-settings-screen.native.js.map +1 -1
- package/build/text-color/index.native.js +192 -0
- package/build/text-color/index.native.js.map +1 -0
- package/build/text-color/inline.js +1 -0
- package/build/text-color/inline.js.map +1 -1
- package/build/text-color/inline.native.js +191 -0
- package/build/text-color/inline.native.js.map +1 -0
- package/build-module/default-formats.native.js +2 -1
- package/build-module/default-formats.native.js.map +1 -1
- package/build-module/link/index.native.js +1 -1
- package/build-module/link/index.native.js.map +1 -1
- package/build-module/link/modal-screens/link-picker-screen.native.js +12 -26
- 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 +50 -19
- package/build-module/link/modal-screens/link-settings-screen.native.js.map +1 -1
- package/build-module/text-color/index.native.js +173 -0
- package/build-module/text-color/index.native.js.map +1 -0
- package/build-module/text-color/inline.js +1 -2
- package/build-module/text-color/inline.js.map +1 -1
- package/build-module/text-color/inline.native.js +177 -0
- package/build-module/text-color/inline.native.js.map +1 -0
- package/package.json +15 -15
- package/src/default-formats.native.js +2 -1
- package/src/link/index.native.js +1 -1
- package/src/link/modal-screens/link-picker-screen.native.js +12 -23
- package/src/link/modal-screens/link-settings-screen.native.js +27 -14
- package/src/link/test/index.native.js +137 -0
- package/src/link/test/modal.native.js +3 -3
- package/src/text-color/index.native.js +194 -0
- package/src/text-color/inline.js +1 -1
- package/src/text-color/inline.native.js +186 -0
- package/src/text-color/style.native.scss +23 -0
- package/src/text-color/test/__snapshots__/index.native.js.snap +19 -0
- package/src/text-color/test/index.native.js +164 -0
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { createElement, Fragment } from "@wordpress/element";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* External dependencies
|
|
5
|
+
*/
|
|
6
|
+
import { isEmpty } from 'lodash';
|
|
7
|
+
import { View } from 'react-native';
|
|
8
|
+
/**
|
|
9
|
+
* WordPress dependencies
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { __ } from '@wordpress/i18n';
|
|
13
|
+
import { useCallback, useMemo, useState } from '@wordpress/element';
|
|
14
|
+
import { BlockControls, useSetting } from '@wordpress/block-editor';
|
|
15
|
+
import { ToolbarGroup, ToolbarButton } from '@wordpress/components';
|
|
16
|
+
import { Icon, textColor as textColorIcon } from '@wordpress/icons';
|
|
17
|
+
import { removeFormat } from '@wordpress/rich-text';
|
|
18
|
+
import { usePreferredColorSchemeStyle } from '@wordpress/compose';
|
|
19
|
+
/**
|
|
20
|
+
* Internal dependencies
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
import { getActiveColors } from './inline.js';
|
|
24
|
+
import { transparentValue } from './index.js';
|
|
25
|
+
import { default as InlineColorUI } from './inline';
|
|
26
|
+
import styles from './style.scss';
|
|
27
|
+
const name = 'core/text-color';
|
|
28
|
+
|
|
29
|
+
const title = __('Text color');
|
|
30
|
+
|
|
31
|
+
const EMPTY_ARRAY = [];
|
|
32
|
+
|
|
33
|
+
function getComputedStyleProperty(element, property) {
|
|
34
|
+
const {
|
|
35
|
+
props: {
|
|
36
|
+
style = {}
|
|
37
|
+
}
|
|
38
|
+
} = element;
|
|
39
|
+
|
|
40
|
+
if (property === 'background-color') {
|
|
41
|
+
var _baseColors$color;
|
|
42
|
+
|
|
43
|
+
const {
|
|
44
|
+
backgroundColor,
|
|
45
|
+
baseColors
|
|
46
|
+
} = style;
|
|
47
|
+
|
|
48
|
+
if (backgroundColor !== 'transparent') {
|
|
49
|
+
return backgroundColor;
|
|
50
|
+
} else if (baseColors && baseColors !== null && baseColors !== void 0 && (_baseColors$color = baseColors.color) !== null && _baseColors$color !== void 0 && _baseColors$color.background) {
|
|
51
|
+
var _baseColors$color2;
|
|
52
|
+
|
|
53
|
+
return baseColors === null || baseColors === void 0 ? void 0 : (_baseColors$color2 = baseColors.color) === null || _baseColors$color2 === void 0 ? void 0 : _baseColors$color2.background;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return 'transparent';
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function fillComputedColors(element, _ref) {
|
|
61
|
+
let {
|
|
62
|
+
color,
|
|
63
|
+
backgroundColor
|
|
64
|
+
} = _ref;
|
|
65
|
+
|
|
66
|
+
if (!color && !backgroundColor) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return {
|
|
71
|
+
color: color || getComputedStyleProperty(element, 'color'),
|
|
72
|
+
backgroundColor: getComputedStyleProperty(element, 'background-color')
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function TextColorEdit(_ref2) {
|
|
77
|
+
let {
|
|
78
|
+
value,
|
|
79
|
+
onChange,
|
|
80
|
+
isActive,
|
|
81
|
+
activeAttributes,
|
|
82
|
+
contentRef
|
|
83
|
+
} = _ref2;
|
|
84
|
+
const allowCustomControl = useSetting('color.custom');
|
|
85
|
+
const colors = useSetting('color.palette') || EMPTY_ARRAY;
|
|
86
|
+
const [isAddingColor, setIsAddingColor] = useState(false);
|
|
87
|
+
const enableIsAddingColor = useCallback(() => setIsAddingColor(true), [setIsAddingColor]);
|
|
88
|
+
const disableIsAddingColor = useCallback(() => setIsAddingColor(false), [setIsAddingColor]);
|
|
89
|
+
const colorIndicatorStyle = useMemo(() => fillComputedColors(contentRef, getActiveColors(value, name, colors)), [value, colors]);
|
|
90
|
+
const hasColorsToChoose = !isEmpty(colors) || !allowCustomControl;
|
|
91
|
+
const onPressButton = useCallback(() => {
|
|
92
|
+
if (hasColorsToChoose) {
|
|
93
|
+
enableIsAddingColor();
|
|
94
|
+
} else {
|
|
95
|
+
onChange(removeFormat(value, name));
|
|
96
|
+
}
|
|
97
|
+
}, [hasColorsToChoose, value]);
|
|
98
|
+
const outlineStyle = usePreferredColorSchemeStyle(styles['components-inline-color__outline'], styles['components-inline-color__outline--dark']);
|
|
99
|
+
|
|
100
|
+
if (!hasColorsToChoose && !isActive) {
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const isActiveStyle = { ...colorIndicatorStyle,
|
|
105
|
+
...(!(colorIndicatorStyle !== null && colorIndicatorStyle !== void 0 && colorIndicatorStyle.backgroundColor) ? {
|
|
106
|
+
backgroundColor: 'transparent'
|
|
107
|
+
} : {}),
|
|
108
|
+
...styles['components-inline-color--is-active']
|
|
109
|
+
};
|
|
110
|
+
const customContainerStyles = styles['components-inline-color__button-container'];
|
|
111
|
+
return createElement(Fragment, null, createElement(BlockControls, null, createElement(ToolbarGroup, null, isActive && createElement(View, {
|
|
112
|
+
style: outlineStyle,
|
|
113
|
+
pointerEvents: "none"
|
|
114
|
+
}), createElement(ToolbarButton, {
|
|
115
|
+
name: "text-color",
|
|
116
|
+
isActive: isActive,
|
|
117
|
+
icon: createElement(Icon, {
|
|
118
|
+
icon: textColorIcon,
|
|
119
|
+
style: (colorIndicatorStyle === null || colorIndicatorStyle === void 0 ? void 0 : colorIndicatorStyle.color) && {
|
|
120
|
+
color: colorIndicatorStyle.color
|
|
121
|
+
}
|
|
122
|
+
}),
|
|
123
|
+
title: title,
|
|
124
|
+
extraProps: {
|
|
125
|
+
isActiveStyle,
|
|
126
|
+
customContainerStyles
|
|
127
|
+
} // If has no colors to choose but a color is active remove the color onClick
|
|
128
|
+
,
|
|
129
|
+
onClick: onPressButton
|
|
130
|
+
}))), isAddingColor && createElement(InlineColorUI, {
|
|
131
|
+
name: name,
|
|
132
|
+
onClose: disableIsAddingColor,
|
|
133
|
+
activeAttributes: activeAttributes,
|
|
134
|
+
value: value,
|
|
135
|
+
onChange: onChange,
|
|
136
|
+
contentRef: contentRef
|
|
137
|
+
}));
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export const textColor = {
|
|
141
|
+
name,
|
|
142
|
+
title,
|
|
143
|
+
tagName: 'mark',
|
|
144
|
+
className: 'has-inline-color',
|
|
145
|
+
attributes: {
|
|
146
|
+
style: 'style',
|
|
147
|
+
class: 'class'
|
|
148
|
+
},
|
|
149
|
+
|
|
150
|
+
/*
|
|
151
|
+
* Since this format relies on the <mark> tag, it's important to
|
|
152
|
+
* prevent the default yellow background color applied by most
|
|
153
|
+
* browsers. The solution is to detect when this format is used with a
|
|
154
|
+
* text color but no background color, and in such cases to override
|
|
155
|
+
* the default styling with a transparent background.
|
|
156
|
+
*
|
|
157
|
+
* @see https://github.com/WordPress/gutenberg/pull/35516
|
|
158
|
+
*/
|
|
159
|
+
__unstableFilterAttributeValue(key, value) {
|
|
160
|
+
if (key !== 'style') return value; // We need to remove the extra spaces within the styles on mobile
|
|
161
|
+
|
|
162
|
+
const newValue = value.replace(/ /g, ''); // We should not add a background-color if it's already set
|
|
163
|
+
|
|
164
|
+
if (newValue && newValue.includes('background-color')) return newValue;
|
|
165
|
+
const addedCSS = ['background-color', transparentValue].join(':'); // Prepend `addedCSS` to avoid a double `;;` as any the existing CSS
|
|
166
|
+
// rules will already include a `;`.
|
|
167
|
+
|
|
168
|
+
return newValue ? [addedCSS, newValue].join(';') : addedCSS;
|
|
169
|
+
},
|
|
170
|
+
|
|
171
|
+
edit: TextColorEdit
|
|
172
|
+
};
|
|
173
|
+
//# sourceMappingURL=index.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["@wordpress/format-library/src/text-color/index.native.js"],"names":["isEmpty","View","__","useCallback","useMemo","useState","BlockControls","useSetting","ToolbarGroup","ToolbarButton","Icon","textColor","textColorIcon","removeFormat","usePreferredColorSchemeStyle","getActiveColors","transparentValue","default","InlineColorUI","styles","name","title","EMPTY_ARRAY","getComputedStyleProperty","element","property","props","style","backgroundColor","baseColors","color","background","fillComputedColors","TextColorEdit","value","onChange","isActive","activeAttributes","contentRef","allowCustomControl","colors","isAddingColor","setIsAddingColor","enableIsAddingColor","disableIsAddingColor","colorIndicatorStyle","hasColorsToChoose","onPressButton","outlineStyle","isActiveStyle","customContainerStyles","tagName","className","attributes","class","__unstableFilterAttributeValue","key","newValue","replace","includes","addedCSS","join","edit"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,OAAT,QAAwB,QAAxB;AACA,SAASC,IAAT,QAAqB,cAArB;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,SAASC,YAAT,EAAuBC,aAAvB,QAA4C,uBAA5C;AACA,SAASC,IAAT,EAAeC,SAAS,IAAIC,aAA5B,QAAiD,kBAAjD;AACA,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,GAAGnB,EAAE,CAAE,YAAF,CAAhB;;AAEA,MAAMoB,WAAW,GAAG,EAApB;;AAEA,SAASC,wBAAT,CAAmCC,OAAnC,EAA4CC,QAA5C,EAAuD;AACtD,QAAM;AACLC,IAAAA,KAAK,EAAE;AAAEC,MAAAA,KAAK,GAAG;AAAV;AADF,MAEFH,OAFJ;;AAIA,MAAKC,QAAQ,KAAK,kBAAlB,EAAu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AAKD,QAAQ,IAAIA,QAAQ,CAACE,QAAT,CAAmB,kBAAnB,CAAjB,EACC,OAAOF,QAAP;AACD,UAAMG,QAAQ,GAAG,CAAE,kBAAF,EAAsB5C,gBAAtB,EAAyC6C,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,EAAE7B;AA9BkB,CAAlB","sourcesContent":["/**\n * External dependencies\n */\nimport { isEmpty } from 'lodash';\nimport { View } from 'react-native';\n\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useCallback, useMemo, useState } from '@wordpress/element';\nimport { BlockControls, useSetting } from '@wordpress/block-editor';\nimport { ToolbarGroup, ToolbarButton } from '@wordpress/components';\nimport { Icon, textColor as textColorIcon } from '@wordpress/icons';\nimport { removeFormat } from '@wordpress/rich-text';\nimport { usePreferredColorSchemeStyle } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { getActiveColors } from './inline.js';\nimport { transparentValue } from './index.js';\nimport { default as InlineColorUI } from './inline';\nimport styles from './style.scss';\n\nconst name = 'core/text-color';\nconst title = __( 'Text color' );\n\nconst EMPTY_ARRAY = [];\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 = useSetting( 'color.palette' ) || EMPTY_ARRAY;\n\tconst [ isAddingColor, setIsAddingColor ] = useState( false );\n\tconst enableIsAddingColor = useCallback( () => setIsAddingColor( true ), [\n\t\tsetIsAddingColor,\n\t] );\n\tconst disableIsAddingColor = useCallback( () => setIsAddingColor( false ), [\n\t\tsetIsAddingColor,\n\t] );\n\tconst colorIndicatorStyle = useMemo(\n\t\t() =>\n\t\t\tfillComputedColors(\n\t\t\t\tcontentRef,\n\t\t\t\tgetActiveColors( value, name, colors )\n\t\t\t),\n\t\t[ value, colors ]\n\t);\n\n\tconst hasColorsToChoose = ! isEmpty( colors ) || ! allowCustomControl;\n\n\tconst onPressButton = useCallback( () => {\n\t\tif ( hasColorsToChoose ) {\n\t\t\tenableIsAddingColor();\n\t\t} else {\n\t\t\tonChange( removeFormat( value, name ) );\n\t\t}\n\t}, [ hasColorsToChoose, value ] );\n\n\tconst outlineStyle = usePreferredColorSchemeStyle(\n\t\tstyles[ 'components-inline-color__outline' ],\n\t\tstyles[ 'components-inline-color__outline--dark' ]\n\t);\n\n\tif ( ! hasColorsToChoose && ! isActive ) {\n\t\treturn null;\n\t}\n\n\tconst isActiveStyle = {\n\t\t...colorIndicatorStyle,\n\t\t...( ! colorIndicatorStyle?.backgroundColor\n\t\t\t? { backgroundColor: 'transparent' }\n\t\t\t: {} ),\n\t\t...styles[ 'components-inline-color--is-active' ],\n\t};\n\n\tconst customContainerStyles =\n\t\tstyles[ 'components-inline-color__button-container' ];\n\n\treturn (\n\t\t<>\n\t\t\t<BlockControls>\n\t\t\t\t<ToolbarGroup>\n\t\t\t\t\t{ isActive && (\n\t\t\t\t\t\t<View style={ outlineStyle } pointerEvents=\"none\" />\n\t\t\t\t\t) }\n\n\t\t\t\t\t<ToolbarButton\n\t\t\t\t\t\tname=\"text-color\"\n\t\t\t\t\t\tisActive={ isActive }\n\t\t\t\t\t\ticon={\n\t\t\t\t\t\t\t<Icon\n\t\t\t\t\t\t\t\ticon={ textColorIcon }\n\t\t\t\t\t\t\t\tstyle={\n\t\t\t\t\t\t\t\t\tcolorIndicatorStyle?.color && {\n\t\t\t\t\t\t\t\t\t\tcolor: colorIndicatorStyle.color,\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t}\n\t\t\t\t\t\ttitle={ title }\n\t\t\t\t\t\textraProps={ {\n\t\t\t\t\t\t\tisActiveStyle,\n\t\t\t\t\t\t\tcustomContainerStyles,\n\t\t\t\t\t\t} }\n\t\t\t\t\t\t// If has no colors to choose but a color is active remove the color onClick\n\t\t\t\t\t\tonClick={ onPressButton }\n\t\t\t\t\t/>\n\t\t\t\t</ToolbarGroup>\n\t\t\t</BlockControls>\n\t\t\t{ isAddingColor && (\n\t\t\t\t<InlineColorUI\n\t\t\t\t\tname={ name }\n\t\t\t\t\tonClose={ disableIsAddingColor }\n\t\t\t\t\tactiveAttributes={ activeAttributes }\n\t\t\t\t\tvalue={ value }\n\t\t\t\t\tonChange={ onChange }\n\t\t\t\t\tcontentRef={ contentRef }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nexport const textColor = {\n\tname,\n\ttitle,\n\ttagName: 'mark',\n\tclassName: 'has-inline-color',\n\tattributes: {\n\t\tstyle: 'style',\n\t\tclass: 'class',\n\t},\n\t/*\n\t * Since this format relies on the <mark> tag, it's important to\n\t * prevent the default yellow background color applied by most\n\t * browsers. The solution is to detect when this format is used with a\n\t * text color but no background color, and in such cases to override\n\t * the default styling with a transparent background.\n\t *\n\t * @see https://github.com/WordPress/gutenberg/pull/35516\n\t */\n\t__unstableFilterAttributeValue( key, value ) {\n\t\tif ( key !== 'style' ) return value;\n\t\t// We need to remove the extra spaces within the styles on mobile\n\t\tconst newValue = value.replace( / /g, '' );\n\t\t// We should not add a background-color if it's already set\n\t\tif ( newValue && newValue.includes( 'background-color' ) )\n\t\t\treturn newValue;\n\t\tconst addedCSS = [ 'background-color', transparentValue ].join( ':' );\n\t\t// Prepend `addedCSS` to avoid a double `;;` as any the existing CSS\n\t\t// rules will already include a `;`.\n\t\treturn newValue ? [ addedCSS, newValue ].join( ';' ) : addedCSS;\n\t},\n\tedit: TextColorEdit,\n};\n"]}
|
|
@@ -33,7 +33,7 @@ function parseCSS() {
|
|
|
33
33
|
}, {});
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
function parseClassName() {
|
|
36
|
+
export function parseClassName() {
|
|
37
37
|
let className = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
38
38
|
let colorSettings = arguments.length > 1 ? arguments[1] : undefined;
|
|
39
39
|
return className.split(' ').reduce((accumulator, name) => {
|
|
@@ -47,7 +47,6 @@ function parseClassName() {
|
|
|
47
47
|
return accumulator;
|
|
48
48
|
}, {});
|
|
49
49
|
}
|
|
50
|
-
|
|
51
50
|
export function getActiveColors(value, name, colorSettings) {
|
|
52
51
|
const activeColorFormat = getActiveFormat(value, name);
|
|
53
52
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/format-library/src/text-color/inline.js"],"names":["get","useCallback","useMemo","useSelect","applyFormat","removeFormat","getActiveFormat","useAnchorRef","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","anchorRef","ref","title","tab"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,GAAT,QAAoB,QAApB;AAEA;AACA;AACA;;AACA,SAASC,WAAT,EAAsBC,OAAtB,QAAqC,oBAArC;AACA,SAASC,SAAT,QAA0B,iBAA1B;AACA,SACCC,WADD,EAECC,YAFD,EAGCC,eAHD,EAICC,YAJD,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,GAA8B;AAAA,MAAXC,GAAW,uEAAL,EAAK;AAC7B,SAAOA,GAAG,CAACC,KAAJ,CAAW,GAAX,EAAiBC,MAAjB,CAAyB,CAAEC,WAAF,EAAeC,IAAf,KAAyB;AACxD,QAAKA,IAAL,EAAY;AACX,YAAM,CAAEC,QAAF,EAAYC,KAAZ,IAAsBF,IAAI,CAACH,KAAL,CAAY,GAAZ,CAA5B;AACA,UAAKI,QAAQ,KAAK,OAAlB,EAA4BF,WAAW,CAACI,KAAZ,GAAoBD,KAApB;AAC5B,UAAKD,QAAQ,KAAK,kBAAb,IAAmCC,KAAK,KAAKR,gBAAlD,EACCK,WAAW,CAACK,eAAZ,GAA8BF,KAA9B;AACD;;AACD,WAAOH,WAAP;AACA,GARM,EAQJ,EARI,CAAP;AASA;;AAED,SAASM,cAAT,GAAyD;AAAA,MAAhCC,SAAgC,uEAApB,EAAoB;AAAA,MAAhBC,aAAgB;AACxD,SAAOD,SAAS,CAACT,KAAV,CAAiB,GAAjB,EAAuBC,MAAvB,CAA+B,CAAEC,WAAF,EAAeS,IAAf,KAAyB;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AAK,EAAEhD,EAAE,CAAE,MAAF;AAFV,KADM,EAKN;AACCiB,MAAAA,IAAI,EAAE,iBADP;AAEC+B,MAAAA,KAAK,EAAEhD,EAAE,CAAE,YAAF;AAFV,KALM;AADR,KAYKiD,GAAF,IACD,cAAC,WAAD;AACC,IAAA,IAAI,EAAGhC,IADR;AAEC,IAAA,QAAQ,EAAGgC,GAAG,CAAChC,IAFhB;AAGC,IAAA,KAAK,EAAGN,KAHT;AAIC,IAAA,QAAQ,EAAG2B;AAJZ,IAbF,CALD,CADD;AA6BA","sourcesContent":["/**\n * External dependencies\n */\nimport { get } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { useCallback, useMemo } from '@wordpress/element';\nimport { useSelect } from '@wordpress/data';\nimport {\n\tapplyFormat,\n\tremoveFormat,\n\tgetActiveFormat,\n\tuseAnchorRef,\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\nfunction 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 get( 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 useAnchorRef 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 anchorRef = useCachedTruthy(\n\t\tuseAnchorRef( { ref: contentRef, value, settings } )\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\tanchorRef={ anchorRef }\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,"sources":["@wordpress/format-library/src/text-color/inline.js"],"names":["get","useCallback","useMemo","useSelect","applyFormat","removeFormat","getActiveFormat","useAnchorRef","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","anchorRef","ref","title","tab"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,GAAT,QAAoB,QAApB;AAEA;AACA;AACA;;AACA,SAASC,WAAT,EAAsBC,OAAtB,QAAqC,oBAArC;AACA,SAASC,SAAT,QAA0B,iBAA1B;AACA,SACCC,WADD,EAECC,YAFD,EAGCC,eAHD,EAICC,YAJD,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,GAA8B;AAAA,MAAXC,GAAW,uEAAL,EAAK;AAC7B,SAAOA,GAAG,CAACC,KAAJ,CAAW,GAAX,EAAiBC,MAAjB,CAAyB,CAAEC,WAAF,EAAeC,IAAf,KAAyB;AACxD,QAAKA,IAAL,EAAY;AACX,YAAM,CAAEC,QAAF,EAAYC,KAAZ,IAAsBF,IAAI,CAACH,KAAL,CAAY,GAAZ,CAA5B;AACA,UAAKI,QAAQ,KAAK,OAAlB,EAA4BF,WAAW,CAACI,KAAZ,GAAoBD,KAApB;AAC5B,UAAKD,QAAQ,KAAK,kBAAb,IAAmCC,KAAK,KAAKR,gBAAlD,EACCK,WAAW,CAACK,eAAZ,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AAA,KAAnB;AAA0BT,IAAAA;AAA1B,GAAF,CADoB,CAAjC;AAIA,SACC,cAAC,OAAD;AACC,IAAA,OAAO,EAAG0C,OADX;AAEC,IAAA,SAAS,EAAC,iCAFX;AAGC,IAAA,SAAS,EAAGE;AAHb,KAKC,cAAC,QAAD;AACC,IAAA,IAAI,EAAG,CACN;AACC7B,MAAAA,IAAI,EAAE,OADP;AAEC+B,MAAAA,KAAK,EAAEhD,EAAE,CAAE,MAAF;AAFV,KADM,EAKN;AACCiB,MAAAA,IAAI,EAAE,iBADP;AAEC+B,MAAAA,KAAK,EAAEhD,EAAE,CAAE,YAAF;AAFV,KALM;AADR,KAYKiD,GAAF,IACD,cAAC,WAAD;AACC,IAAA,IAAI,EAAGhC,IADR;AAEC,IAAA,QAAQ,EAAGgC,GAAG,CAAChC,IAFhB;AAGC,IAAA,KAAK,EAAGN,KAHT;AAIC,IAAA,QAAQ,EAAG2B;AAJZ,IAbF,CALD,CADD;AA6BA","sourcesContent":["/**\n * External dependencies\n */\nimport { get } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { useCallback, useMemo } from '@wordpress/element';\nimport { useSelect } from '@wordpress/data';\nimport {\n\tapplyFormat,\n\tremoveFormat,\n\tgetActiveFormat,\n\tuseAnchorRef,\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 get( 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 useAnchorRef 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 anchorRef = useCachedTruthy(\n\t\tuseAnchorRef( { ref: contentRef, value, settings } )\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\tanchorRef={ anchorRef }\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"]}
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { createElement } from "@wordpress/element";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* External dependencies
|
|
5
|
+
*/
|
|
6
|
+
import { reject } from 'lodash';
|
|
7
|
+
/**
|
|
8
|
+
* WordPress dependencies
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { useCallback, useMemo } from '@wordpress/element';
|
|
12
|
+
import { applyFormat, removeFormat, getActiveFormat } from '@wordpress/rich-text';
|
|
13
|
+
import { useSetting, getColorClassName, getColorObjectByColorValue } from '@wordpress/block-editor';
|
|
14
|
+
import { BottomSheet, ColorSettings } from '@wordpress/components';
|
|
15
|
+
/**
|
|
16
|
+
* Internal dependencies
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import { textColor as settings } from './index';
|
|
20
|
+
import { transparentValue } from './index.js';
|
|
21
|
+
import { parseClassName } from './inline.js';
|
|
22
|
+
|
|
23
|
+
function parseCSS() {
|
|
24
|
+
let css = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
25
|
+
return css.split(';').reduce((accumulator, rule) => {
|
|
26
|
+
if (rule) {
|
|
27
|
+
const [property, value] = rule.replace(/ /g, '').split(':');
|
|
28
|
+
if (property === 'color') accumulator.color = value;
|
|
29
|
+
if (property === 'background-color' && value !== transparentValue) accumulator.backgroundColor = value;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return accumulator;
|
|
33
|
+
}, {});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function getActiveColors(value, name, colorSettings) {
|
|
37
|
+
const activeColorFormat = getActiveFormat(value, name);
|
|
38
|
+
|
|
39
|
+
if (!activeColorFormat) {
|
|
40
|
+
return {};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return { ...parseCSS(activeColorFormat.attributes.style),
|
|
44
|
+
...parseClassName(activeColorFormat.attributes.class, colorSettings)
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function setColors(value, name, colorSettings, colors) {
|
|
49
|
+
const {
|
|
50
|
+
color,
|
|
51
|
+
backgroundColor
|
|
52
|
+
} = { ...getActiveColors(value, name, colorSettings),
|
|
53
|
+
...colors
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
if (!color && !backgroundColor) {
|
|
57
|
+
return removeFormat(value, name);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const styles = [];
|
|
61
|
+
const classNames = [];
|
|
62
|
+
const attributes = {};
|
|
63
|
+
|
|
64
|
+
if (backgroundColor) {
|
|
65
|
+
styles.push(['background-color', backgroundColor].join(':'));
|
|
66
|
+
} else {
|
|
67
|
+
// Override default browser color for mark element.
|
|
68
|
+
styles.push(['background-color', transparentValue].join(':'));
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (color) {
|
|
72
|
+
const colorObject = getColorObjectByColorValue(colorSettings, color);
|
|
73
|
+
|
|
74
|
+
if (colorObject) {
|
|
75
|
+
classNames.push(getColorClassName('color', colorObject.slug));
|
|
76
|
+
styles.push(['color', colorObject.color].join(':'));
|
|
77
|
+
} else {
|
|
78
|
+
styles.push(['color', color].join(':'));
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (styles.length) attributes.style = styles.join(';');
|
|
83
|
+
if (classNames.length) attributes.class = classNames.join(' ');
|
|
84
|
+
const format = {
|
|
85
|
+
type: name,
|
|
86
|
+
attributes
|
|
87
|
+
};
|
|
88
|
+
const hasNoSelection = value.start === value.end;
|
|
89
|
+
const isAtTheEnd = value.end === value.text.length;
|
|
90
|
+
const previousCharacter = value.text.charAt(value.end - 1); // Force formatting due to limitations in the native implementation
|
|
91
|
+
|
|
92
|
+
if (hasNoSelection && (value.text.length === 0 || previousCharacter === ' ' && isAtTheEnd)) {
|
|
93
|
+
// For cases where there's no text selected, there's a space before
|
|
94
|
+
// the current caret position and it's at the end of the text.
|
|
95
|
+
return applyFormat(value, format, value.start - 1, value.end + 1);
|
|
96
|
+
} else if (hasNoSelection && isAtTheEnd) {
|
|
97
|
+
// If there's no selection and is at the end of the text
|
|
98
|
+
// manually add the format within the current caret position.
|
|
99
|
+
const newFormat = applyFormat(value, format);
|
|
100
|
+
const {
|
|
101
|
+
activeFormats
|
|
102
|
+
} = newFormat;
|
|
103
|
+
newFormat.formats[value.start] = [...reject(activeFormats, {
|
|
104
|
+
type: format.type
|
|
105
|
+
}), format];
|
|
106
|
+
return newFormat;
|
|
107
|
+
} else if (hasNoSelection) {
|
|
108
|
+
return removeFormat(value, format);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return applyFormat(value, format);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function ColorPicker(_ref) {
|
|
115
|
+
let {
|
|
116
|
+
name,
|
|
117
|
+
value,
|
|
118
|
+
onChange
|
|
119
|
+
} = _ref;
|
|
120
|
+
const property = 'color';
|
|
121
|
+
const colors = useSetting('color.palette') || settings.colors;
|
|
122
|
+
const colorSettings = {
|
|
123
|
+
colors
|
|
124
|
+
};
|
|
125
|
+
const onColorChange = useCallback(color => {
|
|
126
|
+
var _value$text;
|
|
127
|
+
|
|
128
|
+
if (color !== '') {
|
|
129
|
+
onChange(setColors(value, name, colors, {
|
|
130
|
+
[property]: color
|
|
131
|
+
})); // Remove formatting if the color was reset, there's no
|
|
132
|
+
// current selection and the previous character is a space
|
|
133
|
+
} else if ((value === null || value === void 0 ? void 0 : value.start) === (value === null || value === void 0 ? void 0 : value.end) && ((_value$text = value.text) === null || _value$text === void 0 ? void 0 : _value$text.charAt((value === null || value === void 0 ? void 0 : value.end) - 1)) === ' ') {
|
|
134
|
+
onChange(removeFormat(value, name, value.end - 1, value.end));
|
|
135
|
+
} else {
|
|
136
|
+
onChange(removeFormat(value, name));
|
|
137
|
+
}
|
|
138
|
+
}, [colors, onChange, property]);
|
|
139
|
+
const activeColors = useMemo(() => getActiveColors(value, name, colors), [name, value, colors]);
|
|
140
|
+
return createElement(ColorSettings, {
|
|
141
|
+
colorValue: activeColors[property],
|
|
142
|
+
onColorChange: onColorChange,
|
|
143
|
+
defaultSettings: colorSettings,
|
|
144
|
+
hideNavigation: true
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export default function InlineColorUI(_ref2) {
|
|
149
|
+
let {
|
|
150
|
+
name,
|
|
151
|
+
value,
|
|
152
|
+
onChange,
|
|
153
|
+
onClose
|
|
154
|
+
} = _ref2;
|
|
155
|
+
return createElement(BottomSheet, {
|
|
156
|
+
isVisible: true,
|
|
157
|
+
onClose: onClose,
|
|
158
|
+
hideHeader: true,
|
|
159
|
+
contentStyle: {
|
|
160
|
+
paddingLeft: 0,
|
|
161
|
+
paddingRight: 0
|
|
162
|
+
},
|
|
163
|
+
hasNavigation: true,
|
|
164
|
+
leftButton: null,
|
|
165
|
+
testID: "inline-text-color-modal"
|
|
166
|
+
}, createElement(BottomSheet.NavigationContainer, {
|
|
167
|
+
animate: true,
|
|
168
|
+
main: true
|
|
169
|
+
}, createElement(BottomSheet.NavigationScreen, {
|
|
170
|
+
name: "text-color"
|
|
171
|
+
}, createElement(ColorPicker, {
|
|
172
|
+
name: name,
|
|
173
|
+
value: value,
|
|
174
|
+
onChange: onChange
|
|
175
|
+
}))));
|
|
176
|
+
}
|
|
177
|
+
//# sourceMappingURL=inline.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["@wordpress/format-library/src/text-color/inline.native.js"],"names":["reject","useCallback","useMemo","applyFormat","removeFormat","getActiveFormat","useSetting","getColorClassName","getColorObjectByColorValue","BottomSheet","ColorSettings","textColor","settings","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","ColorPicker","onChange","onColorChange","activeColors","InlineColorUI","onClose","paddingLeft","paddingRight"],"mappings":";;AAAA;AACA;AACA;AAEA,SAASA,MAAT,QAAuB,QAAvB;AAEA;AACA;AACA;;AACA,SAASC,WAAT,EAAsBC,OAAtB,QAAqC,oBAArC;AACA,SACCC,WADD,EAECC,YAFD,EAGCC,eAHD,QAIO,sBAJP;AAKA,SACCC,UADD,EAECC,iBAFD,EAGCC,0BAHD,QAIO,yBAJP;AAKA,SAASC,WAAT,EAAsBC,aAAtB,QAA2C,uBAA3C;AAEA;AACA;AACA;;AACA,SAASC,SAAS,IAAIC,QAAtB,QAAsC,SAAtC;AACA,SAASC,gBAAT,QAAiC,YAAjC;AACA,SAASC,cAAT,QAA+B,aAA/B;;AAEA,SAASC,QAAT,GAA8B;AAAA,MAAXC,GAAW,uEAAL,EAAK;AAC7B,SAAOA,GAAG,CAACC,KAAJ,CAAW,GAAX,EAAiBC,MAAjB,CAAyB,CAAEC,WAAF,EAAeC,IAAf,KAAyB;AACxD,QAAKA,IAAL,EAAY;AACX,YAAM,CAAEC,QAAF,EAAYC,KAAZ,IAAsBF,IAAI,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,SAASO,eAAT,CAA0BJ,KAA1B,EAAiCK,IAAjC,EAAuCC,aAAvC,EAAuD;AACtD,QAAMC,iBAAiB,GAAGxB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nC,KACC,cAAC,WAAD;AACC,IAAA,IAAI,EAAGlC,IADR;AAEC,IAAA,KAAK,EAAGL,KAFT;AAGC,IAAA,QAAQ,EAAGiC;AAHZ,IADD,CADD,CATD,CADD;AAqBA","sourcesContent":["/**\n * External dependencies\n */\n\nimport { reject } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { useCallback, useMemo } from '@wordpress/element';\nimport {\n\tapplyFormat,\n\tremoveFormat,\n\tgetActiveFormat,\n} from '@wordpress/rich-text';\nimport {\n\tuseSetting,\n\tgetColorClassName,\n\tgetColorObjectByColorValue,\n} from '@wordpress/block-editor';\nimport { BottomSheet, ColorSettings } from '@wordpress/components';\n\n/**\n * Internal dependencies\n */\nimport { textColor as settings } from './index';\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...reject( activeFormats, { type: format.type } ),\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 = useSetting( 'color.palette' ) || settings.colors;\n\tconst colorSettings = {\n\t\tcolors,\n\t};\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"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/format-library",
|
|
3
|
-
"version": "3.0
|
|
3
|
+
"version": "3.1.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,23 +26,23 @@
|
|
|
26
26
|
"react-native": "src/index",
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@babel/runtime": "^7.16.0",
|
|
29
|
-
"@wordpress/a11y": "^3.
|
|
30
|
-
"@wordpress/block-editor": "^8.0
|
|
31
|
-
"@wordpress/components": "^19.
|
|
32
|
-
"@wordpress/compose": "^5.0
|
|
33
|
-
"@wordpress/data": "^6.
|
|
34
|
-
"@wordpress/dom": "^3.
|
|
35
|
-
"@wordpress/element": "^4.0
|
|
36
|
-
"@wordpress/html-entities": "^3.
|
|
37
|
-
"@wordpress/i18n": "^4.
|
|
38
|
-
"@wordpress/icons": "^6.
|
|
39
|
-
"@wordpress/keycodes": "^3.
|
|
40
|
-
"@wordpress/rich-text": "^5.0
|
|
41
|
-
"@wordpress/url": "^3.
|
|
29
|
+
"@wordpress/a11y": "^3.3.0",
|
|
30
|
+
"@wordpress/block-editor": "^8.1.0",
|
|
31
|
+
"@wordpress/components": "^19.3.0",
|
|
32
|
+
"@wordpress/compose": "^5.1.0",
|
|
33
|
+
"@wordpress/data": "^6.2.0",
|
|
34
|
+
"@wordpress/dom": "^3.3.0",
|
|
35
|
+
"@wordpress/element": "^4.1.0",
|
|
36
|
+
"@wordpress/html-entities": "^3.3.0",
|
|
37
|
+
"@wordpress/i18n": "^4.3.0",
|
|
38
|
+
"@wordpress/icons": "^6.2.0",
|
|
39
|
+
"@wordpress/keycodes": "^3.3.0",
|
|
40
|
+
"@wordpress/rich-text": "^5.1.0",
|
|
41
|
+
"@wordpress/url": "^3.4.0",
|
|
42
42
|
"lodash": "^4.17.21"
|
|
43
43
|
},
|
|
44
44
|
"publishConfig": {
|
|
45
45
|
"access": "public"
|
|
46
46
|
},
|
|
47
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "d95ccb9366e249133cdb1d7b25c382446b9ee502"
|
|
48
48
|
}
|
|
@@ -5,5 +5,6 @@ import { bold } from './bold';
|
|
|
5
5
|
import { italic } from './italic';
|
|
6
6
|
import { link } from './link';
|
|
7
7
|
import { strikethrough } from './strikethrough';
|
|
8
|
+
import { textColor } from './text-color';
|
|
8
9
|
|
|
9
|
-
export default [ bold, italic, link, strikethrough ];
|
|
10
|
+
export default [ bold, italic, link, strikethrough, textColor ];
|
package/src/link/index.native.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
4
|
+
import { Keyboard } from 'react-native';
|
|
5
5
|
import { useNavigation, useRoute } from '@react-navigation/native';
|
|
6
6
|
import { delay } from 'lodash';
|
|
7
7
|
/**
|
|
@@ -20,31 +20,20 @@ const LinkPickerScreen = () => {
|
|
|
20
20
|
const navigation = useNavigation();
|
|
21
21
|
const route = useRoute();
|
|
22
22
|
const onLinkPicked = ( { url, title } ) => {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}, 100 );
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
navigation.navigate( linkSettingsScreens.settings, {
|
|
34
|
-
inputValue: url,
|
|
35
|
-
text: title,
|
|
36
|
-
} );
|
|
23
|
+
Keyboard.dismiss();
|
|
24
|
+
delay( () => {
|
|
25
|
+
navigation.navigate( linkSettingsScreens.settings, {
|
|
26
|
+
inputValue: url,
|
|
27
|
+
text: title,
|
|
28
|
+
} );
|
|
29
|
+
}, 100 );
|
|
37
30
|
};
|
|
38
31
|
|
|
39
32
|
const onCancel = () => {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}, 100 );
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
navigation.goBack();
|
|
33
|
+
Keyboard.dismiss();
|
|
34
|
+
delay( () => {
|
|
35
|
+
navigation.goBack();
|
|
36
|
+
}, 100 );
|
|
48
37
|
};
|
|
49
38
|
|
|
50
39
|
const { inputValue } = route.params;
|