UNPKG

@blocknote/react

Version:

A "Notion-style" block-based extensible text editor built on top of Prosemirror and Tiptap.

1,509 lines 111 kB
import { a as e, c as t, d as n, f as r, g as i, h as a, i as o, l as s, m as c, o as l, p as u, r as d, s as f, u as p } from "./defaultCommentEditorSchema-3DnX6Knw.js"; import { a as m, c as h, i as g, o as _, r as v, s as y, t as b } from "./FloatingThreadController-BZkNOp17.js"; import { r as ee, t as te } from "./FloatingComposerController-5A3GJtK4.js"; import ne, { Suspense as re, createContext as ie, forwardRef as ae, lazy as x, useCallback as S, useContext as oe, useEffect as C, useImperativeHandle as se, useMemo as w, useReducer as T, useRef as E, useState as D, useSyncExternalStore as ce } from "react"; import { CommentsExtension as O } from "@blocknote/core/comments"; import { DEFAULT_LINK_PROTOCOL as le, FilePanelExtension as k, FormattingToolbarExtension as A, LinkToolbarExtension as j, ShowSelectionExtension as ue, SideMenuExtension as M, SuggestionMenu as N, TableHandlesExtension as P, VALID_LINK_PROTOCOLS as de, filterSuggestionItems as fe, getDefaultEmojiPickerItems as pe, getDefaultSlashMenuItems as me } from "@blocknote/core/extensions"; import { autoPlacement as he, autoUpdate as ge, flip as _e, offset as F, safePolygon as ve, shift as ye, size as I, useFloating as be, useTransitionStyles as xe } from "@floating-ui/react"; import { EMPTY_CELL_HEIGHT as Se, EMPTY_CELL_WIDTH as Ce, UnreachableCaseError as we, addInlineContentAttributes as Te, addInlineContentKeyboardShortcuts as Ee, addStyleAttributes as De, audioParse as Oe, blockHasType as L, camelToDataKebab as ke, createAudioBlockConfig as Ae, createFileBlockConfig as je, createImageBlockConfig as Me, createInternalInlineContentSpec as Ne, createInternalStyleSpec as Pe, createVideoBlockConfig as Fe, defaultProps as R, defaultToggledState as z, editorHasBlockWithType as B, fileParse as Ie, filenameFromURL as Le, formatKeyboardShortcut as V, getBlockFromPos as Re, getColspan as ze, getInlineContentParseRules as Be, getNodeById as Ve, getPageBreakSlashMenuItems as He, getRowspan as Ue, getStyleParseRules as We, imageParse as Ge, inlineContentToNodes as Ke, isTableCell as H, isTableCellSelection as qe, mapTableCell as U, mergeCSSClasses as W, nodeToCustomInlineContent as Je, propsToAttributes as Ye, stylePropsToAttributes as Xe, videoParse as Ze } from "@blocknote/core"; import { Fragment as G, jsx as K, jsxs as q } from "react/jsx-runtime"; import { Node as Qe } from "@tiptap/core"; import { RiAddFill as $e, RiAlignCenter as et, RiAlignJustify as tt, RiAlignLeft as nt, RiAlignRight as rt, RiBold as it, RiChat3Line as at, RiCodeBlock as ot, RiCodeFill as st, RiDeleteBin7Line as ct, RiDownload2Fill as lt, RiEmotionFill as ut, RiExternalLinkFill as dt, RiFile2Line as ft, RiFilmLine as pt, RiFontFamily as mt, RiH1 as ht, RiH2 as gt, RiH3 as _t, RiH4 as vt, RiH5 as yt, RiH6 as bt, RiImage2Fill as xt, RiImageAddFill as St, RiImageEditFill as Ct, RiIndentDecrease as wt, RiIndentIncrease as Tt, RiInputField as Et, RiItalic as Dt, RiLink as Ot, RiLinkUnlink as kt, RiListCheck3 as At, RiListOrdered as jt, RiListUnordered as Mt, RiMergeCellsHorizontal as Nt, RiMergeCellsVertical as Pt, RiPlayList2Fill as Ft, RiQuoteText as It, RiStrikethrough as Lt, RiSubtractLine as Rt, RiTable2 as zt, RiText as Bt, RiUnderline as Vt, RiVideoFill as Ht, RiVolumeUpFill as Ut } from "react-icons/ri"; import { AiOutlinePlus as Wt } from "react-icons/ai"; import { MdArrowDropDown as Gt, MdDragIndicator as Kt } from "react-icons/md"; import { createPortal as qt, flushSync as Jt } from "react-dom"; import { Mark as Yt, NodeViewWrapper as Xt, ReactMarkViewContext as Zt, ReactMarkViewRenderer as Qt, ReactNodeViewRenderer as $t, useReactNodeView as en } from "@tiptap/react"; import { createRoot as tn } from "react-dom/client"; import { TbPageBreak as nn } from "react-icons/tb"; //#region src/components/Popovers/BlockPopover.tsx var rn = (e) => { let { blockId: t, children: n, portalElement: r, ...i } = e, a = c(); return /* @__PURE__ */ K(p, { reference: w(() => a.transact((e) => { if (!t) return; let n = Ve(t, e.doc); if (!n) return; let { node: r } = a.prosemirrorView.domAtPos(n.posBeforeNode + 1); if (r instanceof Element) return { element: r }; }), [a, t]), portalElement: r, ...i, children: t !== void 0 && n }); }, an = (e) => { let t = s(), n = f(), r = c(), i = r.getBlock(e.blockId), [a, o] = D(""), l = S((e) => { o(e.currentTarget.value); }, []), u = S((e) => { e.key === "Enter" && !e.nativeEvent.isComposing && (e.preventDefault(), r.updateBlock(i.id, { props: { name: Le(a), url: a } })); }, [ r, i.id, a ]), d = S(() => { r.updateBlock(i.id, { props: { name: Le(a), url: a } }); }, [ r, i.id, a ]); return /* @__PURE__ */ q(t.FilePanel.TabPanel, { className: "bn-tab-panel", children: [/* @__PURE__ */ K(t.FilePanel.TextInput, { className: "bn-text-input", placeholder: n.file_panel.embed.url_placeholder, value: a, onChange: l, onKeyDown: u, "data-test": "embed-input" }), /* @__PURE__ */ K(t.FilePanel.Button, { className: "bn-button", onClick: d, "data-test": "embed-input-button", children: n.file_panel.embed.embed_button[i.type] || n.file_panel.embed.embed_button.file })] }); }, on = (e) => { let t = s(), n = f(), { setLoading: r } = e, i = c(), a = i.getBlock(e.blockId), [o, l] = D(!1); C(() => { o && setTimeout(() => { l(!1); }, 3e3); }, [o]); let u = S((t) => { if (t === null) return; async function n(t) { if (r(!0), i.uploadFile !== void 0) try { let n = await i.uploadFile(t, e.blockId); typeof n == "string" && (n = { props: { name: t.name, url: n } }), i.updateBlock(e.blockId, n); } catch { l(!0); } finally { r(!1); } } n(t); }, [ e.blockId, i, r ]), d = i.schema.blockSpecs[a.type], p = d.implementation.meta?.fileBlockAccept?.length ? d.implementation.meta.fileBlockAccept.join(",") : "*/*"; return /* @__PURE__ */ q(t.FilePanel.TabPanel, { className: "bn-tab-panel", children: [/* @__PURE__ */ K(t.FilePanel.FileInput, { className: "bn-file-input", "data-test": "upload-input", accept: p, placeholder: n.file_panel.upload.file_placeholder[a.type] || n.file_panel.upload.file_placeholder.file, value: null, onChange: u }), o && /* @__PURE__ */ K("div", { className: "bn-error-text", children: n.file_panel.upload.upload_error })] }); }, sn = (e) => { let t = s(), n = f(), r = c(), [i, a] = D(!1), o = e.tabs ?? [...r.uploadFile === void 0 ? [] : [{ name: n.file_panel.upload.title, tabPanel: /* @__PURE__ */ K(on, { blockId: e.blockId, setLoading: a }) }], { name: n.file_panel.embed.title, tabPanel: /* @__PURE__ */ K(an, { blockId: e.blockId }) }], [l, u] = D(e.defaultOpenTab || o[0].name); return /* @__PURE__ */ K(t.FilePanel.Root, { className: "bn-panel", defaultOpenTab: l, openTab: l, setOpenTab: u, tabs: o, loading: i }); }, cn = (e) => { let t = c(), n = r(k), i = u(k), a = w(() => ({ ...e.floatingUIOptions, useFloatingOptions: { open: !!i, onOpenChange: (e, r, i) => { e || n.closeMenu(), i === "escape-key" && t.focus(); }, middleware: [F(10), _e()], ...e.floatingUIOptions?.useFloatingOptions }, focusManagerProps: { disabled: !0, ...e.floatingUIOptions?.focusManagerProps }, elementProps: { style: { zIndex: 90 }, ...e.floatingUIOptions?.elementProps } }), [ i, t, n, e.floatingUIOptions ]), o = e.filePanel || sn; return /* @__PURE__ */ K(rn, { blockId: i, portalElement: e.portalElement, ...a, children: i && /* @__PURE__ */ K(o, { blockId: i }) }); }, ln = { bold: it, italic: Dt, underline: Vt, strike: Lt, code: st }; function un(e, t) { return e in t.schema.styleSchema && t.schema.styleSchema[e].type === e && t.schema.styleSchema[e].propSchema === "boolean"; } var J = (e) => { let t = f(), n = s(), r = c(), i = l({ editor: r, selector: ({ editor: t }) => { if (!(!t.isEditable || !un(e.basicTextStyle, t) || !(t.getSelection()?.blocks || [t.getTextCursorPosition().block]).find((e) => e.content !== void 0))) return e.basicTextStyle in t.getActiveStyles() ? { active: !0 } : { active: !1 }; } }), a = S((e) => { r.focus(), r.toggleStyles({ [e]: !0 }); }, [r, e]); if (i === void 0) return null; let o = ln[e.basicTextStyle]; return /* @__PURE__ */ K(n.FormattingToolbar.Button, { className: "bn-button", "data-test": e.basicTextStyle, onClick: () => a(e.basicTextStyle), isSelected: i.active, label: t.formatting_toolbar[e.basicTextStyle].tooltip, mainTooltip: t.formatting_toolbar[e.basicTextStyle].tooltip, secondaryTooltip: V(t.formatting_toolbar[e.basicTextStyle].secondary_tooltip, t.generic.ctrl_shortcut), icon: /* @__PURE__ */ K(o, {}) }); }, dn = (e) => { let t = e.textColor || "default", n = e.backgroundColor || "default", r = e.size || 16; return /* @__PURE__ */ K("div", { className: "bn-color-icon", "data-background-color": n, "data-text-color": t, style: w(() => ({ pointerEvents: "none", fontSize: (r * .75).toString() + "px", height: r.toString() + "px", lineHeight: r.toString() + "px", textAlign: "center", width: r.toString() + "px" }), [r]), children: "A" }); }, fn = [ "default", "gray", "brown", "red", "orange", "yellow", "green", "blue", "purple", "pink" ], pn = (e) => { let t = s(), n = f(); return /* @__PURE__ */ q(G, { children: [/* @__PURE__ */ K(() => e.text ? /* @__PURE__ */ q(G, { children: [/* @__PURE__ */ K(t.Generic.Menu.Label, { children: n.color_picker.text_title }), fn.map((r) => /* @__PURE__ */ K(t.Generic.Menu.Item, { onClick: () => { e.onClick && e.onClick(), e.text.setColor(r); }, "data-test": "text-color-" + r, icon: /* @__PURE__ */ K(dn, { textColor: r, size: e.iconSize }), checked: e.text.color === r, children: n.color_picker.colors[r] }, "text-color-" + r))] }) : null, {}), /* @__PURE__ */ K(() => e.background ? /* @__PURE__ */ q(G, { children: [/* @__PURE__ */ K(t.Generic.Menu.Label, { children: n.color_picker.background_title }), fn.map((r) => /* @__PURE__ */ K(t.Generic.Menu.Item, { onClick: () => { e.onClick && e.onClick(), e.background.setColor(r); }, "data-test": "background-color-" + r, icon: /* @__PURE__ */ K(dn, { backgroundColor: r, size: e.iconSize }), checked: e.background.color === r, children: n.color_picker.colors[r] }, "background-color-" + r))] }) : null, {})] }); }; //#endregion //#region src/components/FormattingToolbar/DefaultButtons/ColorStyleButton.tsx function mn(e, t) { return `${e}Color` in t.schema.styleSchema && t.schema.styleSchema[`${e}Color`].type === `${e}Color` && t.schema.styleSchema[`${e}Color`].propSchema === "string"; } var hn = () => { let e = s(), t = f(), n = c(), r = mn("text", n), i = mn("background", n), a = l({ editor: n, selector: ({ editor: e }) => { if (!e.isEditable || !(e.getSelection()?.blocks || [e.getTextCursorPosition().block]).find((e) => e.content !== void 0)) return; let t = mn("text", e), n = mn("background", e); if (!(!t && !n)) return { textColor: t ? e.getActiveStyles().textColor || "default" : void 0, backgroundColor: n ? e.getActiveStyles().backgroundColor || "default" : void 0 }; } }), o = S((e) => { if (!r) throw Error("Tried to set text color, but style does not exist in editor schema."); e === "default" ? n.removeStyles({ textColor: e }) : n.addStyles({ textColor: e }), setTimeout(() => { n.focus(); }); }, [n, r]), u = S((e) => { if (!i) throw Error("Tried to set background color, but style does not exist in editor schema."); e === "default" ? n.removeStyles({ backgroundColor: e }) : n.addStyles({ backgroundColor: e }), setTimeout(() => { n.focus(); }); }, [i, n]); return a === void 0 ? null : /* @__PURE__ */ q(e.Generic.Menu.Root, { children: [/* @__PURE__ */ K(e.Generic.Menu.Trigger, { children: /* @__PURE__ */ K(e.FormattingToolbar.Button, { className: "bn-button", "data-test": "colors", label: t.formatting_toolbar.colors.tooltip, mainTooltip: t.formatting_toolbar.colors.tooltip, icon: /* @__PURE__ */ K(dn, { textColor: a.textColor, backgroundColor: a.backgroundColor, size: 20 }) }) }), /* @__PURE__ */ K(e.Generic.Menu.Dropdown, { className: "bn-menu-dropdown bn-color-picker-dropdown", children: /* @__PURE__ */ K(pn, { text: a.textColor ? { color: a.textColor, setColor: o } : void 0, background: a.backgroundColor ? { color: a.backgroundColor, setColor: u } : void 0 }) })] }); }, gn = (e) => { for (let t of de) if (e.startsWith(t)) return e; return `${le}://${e}`; }, _n = (e) => { let t = s(), n = f(), { editLink: i } = r(j), { url: a, text: o, showTextField: c } = e, [l, u] = D(a), [d, p] = D(o); C(() => { u(a), p(o); }, [o, a]); let m = S((t) => { t.key === "Enter" && !t.nativeEvent.isComposing && (t.preventDefault(), i(gn(l), d, e.range.from), e.setToolbarOpen?.(!1), e.setToolbarPositionFrozen?.(!1)); }, [ i, l, d, e ]), h = S((e) => u(e.currentTarget.value), []), g = S((e) => p(e.currentTarget.value), []), _ = S(() => { i(gn(l), d, e.range.from), e.setToolbarOpen?.(!1), e.setToolbarPositionFrozen?.(!1); }, [ i, l, d, e ]); return /* @__PURE__ */ q(t.Generic.Form.Root, { children: [/* @__PURE__ */ K(t.Generic.Form.TextInput, { className: "bn-text-input", name: "url", icon: /* @__PURE__ */ K(Ot, {}), autoFocus: !0, placeholder: n.link_toolbar.form.url_placeholder, value: l, onKeyDown: m, onChange: h, onSubmit: _ }), c !== !1 && /* @__PURE__ */ K(t.Generic.Form.TextInput, { className: "bn-text-input", name: "title", icon: /* @__PURE__ */ K(Bt, {}), placeholder: n.link_toolbar.form.title_placeholder, value: d, onKeyDown: m, onChange: g, onSubmit: _ })] }); }; //#endregion //#region src/components/FormattingToolbar/DefaultButtons/CreateLinkButton.tsx function vn(e) { return "link" in e.schema.inlineContentSchema && e.schema.inlineContentSchema.link === "link"; } var yn = () => { let t = c(), n = e(), i = s(), a = f(), o = r(A), { showSelection: u } = r(ue), [d, p] = D(!1); C(() => (u(d, "createLinkButton"), () => u(!1, "createLinkButton")), [d, u]); let m = l({ editor: t, selector: ({ editor: e }) => { if (!(!e.isEditable || !vn(e) || qe(e.prosemirrorState.selection) || !(e.getSelection()?.blocks || [e.getTextCursorPosition().block]).find((e) => e.content !== void 0))) return { url: e.getSelectedLinkUrl(), text: e.getSelectedText(), range: { from: e.prosemirrorState.selection.from, to: e.prosemirrorState.selection.to } }; } }); return C(() => { p(!1); }, [m]), C(() => { let e = (e) => { (e.ctrlKey || e.metaKey) && e.key === "k" && (p(!0), e.preventDefault()); }; return n?.addEventListener("keydown", e), () => { n?.removeEventListener("keydown", e); }; }, [n]), m === void 0 ? null : /* @__PURE__ */ q(i.Generic.Popover.Root, { open: d, onOpenChange: p, children: [/* @__PURE__ */ K(i.Generic.Popover.Trigger, { children: /* @__PURE__ */ K(i.FormattingToolbar.Button, { className: "bn-button", "data-test": "createLink", label: a.formatting_toolbar.link.tooltip, mainTooltip: a.formatting_toolbar.link.tooltip, secondaryTooltip: V(a.formatting_toolbar.link.secondary_tooltip, a.generic.ctrl_shortcut), icon: /* @__PURE__ */ K(Ot, {}), onClick: () => p((e) => !e) }) }), /* @__PURE__ */ K(i.Generic.Popover.Content, { className: "bn-popover-content bn-form-popover", variant: "form-popover", children: /* @__PURE__ */ K(_n, { url: m.url || "", text: m.text, range: m.range, showTextField: !1, setToolbarOpen: (e) => o.store.setState(e) }) })] }); }, bn = () => { let e = f(), t = s(), n = c(), r = l({ editor: n, selector: ({ editor: e }) => { if (!e.isEditable) return; let t = e.getSelection()?.blocks || [e.getTextCursorPosition().block]; if (t.length !== 1) return; let n = t[0]; if (L(n, e, n.type, { url: "string", caption: "string" })) return n; } }), [i, a] = D(!1), o = S((e) => { r !== void 0 && B(n, r.type, { caption: "string" }) && n.updateBlock(r.id, { props: { caption: e.currentTarget.value } }); }, [r, n]), u = S((e) => { e.key === "Enter" && !e.nativeEvent.isComposing && (e.preventDefault(), a(!1)); }, []); return r === void 0 ? null : /* @__PURE__ */ q(t.Generic.Popover.Root, { open: i, onOpenChange: a, children: [/* @__PURE__ */ K(t.Generic.Popover.Trigger, { children: /* @__PURE__ */ K(t.FormattingToolbar.Button, { className: "bn-button", label: e.formatting_toolbar.file_caption.tooltip, mainTooltip: e.formatting_toolbar.file_caption.tooltip, icon: /* @__PURE__ */ K(Et, {}), onClick: () => a((e) => !e) }) }), /* @__PURE__ */ K(t.Generic.Popover.Content, { className: "bn-popover-content bn-form-popover", variant: "form-popover", children: /* @__PURE__ */ K(t.Generic.Form.Root, { children: /* @__PURE__ */ K(t.Generic.Form.TextInput, { name: "file-caption", icon: /* @__PURE__ */ K(Et, {}), value: r.props.caption, autoFocus: !0, placeholder: e.formatting_toolbar.file_caption.input_placeholder, onKeyDown: u, onChange: o }) }) })] }); }, xn = () => { let e = f(), t = s(), n = c(), r = l({ editor: n, selector: ({ editor: e }) => { if (!e.isEditable) return; let t = e.getSelection()?.blocks || [e.getTextCursorPosition().block]; if (t.length !== 1) return; let n = t[0]; if (L(n, e, n.type, { url: "string" })) return n; } }), i = S(() => { r !== void 0 && (n.focus(), n.removeBlocks([r.id])); }, [r, n]); return r === void 0 ? null : /* @__PURE__ */ K(t.FormattingToolbar.Button, { className: "bn-button", label: e.formatting_toolbar.file_delete.tooltip[r.type] || e.formatting_toolbar.file_delete.tooltip.file, mainTooltip: e.formatting_toolbar.file_delete.tooltip[r.type] || e.formatting_toolbar.file_delete.tooltip.file, icon: /* @__PURE__ */ K(ct, {}), onClick: i }); }, Sn = () => { let e = f(), t = s(), n = c(), r = l({ editor: n, selector: ({ editor: e }) => { if (!e.isEditable) return; let t = e.getSelection()?.blocks || [e.getTextCursorPosition().block]; if (t.length !== 1) return; let n = t[0]; if (L(n, e, n.type, { url: "string", name: "string" })) return n; } }), [i, a] = D(!1), o = S((e) => { r !== void 0 && B(n, r.type, { name: "string" }) && n.updateBlock(r.id, { props: { name: e.currentTarget.value } }); }, [r, n]), u = S((e) => { e.key === "Enter" && !e.nativeEvent.isComposing && (e.preventDefault(), a(!1)); }, []); return r === void 0 ? null : /* @__PURE__ */ q(t.Generic.Popover.Root, { open: i, onOpenChange: a, children: [/* @__PURE__ */ K(t.Generic.Popover.Trigger, { children: /* @__PURE__ */ K(t.FormattingToolbar.Button, { className: "bn-button", label: e.formatting_toolbar.file_rename.tooltip[r.type] || e.formatting_toolbar.file_rename.tooltip.file, mainTooltip: e.formatting_toolbar.file_rename.tooltip[r.type] || e.formatting_toolbar.file_rename.tooltip.file, icon: /* @__PURE__ */ K(mt, {}), onClick: () => a((e) => !e) }) }), /* @__PURE__ */ K(t.Generic.Popover.Content, { className: "bn-popover-content bn-form-popover", variant: "form-popover", children: /* @__PURE__ */ K(t.Generic.Form.Root, { children: /* @__PURE__ */ K(t.Generic.Form.TextInput, { name: "file-name", icon: /* @__PURE__ */ K(mt, {}), value: r.props.name, autoFocus: !0, placeholder: e.formatting_toolbar.file_rename.input_placeholder[r.type] || e.formatting_toolbar.file_rename.input_placeholder.file, onKeyDown: u, onChange: o }) }) })] }); }, Cn = () => { let e = f(), t = s(), n = l({ editor: c(), selector: ({ editor: e }) => { if (!e.isEditable) return; let t = e.getSelection()?.blocks || [e.getTextCursorPosition().block]; if (t.length !== 1) return; let n = t[0]; if (L(n, e, n.type, { url: "string" })) return n; } }); return n === void 0 ? null : /* @__PURE__ */ q(t.Generic.Popover.Root, { position: "bottom", children: [/* @__PURE__ */ K(t.Generic.Popover.Trigger, { children: /* @__PURE__ */ K(t.FormattingToolbar.Button, { className: "bn-button", mainTooltip: e.formatting_toolbar.file_replace.tooltip[n.type] || e.formatting_toolbar.file_replace.tooltip.file, label: e.formatting_toolbar.file_replace.tooltip[n.type] || e.formatting_toolbar.file_replace.tooltip.file, icon: /* @__PURE__ */ K(Ct, {}) }) }), /* @__PURE__ */ K(t.Generic.Popover.Content, { className: "bn-popover-content bn-panel-popover", variant: "panel-popover", children: /* @__PURE__ */ K(sn, { blockId: n.id }) })] }); }, wn = () => { let e = f(), t = s(), n = c(), r = l({ editor: n, selector: ({ editor: e }) => { if (!(!e.isEditable || !(e.getSelection()?.blocks || [e.getTextCursorPosition().block]).find((e) => e.content !== void 0))) return { canNestBlock: e.canNestBlock() }; } }), i = S(() => { r !== void 0 && r.canNestBlock && (n.focus(), n.nestBlock()); }, [n, r]); return r === void 0 ? null : /* @__PURE__ */ K(t.FormattingToolbar.Button, { className: "bn-button", "data-test": "nestBlock", onClick: i, isDisabled: !r.canNestBlock, label: e.formatting_toolbar.nest.tooltip, mainTooltip: e.formatting_toolbar.nest.tooltip, secondaryTooltip: V(e.formatting_toolbar.nest.secondary_tooltip, e.generic.ctrl_shortcut), icon: /* @__PURE__ */ K(Tt, {}) }); }, Tn = () => { let e = f(), t = s(), n = c(), r = l({ editor: n, selector: ({ editor: e }) => { if (!(!e.isEditable || !(e.getSelection()?.blocks || [e.getTextCursorPosition().block]).find((e) => e.content !== void 0))) return { canUnnestBlock: e.canUnnestBlock() }; } }), i = S(() => { r !== void 0 && r.canUnnestBlock && (n.focus(), n.unnestBlock()); }, [n, r]); return r === void 0 ? null : /* @__PURE__ */ K(t.FormattingToolbar.Button, { className: "bn-button", "data-test": "unnestBlock", onClick: i, isDisabled: !r.canUnnestBlock, label: e.formatting_toolbar.unnest.tooltip, mainTooltip: e.formatting_toolbar.unnest.tooltip, secondaryTooltip: V(e.formatting_toolbar.unnest.secondary_tooltip, e.generic.ctrl_shortcut), icon: /* @__PURE__ */ K(wt, {}) }); }, En = (e) => [ { name: e.slash_menu.paragraph.title, type: "paragraph", icon: Bt }, { name: e.slash_menu.heading.title, type: "heading", props: { level: 1, isToggleable: !1 }, icon: ht }, { name: e.slash_menu.heading_2.title, type: "heading", props: { level: 2, isToggleable: !1 }, icon: gt }, { name: e.slash_menu.heading_3.title, type: "heading", props: { level: 3, isToggleable: !1 }, icon: _t }, { name: e.slash_menu.heading_4.title, type: "heading", props: { level: 4, isToggleable: !1 }, icon: vt }, { name: e.slash_menu.heading_5.title, type: "heading", props: { level: 5, isToggleable: !1 }, icon: yt }, { name: e.slash_menu.heading_6.title, type: "heading", props: { level: 6, isToggleable: !1 }, icon: bt }, { name: e.slash_menu.toggle_heading.title, type: "heading", props: { level: 1, isToggleable: !0 }, icon: ht }, { name: e.slash_menu.toggle_heading_2.title, type: "heading", props: { level: 2, isToggleable: !0 }, icon: gt }, { name: e.slash_menu.toggle_heading_3.title, type: "heading", props: { level: 3, isToggleable: !0 }, icon: _t }, { name: e.slash_menu.quote.title, type: "quote", icon: It }, { name: e.slash_menu.toggle_list.title, type: "toggleListItem", icon: Ft }, { name: e.slash_menu.bullet_list.title, type: "bulletListItem", icon: Mt }, { name: e.slash_menu.numbered_list.title, type: "numberedListItem", icon: jt }, { name: e.slash_menu.check_list.title, type: "checkListItem", icon: At } ], Dn = (e) => { let t = s(), n = c(), r = l({ editor: n, selector: ({ editor: e }) => e.getSelection()?.blocks || [e.getTextCursorPosition().block] }), i = r[0], a = w(() => (e.items || En(n.dictionary)).filter((e) => B(n, e.type, Object.fromEntries(Object.entries(e.props || {}).map(([e, t]) => [e, typeof t])))), [n, e.items]), o = w(() => a.map((e) => { let t = e.icon, a = e.type === i.type, o = Object.entries(e.props || {}).filter(([e, t]) => t !== i.props[e]).length === 0; return { text: e.name, icon: /* @__PURE__ */ K(t, { size: 16 }), onClick: () => { n.focus(), n.transact(() => { for (let t of r) n.updateBlock(t, { type: e.type, props: e.props }); }); }, isSelected: a && o }; }), [ n, a, i.props, i.type, r ]); return !w(() => o.find((e) => e.isSelected) !== void 0, [o]) || !n.isEditable ? null : /* @__PURE__ */ K(t.FormattingToolbar.Select, { className: "bn-select", items: o }); }, On = () => { let e = f(), t = s(), n = r("comments"), { store: i } = r(A), a = S(() => { n.startPendingComment(), i.setState(!1); }, [n, i]); return /* @__PURE__ */ K(t.FormattingToolbar.Button, { className: "bn-button", label: e.formatting_toolbar.comment.tooltip, mainTooltip: e.formatting_toolbar.comment.tooltip, icon: /* @__PURE__ */ K(at, {}), onClick: a }); }, kn = () => c().getExtension("comments") ? /* @__PURE__ */ K(On, {}) : null, An = () => { let e = f(), t = s(), n = c(), r = S(() => { n._tiptapEditor.chain().focus().addPendingComment().run(); }, [n]); return !n._tiptapEditor.commands.addPendingComment || !n.isEditable ? null : /* @__PURE__ */ K(t.FormattingToolbar.Button, { className: "bn-button", label: e.formatting_toolbar.comment.tooltip, mainTooltip: e.formatting_toolbar.comment.tooltip, icon: /* @__PURE__ */ K(at, {}), onClick: r }); }; //#endregion //#region src/util/sanitizeUrl.ts function jn(e, t) { try { let n = new URL(e, t); if (n.protocol !== "javascript:") return n.href; } catch {} return "#"; } //#endregion //#region src/components/FormattingToolbar/DefaultButtons/FileDownloadButton.tsx var Mn = () => { let e = f(), t = s(), n = c(), r = l({ editor: n, selector: ({ editor: e }) => { let t = e.getSelection()?.blocks || [e.getTextCursorPosition().block]; if (t.length !== 1) return; let n = t[0]; if (L(n, e, n.type, { url: "string" })) return n; } }), i = S(() => { r !== void 0 && (n.focus(), n.resolveFileUrl ? n.resolveFileUrl(r.props.url).then((e) => window.open(jn(e, window.location.href))) : window.open(jn(r.props.url, window.location.href))); }, [r, n]); return r === void 0 ? null : /* @__PURE__ */ K(t.FormattingToolbar.Button, { className: "bn-button", label: e.formatting_toolbar.file_download.tooltip[r.type] || e.formatting_toolbar.file_download.tooltip.file, mainTooltip: e.formatting_toolbar.file_download.tooltip[r.type] || e.formatting_toolbar.file_download.tooltip.file, icon: /* @__PURE__ */ K(lt, {}), onClick: i }); }, Nn = () => { let e = f(), t = s(), n = c(), r = l({ editor: n, selector: ({ editor: e }) => { if (!e.isEditable) return; let t = e.getSelection()?.blocks || [e.getTextCursorPosition().block]; if (t.length !== 1) return; let n = t[0]; if (L(n, e, n.type, { url: "string", showPreview: "boolean" })) return n; } }), i = S(() => { r !== void 0 && B(n, r.type, { showPreview: "boolean" }) && n.updateBlock(r.id, { props: { showPreview: !r.props.showPreview } }); }, [r, n]); return r === void 0 ? null : /* @__PURE__ */ K(t.FormattingToolbar.Button, { className: "bn-button", label: "Toggle preview", mainTooltip: e.formatting_toolbar.file_preview_toggle.tooltip, icon: /* @__PURE__ */ K(St, {}), isSelected: r.props.showPreview, onClick: i }); }, Pn = () => { let e = f(), t = s(), n = c(), i = r(P), a = l({ editor: n, selector: ({ editor: e }) => { if (!e.isEditable || !e.settings.tables.splitCells) return; let t = e.getSelection()?.blocks || [e.getTextCursorPosition().block]; if (t.length !== 1) return; let n = t[0]; if (n.type === "table") return { mergeDirection: i.getMergeDirection(n) }; } }), o = S(() => { i?.mergeCells(); }, [i]); return a === void 0 ? null : /* @__PURE__ */ K(t.FormattingToolbar.Button, { className: "bn-button", label: e.formatting_toolbar.table_cell_merge.tooltip, mainTooltip: e.formatting_toolbar.table_cell_merge.tooltip, icon: a.mergeDirection === "horizontal" ? /* @__PURE__ */ K(Nt, {}) : /* @__PURE__ */ K(Pt, {}), onClick: o }); }, Fn = () => c().getExtension(P) ? /* @__PURE__ */ K(Pn, {}) : null, In = { left: nt, center: et, right: rt, justify: tt }, Ln = (e) => { let t = s(), n = f(), r = c(), i = l({ editor: r, selector: ({ editor: e }) => { if (!e.isEditable) return; let t = e.getSelection()?.blocks || [e.getTextCursorPosition().block], n = t[0]; if (L(n, e, n.type, { textAlignment: R.textAlignment })) return { textAlignment: n.props.textAlignment, blocks: t }; if (t.length === 1 && L(n, e, "table")) return e.getExtension(P)?.getCellSelection() ? { textAlignment: U(n.content.rows[0].cells[0]).props.textAlignment, blocks: [n] } : void 0; } }), a = S((e) => { if (i !== void 0) { r.focus(); for (let t of i.blocks) if (L(t, r, t.type, { textAlignment: R.textAlignment }) && B(r, t.type, { textAlignment: R.textAlignment })) r.updateBlock(t, { props: { textAlignment: e } }); else if (t.type === "table") { let n = r.getExtension(P)?.getCellSelection(); if (!n) continue; let i = t.content.rows.map((e) => ({ ...e, cells: e.cells.map((e) => U(e)) })); n.cells.forEach(({ row: t, col: n }) => { i[t].cells[n].props.textAlignment = e; }), r.updateBlock(t, { type: "table", content: { ...t.content, type: "tableContent", rows: i } }), r.setTextCursorPosition(t); } } }, [r, i]); if (i === void 0) return null; let o = In[e.textAlignment]; return /* @__PURE__ */ K(t.FormattingToolbar.Button, { className: "bn-button", "data-test": `alignText${e.textAlignment.slice(0, 1).toUpperCase() + e.textAlignment.slice(1)}`, onClick: () => a(e.textAlignment), isSelected: i.textAlignment === e.textAlignment, label: n.formatting_toolbar[`align_${e.textAlignment}`].tooltip, mainTooltip: n.formatting_toolbar[`align_${e.textAlignment}`].tooltip, icon: /* @__PURE__ */ K(o, {}) }); }, Rn = (e) => [ /* @__PURE__ */ K(Dn, { items: e }, "blockTypeSelect"), /* @__PURE__ */ K(Fn, {}, "tableCellMergeButton"), /* @__PURE__ */ K(bn, {}, "fileCaptionButton"), /* @__PURE__ */ K(Cn, {}, "replaceFileButton"), /* @__PURE__ */ K(Sn, {}, "fileRenameButton"), /* @__PURE__ */ K(xn, {}, "fileDeleteButton"), /* @__PURE__ */ K(Mn, {}, "fileDownloadButton"), /* @__PURE__ */ K(Nn, {}, "filePreviewButton"), /* @__PURE__ */ K(J, { basicTextStyle: "bold" }, "boldStyleButton"), /* @__PURE__ */ K(J, { basicTextStyle: "italic" }, "italicStyleButton"), /* @__PURE__ */ K(J, { basicTextStyle: "underline" }, "underlineStyleButton"), /* @__PURE__ */ K(J, { basicTextStyle: "strike" }, "strikeStyleButton"), /* @__PURE__ */ K(Ln, { textAlignment: "left" }, "textAlignLeftButton"), /* @__PURE__ */ K(Ln, { textAlignment: "center" }, "textAlignCenterButton"), /* @__PURE__ */ K(Ln, { textAlignment: "right" }, "textAlignRightButton"), /* @__PURE__ */ K(hn, {}, "colorStyleButton"), /* @__PURE__ */ K(wn, {}, "nestBlockButton"), /* @__PURE__ */ K(Tn, {}, "unnestBlockButton"), /* @__PURE__ */ K(yn, {}, "createLinkButton"), /* @__PURE__ */ K(kn, {}, "addCommentButton"), /* @__PURE__ */ K(An, {}, "addTiptapCommentButton") ], zn = (e) => /* @__PURE__ */ K(s().FormattingToolbar.Root, { className: "bn-toolbar bn-formatting-toolbar", children: e.children || Rn(e.blockTypeSelectItems) }), Bn = (e) => { switch (e) { case "left": return "top-start"; case "center": return "top"; case "right": return "top-end"; default: return "top-start"; } }, Vn = (e) => { let t = c(), n = r(A, { editor: t }), i = u(A, { editor: t }), a = l({ editor: t, selector: ({ editor: e }) => n.store.state ? { from: e.prosemirrorState.selection.from, to: e.prosemirrorState.selection.to } : void 0 }), s = l({ editor: t, selector: ({ editor: e }) => { let t = e.getTextCursorPosition().block; return L(t, e, t.type, { textAlignment: R.textAlignment }) ? Bn(t.props.textAlignment) : "top-start"; } }), d = w(() => ({ ...e.floatingUIOptions, useFloatingOptions: { open: i, onOpenChange: (e, r, i) => { n.store.setState(e), i === "escape-key" && t.focus(); }, placement: s, middleware: [ F(10), ye(), _e() ], ...e.floatingUIOptions?.useFloatingOptions }, focusManagerProps: { disabled: !0, ...e.floatingUIOptions?.focusManagerProps }, elementProps: { style: { zIndex: 40 }, ...e.floatingUIOptions?.elementProps } }), [ i, s, e.floatingUIOptions, n.store, t ]), f = e.formattingToolbar || zn; return /* @__PURE__ */ K(o, { position: a, portalElement: e.portalElement, ...d, children: i && /* @__PURE__ */ K(f, {}) }); }, Hn = (e) => { let t = s(), n = f(), { deleteLink: i } = r(j); return /* @__PURE__ */ K(t.LinkToolbar.Button, { className: "bn-button", label: n.link_toolbar.delete.tooltip, mainTooltip: n.link_toolbar.delete.tooltip, isSelected: !1, onClick: () => { i(e.range.from), e.setToolbarOpen?.(!1); }, icon: /* @__PURE__ */ K(kt, {}) }); }, Un = (e) => { let t = s(), n = f(); return /* @__PURE__ */ q(t.Generic.Popover.Root, { onOpenChange: e.setToolbarPositionFrozen, children: [/* @__PURE__ */ K(t.Generic.Popover.Trigger, { children: /* @__PURE__ */ K(t.LinkToolbar.Button, { className: "bn-button", mainTooltip: n.link_toolbar.edit.tooltip, isSelected: !1, children: n.link_toolbar.edit.text }) }), /* @__PURE__ */ K(t.Generic.Popover.Content, { className: "bn-popover-content bn-form-popover", variant: "form-popover", children: /* @__PURE__ */ K(_n, { url: e.url, text: e.text, range: e.range, setToolbarOpen: e.setToolbarOpen, setToolbarPositionFrozen: e.setToolbarPositionFrozen }) })] }); }, Wn = (e) => { let t = s(), n = f(); return /* @__PURE__ */ K(t.LinkToolbar.Button, { className: "bn-button", mainTooltip: n.link_toolbar.open.tooltip, label: n.link_toolbar.open.tooltip, isSelected: !1, onClick: () => { window.open(jn(e.url, window.location.href), "_blank"); }, icon: /* @__PURE__ */ K(dt, {}) }); }, Gn = (e) => /* @__PURE__ */ K(s().LinkToolbar.Root, { className: "bn-toolbar bn-link-toolbar", children: e.children || /* @__PURE__ */ q(G, { children: [ /* @__PURE__ */ K(Un, { url: e.url, text: e.text, range: e.range, setToolbarOpen: e.setToolbarOpen, setToolbarPositionFrozen: e.setToolbarPositionFrozen }), /* @__PURE__ */ K(Wn, { url: e.url }), /* @__PURE__ */ K(Hn, { range: e.range, setToolbarOpen: e.setToolbarOpen }) ] }) }), Kn = (t) => { let n = c(), [i, a] = D(!1), [o, s] = D(!1), l = e(), u = r(j), [d, f] = D(void 0); C(() => { let e = () => { let e = u.getLinkAtSelection(); if (!e) { f(void 0), o || a(!1); return; } f({ cursorType: "text", url: e.mark.attrs.href, text: e.text, range: e.range, element: u.getLinkElementAtPos(e.range.from) }), o || a(!0); }, t = (e) => { if (d !== void 0 && d.cursorType === "text" || !(e.target instanceof HTMLElement)) return; let t = u.getLinkAtElement(e.target); t && f({ cursorType: "mouse", url: t.mark.attrs.href, text: t.text, range: t.range, element: u.getLinkElementAtPos(t.range.from) }); }, r = n.onChange(e), i = n.onSelectionChange(e); return l?.addEventListener("mouseover", t), () => { r(), i(), l?.removeEventListener("mouseover", t); }; }, [ n, l, u, d, o ]); let m = w(() => ({ ...t.floatingUIOptions, useFloatingOptions: { open: i, onOpenChange: (e, t, r) => { o || d !== void 0 && d.cursorType === "text" && r === "hover" || (r === "escape-key" && n.focus(), a(e)); }, placement: "top-start", middleware: [F(10), _e()], ...t.floatingUIOptions?.useFloatingOptions }, useHoverProps: { enabled: d !== void 0 && d.cursorType === "mouse", delay: { open: 250, close: 250 }, handleClose: ve(), ...t.floatingUIOptions?.useHoverProps }, focusManagerProps: { disabled: !0, ...t.floatingUIOptions?.focusManagerProps }, elementProps: { style: { zIndex: 50 }, ...t.floatingUIOptions?.elementProps } }), [ n, d, t.floatingUIOptions, i, o ]), h = w(() => d?.element ? { element: d.element } : void 0, [d?.element]); if (!n.isEditable) return null; let g = t.linkToolbar || Gn; return /* @__PURE__ */ K(p, { reference: h, portalElement: t.portalElement, ...m, children: d && /* @__PURE__ */ K(g, { url: d.url, text: d.text, range: d.range, setToolbarOpen: a, setToolbarPositionFrozen: s }) }); }, qn = () => { let e = s(), t = f(), n = c(), i = r(N), a = u(M, { editor: n, selector: (e) => e?.block }), o = S(() => { if (a === void 0) return; let e = a.content; if (e !== void 0 && Array.isArray(e) && e.length === 0) n.setTextCursorPosition(a), i.openSuggestionMenu("/"); else { let e = n.insertBlocks([{ type: "paragraph" }], a, "after")[0]; n.setTextCursorPosition(e), i.openSuggestionMenu("/"); } }, [ a, n, i ]); return a === void 0 ? null : /* @__PURE__ */ K(e.SideMenu.Button, { className: "bn-button", label: t.side_menu.add_block_label, icon: /* @__PURE__ */ K(Wt, { size: 24, onClick: o, "data-test": "dragHandleAdd" }) }); }, Jn = (e) => { let t = s(), n = c(), r = u(M, { editor: n, selector: (e) => e?.block }); return r === void 0 || !L(r, n, r.type, { textColor: "string" }) && !L(r, n, r.type, { backgroundColor: "string" }) ? null : /* @__PURE__ */ q(t.Generic.Menu.Root, { position: "right", sub: !0, children: [/* @__PURE__ */ K(t.Generic.Menu.Trigger, { sub: !0, children: /* @__PURE__ */ K(t.Generic.Menu.Item, { className: "bn-menu-item", subTrigger: !0, children: e.children }) }), /* @__PURE__ */ K(t.Generic.Menu.Dropdown, { sub: !0, className: "bn-menu-dropdown bn-color-picker-dropdown", children: /* @__PURE__ */ K(pn, { iconSize: 18, text: L(r, n, r.type, { textColor: "string" }) && B(n, r.type, { textColor: "string" }) ? { color: r.props.textColor, setColor: (e) => n.updateBlock(r, { type: r.type, props: { textColor: e } }) } : void 0, background: L(r, n, r.type, { backgroundColor: "string" }) && B(n, r.type, { backgroundColor: "string" }) ? { color: r.props.backgroundColor, setColor: (e) => n.updateBlock(r, { props: { backgroundColor: e } }) } : void 0 }) })] }); }, Yn = (e) => { let t = s(), n = c(), r = u(M, { editor: n, selector: (e) => e?.block }); return r === void 0 ? null : /* @__PURE__ */ K(t.Generic.Menu.Item, { className: "bn-menu-item", onClick: () => { let e = n.getSelection()?.blocks, t = e && e.some((e) => e.id === r.id) ? e : [r]; n.removeBlocks(t); }, children: e.children }); }, Xn = (e) => { let t = s(), n = c(), r = u(M, { editor: n, selector: (e) => e?.block }); if (r === void 0 || r.type !== "table" || !n.settings.tables.headers) return null; let i = !!r.content.headerRows; return /* @__PURE__ */ K(t.Generic.Menu.Item, { className: "bn-menu-item", checked: i, onClick: () => { n.updateBlock(r, { content: { ...r.content, headerRows: i ? void 0 : 1 } }); }, children: e.children }); }, Zn = (e) => { let t = s(), n = c(), r = u(M, { editor: n, selector: (e) => e?.block }); if (r === void 0 || r.type !== "table" || !n.settings.tables.headers) return null; let i = !!r.content.headerCols; return /* @__PURE__ */ K(t.Generic.Menu.Item, { className: "bn-menu-item", checked: i, onClick: () => { n.updateBlock(r, { content: { ...r.content, headerCols: i ? void 0 : 1 } }); }, children: e.children }); }, Qn = (e) => { let t = s(), n = f(); return /* @__PURE__ */ K(t.Generic.Menu.Dropdown, { className: "bn-menu-dropdown bn-drag-handle-menu", children: e.children || /* @__PURE__ */ q(G, { children: [ /* @__PURE__ */ K(Yn, { children: n.drag_handle.delete_menuitem }), /* @__PURE__ */ K(Jn, { children: n.drag_handle.colors_menuitem }), /* @__PURE__ */ K(Xn, { children: n.drag_handle.header_row_menuitem }), /* @__PURE__ */ K(Zn, { children: n.drag_handle.header_column_menuitem }) ] }) }); }, $n = (e) => { let t = s(), n = f(), i = r(M), a = u(M, { selector: (e) => e?.block }); if (a === void 0) return null; let o = e.dragHandleMenu || Qn; return /* @__PURE__ */ q(t.Generic.Menu.Root, { onOpenChange: (e) => { e ? i.freezeMenu() : i.unfreezeMenu(); }, position: "left", children: [/* @__PURE__ */ K(t.Generic.Menu.Trigger, { children: /* @__PURE__ */ K(t.SideMenu.Button, { label: n.side_menu.drag_handle_label, draggable: !0, onDragStart: (e) => i.blockDragStart(e, a), onDragEnd: i.blockDragEnd, className: "bn-button", icon: /* @__PURE__ */ K(Kt, { size: 24, "data-test": "dragHandle" }) }) }), /* @__PURE__ */ K(o, { children: e.children })] }); }, er = (e) => { let t = s(), n = c(), r = u(M, { editor: n, selector: (e) => e?.block }), i = w(() => { if (r === void 0) return {}; let e = { "data-block-type": r.type }; return r.type === "heading" && (e["data-level"] = r.props.level.toString()), n.schema.blockSpecs[r.type].implementation.meta?.fileBlockAccept && (r.props.url ? e["data-url"] = "true" : e["data-url"] = "false"), e; }, [r, n.schema.blockSpecs]); return /* @__PURE__ */ K(t.SideMenu.Root, { className: "bn-side-menu", ...i, children: e.children || /* @__PURE__ */ q(G, { children: [/* @__PURE__ */ K(qn, {}), /* @__PURE__ */ K($n, { dragHandleMenu: e.dragHandleMenu })] }) }); }, tr = (e) => { let t = c(), { show: n, block: r } = u(M, { selector: (e) => e === void 0 ? void 0 : { show: e.show, block: e.block } }) || {}, i = S((e, n, r) => { let i = !1; return ge(e, n, () => { if (!i) { i = !0; return; } t.getExtension(M)?.hideMenuIfNotFrozen(); }, { ancestorScroll: !0, ancestorResize: !1, elementResize: !1, layoutShift: !1 }); }, [t]), a = w(() => ({ ...e.floatingUIOptions, useFloatingOptions: { open: n, placement: "left-start", whileElementsMounted: i, ...e.floatingUIOptions?.useFloatingOptions }, useDismissProps: { enabled: !1, ...e.floatingUIOptions?.useDismissProps }, focusManagerProps: { disabled: !0, ...e.floatingUIOptions?.focusManagerProps }, elementProps: { style: { zIndex: 20 }, ...e.floatingUIOptions?.elementProps } }), [ e.floatingUIOptions, n, i ]), o = e.sideMenu || er; return /* @__PURE__ */ K(rn, { blockId: n ? r?.id : void 0, portalElement: e.portalElement, ...a, children: r?.id && /* @__PURE__ */ K(o, {}) }); }; //#endregion //#region src/components/SuggestionMenu/GridSuggestionMenu/getDefaultReactEmojiPickerItems.tsx async function nr(e, t) { return (await pe(e, t)).map(({ id: e, onItemClick: t }) => ({ id: e, onItemClick: t, icon: e })); } //#endregion //#region src/components/SuggestionMenu/GridSuggestionMenu/GridSuggestionMenu.tsx function rr(e) { let t = s(), n = f(), { items: r, loadingState: i, selectedIndex: a, onItemClick: o, columns: c } = e, l = i === "loading-initial" || i === "loading" ? /* @__PURE__ */ K(t.GridSuggestionMenu.Loader, { className: "bn-grid-suggestion-menu-loader", columns: c }) : null, u = w(() => { let e = []; for (let n = 0; n < r.length; n++) { let i = r[n]; e.push(/* @__PURE__ */ K(t.GridSuggestionMenu.Item, { className: "bn-grid-suggestion-menu-item", item: i, id: `bn-grid-suggestion-menu-item-${n}`, isSelected: n === a, onClick: () => o?.(i) }, i.id)); } return e; }, [ t, r, o, a ]); return /* @__PURE__ */ q(t.GridSuggestionMenu.Root, { id: "bn-grid-suggestion-menu", columns: c, className: "bn-grid-suggestion-menu", children: [ l, u, u.length === 0 && e.loadingState === "loaded" && /* @__PURE__ */ K(t.GridSuggestionMenu.EmptyItem, { className: "bn-grid-suggestion-menu-empty-item", columns: c, children: n.suggestion_menu.no_items_title }) ] }); } //#endregion //#region src/components/SuggestionMenu/hooks/useCloseSuggestionMenuNoItems.ts function ir(e, t, n, r = 3) { let i = E(0); C(() => { t !== void 0 && (e.length > 0 ? i.current = t.length : t.length - i.current > r && n()); }, [ n, r, e.length, t ]); } //#endregion //#region src/components/SuggestionMenu/hooks/useLoadSuggestionMenuItems.ts function ar(e, t) { let [n, r] = D([]), [i, a] = D(!1), o = E(void 0), s = E(void 0); return C(() => { let n = e; o.current = e, a(!0), t(e).then((e) => { o.current === n && (r(e), a(!1), s.current = n); }); }, [e, t]), { items: n || [], usedQuery: s.current, loadingState: s.current === void 0 ? "loading-initial" : i ? "loading" : "loaded" }; } //#endregion //#region src/components/SuggestionMenu/GridSuggestionMenu/hooks/useGridSuggestionMenuKeyboardNavigation.ts function or(t, n, r, i, a) { let o = e(t), [s, c] = D(0); return C(() => { let e = (e) => (e.key === "ArrowLeft" && (e.preventDefault(), r.length && c((s - 1 + r.length) % r.length)), e.key === "ArrowRight" && (e.preventDefault(), r.length && c((s + 1 + r.length) % r.length)), e.key === "ArrowUp" ? (e.preventDefault(), r.length && c((s - i + r.length) % r.length), !0) : e.key === "ArrowDown" ? (e.preventDefault(), r.length && c((s + i) % r.length), !0) : e.key === "Enter" && !e.isComposing ? (e.stopPropagation(), e.preventDefault(), r.length && a?.(r[s]), !0) : !1); return o?.addEventListener("keydown", e, !0), () => { o?.removeEventListener("keydown", e, !0); }; }, [ o, r, s, a, i, i !== void 0 && i > 1 ]), C(() => { c(0); }, [n]), { selectedIndex: r.length === 0 ? void 0 : s }; } //#endregion //#region src/components/SuggestionMenu/GridSuggestionMenu/GridSuggestionMenuWrapper.tsx function sr(e) { let t = i().setContentEditableProps, n = c(), { getItems: r, gridSuggestionMenuComponent: a, query: o, clearQuery: s, closeMenu: l, onItemClick: u, columns: d } = e, f = S((e) => { l(), s(), u?.(e); }, [ u, l, s ]), { items: p, usedQuery: m, loadingState: h } = ar(o, r); ir(p, m, l); let { selectedIndex: g } = or(n, o, p, d, f); return C(() => (t((e) => ({ ...e, "aria-expanded": !0, "aria-controls": "bn-suggestion-menu" })), () => { t((e) => ({ ...e, "aria-expanded": !1, "aria-controls": void 0 })); }), [t]), C(() => (t((e) => ({ ...e, "aria-activedescendant": g ? "bn-suggestion-menu-item-" + g : void 0 })), () => { t((e) => ({ ...e, "aria-activedescendant": void 0 })); }), [t, g]), /* @__PURE__ */ K(a, { items: p, onItemClick: f, loadingState: h, selectedIndex: g, columns: d }); } //#endregion //#region src/components/SuggestionMenu/GridSuggestionMenu/GridSuggestionMenuController.tsx function cr(t) { let n = c(), i = e(), { triggerCharacter: a, gridSuggestionMenuComponent: o, columns: s, shouldOpen: l, minQueryLength: d, onItemClick: f, getItems: m } = t, h = w(() => f || ((e) => { e.onItemClick(n); }), [n, f]), g = w(() => m || (async (e) => await nr(n, e)), [n, m]), _ = r(N); C(() => { _.addSuggestionMenu({ triggerCharacter: a, shouldOpen: l }); }, [ _, a, l ]); let v = u(N), y = u(N, { selector: (e) => ({ element: i?.firstChild || void 0, getBoundingClientRect: () => e?.referencePos || new DOMRect() }) }), b = w(() => ({ ...t.floatingUIOptions, useFloatingOptions: { open: v?.show && v?.triggerCharacter === a, onOpenChange: (e) => { e || _.closeMenu(); }, placement: "bottom-start", middleware: [ F(10), he({ allowedPlacements: ["bottom-start", "top-start"], padding: 10 }), ye(), I({ apply({ elements: e, availableHeight: t }) { e.floating.style.maxHeight = `${Math.max(0, t)}px`; }, padding: 10 }) ], ...t.floatingUIOptions?.useFloatingOptions }, focusManagerProps: { disabled: !0, ...t.floatingUIOptions?.focusManagerProps }, elementProps: { onMouseDownCapture: (e) => e.preventDefault(), style: { zIndex: 70 }, ...t.floatingUIOptions?.elementProps } }), [ t.floatingUIOptions, v?.show, v?.triggerCharacter, _, a ]); return !v || !v.ignoreQueryLength && d && (v.query.startsWith(" ") || v.query.length < d) ? null : /* @__PURE__ */ K(p, { reference: y, portalElement: t.portalElement, ...b, children: a && /* @__PURE__ */ K(sr, { query: v.query, closeMenu: _.closeMenu, clearQuery: _.clearQuery, getItems: g, columns: s, gridSuggestionMenuComponent: o || rr, onItemClick: h }) }); } //#endregion //#region src/components/SuggestionMenu/SuggestionMenu.tsx function lr(e) { let t = s(), n = f(), { items: r, loadingState: i, selectedIndex: a, onItemClick: o } = e, c = i === "loading-initial" || i === "loading" ? /* @__PURE__ */ K(t.SuggestionMenu.Loader, { className: "bn-suggestion-menu-loader" }) : null, l = w(() => { let e, n = []; for (let i = 0; i < r.length; i++) { let s = r[i]; s.group !== e && (e = s.group, n.push(/* @__PURE__ */ K(t.SuggestionMenu.Label, { className: "bn-suggestion-menu-label", children: e }, e))), n.push(/* @__PURE__ */ K(t.SuggestionMenu.Item, { className: W("bn-suggestion-menu-item", s.size === "small" ? "bn-suggestion-menu-item-small" : ""), item: s, id: `bn-suggestion-menu-item-${i}`, isSelected: i === a, onClick: () =>