Skip to content

Commit 9825116

Browse files
committed
refactor: make into an internal API
1 parent 1d2906b commit 9825116

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed

packages/core/src/api/positionMapping.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ export class PositionStorage<
100100
* This is the side of the position to track. "left" is the default. "right" would move with the change if the change is in the right direction.
101101
*/
102102
side: "left" | "right" = "left"
103-
): () => number {
103+
): () => number | undefined {
104104
const ySyncPluginState = ySyncPluginKey.getState(
105105
this.editor._tiptapEditor.state
106106
) as YSyncPluginState;
@@ -136,7 +136,7 @@ export class PositionStorage<
136136

137137
// This can happen if the element is deleted
138138
if (rel === null) {
139-
throw new Error("Element deleted");
139+
return undefined;
140140
}
141141

142142
return rel + (side === "right" ? -1 : 0);

packages/core/src/editor/BlockNoteEditor.ts

+17-9
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,17 @@ export class BlockNoteEditor<
368368
contentComponent: any;
369369
} = undefined as any; // TODO: Type should actually reflect that it can be `undefined` in headless mode
370370

371+
/**
372+
* Internal properties that are not part of the public API and may change in the future.
373+
*
374+
* @internal
375+
*/
376+
public readonly _internal: {
377+
/**
378+
* Stores positions of elements in the editor.
379+
*/
380+
positionStorage: PositionStorage<BSchema, ISchema, SSchema>;
381+
};
371382
/**
372383
* Used by React to store a reference to an `ElementRenderer` helper utility to make sure we can render React elements
373384
* in the correct context (used by `ReactRenderUtil`)
@@ -396,11 +407,6 @@ export class BlockNoteEditor<
396407
public readonly inlineContentImplementations: InlineContentSpecs;
397408
public readonly styleImplementations: StyleSpecs;
398409

399-
/**
400-
* Stores positions of elements in the editor.
401-
*/
402-
public readonly positionStorage: PositionStorage<BSchema, ISchema, SSchema>;
403-
404410
public readonly formattingToolbar: FormattingToolbarProsemirrorPlugin;
405411
public readonly linkToolbar: LinkToolbarProsemirrorPlugin<
406412
BSchema,
@@ -692,10 +698,12 @@ export class BlockNoteEditor<
692698
this.pmSchema = getSchema(tiptapOptions.extensions!);
693699
}
694700

695-
this.positionStorage = new PositionStorage<BSchema, ISchema, SSchema>(
696-
this,
697-
{ shouldMount: !this.headless }
698-
);
701+
this._internal = {
702+
positionStorage: new PositionStorage<BSchema, ISchema, SSchema>(this, {
703+
shouldMount: !this.headless,
704+
}),
705+
};
706+
699707
this.emit("create");
700708
}
701709

packages/core/src/extensions/SuggestionMenu/SuggestionPlugin.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ export class SuggestionMenuProseMirrorPlugin<
218218
suggestionPluginTransactionMeta !== null &&
219219
prev === undefined
220220
) {
221-
const trackedPosition = editor.positionStorage.track(
221+
const trackedPosition = editor._internal.positionStorage.track(
222222
newState.selection.from -
223223
// Need to account for the trigger char that was inserted, so we offset the position by the length of the trigger character.
224224
suggestionPluginTransactionMeta.triggerCharacter.length
@@ -231,7 +231,7 @@ export class SuggestionMenuProseMirrorPlugin<
231231
false,
232232
// When reading the queryStartPos, we offset the result by the length of the trigger character, to make it easy on the caller
233233
queryStartPos: () =>
234-
trackedPosition() +
234+
trackedPosition()! +
235235
suggestionPluginTransactionMeta.triggerCharacter.length,
236236
query: "",
237237
decorationId: `id_${Math.floor(Math.random() * 0xffffffff)}`,

0 commit comments

Comments
 (0)