@mantine/tiptap
Version:
Rich text editor based on tiptap
90 lines (86 loc) • 2.94 kB
JavaScript
'use client';
;
var jsxRuntime = require('react/jsx-runtime');
var react = require('react');
var core = require('@mantine/core');
var RichTextEditor_context = require('../RichTextEditor.context.cjs');
var RichTextEditor_module = require('../RichTextEditor.module.css.cjs');
const defaultProps = {
interactive: true
};
const RichTextEditorControl = core.factory((_props, ref) => {
const props = core.useProps("RichTextEditorControl", defaultProps, _props);
const {
classNames,
className,
style,
styles,
vars,
interactive,
active,
onMouseDown,
disabled,
...others
} = props;
const ctx = RichTextEditor_context.useRichTextEditorContext();
return /* @__PURE__ */ jsxRuntime.jsx(
core.UnstyledButton,
{
...others,
...ctx.getStyles("control", { className, style, classNames, styles }),
disabled,
"data-rich-text-editor-control": true,
tabIndex: interactive ? 0 : -1,
"data-interactive": interactive || void 0,
"data-disabled": disabled || void 0,
"data-active": active || void 0,
"aria-pressed": active && interactive || void 0,
"aria-hidden": !interactive || void 0,
ref,
unstyled: ctx.unstyled,
variant: ctx.variant || "default",
onMouseDown: (event) => {
event.preventDefault();
onMouseDown?.(event);
}
}
);
});
RichTextEditorControl.classes = RichTextEditor_module;
RichTextEditorControl.displayName = "@mantine/tiptap/RichTextEditorControl";
const RichTextEditorControlBase = react.forwardRef(({ className, icon: Icon, ...others }, ref) => {
const ctx = RichTextEditor_context.useRichTextEditorContext();
return /* @__PURE__ */ jsxRuntime.jsx(RichTextEditorControl, { ref, ...others, children: /* @__PURE__ */ jsxRuntime.jsx(Icon, { ...ctx.getStyles("controlIcon") }) });
});
RichTextEditorControlBase.displayName = "@mantine/tiptap/RichTextEditorControlBase";
function createControl({
label,
isActive,
operation,
icon,
isDisabled
}) {
const Control = react.forwardRef((props, ref) => {
const { editor, labels } = RichTextEditor_context.useRichTextEditorContext();
const _label = labels[label];
return /* @__PURE__ */ jsxRuntime.jsx(
RichTextEditorControlBase,
{
"aria-label": _label,
title: _label,
active: isActive?.name ? editor?.isActive(isActive.name, isActive.attributes) : false,
ref,
icon: props.icon || icon,
disabled: isDisabled?.(editor) || false,
...props,
onClick: () => editor?.chain().focus()[operation.name](operation.attributes).run()
}
);
});
Control.displayName = `@mantine/tiptap/${label}`;
return Control;
}
exports.RichTextEditorControl = RichTextEditorControl;
exports.RichTextEditorControlBase = RichTextEditorControlBase;
exports.createControl = createControl;
//# sourceMappingURL=RichTextEditorControl.cjs.map