Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: AI block UI #980

Open
wants to merge 63 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
3e1983b
Added AI block
matthewlipski Aug 1, 2024
0da498e
Added inline and slash menu AI
matthewlipski Aug 6, 2024
d48d91e
Small fix
matthewlipski Aug 6, 2024
82a56a9
UX improvements & refactor
matthewlipski Aug 6, 2024
5c66cfe
Extracted AI to separate package & changed AI block toolbar UX
matthewlipski Sep 9, 2024
22db2b4
Finished initial package split
matthewlipski Sep 9, 2024
e0f60a8
Moved last AI references to AI package
matthewlipski Sep 9, 2024
a2bab5d
Reverted minor unneeded changes
matthewlipski Sep 9, 2024
bcf9d31
refactor architecture
YousefED Sep 10, 2024
b814336
add extensions
YousefED Sep 10, 2024
cfc1bed
Refactored AI dictionary
matthewlipski Sep 10, 2024
ec36733
clean dictionary
YousefED Sep 10, 2024
78ac784
fix
YousefED Sep 10, 2024
2970e9d
fix
YousefED Sep 10, 2024
78924bb
Made AI button use suggestion menu components
matthewlipski Sep 11, 2024
4083cd9
Added keyboard navigation to AI button
matthewlipski Sep 11, 2024
d0d82a4
Refactored AI button
matthewlipski Sep 11, 2024
2df84f5
Changed AI from suggestion menu to propriety menu
matthewlipski Sep 11, 2024
644aa15
Minor changes
matthewlipski Sep 11, 2024
0fcb46a
Prevented focus swapping on suggestion menu items
matthewlipski Sep 11, 2024
251e82b
- AI Menu input spans full block width
matthewlipski Sep 11, 2024
736a8ff
Fixed AI Menu position for empty blocks
matthewlipski Sep 11, 2024
ffa466d
Made AI block react instead of vanilla
matthewlipski Sep 12, 2024
2c20238
fix build
YousefED Sep 16, 2024
f474949
schema
YousefED Sep 17, 2024
6ddf7b0
improve json schema methods
YousefED Sep 18, 2024
34abf80
Merge remote-tracking branch 'origin/main' into ai-block
YousefED Sep 23, 2024
b3926fe
merge
YousefED Sep 23, 2024
a9d25c9
improve json schema methods
YousefED Sep 23, 2024
2021ce7
fix build
YousefED Sep 23, 2024
10c6f5e
WIP: schemas and selections
YousefED Sep 25, 2024
a554ff1
selections wip
YousefED Sep 25, 2024
6833d9d
update selections
YousefED Sep 25, 2024
39642ce
wip selectionmarkers
YousefED Sep 25, 2024
7693b10
drop core / react structure
YousefED Sep 26, 2024
a8752e1
ai menu
YousefED Sep 26, 2024
979b917
add comment
YousefED Sep 26, 2024
f88a986
misc
YousefED Sep 26, 2024
3b7a80b
Added `size` field to React suggestion menu items
matthewlipski Sep 26, 2024
5f20d34
Merge branch 'ai-block' of github.com:TypeCellOS/BlockNote into ai-block
YousefED Sep 27, 2024
bb02ee6
basis for accept / reject menu
YousefED Sep 27, 2024
da2f06d
selection commands
YousefED Sep 27, 2024
f7bbf0e
Added `.env` file for API key and AI menu buttons for after an AI com…
matthewlipski Sep 27, 2024
6952a2e
Merge remote-tracking branch 'origin/ai-block' into ai-block
matthewlipski Sep 27, 2024
3ae2152
Added loader to AI menu
matthewlipski Sep 27, 2024
08d31a9
Updated styles
matthewlipski Sep 29, 2024
b0993e2
wip
YousefED Sep 30, 2024
5367284
gitignore
YousefED Sep 30, 2024
8d32b78
Merge remote-tracking branch 'origin/main' into ai-block
YousefED Nov 26, 2024
a271b22
move to xl-ai and add server
YousefED Nov 26, 2024
b8ac4db
fix test
YousefED Nov 27, 2024
0262670
small merge fixes
YousefED Nov 27, 2024
2934697
Merge remote-tracking branch 'origin/main' into ai-block
YousefED Dec 4, 2024
faa52f7
update lock
YousefED Dec 4, 2024
0b8c728
update ai sdk
YousefED Dec 4, 2024
908a3db
improve tests
YousefED Dec 4, 2024
4f8a337
model selector
YousefED Dec 5, 2024
075c025
add markdowndiff
YousefED Dec 10, 2024
fb0a2e1
wip
YousefED Dec 11, 2024
2829adc
split and update tests
YousefED Dec 11, 2024
f533c91
add list support
YousefED Dec 11, 2024
f7e0e81
wip
YousefED Dec 11, 2024
449d0b6
Merge remote-tracking branch 'origin/main' into ai-block
YousefED Dec 11, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,5 @@ release
/test-results/
/playwright-report/
/playwright/.cache/
.env
*.pem
7 changes: 7 additions & 0 deletions .todo.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

review toolbar code
fix design of menus (smaller items, border?)

see if addToHistory: false is needed
track last affected position to update toolbar
enable / disable show selection plugin
3 changes: 2 additions & 1 deletion docs/pages/examples/_meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
"interoperability": "Interoperability",
"custom-schema": "Custom Schemas",
"collaboration": "Collaboration",
"extensions": "Extensions"
"extensions": "Extensions",
"ai": "AI"
}
5 changes: 4 additions & 1 deletion examples/01-basic/01-minimal/.bnexample.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@
"playground": true,
"docs": true,
"author": "matthewlipski",
"tags": ["Basic"]
"tags": ["Basic"],
"dependencies": {
"@blocknote/xl-ai": "latest"
}
}
89 changes: 86 additions & 3 deletions examples/01-basic/01-minimal/App.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,95 @@
import {
AIBlock,
AIBlockToolbarProsemirrorPlugin,
AIButton,
AIShowSelectionPlugin,
BlockNoteAIContextProvider,
BlockNoteAIUI,
aiBlockTypeSelectItems,
locales as aiLocales,
getAISlashMenuItems,
useBlockNoteAIContext,
} from "@blocknote/xl-ai";

import {
BlockNoteEditor,
BlockNoteSchema,
defaultBlockSpecs,
filterSuggestionItems,
locales,
} from "@blocknote/core";
import "@blocknote/core/fonts/inter.css";
import { BlockNoteView } from "@blocknote/mantine";
import "@blocknote/mantine/style.css";
import { useCreateBlockNote } from "@blocknote/react";
import {
FormattingToolbar,
FormattingToolbarController,
SuggestionMenuController,
blockTypeSelectItems,
getDefaultReactSlashMenuItems,
getFormattingToolbarItems,
useCreateBlockNote,
} from "@blocknote/react";
import "@blocknote/xl-ai/style.css";

const schema = BlockNoteSchema.create({
blockSpecs: {
...defaultBlockSpecs,
ai: AIBlock,
},
});
export default function App() {
// Creates a new editor instance.
const editor = useCreateBlockNote();
const editor = useCreateBlockNote({
schema,
dictionary: {
...locales.en,
ai: aiLocales.en,
} as any,
_extensions: {
// TODO: things will break when user provides different keys. Define name on plugins instead?
aiBlockToolbar: new AIBlockToolbarProsemirrorPlugin(),
aiSelection: new AIShowSelectionPlugin(),
},
});

// Renders the editor instance using a React component.
return <BlockNoteView editor={editor} />;
return (
<BlockNoteView editor={editor} formattingToolbar={false} slashMenu={false}>
<BlockNoteAIContextProvider>
<BlockNoteAIUI />
<FormattingToolbarController
formattingToolbar={() => (
<FormattingToolbar>
{...getFormattingToolbarItems([
...blockTypeSelectItems(editor.dictionary),
...aiBlockTypeSelectItems(aiLocales.en),
])}
<AIButton />
</FormattingToolbar>
)}
/>
<SuggestionMenu editor={editor} />
</BlockNoteAIContextProvider>
{/* TODO: Side Menu customization */}
</BlockNoteView>
);
}

function SuggestionMenu(props: { editor: BlockNoteEditor<any, any, any> }) {
const ctx = useBlockNoteAIContext();
return (
<SuggestionMenuController
triggerCharacter="/"
getItems={async (query) =>
filterSuggestionItems(
[
...getDefaultReactSlashMenuItems(props.editor),
...getAISlashMenuItems(props.editor as any, ctx), // TODO
],
query
)
}
/>
);
}
3 changes: 2 additions & 1 deletion examples/01-basic/01-minimal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"@blocknote/mantine": "latest",
"@blocknote/shadcn": "latest",
"react": "^18.3.1",
"react-dom": "^18.3.1"
"react-dom": "^18.3.1",
"@blocknote/xl-ai": "latest"
},
"devDependencies": {
"@types/react": "^18.0.25",
Expand Down
6 changes: 3 additions & 3 deletions examples/01-basic/01-minimal/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ export default defineConfig((conf) => ({
resolve: {
alias:
conf.command === "build" ||
!fs.existsSync(path.resolve(__dirname, "../../packages/core/src"))
!fs.existsSync(path.resolve(__dirname, "../../../packages/core/src"))
? {}
: ({
// Comment out the lines below to load a built version of blocknote
// or, keep as is to load live from sources with live reload working
"@blocknote/core": path.resolve(
__dirname,
"../../packages/core/src/"
"../../../packages/core/src/"
),
"@blocknote/react": path.resolve(
__dirname,
"../../packages/react/src/"
"../../../packages/react/src/"
),
} as any),
},
Expand Down
6 changes: 3 additions & 3 deletions examples/01-basic/02-block-objects/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ export default defineConfig((conf) => ({
resolve: {
alias:
conf.command === "build" ||
!fs.existsSync(path.resolve(__dirname, "../../packages/core/src"))
!fs.existsSync(path.resolve(__dirname, "../../../packages/core/src"))
? {}
: ({
// Comment out the lines below to load a built version of blocknote
// or, keep as is to load live from sources with live reload working
"@blocknote/core": path.resolve(
__dirname,
"../../packages/core/src/"
"../../../packages/core/src/"
),
"@blocknote/react": path.resolve(
__dirname,
"../../packages/react/src/"
"../../../packages/react/src/"
),
} as any),
},
Expand Down
6 changes: 3 additions & 3 deletions examples/01-basic/03-multi-column/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ export default defineConfig((conf) => ({
resolve: {
alias:
conf.command === "build" ||
!fs.existsSync(path.resolve(__dirname, "../../packages/core/src"))
!fs.existsSync(path.resolve(__dirname, "../../../packages/core/src"))
? {}
: ({
// Comment out the lines below to load a built version of blocknote
// or, keep as is to load live from sources with live reload working
"@blocknote/core": path.resolve(
__dirname,
"../../packages/core/src/"
"../../../packages/core/src/"
),
"@blocknote/react": path.resolve(
__dirname,
"../../packages/react/src/"
"../../../packages/react/src/"
),
} as any),
},
Expand Down
6 changes: 3 additions & 3 deletions examples/01-basic/04-all-blocks/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ export default defineConfig((conf) => ({
resolve: {
alias:
conf.command === "build" ||
!fs.existsSync(path.resolve(__dirname, "../../packages/core/src"))
!fs.existsSync(path.resolve(__dirname, "../../../packages/core/src"))
? {}
: ({
// Comment out the lines below to load a built version of blocknote
// or, keep as is to load live from sources with live reload working
"@blocknote/core": path.resolve(
__dirname,
"../../packages/core/src/"
"../../../packages/core/src/"
),
"@blocknote/react": path.resolve(
__dirname,
"../../packages/react/src/"
"../../../packages/react/src/"
),
} as any),
},
Expand Down
6 changes: 3 additions & 3 deletions examples/01-basic/05-removing-default-blocks/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ export default defineConfig((conf) => ({
resolve: {
alias:
conf.command === "build" ||
!fs.existsSync(path.resolve(__dirname, "../../packages/core/src"))
!fs.existsSync(path.resolve(__dirname, "../../../packages/core/src"))
? {}
: ({
// Comment out the lines below to load a built version of blocknote
// or, keep as is to load live from sources with live reload working
"@blocknote/core": path.resolve(
__dirname,
"../../packages/core/src/"
"../../../packages/core/src/"
),
"@blocknote/react": path.resolve(
__dirname,
"../../packages/react/src/"
"../../../packages/react/src/"
),
} as any),
},
Expand Down
6 changes: 3 additions & 3 deletions examples/01-basic/06-block-manipulation/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ export default defineConfig((conf) => ({
resolve: {
alias:
conf.command === "build" ||
!fs.existsSync(path.resolve(__dirname, "../../packages/core/src"))
!fs.existsSync(path.resolve(__dirname, "../../../packages/core/src"))
? {}
: ({
// Comment out the lines below to load a built version of blocknote
// or, keep as is to load live from sources with live reload working
"@blocknote/core": path.resolve(
__dirname,
"../../packages/core/src/"
"../../../packages/core/src/"
),
"@blocknote/react": path.resolve(
__dirname,
"../../packages/react/src/"
"../../../packages/react/src/"
),
} as any),
},
Expand Down
6 changes: 3 additions & 3 deletions examples/01-basic/07-selection-blocks/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ export default defineConfig((conf) => ({
resolve: {
alias:
conf.command === "build" ||
!fs.existsSync(path.resolve(__dirname, "../../packages/core/src"))
!fs.existsSync(path.resolve(__dirname, "../../../packages/core/src"))
? {}
: ({
// Comment out the lines below to load a built version of blocknote
// or, keep as is to load live from sources with live reload working
"@blocknote/core": path.resolve(
__dirname,
"../../packages/core/src/"
"../../../packages/core/src/"
),
"@blocknote/react": path.resolve(
__dirname,
"../../packages/react/src/"
"../../../packages/react/src/"
),
} as any),
},
Expand Down
6 changes: 3 additions & 3 deletions examples/01-basic/08-ariakit/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ export default defineConfig((conf) => ({
resolve: {
alias:
conf.command === "build" ||
!fs.existsSync(path.resolve(__dirname, "../../packages/core/src"))
!fs.existsSync(path.resolve(__dirname, "../../../packages/core/src"))
? {}
: ({
// Comment out the lines below to load a built version of blocknote
// or, keep as is to load live from sources with live reload working
"@blocknote/core": path.resolve(
__dirname,
"../../packages/core/src/"
"../../../packages/core/src/"
),
"@blocknote/react": path.resolve(
__dirname,
"../../packages/react/src/"
"../../../packages/react/src/"
),
} as any),
},
Expand Down
6 changes: 3 additions & 3 deletions examples/01-basic/09-shadcn/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ export default defineConfig((conf) => ({
resolve: {
alias:
conf.command === "build" ||
!fs.existsSync(path.resolve(__dirname, "../../packages/core/src"))
!fs.existsSync(path.resolve(__dirname, "../../../packages/core/src"))
? {}
: ({
// Comment out the lines below to load a built version of blocknote
// or, keep as is to load live from sources with live reload working
"@blocknote/core": path.resolve(
__dirname,
"../../packages/core/src/"
"../../../packages/core/src/"
),
"@blocknote/react": path.resolve(
__dirname,
"../../packages/react/src/"
"../../../packages/react/src/"
),
} as any),
},
Expand Down
6 changes: 3 additions & 3 deletions examples/01-basic/10-localization/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ export default defineConfig((conf) => ({
resolve: {
alias:
conf.command === "build" ||
!fs.existsSync(path.resolve(__dirname, "../../packages/core/src"))
!fs.existsSync(path.resolve(__dirname, "../../../packages/core/src"))
? {}
: ({
// Comment out the lines below to load a built version of blocknote
// or, keep as is to load live from sources with live reload working
"@blocknote/core": path.resolve(
__dirname,
"../../packages/core/src/"
"../../../packages/core/src/"
),
"@blocknote/react": path.resolve(
__dirname,
"../../packages/react/src/"
"../../../packages/react/src/"
),
} as any),
},
Expand Down
6 changes: 3 additions & 3 deletions examples/01-basic/11-custom-placeholder/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ export default defineConfig((conf) => ({
resolve: {
alias:
conf.command === "build" ||
!fs.existsSync(path.resolve(__dirname, "../../packages/core/src"))
!fs.existsSync(path.resolve(__dirname, "../../../packages/core/src"))
? {}
: ({
// Comment out the lines below to load a built version of blocknote
// or, keep as is to load live from sources with live reload working
"@blocknote/core": path.resolve(
__dirname,
"../../packages/core/src/"
"../../../packages/core/src/"
),
"@blocknote/react": path.resolve(
__dirname,
"../../packages/react/src/"
"../../../packages/react/src/"
),
} as any),
},
Expand Down
Loading
Loading