@mantine/tiptap
Version:
Rich text editor based on tiptap
110 lines (107 loc) • 4.48 kB
JavaScript
'use client';
import { jsx } from 'react/jsx-runtime';
import { useMemo } from 'react';
import { factory, useProps, useStyles, Box } from '@mantine/core';
import { DEFAULT_LABELS } from './labels.mjs';
import { RichTextEditorProvider } from './RichTextEditor.context.mjs';
import { RichTextEditorContent } from './RichTextEditorContent/RichTextEditorContent.mjs';
import { BoldControl, ItalicControl, StrikeThroughControl, UnderlineControl, ClearFormattingControl, H1Control, H2Control, H3Control, H4Control, H5Control, H6Control, BulletListControl, OrderedListControl, UnlinkControl, BlockquoteControl, AlignLeftControl, AlignRightControl, AlignCenterControl, AlignJustifyControl, SuperscriptControl, SubscriptControl, CodeControl, CodeBlockControl, HighlightControl, HrControl, UnsetColorControl, UndoControl, RedoControl, TaskListControl, TaskListSinkControl, TaskListLiftControl } from './RichTextEditorControl/controls.mjs';
import { RichTextEditorLinkControl } from './RichTextEditorControl/RichTextEditorLinkControl.mjs';
import { RichTextEditorColorPickerControl } from './RichTextEditorControl/RichTextEditorColorPickerControl.mjs';
import { RichTextEditorColorControl } from './RichTextEditorControl/RichTextEditorColorControl.mjs';
import { RichTextEditorControl } from './RichTextEditorControl/RichTextEditorControl.mjs';
import { RichTextEditorControlsGroup } from './RichTextEditorControlsGroup/RichTextEditorControlsGroup.mjs';
import { RichTextEditorToolbar } from './RichTextEditorToolbar/RichTextEditorToolbar.mjs';
import classes from './RichTextEditor.module.css.mjs';
const defaultProps = {
withCodeHighlightStyles: true,
withTypographyStyles: true,
variant: "default"
};
const RichTextEditor = factory((_props, ref) => {
const props = useProps("RichTextEditor", defaultProps, _props);
const {
classNames,
className,
style,
styles,
unstyled,
vars,
editor,
withCodeHighlightStyles,
withTypographyStyles,
labels,
children,
variant,
...others
} = props;
const getStyles = useStyles({
name: "RichTextEditor",
classes,
props,
className,
style,
classNames,
styles,
unstyled,
vars
});
const mergedLabels = useMemo(() => ({ ...DEFAULT_LABELS, ...labels }), [labels]);
return /* @__PURE__ */ jsx(
RichTextEditorProvider,
{
value: {
editor,
getStyles,
labels: mergedLabels,
withCodeHighlightStyles,
withTypographyStyles,
unstyled,
variant
},
children: /* @__PURE__ */ jsx(Box, { ...getStyles("root"), ...others, ref, children })
}
);
});
RichTextEditor.classes = classes;
RichTextEditor.displayName = "@mantine/tiptap/RichTextEditor";
RichTextEditor.Content = RichTextEditorContent;
RichTextEditor.Control = RichTextEditorControl;
RichTextEditor.Toolbar = RichTextEditorToolbar;
RichTextEditor.ControlsGroup = RichTextEditorControlsGroup;
RichTextEditor.Bold = BoldControl;
RichTextEditor.Italic = ItalicControl;
RichTextEditor.Strikethrough = StrikeThroughControl;
RichTextEditor.Underline = UnderlineControl;
RichTextEditor.ClearFormatting = ClearFormattingControl;
RichTextEditor.H1 = H1Control;
RichTextEditor.H2 = H2Control;
RichTextEditor.H3 = H3Control;
RichTextEditor.H4 = H4Control;
RichTextEditor.H5 = H5Control;
RichTextEditor.H6 = H6Control;
RichTextEditor.BulletList = BulletListControl;
RichTextEditor.OrderedList = OrderedListControl;
RichTextEditor.Link = RichTextEditorLinkControl;
RichTextEditor.Unlink = UnlinkControl;
RichTextEditor.Blockquote = BlockquoteControl;
RichTextEditor.AlignLeft = AlignLeftControl;
RichTextEditor.AlignRight = AlignRightControl;
RichTextEditor.AlignCenter = AlignCenterControl;
RichTextEditor.AlignJustify = AlignJustifyControl;
RichTextEditor.Superscript = SuperscriptControl;
RichTextEditor.Subscript = SubscriptControl;
RichTextEditor.Code = CodeControl;
RichTextEditor.CodeBlock = CodeBlockControl;
RichTextEditor.ColorPicker = RichTextEditorColorPickerControl;
RichTextEditor.Color = RichTextEditorColorControl;
RichTextEditor.Highlight = HighlightControl;
RichTextEditor.Hr = HrControl;
RichTextEditor.UnsetColor = UnsetColorControl;
RichTextEditor.Undo = UndoControl;
RichTextEditor.Redo = RedoControl;
RichTextEditor.TaskList = TaskListControl;
RichTextEditor.TaskListSink = TaskListSinkControl;
RichTextEditor.TaskListLift = TaskListLiftControl;
export { RichTextEditor };
//# sourceMappingURL=RichTextEditor.mjs.map