Skip to content

Commit b0993e2

Browse files
committed
wip
1 parent 08d31a9 commit b0993e2

9 files changed

Lines changed: 51 additions & 8 deletions

File tree

.todo.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
review toolbar code
3+
fix design of menus (smaller items, border?)
4+
5+
see if addToHistory: false is needed
6+
track last affected position to update toolbar
7+
enable / disable show selection plugin

examples/01-basic/01-minimal/App.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {
22
AIBlock,
33
AIBlockToolbarProsemirrorPlugin,
44
AIButton,
5-
AIInlineToolbarProsemirrorPlugin,
5+
AIShowSelectionPlugin,
66
BlockNoteAIContextProvider,
77
BlockNoteAIUI,
88
aiBlockTypeSelectItems,
@@ -49,7 +49,7 @@ export default function App() {
4949
extensions: {
5050
// TODO: things will break when user provides different keys. Define name on plugins instead?
5151
aiBlockToolbar: new AIBlockToolbarProsemirrorPlugin(),
52-
aiInlineToolbar: new AIInlineToolbarProsemirrorPlugin(),
52+
aiSelection: new AIShowSelectionPlugin(),
5353
},
5454
});
5555

packages/ai/src/api/api.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { updateFunction } from "./functions/update";
1414
import { createOperationsArraySchema } from "./schema/operations";
1515
import { blockNoteSchemaToJSONSchema } from "./schema/schemaToJSONSchema";
1616

17+
// TODO don't include child block
1718
export function createMessagesForLLM(opts: {
1819
editor: BlockNoteEditor;
1920
prompt: string;

packages/ai/src/components/AIMenu/BlockPositioner.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import { useUIElementPositioning } from "@blocknote/react";
2-
import { OpenChangeReason, flip, offset, size } from "@floating-ui/react";
2+
import {
3+
OpenChangeReason,
4+
autoUpdate,
5+
flip,
6+
offset,
7+
size,
8+
} from "@floating-ui/react";
39
import { useMemo } from "react";
4-
510
// The block positioner automattically positions it's children below the block with `blockID`
611
export const BlockPositioner = (props: {
712
blockID?: string;
@@ -47,6 +52,7 @@ export const BlockPositioner = (props: {
4752
}),
4853
],
4954
onOpenChange: props.onOpenChange,
55+
whileElementsMounted: autoUpdate,
5056
}
5157
);
5258

packages/ai/src/components/BlockNoteAIUI.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { useBlockNoteEditor } from "@blocknote/react";
22
import { AIBlockToolbarController } from "./AIBlockToolbar/AIBlockToolbarController";
3-
import { AIInlineToolbarController } from "./AIInlineToolbar/AIInlineToolbarController";
43

54
import { AIMenu } from "./AIMenu/AIMenu";
65
import { BlockPositioner } from "./AIMenu/BlockPositioner";
@@ -26,7 +25,6 @@ export function BlockNoteAIUI(props: BlockNoteAIUIProps) {
2625
{editor.extensions.aiBlockToolbar && props.aiBlockToolbar !== false && (
2726
<AIBlockToolbarController />
2827
)}
29-
{props.aiInlineToolbar !== false && <AIInlineToolbarController />}
3028
{props.aiMenu !== false && <AIMenuController />}
3129
</>
3230
);
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import type { BlockNoteEditor } from "@blocknote/core";
2+
import { Plugin, PluginKey } from "prosemirror-state";
3+
import { Decoration, DecorationSet } from "prosemirror-view";
4+
5+
const PLUGIN_KEY = new PluginKey(`blocknote-ai-show-selection`);
6+
7+
export class AIShowSelectionPlugin {
8+
public readonly plugin: Plugin;
9+
10+
public constructor(_editor: BlockNoteEditor<any, any, any>) {
11+
this.plugin = new Plugin({
12+
key: PLUGIN_KEY,
13+
props: {
14+
decorations: (state) => {
15+
const { doc, selection } = state;
16+
17+
const dec = Decoration.inline(selection.from, selection.to, {
18+
"data-ai-show-selection": "true",
19+
});
20+
21+
return DecorationSet.create(doc, [dec]);
22+
},
23+
},
24+
});
25+
}
26+
}

packages/ai/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import "./style.css";
33
export * from "./blocks/AIBlockContent/AIBlockContent";
44
export * from "./blocks/AIBlockContent/mockAIFunctions";
55
export * from "./extensions/AIBlockToolbar/AIBlockToolbarPlugin";
6-
export * from "./extensions/AIInlineToolbar/AIInlineToolbarPlugin";
6+
export * from "./extensions/AIShowSelectionPlugin";
77

88
export * from "./components/AIBlockToolbar/AIBlockToolbar";
99
export * from "./components/AIBlockToolbar/AIBlockToolbarController";

packages/ai/src/style.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,8 @@ div:not(.bn-popover-content) > .bn-combobox-items:not(:empty) {
7777
/*.bn-toolbar .mantine-Button-root.bn-show-prompt-button:hover {*/
7878
/* color: rgba(154, 56, 173, 0.5);*/
7979
/*}*/
80+
81+
[data-ai-show-selection] {
82+
background-color: highlight;
83+
padding: 2px 0;
84+
}

packages/core/src/pm-nodes/BlockContainer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ export const BlockContainer = Node.create<{
286286
state.tr
287287
.replaceWith(
288288
startPos,
289-
endPos,
289+
startPos + contentNode.nodeSize,
290290
state.schema.nodes[newType].create(
291291
{
292292
...contentNode.attrs,

0 commit comments

Comments
 (0)