UNPKG

@empoleon/tiptap

Version:

Rich text editor based on tiptap

107 lines (104 loc) 4.93 kB
import { createComponent, mergeProps } from 'solid-js/web'; import { splitProps, createMemo } from 'solid-js'; import { factory, useProps, useStyles, Box } from '@empoleon/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 => { const props = useProps("RichTextEditor", defaultProps, _props); const [local, others] = splitProps(props, ["classNames", "className", "style", "styles", "unstyled", "vars", "editor", "withCodeHighlightStyles", "withTypographyStyles", "labels", "children", "variant", "ref"]); const getStyles = useStyles({ name: "RichTextEditor", classes, props, className: local.className, style: local.style, classNames: local.classNames, styles: local.styles, unstyled: local.unstyled, vars: local.vars }); const mergedLabels = createMemo(() => ({ ...DEFAULT_LABELS, ...local.labels })); return createComponent(RichTextEditorProvider, { get value() { return { editor: local.editor, getStyles, labels: mergedLabels(), withCodeHighlightStyles: local.withCodeHighlightStyles, withTypographyStyles: local.withTypographyStyles, unstyled: local.unstyled, variant: local.variant }; }, get children() { return createComponent(Box, mergeProps(() => getStyles("root"), others, { ref(r$) { var _ref$ = local.ref; typeof _ref$ === "function" ? _ref$(r$) : local.ref = r$; }, get children() { return local.children; } })); } }); }); RichTextEditor.classes = classes; RichTextEditor.displayName = "@empoleon/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