diff --git a/dist/TrailingNode-CxM966vN.js b/dist/TrailingNode-CxM966vN.js index 3ac6fe16aa9ae605a59916f8343b8440befda89e..52df094addfedadcf5f7cee412fa637ddcd2604b 100644 --- a/dist/TrailingNode-CxM966vN.js +++ b/dist/TrailingNode-CxM966vN.js @@ -1183,6 +1183,10 @@ class Ft { b(this, "updateState", (e) => { this.state = e, this.emitUpdate(this.state); }); + b(this, "hideMenu", () => { + var e; + (e = this.state) != null && e.show && (this.state.show = !1, this.updateState(this.state)); + }); b(this, "updateStateFromMousePos", () => { var o, r, s, i, a; if (this.menuFrozen || !this.mousePos) @@ -1192,33 +1196,39 @@ class Ft { clientY: this.mousePos.y }); if ((e == null ? void 0 : e.element) !== this.pmView.dom || e.distance > se) { - (o = this.state) != null && o.show && (this.state.show = !1, this.updateState(this.state)); + this.hideMenu(); return; } const t = Ht(this.mousePos, this.pmView); if (!t || !this.editor.isEditable) { - (r = this.state) != null && r.show && (this.state.show = !1, this.updateState(this.state)); + this.hideMenu(); + return; + } + if ((s = this.state) != null && s.show && ((i = this.hoveredBlock) != null && i.hasAttribute("data-id")) && ((a = this.hoveredBlock) == null ? void 0 : a.getAttribute("data-id")) === t.id) + return; + this.hoveredBlock = t.node; + const c = this.hoveredBlock.getAttribute("data-id"), l = c ? this.editor.getBlock(c) : void 0; + if (!l) { + this.hideMenu(); return; } - if (!((s = this.state) != null && s.show && ((i = this.hoveredBlock) != null && i.hasAttribute("data-id")) && ((a = this.hoveredBlock) == null ? void 0 : a.getAttribute("data-id")) === t.id) && (this.hoveredBlock = t.node, this.editor.isEditable)) { - const c = t.node.getBoundingClientRect(), l = t.node.closest("[data-node-type=column]"); + if (this.editor.isEditable) { + const u = t.node.getBoundingClientRect(), h = t.node.closest("[data-node-type=column]"); this.state = { show: !0, referencePos: new DOMRect( - l ? ( + h ? ( // We take the first child as column elements have some default // padding. This is a little weird since this child element will // be the first block, but since it's always non-nested and we // only take the x coordinate, it's ok. - l.firstElementChild.getBoundingClientRect().x + h.firstElementChild.getBoundingClientRect().x ) : this.pmView.dom.firstChild.getBoundingClientRect().x, - c.y, - c.width, - c.height + u.y, + u.width, + u.height ), - block: this.editor.getBlock( - this.hoveredBlock.getAttribute("data-id") - ) + block: l }, this.updateState(this.state); } }); @@ -1522,6 +1532,30 @@ function Ut(n) { function M(n) { return Array.prototype.indexOf.call(n.parentElement.childNodes, n); } +function isValidTablePosition(n) { + return Number.isInteger(n) && n >= 0; +} +function isValidCellIndex(n) { + return Number.isInteger(n) && n >= 0; +} +function isValidRelativeCell(n) { + return isValidCellIndex(n.row) && isValidCellIndex(n.col); +} +function resolveCellPosition(n, e, t) { + if (!isValidTablePosition(e) || !isValidRelativeCell(t)) + return; + try { + const o = n.doc.resolve(e + 1); + if (t.row >= o.node().childCount) + return; + const r = n.doc.resolve( + o.posAtIndex(t.row) + 1 + ); + return t.col >= r.node().childCount ? void 0 : n.doc.resolve(r.posAtIndex(t.col)); + } catch { + return; + } +} function _t(n) { let e = n; for (; e && e.nodeName !== "TD" && e.nodeName !== "TH" && !e.classList.contains("tableWrapper"); ) { @@ -1557,6 +1591,12 @@ class Kt { b(this, "menuFrozen", !1); b(this, "mouseState", "up"); b(this, "prevWasEditable", null); + b(this, "hideHandles", (e = {}) => { + const { resetCell: t = !1, resetDragging: o = !1 } = e; + if (!this.state || !this.state.show && !t && !o) + return; + this.state.show = !1, this.state.showAddOrRemoveRowsButton = !1, this.state.showAddOrRemoveColumnsButton = !1, o && (this.state.draggingState = void 0), t && (this.state.rowIndex = void 0, this.state.colIndex = void 0, this.state.referencePosCell = void 0), this.emitUpdate(); + }); b(this, "viewMousedownHandler", () => { this.mouseState = "down"; }); @@ -1569,11 +1609,11 @@ class Kt { return; const t = _t(e.target); if ((t == null ? void 0 : t.type) === "cell" && this.mouseState === "down" && !((l = this.state) != null && l.draggingState)) { - this.mouseState = "selecting", (u = this.state) != null && u.show && (this.state.show = !1, this.state.showAddOrRemoveRowsButton = !1, this.state.showAddOrRemoveColumnsButton = !1, this.emitUpdate()); + this.mouseState = "selecting", this.hideHandles(); return; } if (!t || !this.editor.isEditable) { - (h = this.state) != null && h.show && (this.state.show = !1, this.state.showAddOrRemoveRowsButton = !1, this.state.showAddOrRemoveColumnsButton = !1, this.emitUpdate()); + this.hideHandles(); return; } if (!t.tbodyNode) @@ -1671,9 +1711,7 @@ class Kt { if (this.mouseState = "up", this.state === void 0 || this.state.draggingState === void 0) return !1; if (this.state.rowIndex === void 0 || this.state.colIndex === void 0) - throw new Error( - "Attempted to drop table row or column, but no table block was hovered prior." - ); + return e.preventDefault(), this.hideHandles({ resetCell: !0, resetDragging: !0 }), !1; e.preventDefault(); const { draggingState: t, colIndex: o, rowIndex: r } = this.state, s = this.state.block.content.columnWidths; if (t.draggedCellOrientation === "row") { @@ -1738,7 +1776,7 @@ class Kt { if (this.state.block = this.editor.getBlock(this.state.block.id), !this.state.block || this.state.block.type !== "table" || // when collaborating, the table element might be replaced and out of date // because yjs replaces the element when for example you change the color via the side menu !((r = this.tableElement) != null && r.isConnected)) { - this.state.show = !1, this.state.showAddOrRemoveRowsButton = !1, this.state.showAddOrRemoveColumnsButton = !1, this.emitUpdate(); + this.hideHandles(); return; } const { height: e, width: t } = Ve( @@ -1746,10 +1784,10 @@ class Kt { ); this.state.rowIndex !== void 0 && this.state.colIndex !== void 0 && (this.state.rowIndex >= e && (this.state.rowIndex = e - 1), this.state.colIndex >= t && (this.state.colIndex = t - 1)); const o = this.tableElement.querySelector("tbody"); - if (!o) - throw new Error( - "Table block does not contain a 'tbody' HTML element. This should never happen." - ); + if (!o) { + this.hideHandles({ resetCell: !0 }); + return; + } if (this.state.rowIndex !== void 0 && this.state.colIndex !== void 0) { const i = o.children[this.state.rowIndex].children[this.state.colIndex]; i ? this.state.referencePosCell = i.getBoundingClientRect() : (this.state.rowIndex = void 0, this.state.colIndex = void 0); @@ -1838,10 +1876,10 @@ const D = new P("TableHandlesPlugin"), Po = k(({ editor: n }) => { * is used as the column drag handle. */ colDragStart(o) { - if (e === void 0 || e.state === void 0 || e.state.colIndex === void 0) - throw new Error( - "Attempted to drag table column, but no table block was hovered prior." - ); + if (e === void 0 || e.state === void 0 || e.state.colIndex === void 0 || e.tablePos === void 0) { + e == null || e.hideHandles({ resetCell: !0, resetDragging: !0 }); + return; + } e.state.draggingState = { draggedCellOrientation: "col", originalIndex: e.state.colIndex, @@ -1860,10 +1898,10 @@ const D = new P("TableHandlesPlugin"), Po = k(({ editor: n }) => { * is used as the row drag handle. */ rowDragStart(o) { - if (e.state === void 0 || e.state.rowIndex === void 0) - throw new Error( - "Attempted to drag table row, but no table block was hovered prior." - ); + if (e === void 0 || e.state === void 0 || e.state.rowIndex === void 0 || e.tablePos === void 0) { + e == null || e.hideHandles({ resetCell: !0, resetDragging: !0 }); + return; + } e.state.draggingState = { draggedCellOrientation: "row", originalIndex: e.state.rowIndex, @@ -1882,10 +1920,10 @@ const D = new P("TableHandlesPlugin"), Po = k(({ editor: n }) => { * used as the row drag handle, and the one used as the column drag handle. */ dragEnd() { - if (e.state === void 0) - throw new Error( - "Attempted to drag table row, but no table block was hovered prior." - ); + if (e === void 0 || e.state === void 0) { + n.headless || Ut(n.prosemirrorView.root); + return; + } e.state.draggingState = void 0, e.emitUpdate(), n.transact((o) => o.setMeta(D, null)), !n.headless && Ut(n.prosemirrorView.root); }, /** @@ -1918,30 +1956,37 @@ const D = new P("TableHandlesPlugin"), Po = k(({ editor: n }) => { setCellSelection(o, r, s = r) { if (!e) throw new Error("Table handles view not initialized"); - const i = o.doc.resolve(e.tablePos + 1), a = o.doc.resolve( - i.posAtIndex(r.row) + 1 - ), c = o.doc.resolve( - // No need for +1, since CellSelection expects the position before the cell - a.posAtIndex(r.col) - ), l = o.doc.resolve( - i.posAtIndex(s.row) + 1 - ), u = o.doc.resolve( - // No need for +1, since CellSelection expects the position before the cell - l.posAtIndex(s.col) - ), h = o.tr; - return h.setSelection( - new yt(c, u) - ), o.apply(h); + const i = resolveCellPosition( + o, + e.tablePos, + r + ), a = resolveCellPosition( + o, + e.tablePos, + s + ); + if (!i || !a) + return; + const c = o.tr; + return c.setSelection( + new yt(i, a) + ), o.apply(c); }, /** * Adds a row or column to the table using prosemirror-table commands */ addRowOrColumn(o, r) { + if (!e || !isValidTablePosition(e.tablePos) || !isValidCellIndex(o)) { + e == null || e.hideHandles({ resetCell: !0 }); + return; + } n.exec((s, i) => { const a = this.setCellSelection( s, r.orientation === "row" ? { row: o, col: 0 } : { row: 0, col: o } ); + if (!a) + return e == null || e.hideHandles({ resetCell: !0 }), !1; return r.orientation === "row" ? r.side === "above" ? pt(a, i) : ft(a, i) : r.side === "left" ? gt(a, i) : wt(a, i); }); }, @@ -1949,17 +1994,23 @@ const D = new P("TableHandlesPlugin"), Po = k(({ editor: n }) => { * Removes a row or column from the table using prosemirror-table commands */ removeRowOrColumn(o, r) { + if (!isValidCellIndex(o)) + return !1; return r === "row" ? n.exec((s, i) => { const a = this.setCellSelection(s, { row: o, col: 0 }); + if (!a) + return !1; return ht(a, i); }) : n.exec((s, i) => { const a = this.setCellSelection(s, { row: 0, col: o }); + if (!a) + return !1; return mt(a, i); }); }, @@ -1973,6 +2024,8 @@ const D = new P("TableHandlesPlugin"), Po = k(({ editor: n }) => { o.relativeStartCell, o.relativeEndCell ) : r; + if (!i) + return !1; return ut(i, s); }); }, @@ -1983,6 +2036,8 @@ const D = new P("TableHandlesPlugin"), Po = k(({ editor: n }) => { splitCell(o) { return n.exec((r, s) => { const i = o ? this.setCellSelection(r, o) : r; + if (!i) + return !1; return dt(i, s); }); }, diff --git a/dist/blocknote.js b/dist/blocknote.js index 0f97dc48ddedfb9661b81c7469ce504dc974e284..66600e91f871ed86e4942b794d2bce8f96882ae0 100644 --- a/dist/blocknote.js +++ b/dist/blocknote.js @@ -2037,7 +2037,9 @@ const de = () => { ] }) ); -let fe = !1; +const bnLinkifyProtocolFlag = "__tolariaBlockNoteLinkifyProtocolsRegistered"; +const bnGlobalObject = typeof globalThis > "u" ? void 0 : globalThis; +let fe = Boolean(bnGlobalObject && bnGlobalObject[bnLinkifyProtocolFlag]); function mn(o, e) { const t = [ I.ClipboardTextSerializer, @@ -2062,7 +2064,10 @@ function mn(o, e) { }).configure({ defaultProtocol: Ct, // only call this once if we have multiple editors installed. Or fix https://github.com/ueberdosis/tiptap/issues/5450 - protocols: fe ? [] : Bt + // Tolaria routes editor link clicks through its guarded native opener. + openOnClick: !1, + // Tolaria pre-registers BlockNote's non-native protocols before linkify initializes. + protocols: [] }), ...Object.values(o.schema.styleSpecs).map((n) => n.implementation.mark.configure({ editor: o @@ -2112,7 +2117,7 @@ function mn(o, e) { ), Do(o) ]; - return fe = !0, t; + return fe = !0, bnGlobalObject && (bnGlobalObject[bnLinkifyProtocolFlag] = !0), t; } function kn(o, e) { const t = [ diff --git a/dist/defaultBlocks-DE5GNdJH.js b/dist/defaultBlocks-DE5GNdJH.js index b2761001278486a8b2ac1d10c82420b4994e96d9..c44e9c09100c6d1803bd71b2a338c43e34b74886 100644 --- a/dist/defaultBlocks-DE5GNdJH.js +++ b/dist/defaultBlocks-DE5GNdJH.js @@ -1120,6 +1120,8 @@ const Ut = ({ defaultLanguage: e = "text" }) => ({ ), i.value = t.props.language || e.defaultLanguage || "text", n.isEditable) { const l = (u) => { const d = u.target.value; + if (!n.getBlock(t.id)) + return; n.updateBlock(t.id, { props: { language: d } }); }; i.addEventListener("change", l), s = () => i.removeEventListener("change", l); @@ -1802,9 +1804,12 @@ const ln = () => ({ parseContent: ({ el: e, schema: t }) => Y(e, t, "checkListItem"), render(e, t) { const n = document.createDocumentFragment(), o = document.createElement("input"); o.type = "checkbox", o.checked = e.props.checked, e.props.checked && o.setAttribute("checked", ""), o.addEventListener("change", () => { - t.updateBlock(e, { props: { checked: !e.props.checked } }); + const r = t.getBlock(e.id); + if (!r) + return; + t.updateBlock(r, { props: { checked: !r.props.checked } }); }); const r = document.createElement("p"), a = document.createElement("div"); return a.contentEditable = "false", a.appendChild(o), n.appendChild(a), n.appendChild(r), { dom: n, @@ -2621,6 +2623,9 @@ class On { this.state.referencePos = o.getBoundingClientRect().toJSON(), this.emitUpdate(this.pluginState.triggerCharacter); } }); + M(this, "hideMenu", (t) => { + this.state && (this.state.show = !1, this.emitUpdate(t)); + }); M(this, "closeMenu", () => { this.editor.transact((t) => t.setMeta(B, null)); }); @@ -2634,7 +2639,7 @@ class On { this.editor = t, this.pluginState = void 0, this.emitUpdate = (a) => { var s; if (!this.state) - throw new Error("Attempting to update uninitialized suggestions menu"); + return; n(a, { ...this.state, ignoreQueryLength: (s = this.pluginState) == null ? void 0 : s.ignoreQueryLength @@ -2649,17 +2654,21 @@ class On { if (!a && !(o !== void 0 && r !== void 0) && !s) return; if (this.pluginState = s ? o : r, s || !this.editor.isEditable) { - this.state && (this.state.show = !1), this.emitUpdate(this.pluginState.triggerCharacter); + this.hideMenu(this.pluginState.triggerCharacter); return; } const c = (l = this.rootEl) == null ? void 0 : l.querySelector( `[data-decoration-id="${this.pluginState.decorationId}"]` ); - this.editor.isEditable && c && (this.state = { + if (!c) { + this.hideMenu(this.pluginState.triggerCharacter); + return; + } + this.state = { show: !0, referencePos: c.getBoundingClientRect().toJSON(), query: this.pluginState.query - }, this.emitUpdate(this.pluginState.triggerCharacter)); + }, this.emitUpdate(this.pluginState.triggerCharacter); } destroy() { var t; @@ -2761,7 +2770,7 @@ const B = new Ze("SuggestionMenuPlugin"), _n = k(({ editor: e }) => { if (a === s) { const c = r.state.doc; for (const l of t) { - const u = l.length > 1 ? c.textBetween(a - l.length, a) + i : i; + const u = l.length > 1 ? c.textBetween(a - (l.length - 1), a) + i : i; if (l === u) return r.dispatch(r.state.tr.insertText(i)), r.dispatch( r.state.tr.setMeta(B, { diff --git a/node_modules/.bin/uuid b/node_modules/.bin/uuid new file mode 100755 index 0000000000000000000000000000000000000000..2bc12aee9f172fb55715572a6597f2e4b2e5b4ec --- /dev/null +++ b/node_modules/.bin/uuid @@ -0,0 +1,21 @@ +#!/bin/sh +basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')") + +case `uname` in + *CYGWIN*|*MINGW*|*MSYS*) + if command -v cygpath > /dev/null 2>&1; then + basedir=`cygpath -w "$basedir"` + fi + ;; +esac + +if [ -z "$NODE_PATH" ]; then + export NODE_PATH="/Volumes/Jupiter/Workspace/laputa-app/node_modules/.pnpm/uuid@8.3.2/node_modules/uuid/node_modules:/Volumes/Jupiter/Workspace/laputa-app/node_modules/.pnpm/uuid@8.3.2/node_modules:/Volumes/Jupiter/Workspace/laputa-app/node_modules/.pnpm/node_modules" +else + export NODE_PATH="/Volumes/Jupiter/Workspace/laputa-app/node_modules/.pnpm/uuid@8.3.2/node_modules/uuid/node_modules:/Volumes/Jupiter/Workspace/laputa-app/node_modules/.pnpm/uuid@8.3.2/node_modules:/Volumes/Jupiter/Workspace/laputa-app/node_modules/.pnpm/node_modules:$NODE_PATH" +fi +if [ -x "$basedir/node" ]; then + exec "$basedir/node" "$basedir/../../../../uuid/dist/bin/uuid" "$@" +else + exec node "$basedir/../../../../uuid/dist/bin/uuid" "$@" +fi diff --git a/src/blocks/Code/block.ts b/src/blocks/Code/block.ts index dbb7fc33a9add7a96488349876bc56ad60111a3f..58c3cf181f25467d85cd8c3788b5b73dec88175a 100644 --- a/src/blocks/Code/block.ts +++ b/src/blocks/Code/block.ts @@ -134,6 +134,10 @@ export const createCodeBlockSpec = createBlockSpec( const handleLanguageChange = (event: Event) => { const language = (event.target as HTMLSelectElement).value; + if (!editor.getBlock(block.id)) { + return; + } + editor.updateBlock(block.id, { props: { language } }); }; select.addEventListener("change", handleLanguageChange); diff --git a/src/blocks/ListItem/CheckListItem/block.ts b/src/blocks/ListItem/CheckListItem/block.ts index 682cbba711bd9ca107fe3940f44ab39fc757cfe0..2d2f871ac13836b736543b29a620580a7a3f1057 100644 --- a/src/blocks/ListItem/CheckListItem/block.ts +++ b/src/blocks/ListItem/CheckListItem/block.ts @@ -82,7 +82,12 @@ export const createCheckListItemBlockSpec = createBlockSpec( checkbox.setAttribute("checked", ""); } checkbox.addEventListener("change", () => { - editor.updateBlock(block, { props: { checked: !block.props.checked } }); + const liveBlock = editor.getBlock(block.id); + if (!liveBlock) { + return; + } + + editor.updateBlock(liveBlock, { props: { checked: !liveBlock.props.checked } }); }); // We use a

tag, because for

  • tags we'd need a