@wordpress/format-library 3.0.2 → 3.0.6
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/README.md +1 -1
- package/build/bold/index.js +5 -2
- package/build/bold/index.js.map +1 -1
- package/build/code/index.js +4 -2
- package/build/code/index.js.map +1 -1
- package/build/italic/index.js +5 -2
- package/build/italic/index.js.map +1 -1
- package/build/keyboard/index.js +4 -2
- package/build/keyboard/index.js.map +1 -1
- package/build/link/inline.js +110 -6
- package/build/link/inline.js.map +1 -1
- package/build/link/use-link-instance-key.js +36 -0
- package/build/link/use-link-instance-key.js.map +1 -0
- package/build/link/utils.js +112 -0
- package/build/link/utils.js.map +1 -1
- package/build/strikethrough/index.js +4 -2
- package/build/strikethrough/index.js.map +1 -1
- package/build/subscript/index.js +4 -2
- package/build/subscript/index.js.map +1 -1
- package/build/superscript/index.js +4 -2
- package/build/superscript/index.js.map +1 -1
- package/build/text-color/index.js +60 -21
- package/build/text-color/index.js.map +1 -1
- package/build/text-color/inline.js +105 -37
- package/build/text-color/inline.js.map +1 -1
- package/build/underline/index.js +4 -2
- package/build/underline/index.js.map +1 -1
- package/build-module/bold/index.js +5 -2
- package/build-module/bold/index.js.map +1 -1
- package/build-module/code/index.js +4 -2
- package/build-module/code/index.js.map +1 -1
- package/build-module/italic/index.js +5 -2
- package/build-module/italic/index.js.map +1 -1
- package/build-module/keyboard/index.js +4 -2
- package/build-module/keyboard/index.js.map +1 -1
- package/build-module/link/inline.js +111 -11
- package/build-module/link/inline.js.map +1 -1
- package/build-module/link/use-link-instance-key.js +29 -0
- package/build-module/link/use-link-instance-key.js.map +1 -0
- package/build-module/link/utils.js +110 -1
- package/build-module/link/utils.js.map +1 -1
- package/build-module/strikethrough/index.js +4 -2
- package/build-module/strikethrough/index.js.map +1 -1
- package/build-module/subscript/index.js +4 -2
- package/build-module/subscript/index.js.map +1 -1
- package/build-module/superscript/index.js +4 -2
- package/build-module/superscript/index.js.map +1 -1
- package/build-module/text-color/index.js +61 -22
- package/build-module/text-color/index.js.map +1 -1
- package/build-module/text-color/inline.js +104 -37
- package/build-module/text-color/inline.js.map +1 -1
- package/build-module/underline/index.js +6 -2
- package/build-module/underline/index.js.map +1 -1
- package/build-style/style-rtl.css +2 -25
- package/build-style/style.css +2 -25
- package/package.json +15 -15
- package/src/bold/index.js +2 -2
- package/src/code/index.js +2 -1
- package/src/italic/index.js +2 -2
- package/src/keyboard/index.js +2 -1
- package/src/link/inline.js +121 -8
- package/src/link/test/utils.js +362 -1
- package/src/link/use-link-instance-key.js +31 -0
- package/src/link/utils.js +132 -1
- package/src/strikethrough/index.js +2 -1
- package/src/subscript/index.js +2 -1
- package/src/superscript/index.js +2 -1
- package/src/text-color/index.js +66 -23
- package/src/text-color/inline.js +125 -49
- package/src/text-color/style.scss +2 -24
- package/src/underline/index.js +3 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/format-library/src/strikethrough/index.js"],"names":["name","title","strikethrough","tagName","className","edit","isActive","value","onChange","onFocus","onClick","type","formatStrikethrough"],"mappings":";;;;;;;;;AAGA;;AACA;;AACA;;AACA;;AANA;AACA;AACA;AAMA,MAAMA,IAAI,GAAG,oBAAb;AACA,MAAMC,KAAK,GAAG,cAAI,eAAJ,CAAd;AAEO,MAAMC,aAAa,GAAG;AAC5BF,EAAAA,IAD4B;AAE5BC,EAAAA,KAF4B;AAG5BE,EAAAA,OAAO,EAAE,GAHmB;AAI5BC,EAAAA,SAAS,EAAE,IAJiB;;AAK5BC,EAAAA,IAAI,CAAE;AAAEC,IAAAA,QAAF;AAAYC,IAAAA,KAAZ;AAAmBC,IAAAA,QAAnB;AAA6BC,IAAAA;AAA7B,GAAF,EAA2C;AAC9C,aAASC,OAAT,GAAmB;AAClBF,MAAAA,QAAQ,CAAE,4BAAcD,KAAd,EAAqB;AAAEI,QAAAA,IAAI,EAAEX;
|
|
1
|
+
{"version":3,"sources":["@wordpress/format-library/src/strikethrough/index.js"],"names":["name","title","strikethrough","tagName","className","edit","isActive","value","onChange","onFocus","onClick","type","formatStrikethrough"],"mappings":";;;;;;;;;AAGA;;AACA;;AACA;;AACA;;AANA;AACA;AACA;AAMA,MAAMA,IAAI,GAAG,oBAAb;AACA,MAAMC,KAAK,GAAG,cAAI,eAAJ,CAAd;AAEO,MAAMC,aAAa,GAAG;AAC5BF,EAAAA,IAD4B;AAE5BC,EAAAA,KAF4B;AAG5BE,EAAAA,OAAO,EAAE,GAHmB;AAI5BC,EAAAA,SAAS,EAAE,IAJiB;;AAK5BC,EAAAA,IAAI,CAAE;AAAEC,IAAAA,QAAF;AAAYC,IAAAA,KAAZ;AAAmBC,IAAAA,QAAnB;AAA6BC,IAAAA;AAA7B,GAAF,EAA2C;AAC9C,aAASC,OAAT,GAAmB;AAClBF,MAAAA,QAAQ,CAAE,4BAAcD,KAAd,EAAqB;AAAEI,QAAAA,IAAI,EAAEX,IAAR;AAAcC,QAAAA;AAAd,OAArB,CAAF,CAAR;AACAQ,MAAAA,OAAO;AACP;;AAED,WACC,4BAAC,kCAAD;AACC,MAAA,IAAI,EAAGG,0BADR;AAEC,MAAA,KAAK,EAAGX,KAFT;AAGC,MAAA,OAAO,EAAGS,OAHX;AAIC,MAAA,QAAQ,EAAGJ,QAJZ;AAKC,MAAA,IAAI,EAAC;AALN,MADD;AASA;;AApB2B,CAAtB","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { toggleFormat } from '@wordpress/rich-text';\nimport { RichTextToolbarButton } from '@wordpress/block-editor';\nimport { formatStrikethrough } from '@wordpress/icons';\n\nconst name = 'core/strikethrough';\nconst title = __( 'Strikethrough' );\n\nexport const strikethrough = {\n\tname,\n\ttitle,\n\ttagName: 's',\n\tclassName: null,\n\tedit( { isActive, value, onChange, onFocus } ) {\n\t\tfunction onClick() {\n\t\t\tonChange( toggleFormat( value, { type: name, title } ) );\n\t\t\tonFocus();\n\t\t}\n\n\t\treturn (\n\t\t\t<RichTextToolbarButton\n\t\t\t\ticon={ formatStrikethrough }\n\t\t\t\ttitle={ title }\n\t\t\t\tonClick={ onClick }\n\t\t\t\tisActive={ isActive }\n\t\t\t\trole=\"menuitemcheckbox\"\n\t\t\t/>\n\t\t);\n\t},\n};\n"]}
|
package/build/subscript/index.js
CHANGED
|
@@ -34,7 +34,8 @@ const subscript = {
|
|
|
34
34
|
}) {
|
|
35
35
|
function onToggle() {
|
|
36
36
|
onChange((0, _richText.toggleFormat)(value, {
|
|
37
|
-
type: name
|
|
37
|
+
type: name,
|
|
38
|
+
title
|
|
38
39
|
}));
|
|
39
40
|
}
|
|
40
41
|
|
|
@@ -47,7 +48,8 @@ const subscript = {
|
|
|
47
48
|
icon: _icons.subscript,
|
|
48
49
|
title: title,
|
|
49
50
|
onClick: onClick,
|
|
50
|
-
isActive: isActive
|
|
51
|
+
isActive: isActive,
|
|
52
|
+
role: "menuitemcheckbox"
|
|
51
53
|
});
|
|
52
54
|
}
|
|
53
55
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/format-library/src/subscript/index.js"],"names":["name","title","subscript","tagName","className","edit","isActive","value","onChange","onFocus","onToggle","type","onClick","subscriptIcon"],"mappings":";;;;;;;;;AAGA;;AACA;;AACA;;AACA;;AANA;AACA;AACA;AAMA,MAAMA,IAAI,GAAG,gBAAb;AACA,MAAMC,KAAK,GAAG,cAAI,WAAJ,CAAd;AAEO,MAAMC,SAAS,GAAG;AACxBF,EAAAA,IADwB;AAExBC,EAAAA,KAFwB;AAGxBE,EAAAA,OAAO,EAAE,KAHe;AAIxBC,EAAAA,SAAS,EAAE,IAJa;;AAKxBC,EAAAA,IAAI,CAAE;AAAEC,IAAAA,QAAF;AAAYC,IAAAA,KAAZ;AAAmBC,IAAAA,QAAnB;AAA6BC,IAAAA;AAA7B,GAAF,EAA2C;AAC9C,aAASC,QAAT,GAAoB;AACnBF,MAAAA,QAAQ,CAAE,4BAAcD,KAAd,EAAqB;AAAEI,QAAAA,IAAI,EAAEX;
|
|
1
|
+
{"version":3,"sources":["@wordpress/format-library/src/subscript/index.js"],"names":["name","title","subscript","tagName","className","edit","isActive","value","onChange","onFocus","onToggle","type","onClick","subscriptIcon"],"mappings":";;;;;;;;;AAGA;;AACA;;AACA;;AACA;;AANA;AACA;AACA;AAMA,MAAMA,IAAI,GAAG,gBAAb;AACA,MAAMC,KAAK,GAAG,cAAI,WAAJ,CAAd;AAEO,MAAMC,SAAS,GAAG;AACxBF,EAAAA,IADwB;AAExBC,EAAAA,KAFwB;AAGxBE,EAAAA,OAAO,EAAE,KAHe;AAIxBC,EAAAA,SAAS,EAAE,IAJa;;AAKxBC,EAAAA,IAAI,CAAE;AAAEC,IAAAA,QAAF;AAAYC,IAAAA,KAAZ;AAAmBC,IAAAA,QAAnB;AAA6BC,IAAAA;AAA7B,GAAF,EAA2C;AAC9C,aAASC,QAAT,GAAoB;AACnBF,MAAAA,QAAQ,CAAE,4BAAcD,KAAd,EAAqB;AAAEI,QAAAA,IAAI,EAAEX,IAAR;AAAcC,QAAAA;AAAd,OAArB,CAAF,CAAR;AACA;;AAED,aAASW,OAAT,GAAmB;AAClBF,MAAAA,QAAQ;AACRD,MAAAA,OAAO;AACP;;AAED,WACC,4BAAC,kCAAD;AACC,MAAA,IAAI,EAAGI,gBADR;AAEC,MAAA,KAAK,EAAGZ,KAFT;AAGC,MAAA,OAAO,EAAGW,OAHX;AAIC,MAAA,QAAQ,EAAGN,QAJZ;AAKC,MAAA,IAAI,EAAC;AALN,MADD;AASA;;AAxBuB,CAAlB","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { toggleFormat } from '@wordpress/rich-text';\nimport { RichTextToolbarButton } from '@wordpress/block-editor';\nimport { subscript as subscriptIcon } from '@wordpress/icons';\n\nconst name = 'core/subscript';\nconst title = __( 'Subscript' );\n\nexport const subscript = {\n\tname,\n\ttitle,\n\ttagName: 'sub',\n\tclassName: null,\n\tedit( { isActive, value, onChange, onFocus } ) {\n\t\tfunction onToggle() {\n\t\t\tonChange( toggleFormat( value, { type: name, title } ) );\n\t\t}\n\n\t\tfunction onClick() {\n\t\t\tonToggle();\n\t\t\tonFocus();\n\t\t}\n\n\t\treturn (\n\t\t\t<RichTextToolbarButton\n\t\t\t\ticon={ subscriptIcon }\n\t\t\t\ttitle={ title }\n\t\t\t\tonClick={ onClick }\n\t\t\t\tisActive={ isActive }\n\t\t\t\trole=\"menuitemcheckbox\"\n\t\t\t/>\n\t\t);\n\t},\n};\n"]}
|
|
@@ -34,7 +34,8 @@ const superscript = {
|
|
|
34
34
|
}) {
|
|
35
35
|
function onToggle() {
|
|
36
36
|
onChange((0, _richText.toggleFormat)(value, {
|
|
37
|
-
type: name
|
|
37
|
+
type: name,
|
|
38
|
+
title
|
|
38
39
|
}));
|
|
39
40
|
}
|
|
40
41
|
|
|
@@ -47,7 +48,8 @@ const superscript = {
|
|
|
47
48
|
icon: _icons.superscript,
|
|
48
49
|
title: title,
|
|
49
50
|
onClick: onClick,
|
|
50
|
-
isActive: isActive
|
|
51
|
+
isActive: isActive,
|
|
52
|
+
role: "menuitemcheckbox"
|
|
51
53
|
});
|
|
52
54
|
}
|
|
53
55
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/format-library/src/superscript/index.js"],"names":["name","title","superscript","tagName","className","edit","isActive","value","onChange","onFocus","onToggle","type","onClick","superscriptIcon"],"mappings":";;;;;;;;;AAGA;;AACA;;AACA;;AACA;;AANA;AACA;AACA;AAMA,MAAMA,IAAI,GAAG,kBAAb;AACA,MAAMC,KAAK,GAAG,cAAI,aAAJ,CAAd;AAEO,MAAMC,WAAW,GAAG;AAC1BF,EAAAA,IAD0B;AAE1BC,EAAAA,KAF0B;AAG1BE,EAAAA,OAAO,EAAE,KAHiB;AAI1BC,EAAAA,SAAS,EAAE,IAJe;;AAK1BC,EAAAA,IAAI,CAAE;AAAEC,IAAAA,QAAF;AAAYC,IAAAA,KAAZ;AAAmBC,IAAAA,QAAnB;AAA6BC,IAAAA;AAA7B,GAAF,EAA2C;AAC9C,aAASC,QAAT,GAAoB;AACnBF,MAAAA,QAAQ,CAAE,4BAAcD,KAAd,EAAqB;AAAEI,QAAAA,IAAI,EAAEX;
|
|
1
|
+
{"version":3,"sources":["@wordpress/format-library/src/superscript/index.js"],"names":["name","title","superscript","tagName","className","edit","isActive","value","onChange","onFocus","onToggle","type","onClick","superscriptIcon"],"mappings":";;;;;;;;;AAGA;;AACA;;AACA;;AACA;;AANA;AACA;AACA;AAMA,MAAMA,IAAI,GAAG,kBAAb;AACA,MAAMC,KAAK,GAAG,cAAI,aAAJ,CAAd;AAEO,MAAMC,WAAW,GAAG;AAC1BF,EAAAA,IAD0B;AAE1BC,EAAAA,KAF0B;AAG1BE,EAAAA,OAAO,EAAE,KAHiB;AAI1BC,EAAAA,SAAS,EAAE,IAJe;;AAK1BC,EAAAA,IAAI,CAAE;AAAEC,IAAAA,QAAF;AAAYC,IAAAA,KAAZ;AAAmBC,IAAAA,QAAnB;AAA6BC,IAAAA;AAA7B,GAAF,EAA2C;AAC9C,aAASC,QAAT,GAAoB;AACnBF,MAAAA,QAAQ,CAAE,4BAAcD,KAAd,EAAqB;AAAEI,QAAAA,IAAI,EAAEX,IAAR;AAAcC,QAAAA;AAAd,OAArB,CAAF,CAAR;AACA;;AAED,aAASW,OAAT,GAAmB;AAClBF,MAAAA,QAAQ;AACRD,MAAAA,OAAO;AACP;;AAED,WACC,4BAAC,kCAAD;AACC,MAAA,IAAI,EAAGI,kBADR;AAEC,MAAA,KAAK,EAAGZ,KAFT;AAGC,MAAA,OAAO,EAAGW,OAHX;AAIC,MAAA,QAAQ,EAAGN,QAJZ;AAKC,MAAA,IAAI,EAAC;AALN,MADD;AASA;;AAxByB,CAApB","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { toggleFormat } from '@wordpress/rich-text';\nimport { RichTextToolbarButton } from '@wordpress/block-editor';\nimport { superscript as superscriptIcon } from '@wordpress/icons';\n\nconst name = 'core/superscript';\nconst title = __( 'Superscript' );\n\nexport const superscript = {\n\tname,\n\ttitle,\n\ttagName: 'sup',\n\tclassName: null,\n\tedit( { isActive, value, onChange, onFocus } ) {\n\t\tfunction onToggle() {\n\t\t\tonChange( toggleFormat( value, { type: name, title } ) );\n\t\t}\n\n\t\tfunction onClick() {\n\t\t\tonToggle();\n\t\t\tonFocus();\n\t\t}\n\n\t\treturn (\n\t\t\t<RichTextToolbarButton\n\t\t\t\ticon={ superscriptIcon }\n\t\t\t\ttitle={ title }\n\t\t\t\tonClick={ onClick }\n\t\t\t\tisActive={ isActive }\n\t\t\t\trole=\"menuitemcheckbox\"\n\t\t\t/>\n\t\t);\n\t},\n};\n"]}
|
|
@@ -33,9 +33,40 @@ var _inline = _interopRequireWildcard(require("./inline"));
|
|
|
33
33
|
* Internal dependencies
|
|
34
34
|
*/
|
|
35
35
|
const name = 'core/text-color';
|
|
36
|
-
const title = (0, _i18n.__)('
|
|
36
|
+
const title = (0, _i18n.__)('Highlight');
|
|
37
37
|
const EMPTY_ARRAY = [];
|
|
38
38
|
|
|
39
|
+
function getComputedStyleProperty(element, property) {
|
|
40
|
+
const {
|
|
41
|
+
ownerDocument
|
|
42
|
+
} = element;
|
|
43
|
+
const {
|
|
44
|
+
defaultView
|
|
45
|
+
} = ownerDocument;
|
|
46
|
+
const style = defaultView.getComputedStyle(element);
|
|
47
|
+
const value = style.getPropertyValue(property);
|
|
48
|
+
|
|
49
|
+
if (property === 'background-color' && value === 'rgba(0, 0, 0, 0)' && element.parentElement) {
|
|
50
|
+
return getComputedStyleProperty(element.parentElement, property);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return value;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function fillComputedColors(element, {
|
|
57
|
+
color,
|
|
58
|
+
backgroundColor
|
|
59
|
+
}) {
|
|
60
|
+
if (!color && !backgroundColor) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return {
|
|
65
|
+
color: color || getComputedStyleProperty(element, 'color'),
|
|
66
|
+
backgroundColor: backgroundColor === 'rgba(0, 0, 0, 0)' ? getComputedStyleProperty(element, 'background-color') : backgroundColor
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
39
70
|
function TextColorEdit({
|
|
40
71
|
value,
|
|
41
72
|
onChange,
|
|
@@ -48,17 +79,7 @@ function TextColorEdit({
|
|
|
48
79
|
const [isAddingColor, setIsAddingColor] = (0, _element.useState)(false);
|
|
49
80
|
const enableIsAddingColor = (0, _element.useCallback)(() => setIsAddingColor(true), [setIsAddingColor]);
|
|
50
81
|
const disableIsAddingColor = (0, _element.useCallback)(() => setIsAddingColor(false), [setIsAddingColor]);
|
|
51
|
-
const colorIndicatorStyle = (0, _element.useMemo)(() =>
|
|
52
|
-
const activeColor = (0, _inline.getActiveColor)(name, value, colors);
|
|
53
|
-
|
|
54
|
-
if (!activeColor) {
|
|
55
|
-
return undefined;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
return {
|
|
59
|
-
backgroundColor: activeColor
|
|
60
|
-
};
|
|
61
|
-
}, [value, colors]);
|
|
82
|
+
const colorIndicatorStyle = (0, _element.useMemo)(() => fillComputedColors(contentRef.current, (0, _inline.getActiveColors)(value, name, colors)), [value, colors]);
|
|
62
83
|
const hasColorsToChoose = !(0, _lodash.isEmpty)(colors) || !allowCustomControl;
|
|
63
84
|
|
|
64
85
|
if (!hasColorsToChoose && !isActive) {
|
|
@@ -66,18 +87,16 @@ function TextColorEdit({
|
|
|
66
87
|
}
|
|
67
88
|
|
|
68
89
|
return (0, _element.createElement)(_element.Fragment, null, (0, _element.createElement)(_blockEditor.RichTextToolbarButton, {
|
|
69
|
-
key: isActive ? 'text-color' : 'text-color-not-active',
|
|
70
90
|
className: "format-library-text-color-button",
|
|
71
|
-
|
|
72
|
-
icon: (0, _element.createElement)(
|
|
73
|
-
icon: _icons.textColor
|
|
74
|
-
}), isActive && (0, _element.createElement)("span", {
|
|
75
|
-
className: "format-library-text-color-button__indicator",
|
|
91
|
+
isActive: isActive,
|
|
92
|
+
icon: (0, _element.createElement)(_icons.Icon, {
|
|
93
|
+
icon: _icons.textColor,
|
|
76
94
|
style: colorIndicatorStyle
|
|
77
|
-
})
|
|
95
|
+
}),
|
|
78
96
|
title: title // If has no colors to choose but a color is active remove the color onClick
|
|
79
97
|
,
|
|
80
|
-
onClick: hasColorsToChoose ? enableIsAddingColor : () => onChange((0, _richText.removeFormat)(value, name))
|
|
98
|
+
onClick: hasColorsToChoose ? enableIsAddingColor : () => onChange((0, _richText.removeFormat)(value, name)),
|
|
99
|
+
role: "menuitemcheckbox"
|
|
81
100
|
}), isAddingColor && (0, _element.createElement)(_inline.default, {
|
|
82
101
|
name: name,
|
|
83
102
|
onClose: disableIsAddingColor,
|
|
@@ -91,12 +110,32 @@ function TextColorEdit({
|
|
|
91
110
|
const textColor = {
|
|
92
111
|
name,
|
|
93
112
|
title,
|
|
94
|
-
tagName: '
|
|
113
|
+
tagName: 'mark',
|
|
95
114
|
className: 'has-inline-color',
|
|
96
115
|
attributes: {
|
|
97
116
|
style: 'style',
|
|
98
117
|
class: 'class'
|
|
99
118
|
},
|
|
119
|
+
|
|
120
|
+
/*
|
|
121
|
+
* Since this format relies on the <mark> tag, it's important to
|
|
122
|
+
* prevent the default yellow background color applied by most
|
|
123
|
+
* browsers. The solution is to detect when this format is used with a
|
|
124
|
+
* text color but no background color, and in such cases to override
|
|
125
|
+
* the default styling with a transparent background.
|
|
126
|
+
*
|
|
127
|
+
* @see https://github.com/WordPress/gutenberg/pull/35516
|
|
128
|
+
*/
|
|
129
|
+
__unstableFilterAttributeValue(key, value) {
|
|
130
|
+
if (key !== 'style') return value; // We should not add a background-color if it's already set
|
|
131
|
+
|
|
132
|
+
if (value && value.includes('background-color')) return value;
|
|
133
|
+
const addedCSS = ['background-color', 'rgba(0, 0, 0, 0)'].join(':'); // Prepend `addedCSS` to avoid a double `;;` as any the existing CSS
|
|
134
|
+
// rules will already include a `;`.
|
|
135
|
+
|
|
136
|
+
return value ? [addedCSS, value].join(';') : addedCSS;
|
|
137
|
+
},
|
|
138
|
+
|
|
100
139
|
edit: TextColorEdit
|
|
101
140
|
};
|
|
102
141
|
exports.textColor = textColor;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/format-library/src/text-color/index.js"],"names":["name","title","EMPTY_ARRAY","
|
|
1
|
+
{"version":3,"sources":["@wordpress/format-library/src/text-color/index.js"],"names":["name","title","EMPTY_ARRAY","getComputedStyleProperty","element","property","ownerDocument","defaultView","style","getComputedStyle","value","getPropertyValue","parentElement","fillComputedColors","color","backgroundColor","TextColorEdit","onChange","isActive","activeAttributes","contentRef","allowCustomControl","colors","isAddingColor","setIsAddingColor","enableIsAddingColor","disableIsAddingColor","colorIndicatorStyle","current","hasColorsToChoose","textColorIcon","textColor","tagName","className","attributes","class","__unstableFilterAttributeValue","key","includes","addedCSS","join","edit"],"mappings":";;;;;;;;;AASA;;AANA;;AAKA;;AAEA;;AACA;;AACA;;AAKA;;AAjBA;AACA;AACA;;AAGA;AACA;AACA;;AAOA;AACA;AACA;AAGA,MAAMA,IAAI,GAAG,iBAAb;AACA,MAAMC,KAAK,GAAG,cAAI,WAAJ,CAAd;AAEA,MAAMC,WAAW,GAAG,EAApB;;AAEA,SAASC,wBAAT,CAAmCC,OAAnC,EAA4CC,QAA5C,EAAuD;AACtD,QAAM;AAAEC,IAAAA;AAAF,MAAoBF,OAA1B;AACA,QAAM;AAAEG,IAAAA;AAAF,MAAkBD,aAAxB;AACA,QAAME,KAAK,GAAGD,WAAW,CAACE,gBAAZ,CAA8BL,OAA9B,CAAd;AACA,QAAMM,KAAK,GAAGF,KAAK,CAACG,gBAAN,CAAwBN,QAAxB,CAAd;;AAEA,MACCA,QAAQ,KAAK,kBAAb,IACAK,KAAK,KAAK,kBADV,IAEAN,O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,CAAgB,kBAAhB,CAAd,EAAqD,OAAO5B,KAAP;AACrD,UAAM6B,QAAQ,GAAG,CAAE,kBAAF,EAAsB,kBAAtB,EAA2CC,IAA3C,CAAiD,GAAjD,CAAjB,CAJ4C,CAK5C;AACA;;AACA,WAAO9B,KAAK,GAAG,CAAE6B,QAAF,EAAY7B,KAAZ,EAAoB8B,IAApB,CAA0B,GAA1B,CAAH,GAAqCD,QAAjD;AACA,GA1BuB;;AA2BxBE,EAAAA,IAAI,EAAEzB;AA3BkB,CAAlB","sourcesContent":["/**\n * External dependencies\n */\nimport { isEmpty } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useCallback, useMemo, useState } from '@wordpress/element';\nimport { RichTextToolbarButton, useSetting } from '@wordpress/block-editor';\nimport { Icon, textColor as textColorIcon } from '@wordpress/icons';\nimport { removeFormat } from '@wordpress/rich-text';\n\n/**\n * Internal dependencies\n */\nimport { default as InlineColorUI, getActiveColors } from './inline';\n\nconst name = 'core/text-color';\nconst title = __( 'Highlight' );\n\nconst EMPTY_ARRAY = [];\n\nfunction getComputedStyleProperty( element, property ) {\n\tconst { ownerDocument } = element;\n\tconst { defaultView } = ownerDocument;\n\tconst style = defaultView.getComputedStyle( element );\n\tconst value = style.getPropertyValue( property );\n\n\tif (\n\t\tproperty === 'background-color' &&\n\t\tvalue === 'rgba(0, 0, 0, 0)' &&\n\t\telement.parentElement\n\t) {\n\t\treturn getComputedStyleProperty( element.parentElement, property );\n\t}\n\n\treturn value;\n}\n\nfunction fillComputedColors( element, { color, backgroundColor } ) {\n\tif ( ! color && ! backgroundColor ) {\n\t\treturn;\n\t}\n\n\treturn {\n\t\tcolor: color || getComputedStyleProperty( element, 'color' ),\n\t\tbackgroundColor:\n\t\t\tbackgroundColor === 'rgba(0, 0, 0, 0)'\n\t\t\t\t? getComputedStyleProperty( element, 'background-color' )\n\t\t\t\t: backgroundColor,\n\t};\n}\n\nfunction TextColorEdit( {\n\tvalue,\n\tonChange,\n\tisActive,\n\tactiveAttributes,\n\tcontentRef,\n} ) {\n\tconst allowCustomControl = useSetting( 'color.custom' );\n\tconst colors = useSetting( 'color.palette' ) || EMPTY_ARRAY;\n\tconst [ isAddingColor, setIsAddingColor ] = useState( false );\n\tconst enableIsAddingColor = useCallback( () => 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.current,\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\tif ( ! hasColorsToChoose && ! isActive ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t<RichTextToolbarButton\n\t\t\t\tclassName=\"format-library-text-color-button\"\n\t\t\t\tisActive={ isActive }\n\t\t\t\ticon={\n\t\t\t\t\t<Icon\n\t\t\t\t\t\ticon={ textColorIcon }\n\t\t\t\t\t\tstyle={ colorIndicatorStyle }\n\t\t\t\t\t/>\n\t\t\t\t}\n\t\t\t\ttitle={ title }\n\t\t\t\t// If has no colors to choose but a color is active remove the color onClick\n\t\t\t\tonClick={\n\t\t\t\t\thasColorsToChoose\n\t\t\t\t\t\t? enableIsAddingColor\n\t\t\t\t\t\t: () => onChange( removeFormat( value, name ) )\n\t\t\t\t}\n\t\t\t\trole=\"menuitemcheckbox\"\n\t\t\t/>\n\t\t\t{ isAddingColor && (\n\t\t\t\t<InlineColorUI\n\t\t\t\t\tname={ name }\n\t\t\t\t\tonClose={ disableIsAddingColor }\n\t\t\t\t\tactiveAttributes={ activeAttributes }\n\t\t\t\t\tvalue={ value }\n\t\t\t\t\tonChange={ onChange }\n\t\t\t\t\tcontentRef={ contentRef }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nexport const textColor = {\n\tname,\n\ttitle,\n\ttagName: 'mark',\n\tclassName: 'has-inline-color',\n\tattributes: {\n\t\tstyle: 'style',\n\t\tclass: 'class',\n\t},\n\t/*\n\t * Since this format relies on the <mark> tag, it's important to\n\t * prevent the default yellow background color applied by most\n\t * browsers. The solution is to detect when this format is used with a\n\t * text color but no background color, and in such cases to override\n\t * the default styling with a transparent background.\n\t *\n\t * @see https://github.com/WordPress/gutenberg/pull/35516\n\t */\n\t__unstableFilterAttributeValue( key, value ) {\n\t\tif ( key !== 'style' ) return value;\n\t\t// We should not add a background-color if it's already set\n\t\tif ( value && value.includes( 'background-color' ) ) return value;\n\t\tconst addedCSS = [ 'background-color', 'rgba(0, 0, 0, 0)' ].join( ':' );\n\t\t// Prepend `addedCSS` to avoid a double `;;` as any the existing CSS\n\t\t// rules will already include a `;`.\n\t\treturn value ? [ addedCSS, value ].join( ';' ) : addedCSS;\n\t},\n\tedit: TextColorEdit,\n};\n"]}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.getActiveColors = getActiveColors;
|
|
7
7
|
exports.default = InlineColorUI;
|
|
8
8
|
|
|
9
9
|
var _element = require("@wordpress/element");
|
|
@@ -16,6 +16,10 @@ var _richText = require("@wordpress/rich-text");
|
|
|
16
16
|
|
|
17
17
|
var _blockEditor = require("@wordpress/block-editor");
|
|
18
18
|
|
|
19
|
+
var _components = require("@wordpress/components");
|
|
20
|
+
|
|
21
|
+
var _i18n = require("@wordpress/i18n");
|
|
22
|
+
|
|
19
23
|
var _index = require("./index");
|
|
20
24
|
|
|
21
25
|
/**
|
|
@@ -29,59 +33,108 @@ var _index = require("./index");
|
|
|
29
33
|
/**
|
|
30
34
|
* Internal dependencies
|
|
31
35
|
*/
|
|
32
|
-
function
|
|
33
|
-
|
|
36
|
+
function parseCSS(css = '') {
|
|
37
|
+
return css.split(';').reduce((accumulator, rule) => {
|
|
38
|
+
if (rule) {
|
|
39
|
+
const [property, value] = rule.split(':');
|
|
40
|
+
if (property === 'color') accumulator.color = value;
|
|
41
|
+
if (property === 'background-color') accumulator.backgroundColor = value;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return accumulator;
|
|
45
|
+
}, {});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function parseClassName(className = '', colorSettings) {
|
|
49
|
+
return className.split(' ').reduce((accumulator, name) => {
|
|
50
|
+
const match = name.match(/^has-([^-]+)-color$/);
|
|
51
|
+
|
|
52
|
+
if (match) {
|
|
53
|
+
const [, colorSlug] = name.match(/^has-([^-]+)-color$/);
|
|
54
|
+
const colorObject = (0, _blockEditor.getColorObjectByAttributeValues)(colorSettings, colorSlug);
|
|
55
|
+
accumulator.color = colorObject.color;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return accumulator;
|
|
59
|
+
}, {});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function getActiveColors(value, name, colorSettings) {
|
|
63
|
+
const activeColorFormat = (0, _richText.getActiveFormat)(value, name);
|
|
34
64
|
|
|
35
65
|
if (!activeColorFormat) {
|
|
36
|
-
return;
|
|
66
|
+
return {};
|
|
37
67
|
}
|
|
38
68
|
|
|
39
|
-
|
|
69
|
+
return { ...parseCSS(activeColorFormat.attributes.style),
|
|
70
|
+
...parseClassName(activeColorFormat.attributes.class, colorSettings)
|
|
71
|
+
};
|
|
72
|
+
}
|
|
40
73
|
|
|
41
|
-
|
|
42
|
-
|
|
74
|
+
function setColors(value, name, colorSettings, colors) {
|
|
75
|
+
const {
|
|
76
|
+
color,
|
|
77
|
+
backgroundColor
|
|
78
|
+
} = { ...getActiveColors(value, name, colorSettings),
|
|
79
|
+
...colors
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
if (!color && !backgroundColor) {
|
|
83
|
+
return (0, _richText.removeFormat)(value, name);
|
|
43
84
|
}
|
|
44
85
|
|
|
45
|
-
const
|
|
86
|
+
const styles = [];
|
|
87
|
+
const classNames = [];
|
|
88
|
+
const attributes = {};
|
|
46
89
|
|
|
47
|
-
if (
|
|
48
|
-
|
|
49
|
-
|
|
90
|
+
if (backgroundColor) {
|
|
91
|
+
styles.push(['background-color', backgroundColor].join(':'));
|
|
92
|
+
} else {
|
|
93
|
+
// Override default browser color for mark element.
|
|
94
|
+
styles.push(['background-color', 'rgba(0, 0, 0, 0)'].join(':'));
|
|
50
95
|
}
|
|
96
|
+
|
|
97
|
+
if (color) {
|
|
98
|
+
const colorObject = (0, _blockEditor.getColorObjectByColorValue)(colorSettings, color);
|
|
99
|
+
|
|
100
|
+
if (colorObject) {
|
|
101
|
+
classNames.push((0, _blockEditor.getColorClassName)('color', colorObject.slug));
|
|
102
|
+
} else {
|
|
103
|
+
styles.push(['color', color].join(':'));
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (styles.length) attributes.style = styles.join(';');
|
|
108
|
+
if (classNames.length) attributes.class = classNames.join(' ');
|
|
109
|
+
return (0, _richText.applyFormat)(value, {
|
|
110
|
+
type: name,
|
|
111
|
+
attributes
|
|
112
|
+
});
|
|
51
113
|
}
|
|
52
114
|
|
|
53
|
-
|
|
115
|
+
function ColorPicker({
|
|
54
116
|
name,
|
|
117
|
+
property,
|
|
55
118
|
value,
|
|
56
119
|
onChange
|
|
57
|
-
})
|
|
120
|
+
}) {
|
|
58
121
|
const colors = (0, _data.useSelect)(select => {
|
|
59
122
|
const {
|
|
60
123
|
getSettings
|
|
61
124
|
} = select(_blockEditor.store);
|
|
62
125
|
return (0, _lodash.get)(getSettings(), ['colors'], []);
|
|
63
|
-
});
|
|
126
|
+
}, []);
|
|
64
127
|
const onColorChange = (0, _element.useCallback)(color => {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
class: (0, _blockEditor.getColorClassName)('color', colorObject.slug)
|
|
71
|
-
} : {
|
|
72
|
-
style: `color:${color}`
|
|
73
|
-
}
|
|
74
|
-
}));
|
|
75
|
-
} else {
|
|
76
|
-
onChange((0, _richText.removeFormat)(value, name));
|
|
77
|
-
}
|
|
78
|
-
}, [colors, onChange]);
|
|
79
|
-
const activeColor = (0, _element.useMemo)(() => getActiveColor(name, value, colors), [name, value, colors]);
|
|
128
|
+
onChange(setColors(value, name, colors, {
|
|
129
|
+
[property]: color
|
|
130
|
+
}));
|
|
131
|
+
}, [colors, onChange, property]);
|
|
132
|
+
const activeColors = (0, _element.useMemo)(() => getActiveColors(value, name, colors), [name, value, colors]);
|
|
80
133
|
return (0, _element.createElement)(_blockEditor.ColorPalette, {
|
|
81
|
-
value:
|
|
134
|
+
value: activeColors[property],
|
|
82
135
|
onChange: onColorChange
|
|
83
136
|
});
|
|
84
|
-
}
|
|
137
|
+
}
|
|
85
138
|
|
|
86
139
|
function InlineColorUI({
|
|
87
140
|
name,
|
|
@@ -90,20 +143,35 @@ function InlineColorUI({
|
|
|
90
143
|
onClose,
|
|
91
144
|
contentRef
|
|
92
145
|
}) {
|
|
93
|
-
|
|
146
|
+
/*
|
|
147
|
+
As you change the text color by typing a HEX value into a field,
|
|
148
|
+
the return value of document.getSelection jumps to the field you're editing,
|
|
149
|
+
not the highlighted text. Given that useAnchorRef uses document.getSelection,
|
|
150
|
+
it will return null, since it can't find the <mark> element within the HEX input.
|
|
151
|
+
This caches the last truthy value of the selection anchor reference.
|
|
152
|
+
*/
|
|
153
|
+
const anchorRef = (0, _blockEditor.useCachedTruthy)((0, _richText.useAnchorRef)({
|
|
94
154
|
ref: contentRef,
|
|
95
155
|
value,
|
|
96
156
|
settings: _index.textColor
|
|
97
|
-
});
|
|
98
|
-
return (0, _element.createElement)(
|
|
99
|
-
value: value,
|
|
157
|
+
}));
|
|
158
|
+
return (0, _element.createElement)(_components.Popover, {
|
|
100
159
|
onClose: onClose,
|
|
101
160
|
className: "components-inline-color-popover",
|
|
102
161
|
anchorRef: anchorRef
|
|
103
|
-
}, (0, _element.createElement)(
|
|
162
|
+
}, (0, _element.createElement)(_components.TabPanel, {
|
|
163
|
+
tabs: [{
|
|
164
|
+
name: 'color',
|
|
165
|
+
title: (0, _i18n.__)('Text')
|
|
166
|
+
}, {
|
|
167
|
+
name: 'backgroundColor',
|
|
168
|
+
title: (0, _i18n.__)('Background')
|
|
169
|
+
}]
|
|
170
|
+
}, tab => (0, _element.createElement)(ColorPicker, {
|
|
104
171
|
name: name,
|
|
172
|
+
property: tab.name,
|
|
105
173
|
value: value,
|
|
106
174
|
onChange: onChange
|
|
107
|
-
}));
|
|
175
|
+
})));
|
|
108
176
|
}
|
|
109
177
|
//# sourceMappingURL=inline.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/format-library/src/text-color/inline.js"],"names":["
|
|
1
|
+
{"version":3,"sources":["@wordpress/format-library/src/text-color/inline.js"],"names":["parseCSS","css","split","reduce","accumulator","rule","property","value","color","backgroundColor","parseClassName","className","colorSettings","name","match","colorSlug","colorObject","getActiveColors","activeColorFormat","attributes","style","class","setColors","colors","styles","classNames","push","join","slug","length","type","ColorPicker","onChange","select","getSettings","blockEditorStore","onColorChange","activeColors","InlineColorUI","onClose","contentRef","anchorRef","ref","settings","title","tab"],"mappings":";;;;;;;;AAQA;;AALA;;AAMA;;AACA;;AAMA;;AAQA;;AACA;;AAKA;;AA9BA;AACA;AACA;;AAGA;AACA;AACA;;AAoBA;AACA;AACA;AAGA,SAASA,QAAT,CAAmBC,GAAG,GAAG,EAAzB,EAA8B;AAC7B,SAAOA,GAAG,CAACC,KAAJ,CAAW,GAAX,EAAiBC,MAAjB,CAAyB,CAAEC,WAAF,EAAeC,IAAf,KAAyB;AACxD,QAAKA,IAAL,EAAY;AACX,YAAM,CAAEC,QAAF,EAAYC,KAAZ,IAAsBF,IAAI,CAACH,KAAL,CAAY,GAAZ,CAA5B;AACA,UAAKI,QAAQ,KAAK,O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OAAO,EAAGJ,OADX;AAEC,IAAA,SAAS,EAAC,iCAFX;AAGC,IAAA,SAAS,EAAGE;AAHb,KAKC,4BAAC,oBAAD;AACC,IAAA,IAAI,EAAG,CACN;AACC5B,MAAAA,IAAI,EAAE,OADP;AAEC+B,MAAAA,KAAK,EAAE,cAAI,MAAJ;AAFR,KADM,EAKN;AACC/B,MAAAA,IAAI,EAAE,iBADP;AAEC+B,MAAAA,KAAK,EAAE,cAAI,YAAJ;AAFR,KALM;AADR,KAYKC,GAAF,IACD,4BAAC,WAAD;AACC,IAAA,IAAI,EAAGhC,IADR;AAEC,IAAA,QAAQ,EAAGgC,GAAG,CAAChC,IAFhB;AAGC,IAAA,KAAK,EAAGN,KAHT;AAIC,IAAA,QAAQ,EAAGyB;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 } 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' )\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\tconst match = name.match( /^has-([^-]+)-color$/ );\n\t\tif ( match ) {\n\t\t\tconst [ , colorSlug ] = name.match( /^has-([^-]+)-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', 'rgba(0, 0, 0, 0)' ].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"]}
|
package/build/underline/index.js
CHANGED
|
@@ -17,9 +17,10 @@ var _blockEditor = require("@wordpress/block-editor");
|
|
|
17
17
|
* WordPress dependencies
|
|
18
18
|
*/
|
|
19
19
|
const name = 'core/underline';
|
|
20
|
+
const title = (0, _i18n.__)('Underline');
|
|
20
21
|
const underline = {
|
|
21
22
|
name,
|
|
22
|
-
title
|
|
23
|
+
title,
|
|
23
24
|
tagName: 'span',
|
|
24
25
|
className: null,
|
|
25
26
|
attributes: {
|
|
@@ -35,7 +36,8 @@ const underline = {
|
|
|
35
36
|
type: name,
|
|
36
37
|
attributes: {
|
|
37
38
|
style: 'text-decoration: underline;'
|
|
38
|
-
}
|
|
39
|
+
},
|
|
40
|
+
title
|
|
39
41
|
}));
|
|
40
42
|
};
|
|
41
43
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/format-library/src/underline/index.js"],"names":["name","
|
|
1
|
+
{"version":3,"sources":["@wordpress/format-library/src/underline/index.js"],"names":["name","title","underline","tagName","className","attributes","style","edit","value","onChange","onToggle","type"],"mappings":";;;;;;;;;AAGA;;AACA;;AACA;;AALA;AACA;AACA;AAQA,MAAMA,IAAI,GAAG,gBAAb;AACA,MAAMC,KAAK,GAAG,cAAI,WAAJ,CAAd;AAEO,MAAMC,SAAS,GAAG;AACxBF,EAAAA,IADwB;AAExBC,EAAAA,KAFwB;AAGxBE,EAAAA,OAAO,EAAE,MAHe;AAIxBC,EAAAA,SAAS,EAAE,IAJa;AAKxBC,EAAAA,UAAU,EAAE;AACXC,IAAAA,KAAK,EAAE;AADI,GALY;;AAQxBC,EAAAA,IAAI,CAAE;AAAEC,IAAAA,KAAF;AAASC,IAAAA;AAAT,GAAF,EAAwB;AAC3B,UAAMC,QAAQ,GAAG,MAAM;AACtBD,MAAAA,QAAQ,CACP,4BAAcD,KAAd,EAAqB;AACpBG,QAAAA,IAAI,EAAEX,IADc;AAEpBK,QAAAA,UAAU,EAAE;AACXC,UAAAA,KAAK,EAAE;AADI,SAFQ;AAKpBL,QAAAA;AALoB,OAArB,CADO,CAAR;AASA,KAVD;;AAYA,WACC,qDACC,4BAAC,6BAAD;AACC,MAAA,IAAI,EAAC,SADN;AAEC,MAAA,SAAS,EAAC,GAFX;AAGC,MAAA,KAAK,EAAGS;AAHT,MADD,EAMC,4BAAC,yCAAD;AACC,MAAA,SAAS,EAAC,iBADX;AAEC,MAAA,OAAO,EAAGA;AAFX,MAND,CADD;AAaA;;AAlCuB,CAAlB","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { toggleFormat } from '@wordpress/rich-text';\nimport {\n\tRichTextShortcut,\n\t__unstableRichTextInputEvent,\n} from '@wordpress/block-editor';\n\nconst name = 'core/underline';\nconst title = __( 'Underline' );\n\nexport const underline = {\n\tname,\n\ttitle,\n\ttagName: 'span',\n\tclassName: null,\n\tattributes: {\n\t\tstyle: 'style',\n\t},\n\tedit( { value, onChange } ) {\n\t\tconst onToggle = () => {\n\t\t\tonChange(\n\t\t\t\ttoggleFormat( value, {\n\t\t\t\t\ttype: name,\n\t\t\t\t\tattributes: {\n\t\t\t\t\t\tstyle: 'text-decoration: underline;',\n\t\t\t\t\t},\n\t\t\t\t\ttitle,\n\t\t\t\t} )\n\t\t\t);\n\t\t};\n\n\t\treturn (\n\t\t\t<>\n\t\t\t\t<RichTextShortcut\n\t\t\t\t\ttype=\"primary\"\n\t\t\t\t\tcharacter=\"u\"\n\t\t\t\t\tonUse={ onToggle }\n\t\t\t\t/>\n\t\t\t\t<__unstableRichTextInputEvent\n\t\t\t\t\tinputType=\"formatUnderline\"\n\t\t\t\t\tonInput={ onToggle }\n\t\t\t\t/>\n\t\t\t</>\n\t\t);\n\t},\n};\n"]}
|
|
@@ -25,12 +25,15 @@ export const bold = {
|
|
|
25
25
|
}) {
|
|
26
26
|
function onToggle() {
|
|
27
27
|
onChange(toggleFormat(value, {
|
|
28
|
-
type: name
|
|
28
|
+
type: name,
|
|
29
|
+
title
|
|
29
30
|
}));
|
|
30
31
|
}
|
|
31
32
|
|
|
32
33
|
function onClick() {
|
|
33
|
-
|
|
34
|
+
onChange(toggleFormat(value, {
|
|
35
|
+
type: name
|
|
36
|
+
}));
|
|
34
37
|
onFocus();
|
|
35
38
|
}
|
|
36
39
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/format-library/src/bold/index.js"],"names":["__","toggleFormat","RichTextToolbarButton","RichTextShortcut","__unstableRichTextInputEvent","formatBold","name","title","bold","tagName","className","edit","isActive","value","onChange","onFocus","onToggle","type","onClick"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,EAAT,QAAmB,iBAAnB;AACA,SAASC,YAAT,QAA6B,sBAA7B;AACA,SACCC,qBADD,EAECC,gBAFD,EAGCC,4BAHD,QAIO,yBAJP;AAKA,SAASC,UAAT,QAA2B,kBAA3B;AAEA,MAAMC,IAAI,GAAG,WAAb;;AACA,MAAMC,KAAK,GAAGP,EAAE,CAAE,MAAF,CAAhB;;AAEA,OAAO,MAAMQ,IAAI,GAAG;AACnBF,EAAAA,IADmB;AAEnBC,EAAAA,KAFmB;AAGnBE,EAAAA,OAAO,EAAE,QAHU;AAInBC,EAAAA,SAAS,EAAE,IAJQ;;AAKnBC,EAAAA,IAAI,CAAE;AAAEC,IAAAA,QAAF;AAAYC,IAAAA,KAAZ;AAAmBC,IAAAA,QAAnB;AAA6BC,IAAAA;AAA7B,GAAF,EAA2C;AAC9C,aAASC,QAAT,GAAoB;AACnBF,MAAAA,QAAQ,CAAEb,YAAY,CAAEY,KAAF,EAAS;AAAEI,QAAAA,IAAI,EAAEX;
|
|
1
|
+
{"version":3,"sources":["@wordpress/format-library/src/bold/index.js"],"names":["__","toggleFormat","RichTextToolbarButton","RichTextShortcut","__unstableRichTextInputEvent","formatBold","name","title","bold","tagName","className","edit","isActive","value","onChange","onFocus","onToggle","type","onClick"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,EAAT,QAAmB,iBAAnB;AACA,SAASC,YAAT,Q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AsBA;;AArCkB,CAAb","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { toggleFormat } from '@wordpress/rich-text';\nimport {\n\tRichTextToolbarButton,\n\tRichTextShortcut,\n\t__unstableRichTextInputEvent,\n} from '@wordpress/block-editor';\nimport { formatBold } from '@wordpress/icons';\n\nconst name = 'core/bold';\nconst title = __( 'Bold' );\n\nexport const bold = {\n\tname,\n\ttitle,\n\ttagName: 'strong',\n\tclassName: null,\n\tedit( { isActive, value, onChange, onFocus } ) {\n\t\tfunction onToggle() {\n\t\t\tonChange( toggleFormat( value, { type: name, title } ) );\n\t\t}\n\n\t\tfunction onClick() {\n\t\t\tonChange( toggleFormat( value, { type: name } ) );\n\t\t\tonFocus();\n\t\t}\n\n\t\treturn (\n\t\t\t<>\n\t\t\t\t<RichTextShortcut\n\t\t\t\t\ttype=\"primary\"\n\t\t\t\t\tcharacter=\"b\"\n\t\t\t\t\tonUse={ onToggle }\n\t\t\t\t/>\n\t\t\t\t<RichTextToolbarButton\n\t\t\t\t\tname=\"bold\"\n\t\t\t\t\ticon={ formatBold }\n\t\t\t\t\ttitle={ title }\n\t\t\t\t\tonClick={ onClick }\n\t\t\t\t\tisActive={ isActive }\n\t\t\t\t\tshortcutType=\"primary\"\n\t\t\t\t\tshortcutCharacter=\"b\"\n\t\t\t\t/>\n\t\t\t\t<__unstableRichTextInputEvent\n\t\t\t\t\tinputType=\"formatBold\"\n\t\t\t\t\tonInput={ onToggle }\n\t\t\t\t/>\n\t\t\t</>\n\t\t);\n\t},\n};\n"]}
|
|
@@ -59,7 +59,8 @@ export const code = {
|
|
|
59
59
|
}) {
|
|
60
60
|
function onClick() {
|
|
61
61
|
onChange(toggleFormat(value, {
|
|
62
|
-
type: name
|
|
62
|
+
type: name,
|
|
63
|
+
title
|
|
63
64
|
}));
|
|
64
65
|
onFocus();
|
|
65
66
|
}
|
|
@@ -68,7 +69,8 @@ export const code = {
|
|
|
68
69
|
icon: codeIcon,
|
|
69
70
|
title: title,
|
|
70
71
|
onClick: onClick,
|
|
71
|
-
isActive: isActive
|
|
72
|
+
isActive: isActive,
|
|
73
|
+
role: "menuitemcheckbox"
|
|
72
74
|
});
|
|
73
75
|
}
|
|
74
76
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/format-library/src/code/index.js"],"names":["__","toggleFormat","remove","applyFormat","RichTextToolbarButton","code","codeIcon","name","title","tagName","className","__unstableInputRule","value","BACKTICK","start","text","characterBefore","slice","textBefore","indexBefore","lastIndexOf","startIndex","endIndex","type","edit","onChange","onFocus","isActive","onClick"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,EAAT,QAAmB,iBAAnB;AACA,SAASC,YAAT,EAAuBC,MAAvB,EAA+BC,WAA/B,QAAkD,sBAAlD;AACA,SAASC,qBAAT,QAAsC,yBAAtC;AACA,SAASC,IAAI,IAAIC,QAAjB,QAAiC,kBAAjC;AAEA,MAAMC,IAAI,GAAG,WAAb;;AACA,MAAMC,KAAK,GAAGR,EAAE,CAAE,aAAF,CAAhB;;AAEA,OAAO,MAAMK,IAAI,GAAG;AACnBE,EAAAA,IADmB;AAEnBC,EAAAA,KAFmB;AAGnBC,EAAAA,OAAO,EAAE,MAHU;AAInBC,EAAAA,SAAS,EAAE,IAJQ;;AAKnBC,EAAAA,mBAAmB,CAAEC,KAAF,EAAU;AAC5B,UAAMC,QAAQ,GAAG,GAAjB;AACA,UAAM;AAAEC,MAAAA,KAAF;AAASC,MAAAA;AAAT,QAAkBH,KAAxB;AACA,UAAMI,eAAe,GAAGD,IAAI,CAACE,KAAL,CAAYH,KAAK,GAAG,CAApB,EAAuBA,KAAvB,CAAxB,CAH4B,CAK5B;;AACA,QAAKE,eAAe,KAAKH,QAAzB,EAAoC;AACnC,aAAOD,KAAP;AACA;;AAED,UAAMM,UAAU,GAAGH,IAAI,CAACE,KAAL,CAAY,CAAZ,EAAeH,KAAK,GAAG,CAAvB,CAAnB;AACA,UAAMK,WAAW,GAAGD,UAAU,CAACE,WAAX,CAAwBP,QAAxB,CAApB;;AAEA,QAAKM,WAAW,KAAK,CAAC,CAAtB,EAA0B;AACzB,aAAOP,KAAP;AACA;;AAED,UAAMS,UAAU,GAAGF,WAAnB;AACA,UAAMG,QAAQ,GAAGR,KAAK,GAAG,CAAzB;;AAEA,QAAKO,UAAU,KAAKC,QAApB,EAA+B;AAC9B,aAAOV,KAAP;AACA;;AAEDA,IAAAA,KAAK,GAAGV,MAAM,CAAEU,KAAF,EAASS,UAAT,EAAqBA,UAAU,GAAG,CAAlC,CAAd;AACAT,IAAAA,KAAK,GAAGV,MAAM,CAAEU,KAAF,EAASU,QAAT,EAAmBA,QAAQ,GAAG,CAA9B,CAAd;AACAV,IAAAA,KAAK,GAAGT,WAAW,CAAES,KAAF,EAAS;AAAEW,MAAAA,IAAI,EAAEhB;AAAR,KAAT,EAAyBc,UAAzB,EAAqCC,QAArC,CAAnB;AAEA,WAAOV,KAAP;AACA,GAlCkB;;AAmCnBY,EAAAA,IAAI,CAAE;AAAEZ,IAAAA,KAAF;AAASa,IAAAA,QAAT;AAAmBC,IAAAA,OAAnB;AAA4BC,IAAAA;AAA5B,GAAF,EAA2C;AAC9C,aAASC,OAAT,GAAmB;AAClBH,MAAAA,QAAQ,CAAExB,YAAY,CAAEW,KAAF,EAAS;AAAEW,QAAAA,IAAI,EAAEhB;
|
|
1
|
+
{"version":3,"sources":["@wordpress/format-library/src/code/index.js"],"names":["__","toggleFormat","remove","applyFormat","RichTextToolbarButton","code","codeIcon","name","title","tagName","className","__unstableInputRule","value","BACKTICK","start","text","characterBefore","slice","textBefore","indexBefore","lastIndexOf","startIndex","endIndex","type","edit","onChange","onFocus","isActive","onClick"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,EAAT,QAAmB,iBAAnB;AACA,SAASC,YAAT,EAAuBC,MAAvB,EAA+BC,WAA/B,QAAkD,sBAAlD;AACA,SAASC,qBAAT,QAAsC,yBAAtC;AACA,SAAS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EAAyBc,UAAzB,EAAqCC,QAArC,CAAnB;AAEA,WAAOV,KAAP;AACA,GAlCkB;;AAmCnBY,EAAAA,IAAI,CAAE;AAAEZ,IAAAA,KAAF;AAASa,IAAAA,QAAT;AAAmBC,IAAAA,OAAnB;AAA4BC,IAAAA;AAA5B,GAAF,EAA2C;AAC9C,aAASC,OAAT,GAAmB;AAClBH,MAAAA,QAAQ,CAAExB,YAAY,CAAEW,KAAF,EAAS;AAAEW,QAAAA,IAAI,EAAEhB,IAAR;AAAcC,QAAAA;AAAd,OAAT,CAAd,CAAR;AACAkB,MAAAA,OAAO;AACP;;AAED,WACC,cAAC,qBAAD;AACC,MAAA,IAAI,EAAGpB,QADR;AAEC,MAAA,KAAK,EAAGE,KAFT;AAGC,MAAA,OAAO,EAAGoB,OAHX;AAIC,MAAA,QAAQ,EAAGD,QAJZ;AAKC,MAAA,IAAI,EAAC;AALN,MADD;AASA;;AAlDkB,CAAb","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { toggleFormat, remove, applyFormat } from '@wordpress/rich-text';\nimport { RichTextToolbarButton } from '@wordpress/block-editor';\nimport { code as codeIcon } from '@wordpress/icons';\n\nconst name = 'core/code';\nconst title = __( 'Inline code' );\n\nexport const code = {\n\tname,\n\ttitle,\n\ttagName: 'code',\n\tclassName: null,\n\t__unstableInputRule( value ) {\n\t\tconst BACKTICK = '`';\n\t\tconst { start, text } = value;\n\t\tconst characterBefore = text.slice( start - 1, start );\n\n\t\t// Quick check the text for the necessary character.\n\t\tif ( characterBefore !== BACKTICK ) {\n\t\t\treturn value;\n\t\t}\n\n\t\tconst textBefore = text.slice( 0, start - 1 );\n\t\tconst indexBefore = textBefore.lastIndexOf( BACKTICK );\n\n\t\tif ( indexBefore === -1 ) {\n\t\t\treturn value;\n\t\t}\n\n\t\tconst startIndex = indexBefore;\n\t\tconst endIndex = start - 2;\n\n\t\tif ( startIndex === endIndex ) {\n\t\t\treturn value;\n\t\t}\n\n\t\tvalue = remove( value, startIndex, startIndex + 1 );\n\t\tvalue = remove( value, endIndex, endIndex + 1 );\n\t\tvalue = applyFormat( value, { type: name }, startIndex, endIndex );\n\n\t\treturn value;\n\t},\n\tedit( { value, onChange, onFocus, isActive } ) {\n\t\tfunction onClick() {\n\t\t\tonChange( toggleFormat( value, { type: name, title } ) );\n\t\t\tonFocus();\n\t\t}\n\n\t\treturn (\n\t\t\t<RichTextToolbarButton\n\t\t\t\ticon={ codeIcon }\n\t\t\t\ttitle={ title }\n\t\t\t\tonClick={ onClick }\n\t\t\t\tisActive={ isActive }\n\t\t\t\trole=\"menuitemcheckbox\"\n\t\t\t/>\n\t\t);\n\t},\n};\n"]}
|
|
@@ -25,12 +25,15 @@ export const italic = {
|
|
|
25
25
|
}) {
|
|
26
26
|
function onToggle() {
|
|
27
27
|
onChange(toggleFormat(value, {
|
|
28
|
-
type: name
|
|
28
|
+
type: name,
|
|
29
|
+
title
|
|
29
30
|
}));
|
|
30
31
|
}
|
|
31
32
|
|
|
32
33
|
function onClick() {
|
|
33
|
-
|
|
34
|
+
onChange(toggleFormat(value, {
|
|
35
|
+
type: name
|
|
36
|
+
}));
|
|
34
37
|
onFocus();
|
|
35
38
|
}
|
|
36
39
|
|