|
|
|
@ -51,6 +51,29 @@ const blockTypeToBlockName = {
|
|
|
|
|
ul: 'Bulleted List',
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const FONT_FAMILY_OPTIONS = [
|
|
|
|
|
['Arial', 'Arial'],
|
|
|
|
|
['Courier New', 'Courier New'],
|
|
|
|
|
['Georgia', 'Georgia'],
|
|
|
|
|
['Times New Roman', 'Times New Roman'],
|
|
|
|
|
['Trebuchet MS', 'Trebuchet MS'],
|
|
|
|
|
['Verdana', 'Verdana'],
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
const FONT_SIZE_OPTIONS = [
|
|
|
|
|
['10px', '10px'],
|
|
|
|
|
['11px', '11px'],
|
|
|
|
|
['12px', '12px'],
|
|
|
|
|
['13px', '13px'],
|
|
|
|
|
['14px', '14px'],
|
|
|
|
|
['15px', '15px'],
|
|
|
|
|
['16px', '16px'],
|
|
|
|
|
['17px', '17px'],
|
|
|
|
|
['18px', '18px'],
|
|
|
|
|
['19px', '19px'],
|
|
|
|
|
['20px', '20px'],
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
const ELEMENT_FORMAT_OPTIONS = {
|
|
|
|
|
center: { icon: 'center-align', iconRTL: 'center-align', name: 'Center Align' },
|
|
|
|
|
end: { icon: 'right-align', iconRTL: 'left-align', name: 'End Align' },
|
|
|
|
@ -60,6 +83,14 @@ const ELEMENT_FORMAT_OPTIONS = {
|
|
|
|
|
start: { icon: 'left-align', iconRTL: 'right-align', name: 'Start Align' },
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function dropDownActiveClass(active) {
|
|
|
|
|
if (active) {
|
|
|
|
|
return 'active dropdown-item-active';
|
|
|
|
|
} else {
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function Divider() {
|
|
|
|
|
return <div className='divider' />;
|
|
|
|
|
}
|
|
|
|
@ -432,6 +463,56 @@ function BlockOptionsDropdownList({ editor, blockType, toolbarRef, setShowBlockO
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function FontDropDown({
|
|
|
|
|
editor,
|
|
|
|
|
value,
|
|
|
|
|
style,
|
|
|
|
|
disabled = false,
|
|
|
|
|
}) {
|
|
|
|
|
const handleClick = useCallback(
|
|
|
|
|
(option) => {
|
|
|
|
|
editor.update(() => {
|
|
|
|
|
const selection = $getSelection();
|
|
|
|
|
if (selection !== null) {
|
|
|
|
|
$patchStyleText(selection, {
|
|
|
|
|
[style]: option,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
[editor, style],
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const buttonAriaLabel =
|
|
|
|
|
style === 'font-family'
|
|
|
|
|
? 'Formatting options for font family'
|
|
|
|
|
: 'Formatting options for font size';
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<DropDown
|
|
|
|
|
disabled={disabled}
|
|
|
|
|
buttonClassName={'toolbar-item ' + style}
|
|
|
|
|
// buttonLabel={value}
|
|
|
|
|
buttonIconClassName={
|
|
|
|
|
style === 'font-family' ? 'icon block-type font-family' : ''
|
|
|
|
|
}
|
|
|
|
|
buttonAriaLabel={buttonAriaLabel}>
|
|
|
|
|
{(style === 'font-family' ? FONT_FAMILY_OPTIONS : FONT_SIZE_OPTIONS).map(
|
|
|
|
|
([option, text]) => (
|
|
|
|
|
<DropDownItem
|
|
|
|
|
className={`item font-m-${option.replace(/\s+/g, '_')} ${dropDownActiveClass(value === option)} ${
|
|
|
|
|
style === 'font-size' ? 'fontsize-item' : ''
|
|
|
|
|
}`}
|
|
|
|
|
onClick={() => handleClick(option)}
|
|
|
|
|
key={option}>
|
|
|
|
|
<span className="text">{text}</span>
|
|
|
|
|
</DropDownItem>
|
|
|
|
|
),
|
|
|
|
|
)}
|
|
|
|
|
</DropDown>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function ElementFormatDropdown({ editor, value, isRTL, disabled = false }) {
|
|
|
|
|
const formatOption = ELEMENT_FORMAT_OPTIONS[value || 'left'];
|
|
|
|
|
|
|
|
|
@ -528,6 +609,7 @@ export default function ToolbarPlugin() {
|
|
|
|
|
const [isUnderline, setIsUnderline] = useState(false);
|
|
|
|
|
const [isStrikethrough, setIsStrikethrough] = useState(false);
|
|
|
|
|
const [isCode, setIsCode] = useState(false);
|
|
|
|
|
const [fontFamily, setFontFamily] = useState('Arial');
|
|
|
|
|
const [fontColor, setFontColor] = useState('#000');
|
|
|
|
|
const [bgColor, setBgColor] = useState('#fff');
|
|
|
|
|
const [elementFormat, setElementFormat] = useState('left');
|
|
|
|
@ -600,6 +682,16 @@ export default function ToolbarPlugin() {
|
|
|
|
|
|
|
|
|
|
// Handle buttons
|
|
|
|
|
setFontColor($getSelectionStyleValueForProperty(selection, 'color', '#000'));
|
|
|
|
|
setBgColor(
|
|
|
|
|
$getSelectionStyleValueForProperty(
|
|
|
|
|
selection,
|
|
|
|
|
'background-color',
|
|
|
|
|
'#fff',
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
setFontFamily(
|
|
|
|
|
$getSelectionStyleValueForProperty(selection, 'font-family', 'Arial'),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
let matchingParent;
|
|
|
|
|
if ($isLinkNode(parent)) {
|
|
|
|
@ -715,6 +807,13 @@ export default function ToolbarPlugin() {
|
|
|
|
|
</>
|
|
|
|
|
) : (
|
|
|
|
|
<>
|
|
|
|
|
<FontDropDown
|
|
|
|
|
disabled={!isEditable}
|
|
|
|
|
style={'font-family'}
|
|
|
|
|
value={fontFamily}
|
|
|
|
|
editor={editor}
|
|
|
|
|
/>
|
|
|
|
|
<Divider />
|
|
|
|
|
<button
|
|
|
|
|
onClick={() => {
|
|
|
|
|
editor.dispatchCommand(FORMAT_TEXT_COMMAND, 'bold');
|
|
|
|
|