diff --git a/dist/blocknote-react.js b/dist/blocknote-react.js index 6271d12d2cd5152e924c5bfe78f3b8904844dbfe..12bb96bb36d445a77d51a18d0de446a3f9f0ea59 100644 --- a/dist/blocknote-react.js +++ b/dist/blocknote-react.js @@ -155,8 +155,26 @@ var Rt = (e) => { function so(e) { let t = new DOMRect(); - const n = "getBoundingClientRect" in e ? () => e.getBoundingClientRect() : () => e.element.getBoundingClientRect(); - return () => "element" in e && (e.cacheMountedBoundingClientRect ?? !0) ? (e.element.isConnected && (t = n()), t) : n(); + const n = () => "getBoundingClientRect" in e ? e.getBoundingClientRect() : e.element instanceof Element ? e.element.getBoundingClientRect() : t; + return () => { + if (!("element" in e) || !(e.cacheMountedBoundingClientRect ?? !0)) + return n(); + if (!(e.element instanceof Element)) + return n(); + if (e.element.isConnected) + t = n(); + return t; + }; } +function __bnSafeDomAtPos(e, t) { + const n = e.prosemirrorView; + if (!n || n.isDestroyed) + return null; + try { + return n.domAtPos(t); + } catch { + return null; + } +} const z = (e) => { var h, b, p; const { refs: t, floatingStyles: n, context: o } = Ze({ @@ -216,9 +234,7 @@ const Lt = (e) => { const s = Ue(t, c.doc); if (!s) return; - const { node: a } = r.prosemirrorView.domAtPos( - s.posBeforeNode + 1 - ); + const a = __bnSafeDomAtPos(r, s.posBeforeNode + 1)?.node; if (a instanceof Element) return { element: a @@ -3306,14 +3322,15 @@ const pi = (e) => { ); if (!m) return {}; - const g = m.posBeforeNode + 1, f = t.prosemirrorView.domAtPos( + const g = m.posBeforeNode + 1, f = __bnSafeDomAtPos( + t, g + 1 - ).node; + )?.node; if (!(f instanceof Element)) return {}; if (d.tableReference = { element: f }, r.rowIndex === void 0 || r.colIndex === void 0) return d; - const h = t.prosemirrorState.doc.resolve(g + 1).posAtIndex(r.rowIndex), b = t.prosemirrorState.doc.resolve(h + 1).posAtIndex(r.colIndex), p = t.prosemirrorView.domAtPos(b + 1).node; + const h = t.prosemirrorState.doc.resolve(g + 1).posAtIndex(r.rowIndex), b = t.prosemirrorState.doc.resolve(h + 1).posAtIndex(r.colIndex), p = __bnSafeDomAtPos(t, b + 1)?.node; return p instanceof Element ? (d.cellReference = { element: p }, d.rowReference = { element: f, getBoundingClientRect: () => { @@ -4371,7 +4388,7 @@ const El = (e) => { const a = Ue(t, c.prosemirrorState.doc); if (!a) return; - const u = a.posBeforeNode + 1, d = c.prosemirrorState.doc.resolve(u + 1).posAtIndex(o || 0), m = c.prosemirrorState.doc.resolve(d + 1).posAtIndex(n || 0), { node: g } = c.prosemirrorView.domAtPos(m + 1); + const u = a.posBeforeNode + 1, d = c.prosemirrorState.doc.resolve(u + 1).posAtIndex(o || 0), m = c.prosemirrorState.doc.resolve(d + 1).posAtIndex(n || 0), g = __bnSafeDomAtPos(c, m + 1)?.node; if (g instanceof Element) return g; }, [c, t, n, o]);