Skip to content

Commit 12aa3f2

Browse files
committed
feat: support ai writer
1 parent 04bcc78 commit 12aa3f2

File tree

36 files changed

+710
-153
lines changed

36 files changed

+710
-153
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/database-yjs/__tests__/selector.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ const wrapperCreator =
3535
databaseDoc={doc}
3636
rowDocMap={rowDocMap}
3737
readOnly={true}
38+
workspaceId={''}
3839
>
3940
{children}
4041
</DatabaseContextProvider>

src/application/database-yjs/context.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,15 @@ export interface DatabaseContextState {
2626
navigateToView?: (viewId: string, blockId?: string) => Promise<void>;
2727
onRendered?: (height: number) => void;
2828
showActions?: boolean;
29+
workspaceId: string;
2930
}
3031

3132
export const DatabaseContext = createContext<DatabaseContextState | null>(null);
3233

3334
export const useDatabaseContext = () => {
3435
const context = useContext(DatabaseContext);
3536

36-
if (!context) {
37+
if(!context) {
3738
throw new Error('DatabaseContext is not provided');
3839
}
3940

@@ -89,7 +90,7 @@ export const useDatabaseView = () => {
8990
return viewId ? database?.get(YjsDatabaseKey.views)?.get(viewId) : undefined;
9091
};
9192

92-
export function useDatabaseFields () {
93+
export function useDatabaseFields() {
9394
const database = useDatabase();
9495

9596
return database.get(YjsDatabaseKey.fields);

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: 2 additions & 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;
@@ -1008,6 +1009,7 @@ export interface TextCount {
10081009

10091010
export interface ViewComponentProps {
10101011
doc: YDoc;
1012+
workspaceId: string;
10111013
readOnly: boolean;
10121014
navigateToView?: (viewId: string, blockId?: string) => Promise<void>;
10131015
loadViewMeta?: LoadViewMeta;

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)