@blocknote/react
Version:
A "Notion-style" block-based extensible text editor built on top of Prosemirror and Tiptap.
104 lines (103 loc) • 2.92 kB
JavaScript
import { t as e } from "./rolldown-runtime-CAFD8bLK.js";
import { f as t, i as n, l as r, m as i, n as a, o, p as s, r as c, s as l, t as u } from "./defaultCommentEditorSchema-3DnX6Knw.js";
import { memo as d, useCallback as f, useMemo as p } from "react";
import { CommentsExtension as m } from "@blocknote/core/comments";
import { flip as h, offset as g, shift as _ } from "@floating-ui/react";
import { mergeCSSClasses as v } from "@blocknote/core";
import { jsx as y } from "react/jsx-runtime";
import { TextSelection as b } from "@tiptap/pm/state";
//#region src/components/Comments/FloatingComposer.tsx
var x = d(({ isEmpty: e, onSave: t, Components: n, dict: r }) => /* @__PURE__ */ y(n.Generic.Toolbar.Root, {
className: v("bn-action-toolbar", "bn-comment-actions"),
variant: "action-toolbar",
children: /* @__PURE__ */ y(n.Generic.Toolbar.Button, {
className: "bn-button",
mainTooltip: r.comments.save_button_text,
variant: "compact",
isDisabled: e,
onClick: t,
children: r.comments.save_button_text
})
}));
function S() {
let e = i(), n = t(m), o = r(), s = l(), d = c({
trailingBlock: !1,
dictionary: {
...s,
placeholders: { emptyDocument: s.placeholders.new_comment }
},
schema: n.commentEditorSchema || u
}), p = f(async () => {
await n.createThread({ initialComment: { body: d.document } }), n.stopPendingComment(), e.transact((e) => {
e.setSelection(b.create(e.doc, e.selection.to));
}), e.focus();
}, [
n,
d,
e
]);
return /* @__PURE__ */ y(o.Comments.Card, {
className: "bn-thread",
children: /* @__PURE__ */ y(a, {
autoFocus: !0,
editable: !0,
editor: d,
actions: ({ isFocused: e, isEmpty: t }) => /* @__PURE__ */ y(x, {
isFocused: e,
isEmpty: t,
onSave: p,
Components: o,
dict: s
})
})
});
}
//#endregion
//#region src/components/Comments/FloatingComposerController.tsx
var C = /* @__PURE__ */ e({ default: () => w });
function w(e) {
let r = i(), a = t(m), c = s(m, {
editor: r,
selector: (e) => e.pendingComment
}), l = o({
editor: r,
selector: ({ editor: e }) => c ? {
from: e.prosemirrorState.selection.from,
to: e.prosemirrorState.selection.to
} : void 0
}), u = p(() => ({
...e.floatingUIOptions,
useFloatingOptions: {
open: !!c,
onOpenChange: (e) => {
e || (a.stopPendingComment(), r.focus());
},
placement: "bottom",
middleware: [
g(10),
_(),
h()
],
...e.floatingUIOptions?.useFloatingOptions
},
focusManagerProps: { disabled: !1 },
elementProps: {
style: { zIndex: 60 },
...e.floatingUIOptions?.elementProps
}
}), [
a,
r,
c,
e.floatingUIOptions
]), d = e.floatingComposer || S;
return /* @__PURE__ */ y(n, {
position: l,
portalElement: e.portalElement,
...u,
children: /* @__PURE__ */ y(d, {})
});
}
//#endregion
export { C as n, S as r, w as t };
//# sourceMappingURL=FloatingComposerController-5A3GJtK4.js.map