kopia lustrzana https://gitlab.com/soapbox-pub/soapbox
Lexical: Only allow headings if supported by backend
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>environments/review-lexical-ujdd17/deployments/3354
rodzic
eee7534f58
commit
d1c26a22ba
|
@ -71,55 +71,53 @@ const ComposeEditor = React.forwardRef<string, IComposeEditor>(({
|
||||||
|
|
||||||
const [suggestionsHidden, setSuggestionsHidden] = useState(true);
|
const [suggestionsHidden, setSuggestionsHidden] = useState(true);
|
||||||
|
|
||||||
const initialConfig: InitialConfigType = useMemo(function() {
|
const initialConfig: InitialConfigType = useMemo(() => ({
|
||||||
return {
|
namespace: 'ComposeForm',
|
||||||
namespace: 'ComposeForm',
|
onError: console.error,
|
||||||
onError: console.error,
|
nodes,
|
||||||
nodes,
|
theme: {
|
||||||
theme: {
|
hashtag: 'hover:underline text-primary-600 dark:text-accent-blue hover:text-primary-800 dark:hover:text-accent-blue',
|
||||||
hashtag: 'hover:underline text-primary-600 dark:text-accent-blue hover:text-primary-800 dark:hover:text-accent-blue',
|
mention: 'hover:underline text-primary-600 dark:text-accent-blue hover:text-primary-800 dark:hover:text-accent-blue',
|
||||||
mention: 'hover:underline text-primary-600 dark:text-accent-blue hover:text-primary-800 dark:hover:text-accent-blue',
|
text: {
|
||||||
text: {
|
bold: 'font-bold',
|
||||||
bold: 'font-bold',
|
code: 'font-mono',
|
||||||
code: 'font-mono',
|
italic: 'italic',
|
||||||
italic: 'italic',
|
strikethrough: 'line-through',
|
||||||
strikethrough: 'line-through',
|
underline: 'underline',
|
||||||
underline: 'underline',
|
underlineStrikethrough: 'underline-line-through',
|
||||||
underlineStrikethrough: 'underline-line-through',
|
|
||||||
},
|
|
||||||
heading: {
|
|
||||||
h1: 'text-2xl font-bold',
|
|
||||||
h2: 'text-xl font-bold',
|
|
||||||
h3: 'text-lg font-semibold',
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
editorState: dispatch((_, getState) => {
|
heading: {
|
||||||
const state = getState();
|
h1: 'text-2xl font-bold',
|
||||||
const compose = state.compose.get(composeId);
|
h2: 'text-xl font-bold',
|
||||||
|
h3: 'text-lg font-semibold',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
editorState: dispatch((_, getState) => {
|
||||||
|
const state = getState();
|
||||||
|
const compose = state.compose.get(composeId);
|
||||||
|
|
||||||
if (!compose) return;
|
if (!compose) return;
|
||||||
|
|
||||||
if (compose.editorState) {
|
if (compose.editorState) {
|
||||||
return compose.editorState;
|
return compose.editorState;
|
||||||
|
}
|
||||||
|
|
||||||
|
return function() {
|
||||||
|
if (compose.content_type === 'text/markdown') {
|
||||||
|
$convertFromMarkdownString(compose.text, TO_WYSIWYG_TRANSFORMERS);
|
||||||
|
} else {
|
||||||
|
const paragraph = $createParagraphNode();
|
||||||
|
const textNode = $createTextNode(compose.text);
|
||||||
|
|
||||||
|
paragraph.append(textNode);
|
||||||
|
|
||||||
|
$getRoot()
|
||||||
|
.clear()
|
||||||
|
.append(paragraph);
|
||||||
}
|
}
|
||||||
|
};
|
||||||
return function() {
|
}),
|
||||||
if (compose.content_type === 'text/markdown') {
|
}), []);
|
||||||
$convertFromMarkdownString(compose.text, TO_WYSIWYG_TRANSFORMERS);
|
|
||||||
} else {
|
|
||||||
const paragraph = $createParagraphNode();
|
|
||||||
const textNode = $createTextNode(compose.text);
|
|
||||||
|
|
||||||
paragraph.append(textNode);
|
|
||||||
|
|
||||||
$getRoot()
|
|
||||||
.clear()
|
|
||||||
.append(paragraph);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}),
|
|
||||||
};
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const [floatingAnchorElem, setFloatingAnchorElem] =
|
const [floatingAnchorElem, setFloatingAnchorElem] =
|
||||||
useState<HTMLDivElement | null>(null);
|
useState<HTMLDivElement | null>(null);
|
||||||
|
|
|
@ -45,6 +45,7 @@ import * as React from 'react';
|
||||||
import { createPortal } from 'react-dom';
|
import { createPortal } from 'react-dom';
|
||||||
|
|
||||||
import { Icon } from 'soapbox/components/ui';
|
import { Icon } from 'soapbox/components/ui';
|
||||||
|
import { useInstance } from 'soapbox/hooks';
|
||||||
|
|
||||||
import { getDOMRangeRect } from '../utils/get-dom-range-rect';
|
import { getDOMRangeRect } from '../utils/get-dom-range-rect';
|
||||||
import { getSelectedNode } from '../utils/get-selected-node';
|
import { getSelectedNode } from '../utils/get-selected-node';
|
||||||
|
@ -104,6 +105,8 @@ const BlockTypeDropdown = ({ editor, anchorElem, blockType, icon }: {
|
||||||
blockType: keyof typeof blockTypeToBlockName
|
blockType: keyof typeof blockTypeToBlockName
|
||||||
icon: string
|
icon: string
|
||||||
}) => {
|
}) => {
|
||||||
|
const instance = useInstance();
|
||||||
|
|
||||||
const [showDropDown, setShowDropDown] = useState(false);
|
const [showDropDown, setShowDropDown] = useState(false);
|
||||||
|
|
||||||
const formatParagraph = () => {
|
const formatParagraph = () => {
|
||||||
|
@ -205,21 +208,25 @@ const BlockTypeDropdown = ({ editor, anchorElem, blockType, icon }: {
|
||||||
active={blockType === 'paragraph'}
|
active={blockType === 'paragraph'}
|
||||||
icon={blockTypeToIcon.paragraph}
|
icon={blockTypeToIcon.paragraph}
|
||||||
/>
|
/>
|
||||||
<ToolbarButton
|
{instance.pleroma.getIn(['metadata', 'markup', 'allow_headings']) === true && (
|
||||||
onClick={() => formatHeading('h1')}
|
<>
|
||||||
active={blockType === 'h1'}
|
<ToolbarButton
|
||||||
icon={blockTypeToIcon.h1}
|
onClick={() => formatHeading('h1')}
|
||||||
/>
|
active={blockType === 'h1'}
|
||||||
<ToolbarButton
|
icon={blockTypeToIcon.h1}
|
||||||
onClick={() => formatHeading('h2')}
|
/>
|
||||||
active={blockType === 'h2'}
|
<ToolbarButton
|
||||||
icon={blockTypeToIcon.h2}
|
onClick={() => formatHeading('h2')}
|
||||||
/>
|
active={blockType === 'h2'}
|
||||||
<ToolbarButton
|
icon={blockTypeToIcon.h2}
|
||||||
onClick={() => formatHeading('h3')}
|
/>
|
||||||
active={blockType === 'h3'}
|
<ToolbarButton
|
||||||
icon={blockTypeToIcon.h3}
|
onClick={() => formatHeading('h3')}
|
||||||
/>
|
active={blockType === 'h3'}
|
||||||
|
icon={blockTypeToIcon.h3}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
<ToolbarButton
|
<ToolbarButton
|
||||||
onClick={formatBulletList}
|
onClick={formatBulletList}
|
||||||
active={blockType === 'bullet'}
|
active={blockType === 'bullet'}
|
||||||
|
|
Ładowanie…
Reference in New Issue