Skip to content

Commit 6a9aa6c

Browse files
committed
feat: support ai writer
1 parent 04bcc78 commit 6a9aa6c

File tree

27 files changed

+658
-116
lines changed

27 files changed

+658
-116
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"coverage": "pnpm run test:unit && pnpm run test:components"
1919
},
2020
"dependencies": {
21-
"@appflowyinc/ai-chat": "0.0.15",
21+
"@appflowyinc/ai-chat": "0.0.17",
2222
"@appflowyinc/editor": "^0.1.6",
2323
"@atlaskit/primitives": "^5.5.3",
2424
"@emoji-mart/data": "^1.1.2",

pnpm-lock.yaml

Lines changed: 137 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/@types/translations/en.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1687,7 +1687,9 @@
16871687
"aiWriter": "AI Writer",
16881688
"dateOrReminder": "Date or Reminder",
16891689
"photoGallery": "Photo Gallery",
1690-
"file": "File"
1690+
"file": "File",
1691+
"continueWriting": "Continue Writing",
1692+
"askAIAnything": "Ask AI Anything"
16911693
},
16921694
"subPage": {
16931695
"name": "Document",
@@ -2446,7 +2448,9 @@
24462448
"toggleListShortForm": "Toggle",
24472449
"quoteListShortForm": "Quote",
24482450
"mathEquationShortForm": "Formula",
2449-
"codeBlockShortForm": "Code"
2451+
"codeBlockShortForm": "Code",
2452+
"improveWriting": "Improve writing",
2453+
"askAI": "Ask AI Anything"
24502454
},
24512455
"favorite": {
24522456
"noFavorite": "No favorite page",

src/application/slate-yjs/command/index.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,20 @@ import {
4545
} from '@/application/slate-yjs/utils/yjs';
4646

4747
export const CustomEditor = {
48+
getEditorContent(editor: YjsEditor) {
49+
const allNodes = editor.children ?? [];
50+
51+
return allNodes.map((node) => {
52+
return CustomEditor.getBlockTextContent(node);
53+
}).join('\n');
54+
},
55+
56+
getSelectionContent(editor: YjsEditor) {
57+
const range = editor.selection;
58+
59+
if(!range) return '';
60+
return editor.string(range);
61+
},
4862
// Get the text content of a block node, including the text content of its children and formula nodes
4963
getBlockTextContent(node: Node, depth: number = Infinity): string {
5064
if(Text.isText(node)) {
@@ -78,7 +92,7 @@ export const CustomEditor = {
7892
},
7993

8094
setBlockData<T = BlockData>(editor: YjsEditor, blockId: string, updateData: T, select?: boolean) {
81-
95+
8296
const block = getBlock(blockId, editor.sharedRoot);
8397
const oldData = dataStringTOJson(block.get(YjsEditorKey.block_data));
8498
const newData = {

src/application/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -991,6 +991,7 @@ export interface ViewMetaProps {
991991
cover?: ViewMetaCover;
992992
name?: string;
993993
viewId?: string;
994+
workspaceId?: string;
994995
layout?: ViewLayout;
995996
visibleViewIds?: string[];
996997
extra?: ViewExtra | null;

src/assets/ai.svg

Lines changed: 6 additions & 0 deletions
Loading

src/assets/continue_writing.svg

Lines changed: 9 additions & 0 deletions
Loading

src/assets/improve-writing.svg

Lines changed: 11 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)