Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.
Dart blogconfluence-alternativecontent-managementcontent-servicesdocumentationflutternote-takingnotion-alternativeproject-managementtask-managementteam-collaborationwiki
fix: add sync manager (#6517)
Kilu.He64d71d0d2043
diff --git a/frontend/appflowy_web_app/src/application/services/js-services/http/http_api.ts b/frontend/appflowy_web_app/src/application/services/js-services/http/http_api.tsindex 03c127c951..b2f358365f 100644--- a/frontend/appflowy_web_app/src/application/services/js-services/http/http_api.ts+++ b/frontend/appflowy_web_app/src/application/services/js-services/http/http_api.ts@@ -288,6 +288,24 @@ export async function getPublishViewBlob (namespace: string, publishName: stringreturn blobToBytes(response?.data);}+export async function updateCollab (workspaceId: string, objectId: string, docState: Uint8Array, context: {+ version_vector: number;+}) {+ const url = `/api/workspace/v1/${workspaceId}/collab/${objectId}/web-update`;+ const response = await axiosInstance?.post<{+ code: number;+ message: string;+ }>(url, {+ doc_state: Array.from(docState),+ });++ if (response?.data.code !== 0) {+ return Promise.reject(response?.data);+ }++ return context;+}+export async function getCollab (workspaceId: string, objectId: string, collabType: Types) {const url = `/api/workspace/v1/${workspaceId}/collab/${objectId}`;const response = await axiosInstance?.get<{@@ -1154,4 +1172,50 @@ export async function getActiveSubscription (workspaceId: string) {}return Promise.reject(response?.data);+}++export async function importFile (file: File, onProgress: (progress: number) => void) {+ const url = `/api/import`;++ const fileName = file.name.split('.').slice(0, -1).join('.') || crypto.randomUUID();++ const fileSize = file.size;++ const mimeType = file.type || 'application/octet-stream';++ const validZipTypes = [+ 'application/zip',+ 'application/x-zip',+ 'application/x-zip-compressed',+ 'application/octet-stream',+ ];++ if (!validZipTypes.includes(mimeType) && !file.name.toLowerCase().endsWith('.zip')) {+ throw new Error('Please select a valid ZIP file.');+ }++ const formData = new FormData();++ formData.append(fileName, file, file.name);++ try {+ const response = await axios.post(url, formData, {+ headers: {+ 'Content-Type': 'multipart/form-data',+ 'X-Content-Length': fileSize.toString(),+ },+ onUploadProgress: (progressEvent) => {+ const { progress = 0 } = progressEvent;++ console.log(`Upload progress: ${progress * 100}%`);+ onProgress(progress);+ },+ });++ console.log('Import successful:', response.data);+ return response.data;+ } catch (error) {+ console.error('Error importing file:', error);+ throw error;+ }}\ No newline at end of filediff --git a/frontend/appflowy_web_app/src/application/services/js-services/index.ts b/frontend/appflowy_web_app/src/application/services/js-services/index.tsindex 3c0ea9f5ce..0d04333289 100644--- a/frontend/appflowy_web_app/src/application/services/js-services/index.ts+++ b/frontend/appflowy_web_app/src/application/services/js-services/index.ts@@ -17,6 +17,7 @@ import {fetchViewInfo,} from '@/application/services/js-services/fetch';import { APIService } from '@/application/services/js-services/http';+import { SyncManager } from '@/application/services/js-services/sync';import { AFService, AFServiceConfig } from '@/application/services/services.type';import { emit, EventType } from '@/application/session';@@ -457,4 +458,21 @@ export class AFClientService implements AFService {getActiveSubscription (workspaceId: string) {return APIService.getActiveSubscription(workspaceId);}++ registerDocUpdate (doc: Y.Doc, workspaceId: string, objectId: string) {+ const token = getTokenParsed();+ const userId = token?.user.id;++ if (!userId) {+ throw new Error('User not found');+ }++ const sync = new SyncManager(doc, userId, workspaceId, objectId);++ sync.initialize();+ }++ importFile (file: File, onProgress: (progress: number) => void) {+ return APIService.importFile(file, onProgress);+ }}diff --git a/frontend/appflowy_web_app/src/application/services/js-services/sync.ts b/frontend/appflowy_web_app/src/application/services/js-services/sync.tsnew file mode 100644index 0000000000..d39d2640fb--- /dev/null+++ b/frontend/appflowy_web_app/src/application/services/js-services/sync.ts@@ -0,0 +1,135 @@+import { updateCollab } from '@/application/services/js-services/http/http_api';+import { CollabOrigin } from '@/application/types';+import { debounce } from 'lodash-es';+import * as Y from 'yjs';++const VERSION_VECTOR_KEY = 'ydoc_version_vector';+const UNSYNCED_FLAG_KEY = 'ydoc_unsynced_changes';+const LAST_SYNCED_AT_KEY = 'ydoc_last_synced_at';++export class SyncManager {++ private versionVector: number;++ private lastSyncedAt: string;++ private hasUnsyncedChanges: boolean = false;++ private isSending = false;++ constructor (private doc: Y.Doc, private uuid: string, private workspaceId: string, private objectId: string) {+ this.versionVector = this.loadVersionVector();+ this.hasUnsyncedChanges = this.loadUnsyncedFlag();+ this.lastSyncedAt = this.loadLastSyncedAt();+ this.setupListener();+ }++ private setupListener () {+ this.doc.on('update', (_update: Uint8Array, origin: CollabOrigin) => {+ if (origin === CollabOrigin.Remote) return;++ this.debouncedSendUpdate();+ });+ }++ private getStorageKey (baseKey: string): string {+ return `${this.uuid}_${baseKey}_${this.workspaceId}_${this.objectId}`;+ }++ private loadVersionVector (): number {+ const storedVector = localStorage.getItem(this.getStorageKey(VERSION_VECTOR_KEY));++ return storedVector ? parseInt(storedVector, 10) : 0;+ }++ private saveVersionVector () {+ localStorage.setItem(this.getStorageKey(VERSION_VECTOR_KEY), this.versionVector.toString());+ }++ private loadUnsyncedFlag (): boolean {+ return localStorage.getItem(this.getStorageKey(UNSYNCED_FLAG_KEY)) === 'true';+ }++ private saveUnsyncedFlag () {+ localStorage.setItem(this.getStorageKey(UNSYNCED_FLAG_KEY), this.hasUnsyncedChanges.toString());+ }++ private loadLastSyncedAt (): string {+ return localStorage.getItem(this.getStorageKey(LAST_SYNCED_AT_KEY)) || '';+ }++ private saveLastSyncedAt () {+ localStorage.setItem(this.getStorageKey(LAST_SYNCED_AT_KEY), this.lastSyncedAt);+ }++ private debouncedSendUpdate = debounce(() => {+ this.hasUnsyncedChanges = true;+ this.saveUnsyncedFlag();++ void this.sendUpdate();+ }, 1000); // 1 second debounce++ private async sendUpdate () {+ if (this.isSending) return;+ this.isSending = true;++ try {+ // Increment version vector before sending+ this.versionVector++;+ this.saveVersionVector();++ const update = Y.encodeStateAsUpdate(this.doc);+ const context = { version_vector: this.versionVector };++ const response = await updateCollab(this.workspaceId, this.objectId, update, context);++ if (response) {+ console.log(`Update sent successfully. Server version: ${response.version_vector}`);++ // Update last synced time+ this.lastSyncedAt = String(Date.now());+ this.saveLastSyncedAt();++ if (response.version_vector === this.versionVector) {+ // Our update was the latest+ this.hasUnsyncedChanges = false;+ this.saveUnsyncedFlag();+ console.log('Local changes fully synced');+ } else {+ // There are still unsynced changes (possibly from other clients)+ this.hasUnsyncedChanges = true;+ this.saveUnsyncedFlag();+ console.log('There are still unsynced changes');+ }+ } else {+ return Promise.reject(response);+ }+ } catch (error) {+ console.error('Failed to send update:', error);+ // Keep the unsynced flag as true+ this.hasUnsyncedChanges = true;+ this.saveUnsyncedFlag();+ } finally {+ this.isSending = false;+ }+ }++ public initialize () {+ if (this.hasUnsyncedChanges) {+ // Send an update if there are unsynced changes+ this.debouncedSendUpdate();+ }+ }++ public getUnsyncedStatus (): boolean {+ return this.hasUnsyncedChanges;+ }++ public getLastSyncedAt (): string {+ return this.lastSyncedAt;+ }++ public getCurrentVersionVector (): number {+ return this.versionVector;+ }+}\ No newline at end of filediff --git a/frontend/appflowy_web_app/src/application/services/services.type.ts b/frontend/appflowy_web_app/src/application/services/services.type.tsindex 8581d0398b..282915d84d 100644--- a/frontend/appflowy_web_app/src/application/services/services.type.ts+++ b/frontend/appflowy_web_app/src/application/services/services.type.ts@@ -64,6 +64,8 @@ export interface AppService {getSubscriptionLink: (workspaceId: string, plan: SubscriptionPlan, interval: SubscriptionInterval) => Promise<string>;getSubscriptions: () => Promise<Subscriptions>;getActiveSubscription: (workspaceId: string) => Promise<SubscriptionPlan[]>;+ registerDocUpdate: (doc: YDoc, workspaceId: string, objectId: string) => void;+ importFile: (file: File, onProgress: (progress: number) => void) => Promise<void>;}export interface TemplateService {diff --git a/frontend/appflowy_web_app/src/application/services/tauri-services/index.ts b/frontend/appflowy_web_app/src/application/services/tauri-services/index.tsindex 43497c4fb9..c0a4d8e220 100644--- a/frontend/appflowy_web_app/src/application/services/tauri-services/index.ts+++ b/frontend/appflowy_web_app/src/application/services/tauri-services/index.ts@@ -257,4 +257,12 @@ export class AFClientService implements AFService {getActiveSubscription (_workspaceId: string): Promise<SubscriptionPlan[]> {return Promise.reject('Method not implemented');}++ registerDocUpdate (_doc: YDoc, _workspaceId: string, _objectId: string): void {+ throw new Error('Method not implemented.');+ }++ importFile (_file: File, _onProgress: (progress: number) => void) {+ return Promise.reject('Method not implemented');+ }}diff --git a/frontend/appflowy_web_app/src/application/slate-yjs/command/index.ts b/frontend/appflowy_web_app/src/application/slate-yjs/command/index.tsindex 6336ed2165..006266dcbb 100644--- a/frontend/appflowy_web_app/src/application/slate-yjs/command/index.ts+++ b/frontend/appflowy_web_app/src/application/slate-yjs/command/index.ts@@ -5,7 +5,7 @@ import {executeOperations,getBlock,getBlockEntry,- getSelectionOrThrow,+ getSelectionOrThrow, getSelectionTexts,getSharedRoot,handleCollapsedBreakWithTxn,handleDeleteEntireDocumentWithTxn,@@ -33,14 +33,6 @@ import { BasePoint, BaseRange, Editor, Element, Node, NodeEntry, Path, Range, Teimport { ReactEditor } from 'slate-react';export const CustomEditor = {- findTextNode (editor: ReactEditor, path: number[]): NodeEntry<Element> {- const [node] = editor.nodes({- at: path,- match: (n) => !Editor.isEditor(n) && Element.isElement(n) && n.textId !== undefined,- });-- return node as NodeEntry<Element>;- },// Get the text content of a block node, including the text content of its children and formula nodesgetBlockTextContent (node: Node): string {if (Text.isText(node)) {@@ -236,7 +228,7 @@ export const CustomEditor = {}: {key: EditorMarkFormat, value: boolean | string}) {- if (editor.marks && Object.keys(editor.marks).includes(key)) {+ if (CustomEditor.isMarkActive(editor, key)) {editor.removeMark(key);} else {editor.addMark(key, value);@@ -251,6 +243,10 @@ export const CustomEditor = {editor.addMark(key, value);},+ removeMark (editor: ReactEditor, key: EditorMarkFormat) {+ editor.removeMark(key);+ },+turnToBlock<T extends BlockData> (editor: YjsEditor, blockId: string, type: BlockType, data: T) {const operations: (() => void)[] = [];const sharedRoot = getSharedRoot(editor);@@ -268,4 +264,62 @@ export const CustomEditor = {executeOperations(sharedRoot, operations, 'turnToBlock');},++ isBlockActive (editor: YjsEditor, type: BlockType) {+ try {+ const [node] = getBlockEntry(editor);++ return node.type === type;+ } catch (e) {+ return false;+ }+ },++ hasMark (editor: ReactEditor, key: string) {+ const selection = editor.selection;++ if (!selection) return false;++ const isExpanded = Range.isExpanded(selection);++ if (isExpanded) {++ const texts = getSelectionTexts(editor);++ return texts.some((node) => {+ const { text, ...attributes } = node;++ if (!text) return true;+ return Boolean((attributes as Record<string, boolean | string>)[key]);+ });+ }++ const marks = Editor.marks(editor) as Record<string, string | boolean> | null;++ return marks ? !!marks[key] : false;+ },++ isMarkActive (editor: ReactEditor, key: string) {+ const selection = editor.selection;++ if (!selection) return false;++ const isExpanded = Range.isExpanded(selection);++ if (isExpanded) {++ const texts = getSelectionTexts(editor);++ return texts.every((node) => {+ const { text, ...attributes } = node;++ if (!text) return true;+ return Boolean((attributes as Record<string, boolean | string>)[key]);+ });+ }++ const marks = Editor.marks(editor) as Record<string, string | boolean> | null;++ return marks ? !!marks[key] : false;+ },};diff --git a/frontend/appflowy_web_app/src/application/slate-yjs/utils/applyToYjs.ts b/frontend/appflowy_web_app/src/application/slate-yjs/utils/applyToYjs.tsindex ff207a5950..b475e569d6 100644--- a/frontend/appflowy_web_app/src/application/slate-yjs/utils/applyToYjs.ts+++ b/frontend/appflowy_web_app/src/application/slate-yjs/utils/applyToYjs.ts@@ -79,13 +79,13 @@ function insertText (ydoc: Y.Doc, editor: Editor, { path, offset, text, attributif ('formula' in beforeAttributes) {Object.assign({- formula: undefined,+ formula: null,});}if ('mention' in beforeAttributes) {Object.assign({- mention: undefined,+ mention: null,});}@@ -138,12 +138,11 @@ function applyRemoveText (ydoc: Y.Doc, editor: Editor, op: RemoveTextOperation,}function applySetNode (ydoc: Y.Doc, editor: Editor, op: SetNodeOperation, slateContent: Descendant[]) {- const { newProperties, path } = op;+ const { newProperties, path, properties } = op;const leafKeys = Object.values(EditorMarkFormat) as string[];- const properties = Object.keys(newProperties);- const isLeaf = properties.some((prop: string) => leafKeys.includes(prop));- const isData = properties.some((prop: string) => prop === 'data');+ const isLeaf = Object.keys(newProperties).some((prop: string) => leafKeys.includes(prop)) || (Object.keys(newProperties).length === 0 && Object.keys(properties).some((prop: string) => leafKeys.includes(prop)));+ const isData = Object.keys(newProperties).some((prop: string) => prop === 'data');const sharedRoot = ydoc.getMap(YjsEditorKey.data_section) as YSharedRoot;console.log('applySetNode isLeaf', isLeaf, op);@@ -154,14 +153,32 @@ function applySetNode (ydoc: Y.Doc, editor: Editor, op: SetNodeOperation, slateCif (!textId) return;const yText = getText(textId, sharedRoot);- const [start, end] = Editor.edges(editor, path);+ const start = {+ path,+ offset: 0,+ };+ const end = {+ path,+ offset: (getNodeAtPath(slateContent, path) as Text).text.length,+ };const startRelativeOffset = Math.min(calculateOffsetRelativeToParent(node, start), yText.toJSON().length);const endRelativeOffset = Math.min(calculateOffsetRelativeToParent(node, end), yText.toJSON().length);const length = endRelativeOffset - startRelativeOffset;- yText.format(startRelativeOffset, length, newProperties);+ // eslint-disable-next-line @typescript-eslint/no-explicit-any+ const formats: Record<string, any> = {+ ...newProperties,+ };++ Object.entries(properties).forEach(([key, val]) => {+ if (val && !(key in newProperties)) {+ formats[key] = null;+ }+ });++ yText.format(startRelativeOffset, length, formats);return;}diff --git a/frontend/appflowy_web_app/src/application/slate-yjs/utils/positions.ts b/frontend/appflowy_web_app/src/application/slate-yjs/utils/positions.tsindex f6cc92c897..9dda8afaef 100644--- a/frontend/appflowy_web_app/src/application/slate-yjs/utils/positions.ts+++ b/frontend/appflowy_web_app/src/application/slate-yjs/utils/positions.ts@@ -57,7 +57,11 @@ export function slatePointToRelativePosition (const textId = node.textId as string;const ytext = getText(textId, sharedRoot);- const offset = Math.min(calculateOffsetRelativeToParent(node, point), ytext.toJSON().length);+ if (!ytext) {+ throw new Error('YText not found');+ }++ const offset = Math.min(calculateOffsetRelativeToParent(node, point), ytext.length);const relPos = Y.createRelativePositionFromTypeIndex(ytext, offset);@@ -116,7 +120,7 @@ export function relativePositionToSlatePoint (return calculatePointFromParentOffset(node, path, absIndex);}-function calculatePointFromParentOffset (slateNode: Element, path: number[], parentOffset: number): BasePoint {+export function calculatePointFromParentOffset (slateNode: Element, path: number[], parentOffset: number): BasePoint {let remainingOffset = parentOffset;let childIndex = 0;@@ -151,4 +155,5 @@ function calculatePointFromParentOffset (slateNode: Element, path: number[], par}return calculatePointFromParentOffset(childNode, [...path, childIndex], remainingOffset);-}\ No newline at end of file+}+diff --git a/frontend/appflowy_web_app/src/application/slate-yjs/utils/yjsOperations.ts b/frontend/appflowy_web_app/src/application/slate-yjs/utils/yjsOperations.tsindex 4972f5a81d..31dda29c96 100644--- a/frontend/appflowy_web_app/src/application/slate-yjs/utils/yjsOperations.ts+++ b/frontend/appflowy_web_app/src/application/slate-yjs/utils/yjsOperations.ts@@ -15,10 +15,28 @@ import {import { nanoid } from 'nanoid';import Delta, { Op } from 'quill-delta';-import { BaseRange, Descendant, Editor, Element, Node, NodeEntry, Path, Point, Range, Transforms } from 'slate';+import {+ BaseRange,+ Descendant,+ Text,+ Editor,+ Element,+ Node,+ NodeEntry,+ Path,+ Point,+ Range,+ Transforms,+ BasePoint,+} from 'slate';+import { ReactEditor } from 'slate-react';import * as Y from 'yjs';import { YjsEditor } from '../plugins/withYjs';-import { slatePointToRelativePosition } from './positions';+import {+ calculateOffsetRelativeToParent,+ calculatePointFromParentOffset,+ slatePointToRelativePosition,+} from './positions';export function createEmptyDocument () {const doc = new Y.Doc();@@ -1214,4 +1232,82 @@ export function getNodeAtPath (children: Descendant[], path: Path): Descendant |}return currentNode;+}++export function getSelectionTexts (editor: ReactEditor) {+ const selection = editor.selection;++ if (!selection) return [];++ const texts: Text[] = [];++ const isExpanded = Range.isExpanded(selection);++ if (isExpanded) {+ let anchor = Range.start(selection);+ const focus = Range.end(selection);+ const isEnd = Editor.isEnd(editor, anchor, anchor.path);++ if (isEnd) {+ const after = Editor.after(editor, anchor);++ if (after) {+ anchor = after;+ }+ }++ Array.from(+ Editor.nodes(editor, {+ at: {+ anchor,+ focus,+ },+ }),+ ).forEach((match) => {+ const node = match[0] as Element;++ if (Text.isText(node)) {+ texts.push(node);+ } else if (Editor.isInline(editor, node)) {+ texts.push(...(node.children as Text[]));+ }+ });+ }++ return texts;+}++export function getOffsetPointFromSlateRange (editor: YjsEditor, point: BasePoint): { offset: number; textId: string } {++ const [node] = editor.nodes({+ at: point,+ match: (n) => !Editor.isEditor(n) && Element.isElement(n) && n.textId !== undefined,+ });++ if (!node) {+ throw new Error('Node not found');+ }++ const [textNode] = node as NodeEntry<Element>;++ return {+ textId: textNode.textId as string,+ offset: calculateOffsetRelativeToParent(textNode, point),+ };+}++export function getSlatePointFromOffset (editor: YjsEditor, range: { offset: number; textId: string }): BasePoint {+ const [node] = editor.nodes({+ match: (n) => !Editor.isEditor(n) && Element.isElement(n) && n.textId === range.textId,+ });++ if (!node) {+ throw new Error('Node not found');+ }++ const [textNode, path] = node as NodeEntry<Element>;++ const start = calculatePointFromParentOffset(textNode, path, range.offset);++ return start;}\ No newline at end of filediff --git a/frontend/appflowy_web_app/src/assets/bold.svg b/frontend/appflowy_web_app/src/assets/bold.svgnew file mode 100644index 0000000000..5a6b5fad8e--- /dev/null+++ b/frontend/appflowy_web_app/src/assets/bold.svg@@ -0,0 +1,4 @@+<svg width="32" height="32" viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg">+ <path d="M9.60938 7.75073C9.60938 7.4003 9.89346 7.11621 10.2439 7.11621H16.2719C18.9002 7.11621 21.0308 9.24686 21.0308 11.8751C21.0308 13.2224 20.4709 14.4389 19.5712 15.3047C21.1929 16.1521 22.2999 17.8501 22.2999 19.8067C22.2999 22.6102 20.0272 24.8829 17.2237 24.8829H10.2439C9.89346 24.8829 9.60938 24.5988 9.60938 24.2484V7.75073ZM11.3995 14.7305H16.2719C17.8488 14.7305 19.1272 13.4521 19.1272 11.8751C19.1272 10.2982 17.8488 8.90639 16.2719 8.90639H11.3995V14.7305ZM11.3995 16.6341V22.9793H17.2237C18.9758 22.9793 20.3963 21.5589 20.3963 19.8067C20.3963 18.0545 18.9758 16.6341 17.2237 16.6341H11.3995Z"+ fill="currentColor"/>+</svg>\ No newline at end of filediff --git a/frontend/appflowy_web_app/src/assets/bulleted_list.svg b/frontend/appflowy_web_app/src/assets/bulleted_list.svgnew file mode 100644index 0000000000..c771a8698b--- /dev/null+++ b/frontend/appflowy_web_app/src/assets/bulleted_list.svg@@ -0,0 +1,4 @@+<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">+ <path d="M2.99902 6.10352C2.44702 6.10352 1.99902 6.55152 1.99902 7.10352C1.99902 7.65552 2.44702 8.10352 2.99902 8.10352C3.55102 8.10352 3.99902 7.65552 3.99902 7.10352C3.99902 6.55152 3.55102 6.10352 2.99902 6.10352ZM6.99902 6.10352C6.44702 6.10352 5.99902 6.55152 5.99902 7.10352C5.99902 7.65552 6.44702 8.10352 6.99902 8.10352H20.999C21.551 8.10352 21.999 7.65552 21.999 7.10352C21.999 6.55152 21.551 6.10352 20.999 6.10352H6.99902ZM2.99902 11.1035C2.44702 11.1035 1.99902 11.5515 1.99902 12.1035C1.99902 12.6555 2.44702 13.1035 2.99902 13.1035C3.55102 13.1035 3.99902 12.6555 3.99902 12.1035C3.99902 11.5515 3.55102 11.1035 2.99902 11.1035ZM6.99902 11.1035C6.44702 11.1035 5.99902 11.5515 5.99902 12.1035C5.99902 12.6555 6.44702 13.1035 6.99902 13.1035H20.999C21.551 13.1035 21.999 12.6555 21.999 12.1035C21.999 11.5515 21.551 11.1035 20.999 11.1035H6.99902ZM2.99902 16.1035C2.44702 16.1035 1.99902 16.5515 1.99902 17.1035C1.99902 17.6555 2.44702 18.1035 2.99902 18.1035C3.55102 18.1035 3.99902 17.6555 3.99902 17.1035C3.99902 16.5515 3.55102 16.1035 2.99902 16.1035ZM6.99902 16.1035C6.44702 16.1035 5.99902 16.5515 5.99902 17.1035C5.99902 17.6555 6.44702 18.1035 6.99902 18.1035H20.999C21.551 18.1035 21.999 17.6555 21.999 17.1035C21.999 16.5515 21.551 16.1035 20.999 16.1035H6.99902Z"+ fill="currentColor"/>+</svg>diff --git a/frontend/appflowy_web_app/src/assets/color_theme.svg b/frontend/appflowy_web_app/src/assets/color_theme.svgnew file mode 100644index 0000000000..1c28b40592--- /dev/null+++ b/frontend/appflowy_web_app/src/assets/color_theme.svg@@ -0,0 +1,12 @@+<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none">+ <path d="M12 22C6.49 22 2 17.51 2 12C2 6.49 6.49 2 12 2C17.51 2 22 6.04 22 11C22 14.31 19.31 17 16 17H14.23C13.95 17 13.73 17.22 13.73 17.5C13.73 17.62 13.78 17.73 13.86 17.83C14.27 18.3 14.5 18.89 14.5 19.5C14.5 20.88 13.38 22 12 22ZM12 4C7.59 4 4 7.59 4 12C4 16.41 7.59 20 12 20C12.28 20 12.5 19.78 12.5 19.5C12.5 19.34 12.42 19.22 12.36 19.15C11.95 18.69 11.73 18.1 11.73 17.5C11.73 16.12 12.85 15 14.23 15H16C18.21 15 20 13.21 20 11C20 7.14 16.41 4 12 4Z"+ fill="currentColor"/>+ <path d="M6.5 13C7.32843 13 8 12.3284 8 11.5C8 10.6716 7.32843 10 6.5 10C5.67157 10 5 10.6716 5 11.5C5 12.3284 5.67157 13 6.5 13Z"+ fill="currentColor"/>+ <path d="M9.5 9C10.3284 9 11 8.32843 11 7.5C11 6.67157 10.3284 6 9.5 6C8.67157 6 8 6.67157 8 7.5C8 8.32843 8.67157 9 9.5 9Z"+ fill="currentColor"/>+ <path d="M14.5 9C15.3284 9 16 8.32843 16 7.5C16 6.67157 15.3284 6 14.5 6C13.6716 6 13 6.67157 13 7.5C13 8.32843 13.6716 9 14.5 9Z"+ fill="currentColor"/>+ <path d="M17.5 13C18.3284 13 19 12.3284 19 11.5C19 10.6716 18.3284 10 17.5 10C16.6716 10 16 10.6716 16 11.5C16 12.3284 16.6716 13 17.5 13Z"+ fill="currentColor"/>+</svg>\ No newline at end of filediff --git a/frontend/appflowy_web_app/src/assets/h1.svg b/frontend/appflowy_web_app/src/assets/h1.svgnew file mode 100644index 0000000000..a2ef2663ef--- /dev/null+++ b/frontend/appflowy_web_app/src/assets/h1.svg@@ -0,0 +1,6 @@+<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">+ <path d="M8.25368 3.6001H9.63368V12.0001H8.25368V8.3641H4.65368V12.0001H3.27368V3.6001H4.65368V7.0441H8.25368V3.6001Z"+ fill="currentColor"/>+ <path d="M12.0327 6.4001H12.9927V12.0001H11.8887V7.5681L10.8327 7.8641L10.5607 6.9201L12.0327 6.4001Z"+ fill="currentColor"/>+</svg>diff --git a/frontend/appflowy_web_app/src/assets/h2.svg b/frontend/appflowy_web_app/src/assets/h2.svgnew file mode 100644index 0000000000..45e6e008d6--- /dev/null+++ b/frontend/appflowy_web_app/src/assets/h2.svg@@ -0,0 +1,6 @@+<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">+ <path d="M7.67556 3.6001H9.05556V12.0001H7.67556V8.3641H4.07556V12.0001H2.69556V3.6001H4.07556V7.0441H7.67556V3.6001Z"+ fill="currentColor"/>+ <path d="M10.1106 12.0001V11.1761L12.0226 9.2081C12.4493 8.7601 12.6626 8.38676 12.6626 8.0881C12.6626 7.86943 12.5933 7.69343 12.4546 7.5601C12.3213 7.42676 12.148 7.3601 11.9346 7.3601C11.5133 7.3601 11.2013 7.57876 10.9986 8.0161L10.0706 7.4721C10.2466 7.0881 10.5 6.79476 10.8306 6.5921C11.1613 6.38943 11.524 6.2881 11.9186 6.2881C12.4253 6.2881 12.86 6.4481 13.2226 6.7681C13.5853 7.08276 13.7666 7.50943 13.7666 8.0481C13.7666 8.62943 13.46 9.22677 12.8466 9.8401L11.7506 10.9361H13.8546V12.0001H10.1106Z"+ fill="currentColor"/>+</svg>diff --git a/frontend/appflowy_web_app/src/assets/h3.svg b/frontend/appflowy_web_app/src/assets/h3.svgnew file mode 100644index 0000000000..dacaf7f2c7--- /dev/null+++ b/frontend/appflowy_web_app/src/assets/h3.svg@@ -0,0 +1,6 @@+<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">+ <path d="M7.62087 3.6001H9.00087V12.0001H7.62087V8.3641H4.02087V12.0001H2.64087V3.6001H4.02087V7.0441H7.62087V3.6001Z"+ fill="currentColor"/>+ <path d="M12.6639 8.6721C13.0426 8.7841 13.3493 8.98143 13.5839 9.2641C13.8239 9.54143 13.9439 9.87743 13.9439 10.2721C13.9439 10.8481 13.7493 11.2988 13.3599 11.6241C12.9759 11.9494 12.5039 12.1121 11.9439 12.1121C11.5066 12.1121 11.1146 12.0134 10.7679 11.8161C10.4266 11.6134 10.1786 11.3174 10.0239 10.9281L10.9679 10.3841C11.1066 10.8161 11.4319 11.0321 11.9439 11.0321C12.2266 11.0321 12.4453 10.9654 12.5999 10.8321C12.7599 10.6934 12.8399 10.5068 12.8399 10.2721C12.8399 10.0428 12.7599 9.85876 12.5999 9.7201C12.4453 9.58143 12.2266 9.5121 11.9439 9.5121H11.7039L11.2799 8.8721L12.3839 7.4321H10.1919V6.4001H13.7119V7.3121L12.6639 8.6721Z"+ fill="currentColor"/>+</svg>diff --git a/frontend/appflowy_web_app/src/assets/h4.svg b/frontend/appflowy_web_app/src/assets/h4.svgnew file mode 100644index 0000000000..d92eadd984--- /dev/null+++ b/frontend/appflowy_web_app/src/assets/h4.svg@@ -0,0 +1,4 @@+<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">+ <path d="M2.5 2.5V11.5H3.8V7.5H8.2V11.5H9.5V2.5H8.2V6.2H3.8V2.5H2.5Z" fill="currentColor"/>+ <path d="M11.5 8.5V11.5H13.5V5.5H10.5V6.8H12.2V7.2H11.5V8.5ZM11.5 9.8V10.2H12.2V9.8H11.5Z" fill="currentColor"/>+</svg>\ No newline at end of filediff --git a/frontend/appflowy_web_app/src/assets/h5.svg b/frontend/appflowy_web_app/src/assets/h5.svgnew file mode 100644index 0000000000..55194e83e4--- /dev/null+++ b/frontend/appflowy_web_app/src/assets/h5.svg@@ -0,0 +1,5 @@+<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">+ <path d="M2.5 2.5V11.5H3.8V7.5H8.2V11.5H9.5V2.5H8.2V6.2H3.8V2.5H2.5Z" fill="currentColor"/>+ <path d="M11.5 7.2V8.5H12.8C13.1 8.5 13.3 8.6 13.4 8.8C13.5 9 13.5 9.2 13.4 9.4C13.3 9.6 13.1 9.7 12.8 9.7H11.5V11H12.8C13.4 11 13.9 10.8 14.2 10.4C14.5 10 14.6 9.5 14.5 9C14.4 8.5 14.1 8.1 13.7 7.9C13.3 7.7 12.8 7.6 12.2 7.7L13.5 5.5H10.5V6.8H12.2L11.5 7.2Z"+ fill="currentColor"/>+</svg>\ No newline at end of filediff --git a/frontend/appflowy_web_app/src/assets/h6.svg b/frontend/appflowy_web_app/src/assets/h6.svgnew file mode 100644index 0000000000..cf54c189a8--- /dev/null+++ b/frontend/appflowy_web_app/src/assets/h6.svg@@ -0,0 +1,5 @@+<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">+ <path d="M2.5 2.5V11.5H3.8V7.5H8.2V11.5H9.5V2.5H8.2V6.2H3.8V2.5H2.5Z" fill="currentColor"/>+ <path d="M12.8 7.2C12.3 7.2 11.9 7.4 11.6 7.7C11.3 8 11.2 8.4 11.2 8.9V9.7C11.2 10.2 11.3 10.6 11.6 10.9C11.9 11.2 12.3 11.4 12.8 11.4C13.3 11.4 13.7 11.2 14 10.9C14.3 10.6 14.4 10.2 14.4 9.7V8.9C14.4 8.4 14.3 8 14 7.7C13.7 7.4 13.3 7.2 12.8 7.2ZM13.1 9.7C13.1 9.9 13 10.1 12.9 10.2C12.8 10.3 12.6 10.4 12.4 10.4C12.2 10.4 12 10.3 11.9 10.2C11.8 10.1 11.7 9.9 11.7 9.7V8.9C11.7 8.7 11.8 8.5 11.9 8.4C12 8.3 12.2 8.2 12.4 8.2C12.6 8.2 12.8 8.3 12.9 8.4C13 8.5 13.1 8.7 13.1 8.9V9.7ZM12.8 5.5H10.5V6.8H12.8V5.5Z"+ fill="currentColor"/>+</svg>\ No newline at end of filediff --git a/frontend/appflowy_web_app/src/assets/help.svg b/frontend/appflowy_web_app/src/assets/help.svgindex b16340a6cf..4faf4f31c4 100644--- a/frontend/appflowy_web_app/src/assets/help.svg+++ b/frontend/appflowy_web_app/src/assets/help.svg@@ -1,5 +1,5 @@<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M4.55676 4.62532C4.55676 0.243068 11.4431 0.24313 11.4431 4.62532C11.4431 7.75538 8.31295 7.12932 8.31295 10.8854"- stroke="black" stroke-linecap="round" stroke-linejoin="round"/>- <path d="M8.32104 14.6614L8.33023 14.6512" stroke="black" stroke-linecap="round" stroke-linejoin="round"/>+ stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>+ <path d="M8.32104 14.6614L8.33023 14.6512" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/></svg>\ No newline at end of filediff --git a/frontend/appflowy_web_app/src/assets/import.svg b/frontend/appflowy_web_app/src/assets/import.svgnew file mode 100644index 0000000000..f6ad75bb5a--- /dev/null+++ b/frontend/appflowy_web_app/src/assets/import.svg@@ -0,0 +1,6 @@+<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">+ <path d="M13 10L13 12C13 12.2652 12.8829 12.5196 12.6746 12.7071C12.4662 12.8946 12.1836 13 11.8889 13L4.11111 13C3.81643 13 3.53381 12.8946 3.32544 12.7071C3.11706 12.5196 3 12.2652 3 12L3 10"+ stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>+ <path d="M5 6L8 9L11 6" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>+ <path d="M8 3L8 9" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>+</svg>diff --git a/frontend/appflowy_web_app/src/assets/inline_code.svg b/frontend/appflowy_web_app/src/assets/inline_code.svgnew file mode 100644index 0000000000..8ff26b6edf--- /dev/null+++ b/frontend/appflowy_web_app/src/assets/inline_code.svg@@ -0,0 +1,4 @@+<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">+ <path d="M10 4L14 8L10 12" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>+ <path d="M6 4L2 8L6 12" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>+</svg>diff --git a/frontend/appflowy_web_app/src/assets/italic.svg b/frontend/appflowy_web_app/src/assets/italic.svgnew file mode 100644index 0000000000..354e31d153--- /dev/null+++ b/frontend/appflowy_web_app/src/assets/italic.svg@@ -0,0 +1,4 @@+<svg width="32" height="32" viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg">+ <path d="M18.8356 9.3075L15.2901 22.6921H19.2413C19.8005 22.6921 20.2538 23.1415 20.2538 23.696C20.2538 24.2504 19.8005 24.6998 19.2413 24.6998H9.21172C8.65253 24.6998 8.19922 24.2504 8.19922 23.696C8.19922 23.1415 8.65253 22.6921 9.21172 22.6921H13.1629L16.7083 9.3075H12.7572C12.198 9.3075 11.7447 8.85806 11.7447 8.30365C11.7447 7.74924 12.198 7.2998 12.7572 7.2998H22.7867C23.3459 7.2998 23.7992 7.74924 23.7992 8.30365C23.7992 8.85806 23.3459 9.3075 22.7867 9.3075H18.8356Z"+ fill="currentColor"/>+</svg>\ No newline at end of filediff --git a/frontend/appflowy_web_app/src/assets/notion.svg b/frontend/appflowy_web_app/src/assets/notion.svgnew file mode 100644index 0000000000..3688996669--- /dev/null+++ b/frontend/appflowy_web_app/src/assets/notion.svg@@ -0,0 +1,7 @@+<?xml version="1.0" encoding="utf-8"?><!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools -->+<svg width="800px" height="800px" viewBox="0 0 15 15" fill="none" xmlns="http://www.w3.org/2000/svg">+ <path+ d="M3.25781 3.11684C3.67771 3.45796 3.83523 3.43193 4.62369 3.37933L12.0571 2.93299C12.2147 2.93299 12.0836 2.77571 12.0311 2.74957L10.7965 1.85711C10.56 1.67347 10.2448 1.46315 9.64083 1.51576L2.44308 2.04074C2.18059 2.06677 2.12815 2.19801 2.2327 2.30322L3.25781 3.11684ZM3.7041 4.84917V12.6704C3.7041 13.0907 3.91415 13.248 4.38693 13.222L12.5562 12.7493C13.0292 12.7233 13.0819 12.4341 13.0819 12.0927V4.32397C13.0819 3.98306 12.9508 3.79921 12.6612 3.82545L4.12422 4.32397C3.80918 4.35044 3.7041 4.50803 3.7041 4.84917ZM11.7688 5.26872C11.8212 5.50518 11.7688 5.74142 11.5319 5.76799L11.1383 5.84641V11.6205C10.7965 11.8042 10.4814 11.9092 10.2188 11.9092C9.79835 11.9092 9.69305 11.7779 9.37812 11.3844L6.80345 7.34249V11.2532L7.61816 11.437C7.61816 11.437 7.61816 11.9092 6.96086 11.9092L5.14879 12.0143C5.09615 11.9092 5.14879 11.647 5.33259 11.5944L5.80546 11.4634V6.29276L5.1489 6.24015C5.09625 6.00369 5.22739 5.66278 5.5954 5.63631L7.53935 5.50528L10.2188 9.5998V5.97765L9.53564 5.89924C9.4832 5.61018 9.69305 5.40028 9.95576 5.37425L11.7688 5.26872ZM1.83874 1.33212L9.32557 0.780787C10.245 0.701932 10.4815 0.754753 11.0594 1.17452L13.4492 2.85424C13.8436 3.14309 13.975 3.22173 13.975 3.53661V12.7493C13.975 13.3266 13.7647 13.6681 13.0293 13.7203L4.33492 14.2454C3.78291 14.2717 3.52019 14.193 3.23111 13.8253L1.47116 11.5419C1.1558 11.1216 1.02466 10.8071 1.02466 10.4392V2.25041C1.02466 1.77825 1.23504 1.38441 1.83874 1.33212Z"+ fill="currentColor"+ />+</svg>\ No newline at end of filediff --git a/frontend/appflowy_web_app/src/assets/numbered_list.svg b/frontend/appflowy_web_app/src/assets/numbered_list.svgnew file mode 100644index 0000000000..f22c786307--- /dev/null+++ b/frontend/appflowy_web_app/src/assets/numbered_list.svg@@ -0,0 +1,4 @@+<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">+ <path d="M2.201 6.4H3.001V12H2.081V7.384L0.953 7.704L0.729 6.92L2.201 6.4ZM3.91156 12V11.1L6.35156 8.61C6.9449 8.01667 7.24156 7.50333 7.24156 7.07C7.24156 6.73 7.13823 6.46667 6.93156 6.28C6.73156 6.08667 6.4749 5.99 6.16156 5.99C5.5749 5.99 5.14156 6.28 4.86156 6.86L3.89156 6.29C4.11156 5.82333 4.42156 5.47 4.82156 5.23C5.22156 4.99 5.6649 4.87 6.15156 4.87C6.7649 4.87 7.29156 5.06333 7.73156 5.45C8.17156 5.83667 8.39156 6.36333 8.39156 7.03C8.39156 7.74333 7.9949 8.50333 7.20156 9.31L5.62156 10.89H8.52156V12H3.91156ZM12.9025 7.032C13.5105 7.176 14.0025 7.46 14.3785 7.884C14.7625 8.3 14.9545 8.824 14.9545 9.456C14.9545 10.296 14.6705 10.956 14.1025 11.436C13.5345 11.916 12.8385 12.156 12.0145 12.156C11.3745 12.156 10.7985 12.008 10.2865 11.712C9.78253 11.416 9.41853 10.984 9.19453 10.416L10.3705 9.732C10.6185 10.452 11.1665 10.812 12.0145 10.812C12.4945 10.812 12.8745 10.692 13.1545 10.452C13.4345 10.204 13.5745 9.872 13.5745 9.456C13.5745 9.04 13.4345 8.712 13.1545 8.472C12.8745 8.232 12.4945 8.112 12.0145 8.112H11.7025L11.1505 7.284L12.9625 4.896H9.44653V3.6H14.6065V4.776L12.9025 7.032Z"+ fill="currentColor"/>+</svg>\ No newline at end of filediff --git a/frontend/appflowy_web_app/src/assets/paragraph.svg b/frontend/appflowy_web_app/src/assets/paragraph.svgnew file mode 100644index 0000000000..6bf1ab7e47--- /dev/null+++ b/frontend/appflowy_web_app/src/assets/paragraph.svg@@ -0,0 +1,6 @@+<svg width="32" height="32" viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg">+ <path d="M10.947 8.072L16.597 23.503H14.589L13.36 20.058L13.343 20.01H13.292H6.409H6.358L6.341 20.058L5.112 23.503H3.104L8.754 8.072H10.947ZM7.04 18.122L7.006 18.219H7.108H12.593H12.696L12.661 18.122L9.908 10.445L9.839 10.255L9.771 10.446L7.04 18.122ZM22.969 23.792C21.46 23.792 20.175 23.237 19.11 22.124C18.045 20.996 17.513 19.627 17.513 18.013C17.513 16.399 18.046 15.037 19.11 13.924C20.175 12.796 21.46 12.233 22.969 12.233C24.752 12.233 26.105 12.956 27.038 14.403L27.171 14.609V14.364V12.522H28.928V23.503H27.171V21.662V21.416L27.038 21.622C26.105 23.07 24.752 23.792 22.969 23.792ZM26.036 20.911C26.793 20.125 27.171 19.158 27.171 18.013C27.171 16.868 26.793 15.907 26.036 15.136C25.279 14.351 24.335 13.958 23.209 13.958C22.098 13.958 21.161 14.351 20.404 15.136C19.647 15.907 19.269 16.868 19.269 18.013C19.269 19.158 19.647 20.125 20.404 20.911C21.162 21.682 22.098 22.068 23.209 22.068C24.335 22.068 25.279 21.682 26.036 20.911Z"+ fill="currentColor"/>+ <path d="M10.947 8.072L16.597 23.503H14.589L13.36 20.058L13.343 20.01H13.292H6.409H6.358L6.341 20.058L5.112 23.503H3.104L8.754 8.072H10.947ZM7.04 18.122L7.006 18.219H7.108H12.593H12.696L12.661 18.122L9.908 10.445L9.839 10.255L9.771 10.446L7.04 18.122ZM22.969 23.792C21.46 23.792 20.175 23.237 19.11 22.124C18.045 20.996 17.513 19.627 17.513 18.013C17.513 16.399 18.046 15.037 19.11 13.924C20.175 12.796 21.46 12.233 22.969 12.233C24.752 12.233 26.105 12.956 27.038 14.403L27.171 14.609V14.364V12.522H28.928V23.503H27.171V21.662V21.416L27.038 21.622C26.105 23.07 24.752 23.792 22.969 23.792ZM26.036 20.911C26.793 20.125 27.171 19.158 27.171 18.013C27.171 16.868 26.793 15.907 26.036 15.136C25.279 14.351 24.335 13.958 23.209 13.958C22.098 13.958 21.161 14.351 20.404 15.136C19.647 15.907 19.269 16.868 19.269 18.013C19.269 19.158 19.647 20.125 20.404 20.911C21.162 21.682 22.098 22.068 23.209 22.068C24.335 22.068 25.279 21.682 26.036 20.911Z"+ stroke="currentColor" stroke-width="0.15"/>+</svg>\ No newline at end of filediff --git a/frontend/appflowy_web_app/src/assets/quote.svg b/frontend/appflowy_web_app/src/assets/quote.svgnew file mode 100644index 0000000000..57839231ff--- /dev/null+++ b/frontend/appflowy_web_app/src/assets/quote.svg@@ -0,0 +1,4 @@+<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">+<path fill-rule="evenodd" clip-rule="evenodd" d="M12.4742 9.35161C12.8007 8.99566 13 8.52111 13 8C13 6.89543 12.1046 6 11 6C9.89543 6 9 6.89543 9 8C9 9.04413 9.80011 9.90137 10.8207 9.99207L10.0124 11.1682L10.8365 11.7346L12.4742 9.35161Z" fill="#333333"/>+<path fill-rule="evenodd" clip-rule="evenodd" d="M6.47395 7.35186C6.80061 6.99588 7 6.52123 7 6C7 4.89543 6.10457 4 5 4C3.89543 4 3 4.89543 3 6C3 7.04411 3.80008 7.90134 4.82061 7.99206L4.01231 9.16823L4.83645 9.73461L6.47395 7.35186Z" fill="#333333"/>+</svg>diff --git a/frontend/appflowy_web_app/src/assets/strikethrough.svg b/frontend/appflowy_web_app/src/assets/strikethrough.svgnew file mode 100644index 0000000000..458dde7043--- /dev/null+++ b/frontend/appflowy_web_app/src/assets/strikethrough.svg@@ -0,0 +1,6 @@+<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">+ <path fill-rule="evenodd" clip-rule="evenodd"+ d="M7.99994 3C6.78324 3 5.57768 3.89295 5.26683 5.05868C5.14348 5.52122 5.16418 6.01807 5.36988 6.5H6.53454C6.50039 6.45893 6.46931 6.41816 6.44111 6.37779C6.18329 6.00862 6.14534 5.64531 6.23306 5.31634C6.4222 4.60706 7.21665 4 7.99994 4C8.69325 4 9.21448 4.21587 9.55371 4.46532C9.7248 4.59113 9.84481 4.72187 9.91824 4.83203C9.98388 4.93049 9.99678 4.98806 9.99929 4.99927C9.99983 5.00168 9.99989 5.00194 9.99989 5H10.9999C10.9999 4.73903 10.8893 4.4858 10.7503 4.27735C10.605 4.05938 10.4 3.84637 10.1461 3.65968C9.63538 3.28413 8.90664 3 7.99994 3ZM10.63 9.5H9.4653C9.49948 9.54108 9.53057 9.58188 9.55877 9.62226C9.8166 9.99142 9.85455 10.3547 9.76683 10.6837C9.57769 11.393 8.78324 12 7.99994 12C7.30664 12 6.78541 11.7842 6.44617 11.5347C6.27508 11.4089 6.15508 11.2781 6.08165 11.168C6.01601 11.0695 6.00311 11.012 6.0006 11.0008C6.00006 10.9983 6 10.9981 6 11H5C5 11.261 5.11062 11.5142 5.24958 11.7227C5.39489 11.9406 5.59988 12.1537 5.85377 12.3403C6.36451 12.7159 7.09325 13 7.99994 13C9.21665 13 10.4222 12.1071 10.7331 10.9414C10.8564 10.4788 10.8357 9.98194 10.63 9.5Z"+ fill="currentColor"/>+ <rect width="8" height="1" transform="matrix(1 0 0 -1 4 8.5)" fill="currentColor"/>+</svg>diff --git a/frontend/appflowy_web_app/src/assets/toolbar_align_center.svg b/frontend/appflowy_web_app/src/assets/toolbar_align_center.svgnew file mode 100644index 0000000000..8ef8320859--- /dev/null+++ b/frontend/appflowy_web_app/src/assets/toolbar_align_center.svg@@ -0,0 +1,5 @@+<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">+ <path d="M4 4L12 4" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>+ <path d="M5 8H11" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>+ <path d="M4 12L12 12" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>+</svg>diff --git a/frontend/appflowy_web_app/src/assets/toolbar_align_left.svg b/frontend/appflowy_web_app/src/assets/toolbar_align_left.svgnew file mode 100644index 0000000000..50e0a516be--- /dev/null+++ b/frontend/appflowy_web_app/src/assets/toolbar_align_left.svg@@ -0,0 +1,5 @@+<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">+ <path d="M4 4L12 4" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>+ <path d="M4 8H10" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>+ <path d="M4 12L12 12" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>+</svg>diff --git a/frontend/appflowy_web_app/src/assets/toolbar_align_right.svg b/frontend/appflowy_web_app/src/assets/toolbar_align_right.svgnew file mode 100644index 0000000000..792893bc02--- /dev/null+++ b/frontend/appflowy_web_app/src/assets/toolbar_align_right.svg@@ -0,0 +1,5 @@+<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">+ <path d="M4 4L12 4" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>+ <path d="M6 8H12" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>+ <path d="M4 12L12 12" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>+</svg>diff --git a/frontend/appflowy_web_app/src/assets/underline.svg b/frontend/appflowy_web_app/src/assets/underline.svgnew file mode 100644index 0000000000..0adef1fedf--- /dev/null+++ b/frontend/appflowy_web_app/src/assets/underline.svg@@ -0,0 +1,4 @@+<svg width="32" height="32" viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg">+ <path d="M12.0755 8.01775C12.0755 7.51984 11.6818 7.11621 11.1908 7.11621C10.6998 7.11621 10.2975 7.51985 10.2975 8.01775V13.2467C10.2975 17.0597 12.6237 19.858 16.2242 19.858C19.8248 19.858 22.1509 17.0597 22.1509 13.2467V8.01785C22.1509 7.51992 21.7511 7.11634 21.2601 7.11626C20.7691 7.11618 20.3729 7.51979 20.3729 8.01765V13.2467C20.3729 15.9703 18.796 18.0549 16.2242 18.0549C13.6524 18.0549 12.0755 15.9703 12.0755 13.2467V8.01775ZM8.22299 22.8631C7.73201 22.8631 7.33398 23.2608 7.33398 23.7587C7.33398 24.2566 7.732 24.6662 8.22299 24.6662H24.2251C24.7161 24.6662 25.1141 24.255 25.1141 23.7571C25.1141 23.2592 24.7161 22.8631 24.2251 22.8631H8.22299Z"+ fill="currentColor"/>+</svg>\ No newline at end of filediff --git a/frontend/appflowy_web_app/src/components/_shared/color-picker/ColorPicker.tsx b/frontend/appflowy_web_app/src/components/_shared/color-picker/ColorPicker.tsxnew file mode 100644index 0000000000..050b836b87--- /dev/null+++ b/frontend/appflowy_web_app/src/components/_shared/color-picker/ColorPicker.tsx@@ -0,0 +1,183 @@+import { EditorMarkFormat } from '@/application/slate-yjs/types';+import KeyboardNavigation from '@/components/_shared/keyboard_navigation/KeyboardNavigation';+import { ColorEnum, renderColor } from '@/utils/color';+import React, { useCallback, useRef, useMemo } from 'react';+import Typography from '@mui/material/Typography';++import { useTranslation } from 'react-i18next';+import { TitleOutlined } from '@mui/icons-material';++export interface ColorPickerProps {+ onChange?: (format: EditorMarkFormat.FontColor | EditorMarkFormat.BgColor, color: string) => void;+ onEscape?: () => void;+ disableFocus?: boolean;+}++export function ColorPicker ({ onEscape, onChange, disableFocus }: ColorPickerProps) {+ const { t } = useTranslation();++ const ref = useRef<HTMLDivElement>(null);++ const handleColorChange = useCallback(+ (key: string) => {+ const [format, , color = ''] = key.split('-');+ const formatKey = format === 'font' ? EditorMarkFormat.FontColor : EditorMarkFormat.BgColor;++ onChange?.(formatKey, color);+ },+ [onChange],+ );++ const renderColorItem = useCallback(+ (name: string, color: string, backgroundColor?: string) => {+ return (+ <div+ key={name}+ onClick={() => {+ handleColorChange(backgroundColor ? backgroundColor : color);+ }}+ className={'flex w-full cursor-pointer items-center justify-center gap-2'}+ >+ <div+ style={{+ backgroundColor: backgroundColor ? renderColor(backgroundColor) : 'transparent',+ color: color === '' ? 'var(--text-title)' : renderColor(color),+ }}+ className={'flex h-5 w-5 items-center justify-center rounded border border-line-divider'}+ >+ <TitleOutlined className={'h-4 w-4'} />+ </div>+ <div className={'flex-1 text-xs text-text-title'}>{name}</div>+ </div>+ );+ },+ [handleColorChange],+ );++ const colors = useMemo(() => {+ return [+ {+ key: 'font_color',+ content: (+ <Typography+ className={'px-3 pb-1 pt-3 text-text-caption'}+ variant="subtitle2"+ >+ {t('editor.textColor')}+ </Typography>+ ),+ children: [+ {+ key: 'font-default',+ content: renderColorItem(t('editor.fontColorDefault'), ''),+ },+ {+ key: `font-gray-rgb(120, 119, 116)`,+ content: renderColorItem(t('editor.fontColorGray'), 'rgb(120, 119, 116)'),+ },+ {+ key: 'font-brown-rgb(159, 107, 83)',+ content: renderColorItem(t('editor.fontColorBrown'), 'rgb(159, 107, 83)'),+ },+ {+ key: 'font-orange-rgb(217, 115, 13)',+ content: renderColorItem(t('editor.fontColorOrange'), 'rgb(217, 115, 13)'),+ },+ {+ key: 'font-yellow-rgb(203, 145, 47)',+ content: renderColorItem(t('editor.fontColorYellow'), 'rgb(203, 145, 47)'),+ },+ {+ key: 'font-green-rgb(68, 131, 97)',+ content: renderColorItem(t('editor.fontColorGreen'), 'rgb(68, 131, 97)'),+ },+ {+ key: 'font-blue-rgb(51, 126, 169)',+ content: renderColorItem(t('editor.fontColorBlue'), 'rgb(51, 126, 169)'),+ },+ {+ key: 'font-purple-rgb(144, 101, 176)',+ content: renderColorItem(t('editor.fontColorPurple'), 'rgb(144, 101, 176)'),+ },+ {+ key: 'font-pink-rgb(193, 76, 138)',+ content: renderColorItem(t('editor.fontColorPink'), 'rgb(193, 76, 138)'),+ },+ {+ key: 'font-red-rgb(212, 76, 71)',+ content: renderColorItem(t('editor.fontColorRed'), 'rgb(212, 76, 71)'),+ },+ ],+ },+ {+ key: 'bg_color',+ content: (+ <Typography+ className={'px-3 pb-1 pt-3 text-text-caption'}+ variant="subtitle2"+ >+ {t('editor.backgroundColor')}+ </Typography>+ ),+ children: [+ {+ key: 'bg-default',+ content: renderColorItem(t('editor.backgroundColorDefault'), '', ''),+ },+ {+ key: `bg-lime-${ColorEnum.Lime}`,+ content: renderColorItem(t('editor.backgroundColorLime'), '', ColorEnum.Lime),+ },+ {+ key: `bg-aqua-${ColorEnum.Aqua}`,+ content: renderColorItem(t('editor.backgroundColorAqua'), '', ColorEnum.Aqua),+ },+ {+ key: `bg-orange-${ColorEnum.Orange}`,+ content: renderColorItem(t('editor.backgroundColorOrange'), '', ColorEnum.Orange),+ },+ {+ key: `bg-yellow-${ColorEnum.Yellow}`,+ content: renderColorItem(t('editor.backgroundColorYellow'), '', ColorEnum.Yellow),+ },+ {+ key: `bg-green-${ColorEnum.Green}`,+ content: renderColorItem(t('editor.backgroundColorGreen'), '', ColorEnum.Green),+ },+ {+ key: `bg-blue-${ColorEnum.Blue}`,+ content: renderColorItem(t('editor.backgroundColorBlue'), '', ColorEnum.Blue),+ },+ {+ key: `bg-purple-${ColorEnum.Purple}`,+ content: renderColorItem(t('editor.backgroundColorPurple'), '', ColorEnum.Purple),+ },+ {+ key: `bg-pink-${ColorEnum.Pink}`,+ content: renderColorItem(t('editor.backgroundColorPink'), '', ColorEnum.Pink),+ },+ {+ key: `bg-red-${ColorEnum.LightPink}`,+ content: renderColorItem(t('editor.backgroundColorRed'), '', ColorEnum.LightPink),+ },+ ],+ },+ ];+ }, [renderColorItem, t]);++ return (+ <div+ ref={ref}+ className={'flex h-full max-h-[420px] appflowy-scroller w-full flex-col overflow-y-auto'}+ >+ <KeyboardNavigation+ disableFocus={disableFocus}+ onPressLeft={onEscape}+ scrollRef={ref}+ options={colors}+ onConfirm={handleColorChange}+ onEscape={onEscape}+ />+ </div>+ );+}diff --git a/frontend/appflowy_web_app/src/components/_shared/color-picker/index.ts b/frontend/appflowy_web_app/src/components/_shared/color-picker/index.tsnew file mode 100644index 0000000000..e305fd3f05--- /dev/null+++ b/frontend/appflowy_web_app/src/components/_shared/color-picker/index.ts@@ -0,0 +1 @@+export * from './ColorPicker';\ No newline at end of filediff --git a/frontend/appflowy_web_app/src/components/_shared/file-dropzone/FileDropzone.tsx b/frontend/appflowy_web_app/src/components/_shared/file-dropzone/FileDropzone.tsxindex 9e58f276d7..8bbf938a2b 100644--- a/frontend/appflowy_web_app/src/components/_shared/file-dropzone/FileDropzone.tsx+++ b/frontend/appflowy_web_app/src/components/_shared/file-dropzone/FileDropzone.tsx@@ -8,12 +8,14 @@ interface FileDropzoneProps {onChange?: (files: File[]) => void;accept?: string;multiple?: boolean;+ disabled?: boolean;}function FileDropzone ({onChange,accept,multiple,+ disabled,}: FileDropzoneProps) {const { t } = useTranslation();const [dragging, setDragging] = useState(false);@@ -76,6 +78,8 @@ function FileDropzone ({style={{borderColor: dragging ? 'var(--fill-active)' : undefined,backgroundColor: dragging ? 'var(--fill-active)' : undefined,+ pointerEvents: disabled ? 'none' : undefined,+ cursor: disabled ? 'not-allowed' : undefined,}}><div className={'flex flex-col items-center justify-center gap-4 h-full'}>@@ -86,6 +90,7 @@ function FileDropzone ({</div><inputtype="file"+ disabled={disabled}ref={fileInputRef}style={{ display: 'none' }}accept={accept}diff --git a/frontend/appflowy_web_app/src/components/_shared/help/Help.tsx b/frontend/appflowy_web_app/src/components/_shared/help/Help.tsxindex b7c46fab01..f0caf724b1 100644--- a/frontend/appflowy_web_app/src/components/_shared/help/Help.tsx+++ b/frontend/appflowy_web_app/src/components/_shared/help/Help.tsx@@ -30,24 +30,32 @@ export default function Help () {return (<Portal>- <Box className={'fixed bottom-6 right-6'} sx={{ transform: 'translateZ(0px)', flexGrow: 1 }}>+ <Box+ className={'fixed bottom-6 right-6'}+ sx={{ transform: 'translateZ(0px)', flexGrow: 1 }}+ ><Tooltip title={t('questionBubble.help')}><divref={ref}onClick={() => setOpen(!open)}- className={'w-9 h-9 rounded-full flex items-center justify-center border border-line-divider bg-bg-body hover:bg-fill-list-hover cursor-pointer shadow'}+ className={'w-9 h-9 rounded-full flex items-center justify-center border border-line-border bg-bg-body hover:bg-fill-list-hover cursor-pointer shadow-md'}><SpeedDialIcon className={'w-4 h-4'} /></div></Tooltip>- <Popover {...popoverProps} open={open} anchorEl={ref.current} onClose={() => setOpen(false)}>+ <Popover {...popoverProps} open={open}+ anchorEl={ref.current}+ onClose={() => setOpen(false)}+ ><div className={'flex flex-col gap-1 w-[240px] h-fit p-2'}><Buttoncomponent={'a'}target="_blank"href={'https://www.appflowy.io/what-is-new'}className={'justify-start'}- color={'inherit'} startIcon={<WhatsNewIcon />} variant={'text'}+ color={'inherit'}+ startIcon={<WhatsNewIcon />}+ variant={'text'}>{t('questionBubble.whatsNew')}</Button><Button@@ -55,7 +63,9 @@ export default function Help () {href={'https://discord.gg/9Q2xaN37tV'}className={'justify-start'}target="_blank"- color={'inherit'} startIcon={<SupportIcon />} variant={'text'}+ color={'inherit'}+ startIcon={<SupportIcon />}+ variant={'text'}>{t('questionBubble.help')}</Button><Button@@ -71,7 +81,9 @@ export default function Help () {notify.success(t('questionBubble.debug.success'));}}className={'justify-start'}- color={'inherit'} startIcon={<DebugIcon />} variant={'text'}+ color={'inherit'}+ startIcon={<DebugIcon />}+ variant={'text'}>{t('questionBubble.debug.name')}</Button><Button@@ -79,7 +91,9 @@ export default function Help () {target="_blank"href={'https://github.com/AppFlowy-IO/AppFlowy/issues/new/choose'}className={'justify-start'}- color={'inherit'} startIcon={<FeedbackIcon />} variant={'text'}+ color={'inherit'}+ startIcon={<FeedbackIcon />}+ variant={'text'}>{t('questionBubble.feedback')}</Button><Divider />@@ -89,7 +103,8 @@ export default function Help () {component={'a'}href={'https://forum.appflowy.io/'}className={'justify-start text-text-caption'}- color={'inherit'} variant={'text'}+ color={'inherit'}+ variant={'text'}>Community Forum</Button><Button@@ -98,7 +113,8 @@ export default function Help () {target="_blank"href={'https://x.com/appflowy'}className={'justify-start text-text-caption'}- color={'inherit'} variant={'text'}+ color={'inherit'}+ variant={'text'}>Twitter - @appflowy</Button><Button@@ -107,7 +123,8 @@ export default function Help () {target="_blank"href={'https://www.reddit.com/r/AppFlowy/'}className={'justify-start text-text-caption'}- color={'inherit'} variant={'text'}+ color={'inherit'}+ variant={'text'}>Reddit - r/appflowy</Button></div>diff --git a/frontend/appflowy_web_app/src/components/_shared/keyboard_navigation/KeyboardNavigation.tsx b/frontend/appflowy_web_app/src/components/_shared/keyboard_navigation/KeyboardNavigation.tsxnew file mode 100644index 0000000000..fb8cf88c7b--- /dev/null+++ b/frontend/appflowy_web_app/src/components/_shared/keyboard_navigation/KeyboardNavigation.tsx@@ -0,0 +1,323 @@+import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';+import { MenuItem, Typography } from '@mui/material';+import { scrollIntoView } from './utils';+import { useTranslation } from 'react-i18next';++/**+ * The option of the keyboard navigation+ * the options will be flattened+ * - key: the key of the option+ * - content: the content of the option+ * - children: the children of the option+ */+export interface KeyboardNavigationOption<T = string> {+ key: T;+ content?: React.ReactNode;+ children?: KeyboardNavigationOption<T>[];+ disabled?: boolean;+}++/**+ * - scrollRef: the scrollable element+ * - focusRef: the element to focus when the keyboard navigation is disabled+ * - options: the options to navigate+ * - onSelected: called when an option is selected(hovered)+ * - onConfirm: called when an option is confirmed+ * - onEscape: called when the escape key is pressed+ * - onPressRight: called when the right arrow is pressed+ * - onPressLeft: called when the left arrow key is pressed+ * - disableFocus: disable the focus on the keyboard navigation+ * - disableSelect: disable selecting an option when the options are initialized+ * - onKeyDown: called when a key is pressed+ * - defaultFocusedKey: the default focused key+ * - onFocus: called when the keyboard navigation is focused+ * - onBlur: called when the keyboard navigation is blurred+ */+export interface KeyboardNavigationProps<T> {+ scrollRef?: React.RefObject<HTMLDivElement>;+ focusRef?: React.RefObject<HTMLElement>;+ options: KeyboardNavigationOption<T>[];+ onSelected?: (optionKey: T) => void;+ onConfirm?: (optionKey: T) => void;+ onEscape?: () => void;+ onPressRight?: (optionKey: T) => void;+ onPressLeft?: (optionKey: T) => void;+ disableFocus?: boolean;+ disableSelect?: boolean;+ onKeyDown?: (e: KeyboardEvent) => void;+ defaultFocusedKey?: T;+ onFocus?: () => void;+ onBlur?: () => void;+ itemClassName?: string;+ itemStyle?: React.CSSProperties;+ renderNoResult?: () => React.ReactNode;+}++function KeyboardNavigation<T> ({+ defaultFocusedKey,+ onPressRight,+ onPressLeft,+ onEscape,+ onConfirm,+ scrollRef,+ options,+ onSelected,+ focusRef,+ disableFocus = false,+ onKeyDown: onPropsKeyDown,+ disableSelect = false,+ onBlur,+ onFocus,+ itemClassName,+ itemStyle,+ renderNoResult,+}: KeyboardNavigationProps<T>) {+ const { t } = useTranslation();+ const ref = useRef<HTMLDivElement>(null);+ const mouseY = useRef<number | null>(null);+ const defaultKeyRef = useRef<T | undefined>(defaultFocusedKey);+ // flatten the options+ const flattenOptions = useMemo(() => {+ return options.flatMap((group) => {+ if (group.children) {+ return group.children;+ }++ return [group];+ });+ }, [options]);++ const [focusedKey, setFocusedKey] = useState<T>();++ const firstOptionKey = useMemo(() => {+ if (disableSelect) return;+ const firstOption = flattenOptions.find((option) => !option.disabled);++ return firstOption?.key;+ }, [flattenOptions, disableSelect]);++ // set the default focused key when the options are initialized+ useEffect(() => {+ if (defaultKeyRef.current) {+ setFocusedKey(defaultKeyRef.current);+ defaultKeyRef.current = undefined;+ return;+ }++ setFocusedKey(firstOptionKey);+ }, [firstOptionKey]);++ // call the onSelected callback when the focused key is changed+ useEffect(() => {+ if (focusedKey === undefined) return;+ onSelected?.(focusedKey);++ const scrollElement = scrollRef?.current;++ if (!scrollElement) return;++ const dom = ref.current?.querySelector(`[data-key="${focusedKey}"]`);++ if (!dom) return;+ // scroll the focused option into view+ requestAnimationFrame(() => {+ scrollIntoView(dom as HTMLDivElement, scrollElement);+ });+ }, [focusedKey, onSelected, scrollRef]);++ const onKeyDown = useCallback(+ (e: KeyboardEvent) => {+ onPropsKeyDown?.(e);+ e.stopPropagation();+ const key = e.key;++ if (key === 'Tab') {+ e.preventDefault();+ return;+ }++ if (key === 'Escape') {+ e.preventDefault();+ onEscape?.();+ return;+ }++ if (focusedKey === undefined) return;+ const focusedIndex = flattenOptions.findIndex((option) => option?.key === focusedKey);+ const nextIndex = (focusedIndex + 1) % flattenOptions.length;+ const prevIndex = (focusedIndex - 1 + flattenOptions.length) % flattenOptions.length;++ switch (key) {+ // move the focus to the previous option+ case 'ArrowUp': {+ e.preventDefault();++ const prevKey = flattenOptions[prevIndex]?.key;++ setFocusedKey(prevKey);++ break;+ }++ // move the focus to the next option+ case 'ArrowDown': {+ e.preventDefault();+ const nextKey = flattenOptions[nextIndex]?.key;++ setFocusedKey(nextKey);+ break;+ }++ case 'ArrowRight':+ if (onPressRight) {+ e.preventDefault();+ onPressRight(focusedKey);+ }++ break;+ case 'ArrowLeft':+ if (onPressLeft) {+ e.preventDefault();+ onPressLeft(focusedKey);+ }++ break;+ // confirm the focused option+ case 'Enter': {+ e.preventDefault();+ const disabled = flattenOptions[focusedIndex]?.disabled;++ if (!disabled) {+ onConfirm?.(focusedKey);+ }++ break;+ }++ default:+ break;+ }+ },+ [flattenOptions, focusedKey, onConfirm, onEscape, onPressLeft, onPressRight, onPropsKeyDown],+ );++ const renderOption = useCallback(+ (option: KeyboardNavigationOption<T>, index: number) => {+ const hasChildren = option.children;++ const isFocused = focusedKey === option.key;++ return (+ <div+ className={'flex flex-col gap-1'}+ key={option.key as string}+ >+ {hasChildren ? (+ // render the group name+ option.content && <div className={'text-text-caption'}>{option.content}</div>+ ) : (+ // render the option+ <MenuItem+ disabled={option.disabled}+ data-key={option.key}+ // prevent the focused option is changed when the mouse is not moved but the mouse is entered when scrolling into view+ onMouseMove={(e) => {+ mouseY.current = e.clientY;+ }}+ onMouseEnter={(e) => {+ onFocus?.();+ if (mouseY.current === null || mouseY.current !== e.clientY) {+ setFocusedKey(option.key);+ }++ mouseY.current = e.clientY;+ }}+ onClick={() => {+ setFocusedKey(option.key);+ if (!option.disabled) {+ onConfirm?.(option.key);+ }+ }}+ selected={isFocused}+ style={itemStyle}+ className={`ml-0 flex w-full items-center justify-start rounded-none px-2 py-1 text-xs ${+ !isFocused ? 'hover:bg-transparent' : ''+ } ${itemClassName ?? ''}`}+ >+ {option.content}+ </MenuItem>+ )}++ {option.children?.map((child, childIndex) => {+ return renderOption(child, index + childIndex);+ })}+ </div>+ );+ },+ [itemClassName, focusedKey, onConfirm, onFocus, itemStyle],+ );++ useEffect(() => {+ const element = ref.current;++ if (!disableFocus && element) {+ element.focus();+ element.addEventListener('keydown', onKeyDown);++ return () => {+ element.removeEventListener('keydown', onKeyDown);+ };+ } else {+ let element: HTMLElement | null | undefined = focusRef?.current;++ if (!element) {+ element = document.activeElement as HTMLElement;+ }++ element?.addEventListener('keydown', onKeyDown);+ return () => {+ element?.removeEventListener('keydown', onKeyDown);+ };+ }+ }, [disableFocus, onKeyDown, focusRef]);++ return (+ <div+ tabIndex={0}+ onFocus={(e) => {+ e.stopPropagation();++ onFocus?.();+ }}+ onBlur={(e) => {+ e.stopPropagation();++ const target = e.relatedTarget as HTMLElement;++ if (target?.closest('.keyboard-navigation')) {+ return;+ }++ onBlur?.();+ }}+ autoFocus={!disableFocus}+ className={'keyboard-navigation flex w-full flex-col gap-1 outline-none'}+ ref={ref}+ >+ {options.length > 0 ? (+ options.map(renderOption)+ ) : renderNoResult ? (+ renderNoResult()+ ) : (+ <Typography+ variant="body1"+ className={'p-3 text-xs text-text-caption'}+ >+ {t('findAndReplace.noResult')}+ </Typography>+ )}+ </div>+ );+}++export default KeyboardNavigation;diff --git a/frontend/appflowy_web_app/src/components/_shared/keyboard_navigation/utils.ts b/frontend/appflowy_web_app/src/components/_shared/keyboard_navigation/utils.tsnew file mode 100644index 0000000000..621143869b--- /dev/null+++ b/frontend/appflowy_web_app/src/components/_shared/keyboard_navigation/utils.ts@@ -0,0 +1,32 @@+export function inView(dom: HTMLElement, container: HTMLElement) {+ const domRect = dom.getBoundingClientRect();+ const containerRect = container.getBoundingClientRect();++ if (!domRect || !containerRect) return true;++ return domRect?.bottom <= containerRect?.bottom && domRect?.top >= containerRect?.top;+}++export function getDistanceEdge(dom: HTMLElement, container: HTMLElement) {+ const domRect = dom.getBoundingClientRect();+ const containerRect = container.getBoundingClientRect();++ if (!domRect || !containerRect) return 0;++ const distanceTop = domRect?.top - containerRect?.top;+ const distanceBottom = domRect?.bottom - containerRect?.bottom;++ return Math.abs(distanceTop) < Math.abs(distanceBottom) ? distanceTop : distanceBottom;+}++export function scrollIntoView(dom: HTMLElement, container: HTMLElement) {+ const isDomInView = inView(dom, container);++ if (isDomInView) return;++ dom.scrollIntoView({+ block: 'nearest',+ inline: 'nearest',+ behavior: 'smooth',+ });+}diff --git a/frontend/appflowy_web_app/src/components/_shared/modal/NormalModal.tsx b/frontend/appflowy_web_app/src/components/_shared/modal/NormalModal.tsxindex 1bbdecb6fa..2a159d68bb 100644--- a/frontend/appflowy_web_app/src/components/_shared/modal/NormalModal.tsx+++ b/frontend/appflowy_web_app/src/components/_shared/modal/NormalModal.tsx@@ -49,9 +49,14 @@ export function NormalModal ({><div className={'relative flex flex-col gap-4 p-5'}><div className={'flex w-full items-center justify-between text-base font-medium'}>- <div className={'flex-1 text-center '}>{title}</div>+ <div className={'flex-1 text-center font-medium'}>{title}</div>{closable && <div className={'relative -right-1.5'}>- <IconButton size={'small'} color={'inherit'} className={'h-6 w-6'} onClick={onClose || onCancel}>+ <IconButton+ size={'small'}+ color={'inherit'}+ className={'h-6 w-6'}+ onClick={onClose || onCancel}+ ><CloseIcon className={'h-4 w-4'} /></IconButton></div>}@@ -61,13 +66,15 @@ export function NormalModal ({<div className={'flex-1'}>{children}</div><div className={'flex w-full justify-end gap-3'}><Button- color={'inherit'} variant={'outlined'} onClick={() => {- if (onCancel) {- onCancel();- } else {- onClose?.();- }- }} {...cancelButtonProps}>+ color={'inherit'}+ variant={'outlined'}+ onClick={() => {+ if (onCancel) {+ onCancel();+ } else {+ onClose?.();+ }+ }} {...cancelButtonProps}>{modalCancelText}</Button><Button@@ -80,7 +87,10 @@ export function NormalModal ({}}{...okButtonProps}>- {okLoading ? <CircularProgress color={'inherit'} size={24} /> : modalOkText}+ {okLoading ? <CircularProgress+ color={'inherit'}+ size={24}+ /> : modalOkText}</Button></div></div>diff --git a/frontend/appflowy_web_app/src/components/_shared/more-actions/MoreActions.tsx b/frontend/appflowy_web_app/src/components/_shared/more-actions/MoreActions.tsxindex 49d741e216..6abd716137 100644--- a/frontend/appflowy_web_app/src/components/_shared/more-actions/MoreActions.tsx+++ b/frontend/appflowy_web_app/src/components/_shared/more-actions/MoreActions.tsx@@ -1,5 +1,6 @@import { invalidToken } from '@/application/session/token';import CacheClearingDialog from '@/components/_shared/modal/CacheClearingDialog';+import Import from '@/components/_shared/more-actions/importer/Import';import { Popover } from '@/components/_shared/popover';import { AFConfigContext } from '@/components/main/app.hooks';import { ThemeModeContext } from '@/components/main/useAppThemeMode';@@ -12,8 +13,9 @@ import { ReactComponent as SunIcon } from '@/assets/sun.svg';import { ReactComponent as LoginIcon } from '@/assets/login.svg';import { ReactComponent as ReportIcon } from '@/assets/report.svg';import { ReactComponent as TrashIcon } from '@/assets/trash.svg';+import { ReactComponent as ImportIcon } from '@/assets/import.svg';import { useTranslation } from 'react-i18next';-import { useNavigate } from 'react-router-dom';+import { useNavigate, useSearchParams } from 'react-router-dom';function MoreActions () {const { isDark, setDark } = useContext(ThemeModeContext) || {};@@ -35,18 +37,21 @@ function MoreActions () {const navigate = useNavigate();const isAuthenticated = useContext(AFConfigContext)?.isAuthenticated || false;+ const [, setSearch] = useSearchParams();const handleLogin = useCallback(() => {invalidToken();navigate('/login?redirectTo=' + encodeURIComponent(window.location.href));}, [navigate]);const actions = useMemo(() => {- return [+ const items = [+{Icon: LoginIcon,label: isAuthenticated ? t('button.logout') : t('web.login'),onClick: handleLogin,},+isDark? {Icon: SunIcon,@@ -77,7 +82,25 @@ function MoreActions () {},},];- }, [isAuthenticated, t, handleLogin, isDark, setDark]);++ const importShow = false;++ if (importShow) {+ items.unshift({+ Icon: ImportIcon,+ label: t('web.import'),+ onClick: () => {+ setSearch(prev => {+ prev.set('action', 'import');+ prev.set('source', 'notion');+ return prev;+ });+ },+ });+ }++ return items;+ }, [t, isAuthenticated, handleLogin, isDark, setSearch, setDark]);return (<>@@ -111,7 +134,7 @@ function MoreActions () {'flex items-center gap-2 rounded-[8px] p-1.5 text-sm hover:bg-content-blue-50 focus:bg-content-blue-50 focus:outline-none'}>- <action.Icon />+ <action.Icon className={'w-4 h-4'} /><span>{action.label}</span></button>))}@@ -119,7 +142,11 @@ function MoreActions () {</div></Popover>)}- <CacheClearingDialog open={openConfirm} onClose={() => setOpenConfirm(false)} />+ <CacheClearingDialog+ open={openConfirm}+ onClose={() => setOpenConfirm(false)}+ />+ <Import /></>);}diff --git a/frontend/appflowy_web_app/src/components/_shared/more-actions/importer/Import.tsx b/frontend/appflowy_web_app/src/components/_shared/more-actions/importer/Import.tsxnew file mode 100644index 0000000000..7f7d4f6747--- /dev/null+++ b/frontend/appflowy_web_app/src/components/_shared/more-actions/importer/Import.tsx@@ -0,0 +1,67 @@+import { NormalModal } from '@/components/_shared/modal';+import ImporterModal from '@/components/_shared/more-actions/importer/ImporterModal';+import { useImport } from '@/components/_shared/more-actions/importer/useImport.hook';+import { LoginModal } from '@/components/login';+import { getPlatform } from '@/utils/platform';+import React, { useMemo } from 'react';+import { useTranslation } from 'react-i18next';+import { ReactComponent as CheckedIcon } from '@/assets/check_circle.svg';++function Import () {+ const {+ open,+ handleImportClose,+ handleLoginClose,+ loginOpen,+ url,+ source,+ } = useImport();+ const [openSuccess, setOpenSuccess] = React.useState(false);+ const { t } = useTranslation();+ const isMobile = useMemo(() => {+ return getPlatform().isMobile;+ }, []);++ const handleSuccess = React.useCallback(() => {+ setOpenSuccess(true);+ }, []);++ if (isMobile) return null;+ return (+ <>+ <LoginModal+ redirectTo={url}+ open={loginOpen}+ onClose={handleLoginClose}+ />+ {open && <ImporterModal+ open={open}+ source={source || undefined}+ onClose={handleImportClose}+ onSuccess={handleSuccess}+ />}+ {openSuccess && (<NormalModal+ classes={{ container: 'items-start max-md:mt-auto max-md:items-center mt-[20%] ' }}+ title={+ <div+ className={'font-semibold flex items-center gap-2'}+ >+ <CheckedIcon className={'w-4 h-4 text-function-success'} />+ {t('web.importSuccess')}+ </div>+ }+ open={openSuccess}+ onOk={() => setOpenSuccess(false)}+ cancelButtonProps={{+ className: 'hidden',+ }}+ onClose={() => setOpenSuccess(false)}+ >+ <div className="text-text-caption">{t('web.importSuccessMessage')}</div>+ </NormalModal>)}++ </>+ );+}++export default Import;\ No newline at end of filediff --git a/frontend/appflowy_web_app/src/components/_shared/more-actions/importer/ImporterModal.tsx b/frontend/appflowy_web_app/src/components/_shared/more-actions/importer/ImporterModal.tsxnew file mode 100644index 0000000000..eeb3688ea8--- /dev/null+++ b/frontend/appflowy_web_app/src/components/_shared/more-actions/importer/ImporterModal.tsx@@ -0,0 +1,98 @@+import FileDropzone from '@/components/_shared/file-dropzone/FileDropzone';+import { notify } from '@/components/_shared/notify';+import { ViewTab, ViewTabs, TabPanel } from '@/components/_shared/tabs/ViewTabs';+import { AFConfigContext } from '@/components/main/app.hooks';+import LinearProgress from '@mui/material/LinearProgress';+import React, { useCallback, useContext } from 'react';+import { useTranslation } from 'react-i18next';+import { ReactComponent as NotionIcon } from '@/assets/notion.svg';+import { NormalModal } from '@/components/_shared/modal';+import { ReactComponent as ImportIcon } from '@/assets/import.svg';++export function ImporterModal ({+ open,+ onClose,+ source,+ onSuccess,+}: {+ open: boolean,+ onClose: () => void,+ source?: string,+ onSuccess: () => void,+}) {+ const { t } = useTranslation();+ const service = useContext(AFConfigContext)?.service;+ const [value, setValue] = React.useState<string>(source || 'notion');+ const [progress, setProgress] = React.useState<number>(0);+ const [isError, setIsError] = React.useState<boolean>(false);++ const handleUpload = useCallback(async (file: File) => {+ setIsError(false);+ try {+ await service?.importFile(file, setProgress);+ onSuccess();+ } catch (e) {+ notify.error(t('web.importFailed'));+ setIsError(true);+ }+ }, [onSuccess, service, t]);++ return (+ <NormalModal+ onCancel={onClose}+ title={+ <div className={'flex items-center gap-2 justify-center font-semibold'}>+ <ImportIcon className={'w-6 h-6'} />+ {t('web.import')}+ </div>+ }+ open={open}+ onClose={onClose}+ classes={{ container: 'items-start max-md:mt-auto max-md:items-center mt-[10%] ' }}+ okButtonProps={{+ className: 'hidden',+ }}+ cancelButtonProps={{+ className: 'hidden',+ }}+ >+ <ViewTabs+ className={'border-b border-line-divider'}+ onChange={(_e, newValue) => setValue(newValue)}+ value={value}+ >+ <ViewTab+ className={'flex items-center flex-row justify-center gap-1.5'}+ value={'notion'}+ label={t('web.importNotion')}+ icon={<NotionIcon className={'w-4 h-4 mb-0'} />}+ />++ </ViewTabs>+ <div className={'p-2 pt-8 pb-0'}>+ <TabPanel+ className={'min-w-[480px] flex flex-col gap-2 max-sm:min-w-[80vw]'}+ index={'notion'}+ value={value}+ >+ <FileDropzone+ accept={'.zip,application/zip,application/x-zip,application/x-zip-compressed'}+ multiple={false}+ onChange={files => {+ if (!files.length) return;+ void handleUpload(files[0]);+ }}+ disabled={!isError && progress < 1 && progress > 0}+ />+ {progress > 0 && <LinearProgress+ variant="determinate"+ color={isError ? 'error' : progress === 1 ? 'success' : 'primary'}+ value={progress * 100}+ />}+ </TabPanel>+ </div>+ </NormalModal>+ );+}++export default ImporterModal;\ No newline at end of filediff --git a/frontend/appflowy_web_app/src/components/_shared/more-actions/importer/useImport.hook.ts b/frontend/appflowy_web_app/src/components/_shared/more-actions/importer/useImport.hook.tsnew file mode 100644index 0000000000..f01b5d9d45--- /dev/null+++ b/frontend/appflowy_web_app/src/components/_shared/more-actions/importer/useImport.hook.ts@@ -0,0 +1,48 @@+import { AFConfigContext } from '@/components/main/app.hooks';+import React, { useCallback, useContext, useEffect } from 'react';+import { useSearchParams } from 'react-router-dom';++export function useImport () {+ const isAuthenticated = useContext(AFConfigContext)?.isAuthenticated || false;+ const [search, setSearch] = useSearchParams();+ const [loginOpen, setLoginOpen] = React.useState(false);+ const [open, setOpen] = React.useState(false);+ const url = window.location.href;+ const source = search.get('source');++ useEffect(() => {+ const isImport = search.get('action') === 'import';++ if (!isImport) return;++ setLoginOpen(!isAuthenticated);+ setOpen(isAuthenticated);+ }, [isAuthenticated, search, setSearch]);++ const handleLoginClose = useCallback(() => {+ setLoginOpen(false);+ setSearch((prev) => {+ prev.delete('action');+ prev.delete('source');+ return prev;+ });+ }, [setSearch]);++ const handleImportClose = useCallback(() => {+ setOpen(false);+ setSearch((prev) => {+ prev.delete('action');+ prev.delete('source');+ return prev;+ });+ }, [setSearch]);++ return {+ loginOpen,+ handleLoginClose,+ url,+ open,+ handleImportClose,+ source,+ };+}\ No newline at end of filediff --git a/frontend/appflowy_web_app/src/components/app/app.hooks.tsx b/frontend/appflowy_web_app/src/components/app/app.hooks.tsxindex 0b075b27a4..36d1c0976f 100644--- a/frontend/appflowy_web_app/src/components/app/app.hooks.tsx+++ b/frontend/appflowy_web_app/src/components/app/app.hooks.tsx@@ -7,7 +7,7 @@ import {LoadViewMeta,UserWorkspaceInfo,View,- ViewLayout,+ ViewLayout, YjsDatabaseKey, YjsEditorKey, YSharedRoot,} from '@/application/types';import { findAncestors, findView, findViewByLayout } from '@/components/_shared/outline/utils';import RequestAccess from '@/components/app/landing-pages/RequestAccess';@@ -186,6 +186,17 @@ export const AppProvider = ({ children }: { children: React.ReactNode }) => {throw new Error('View not found');}+ const sharedRoot = res.get(YjsEditorKey.data_section) as YSharedRoot;+ let objectId = id;++ if (sharedRoot.has(YjsEditorKey.database)) {+ const database = sharedRoot.get(YjsEditorKey.database);++ objectId = database?.get(YjsDatabaseKey.id);+ }++ service.registerDocUpdate(res, currentWorkspaceId, objectId);+return res;// eslint-disable-next-line} catch (e: any) {@@ -197,20 +208,26 @@ export const AppProvider = ({ children }: { children: React.ReactNode }) => {const createRowDoc = useCallback(async (rowKey: string) => {+ if (!currentWorkspaceId || !service) {+ throw new Error('Failed to create row doc');+ }+try {- const doc = await service?.createRowDoc(rowKey);+ const doc = await service.createRowDoc(rowKey);if (!doc) {throw new Error('Failed to create row doc');}+ service.registerDocUpdate(doc, currentWorkspaceId, rowKey);+createdRowKeys.current.push(rowKey);return doc;} catch (e) {return Promise.reject(e);}},- [service],+ [currentWorkspaceId, service],);const loadUserWorkspaceInfo = useCallback(async () => {diff --git a/frontend/appflowy_web_app/src/components/app/landing-pages/ApproveRequestPage.tsx b/frontend/appflowy_web_app/src/components/app/landing-pages/ApproveRequestPage.tsxindex 5d4f3833b4..bb76898245 100644--- a/frontend/appflowy_web_app/src/components/app/landing-pages/ApproveRequestPage.tsx+++ b/frontend/appflowy_web_app/src/components/app/landing-pages/ApproveRequestPage.tsx@@ -11,10 +11,8 @@ import ChangeAccount from '@/components/_shared/modal/ChangeAccount';import { notify } from '@/components/_shared/notify';import { getAvatar } from '@/components/_shared/view-icon/utils';import { AFConfigContext, useService } from '@/components/main/app.hooks';-import { downloadPage } from '@/utils/url';-import { ReactComponent as ArrowCircleRightOutlined } from '@/assets/arrow_circle_right.svg';-import { Avatar, Button, Divider, Paper, Typography } from '@mui/material';+import { Avatar, Button } from '@mui/material';import React, { useCallback, useContext, useEffect, useMemo } from 'react';import { Trans, useTranslation } from 'react-i18next';import { useNavigate, useSearchParams } from 'react-router-dom';@@ -33,7 +31,7 @@ function ApproveRequestPage () {const service = useService();const navigate = useNavigate();const { t } = useTranslation();- const [upgradeModalOpen, setUpgradeModalOpen] = React.useState(false);+ const [upgradeModalOpen, setUpgradeModalOpen] = React.useState(true);const [errorModalOpen, setErrorModalOpen] = React.useState(false);const [alreadyProModalOpen, setAlreadyProModalOpen] = React.useState(false);const [clicked, setClicked] = React.useState(false);@@ -106,14 +104,6 @@ function ApproveRequestPage () {}}, [requestInfo, service, isPro]);- const workspaceAvatar = useMemo(() => {- if (!requestInfo) return null;- return getAvatar({- name: requestInfo.workspace.name,- icon: requestInfo.workspace.icon,- });- }, [requestInfo]);-const requesterAvatar = useMemo(() => {if (!requestInfo) return null;return getAvatar({@@ -127,57 +117,35 @@ function ApproveRequestPage () {}, [loadRequestInfo]);return (- <div className={'m-0 flex h-screen w-screen items-center justify-center bg-bg-body p-0'}>- <div className={'flex flex-col px-6 items-center gap-3 text-center max-w-[660px] mb-10'}>- <Typography- variant="h3" className={'mb-[27px] flex items-center gap-4 text-text-title'} gutterBottom+ <div+ className={'text-text-title px-6 max-md:gap-4 flex flex-col gap-12 h-screen appflowy-scroller w-screen overflow-x-hidden overflow-y-auto items-center bg-bg-body'}+ >+ <div+ onClick={() => {+ navigate('/app');+ }}+ className={'flex w-full cursor-pointer max-md:justify-center max-md:h-32 h-20 items-center justify-between sticky'}+ >+ <AppflowyLogo className={'w-32 h-12 max-md:w-52'} />+ </div>+ <div className={'flex w-full flex-1 max-w-[560px] justify-center flex-col items-center gap-6 text-center'}>+ <Avatar+ className={'h-20 w-20 text-[40px] border border-text-title rounded-[16px]'} {...requesterAvatar}+ variant="rounded"+ />+ <div+ className={'text-[40px] max-sm:text-[24px] px-4 whitespace-pre-wrap break-words leading-[127%] text-center'}>- <>- <AppflowyLogo className={'w-48'} />- </>- </Typography>-- <div className={'mb-[16px] max-md:text-[24px] text-[52px] font-semibold leading-[128%] text-text-title'}>- {t('approveAccess.title')}- </div>- <div className={'flex max-md:flex-col gap-6 items-center justify-center'}>- <Paper- onClick={() => {- window.open(`mailto:${requestInfo?.requester.email}`, '_blank');- }}- className={'border transform transition-all border-line-divider hover:scale-110 flex w-[250px] max-md:w-full hover:bg-fill-list-hover cursor-pointer overflow-hidden items-center flex-1 gap-4 p-6'}- >- <Avatar className={'border-2 border-text-title w-12 h-12'} {...requesterAvatar} />- <div className={'flex flex-col flex-1 overflow-hidden items-start gap-2'}>- <div- className={'text-fill-default text-left w-full truncate font-semibold text-sm'}- >@{requestInfo?.requester.name}</div>- <div- className={'text-text-caption text-left truncate w-full text-xs'}- >{requestInfo?.requester.email}</div>- </div>- </Paper>- <ArrowCircleRightOutlined className={'w-12 max-md:rotate-90 max-md:transform h-12 text-text-title'} />- <Paper- onClick={() => {- window.open(`${window.origin}/app/${requestInfo?.workspace?.id}/${requestInfo?.view?.view_id}`, '_blank');- }}- className={'border border-line-divider transform transition-all hover:scale-110 flex overflow-hidden flex-1 cursor-pointer hover:bg-fill-list-hover items-center gap-4 p-6'}- >- <Avatar variant={'rounded'} className={'border-2 border-text-title w-12 h-12'} {...workspaceAvatar} />- <div className={'flex flex-col flex-1 overflow-hidden items-start gap-2'}>- <div- className={'text-text-title text-left w-full truncate font-semibold text-sm'}- >{requestInfo?.workspace.name}</div>- <div className={'text-text-caption text-left w-full truncate text-xs'}>{t('approveAccess.memberCount', {- count: requestInfo?.workspace.memberCount || 0,- })}</div>- </div>- </Paper>-+ <span className={'font-semibold'}>{requestInfo?.requester?.email}</span>+ {' '}+ {t('approveAccess.requestToJoin')}+ {' '}+ <span className={'whitespace-nowrap font-semibold'}>{requestInfo?.workspace?.name}</span>+ {' '}+ {t('approveAccess.asMember')}</div>- <div className={'flex items-center mt-4 w-full gap-4 justify-between'}>+ <div className={'flex mb-52 items-center mt-4 w-full gap-4 justify-between'}><ButtononClick={() => {void handleApprove();@@ -185,7 +153,8 @@ function ApproveRequestPage () {}}disabled={clicked || !requestInfo}className={'flex-1 py-2 px-4 rounded-[8px] text-[20px] font-medium max-md:text-base max-sm:text-[14px] max-md:py-2'}- variant={'contained'} color={'primary'}+ variant={'contained'}+ color={'primary'}>{t('approveAccess.approveButton')}</Button>@@ -194,68 +163,37 @@ function ApproveRequestPage () {navigate('/');}}className={'flex-1 py-2 px-4 rounded-[8px] max-sm:text-[14px] max-md:text-base text-[20px] font-medium max-md:py-2'}- variant={'outlined'} color={'inherit'}+ variant={'outlined'}+ color={'inherit'}>{t('requestAccess.backToHome')}</Button></div>- <Divider className={'w-full mb-3 mt-4'} />- <div className={'max-w-[400px] flex flex-col text-text-caption'}>- <span>- <Trans- i18nKey="approveAccess.ensurePlanLimit"- components={{- upgrade: <span- onClick={() => setUpgradeModalOpen(true)} className={'underline text-fill-default cursor-pointer'}- >{t('approveAccess.upgrade')}</span>,- download: <span- onClick={() => window.open(downloadPage, '_blank')}- className={'underline text-fill-default cursor-pointer'}- >{t('approveAccess.downloadApp')}</span>,- }}- />- </span>- </div>+</div><NormalModalkeepMounted={false}title={- <div className={'text-left font-semibold'}>🎉{t('upgradePlanModal.title')}</div>- } okText={t('upgradePlanModal.actionButton')} cancelText={t('upgradePlanModal.laterButton')}+ <div className={'text-left font-semibold'}>{t('upgradePlanModal.title')}</div>+ }+ okText={t('upgradePlanModal.actionButton')}+ cancelText={t('upgradePlanModal.laterButton')}open={upgradeModalOpen}onClose={() => setUpgradeModalOpen(false)}onOk={handleUpgrade}>- <div className="mt-2 py-3">- <p className="text-sm text-text-caption">- 😄- {t('upgradePlanModal.message')}- </p>- </div>- <div className="mt-4 bg-gray-50 rounded-md p-4">- <p className="text-sm font-medium text-text-caption">- {t('upgradePlanModal.upgradeSteps')}+ <div className="py-3">+ <p className="text-base text-text-caption">+ {t('upgradePlanModal.message', {+ name: requestInfo?.workspace.name,+ })}</p>- <ul className="mt-2 flex flex-col gap-1.5 list-disc list-inside text-sm text-text-caption">- <li>{t('upgradePlanModal.step1')}</li>- <li>{t('upgradePlanModal.step2')}</li>- <li>{t('upgradePlanModal.step3')}</li>- </ul></div>- <p className="mt-4 text-xs text-text-caption flex items-center gap-1">- <WarningIcon className={'w-4 h-4 text-function-info'} />- {t('upgradePlanModal.appNote')}{' '}- <Trans- i18nKey={'upgradePlanModal.refreshNote'} components={{- refresh: <span- className={'underline cursor-pointer text-fill-default'} onClick={() => window.location.reload()}- >{t('upgradePlanModal.refresh')}</span>,- }}- />- </p>-</NormalModal>- <ChangeAccount setModalOpened={setErrorModalOpen} modalOpened={errorModalOpen} />+ <ChangeAccount+ setModalOpened={setErrorModalOpen}+ modalOpened={errorModalOpen}+ /><NormalModalonOk={() => setAlreadyProModalOpen(false)}keepMounted={false}@@ -271,12 +209,13 @@ function ApproveRequestPage () {<div className={'flex flex-col'}><span><Trans- i18nKey={'approveAccess.alreadyProMessage'} components={{- email: <span- onClick={() => window.open(`mailto:[email protected]`, '_blank')}- className={'underline text-fill-default cursor-pointer'}- >[email protected]</span>,- }}+ i18nKey={'approveAccess.alreadyProMessage'}+ components={{+ email: <span+ onClick={() => window.open(`mailto:[email protected]`, '_blank')}+ className={'underline text-fill-default cursor-pointer'}+ >[email protected]</span>,+ }}/></span></div>diff --git a/frontend/appflowy_web_app/src/components/document/Document.tsx b/frontend/appflowy_web_app/src/components/document/Document.tsxindex f26c502e87..d4912214ca 100644--- a/frontend/appflowy_web_app/src/components/document/Document.tsx+++ b/frontend/appflowy_web_app/src/components/document/Document.tsx@@ -8,6 +8,7 @@ import { useSearchParams } from 'react-router-dom';export interface DocumentProps {doc: YDoc;+ readOnly: boolean;navigateToView?: (viewId: string) => Promise<void>;loadViewMeta?: LoadViewMeta;loadView?: LoadView;@@ -20,6 +21,7 @@ export interface DocumentProps {export const Document = ({doc,+ readOnly,loadView,navigateToView,loadViewMeta,@@ -58,7 +60,7 @@ export const Document = ({createRowDoc={createRowDoc}readSummary={isTemplateThumb}doc={doc}- readOnly={true}+ readOnly={readOnly}jumpBlockId={blockId}onJumpedBlockId={onJumpedBlockId}variant={variant}diff --git a/frontend/appflowy_web_app/src/components/editor/Editable.tsx b/frontend/appflowy_web_app/src/components/editor/Editable.tsxindex 9980671154..1f19e760ed 100644--- a/frontend/appflowy_web_app/src/components/editor/Editable.tsx+++ b/frontend/appflowy_web_app/src/components/editor/Editable.tsx@@ -2,20 +2,51 @@ import { useDecorate } from '@/components/editor/components/blocks/code/useDecorimport { Leaf } from '@/components/editor/components/leaf';import { useEditorContext } from '@/components/editor/EditorContext';import { useShortcuts } from '@/components/editor/shortcut.hooks';-import React, { Suspense, useCallback } from 'react';-import { NodeEntry, Range } from 'slate';+import React, { lazy, Suspense, useCallback } from 'react';+import { BaseRange, Editor, NodeEntry, Range } from 'slate';import { Editable, RenderElementProps, useSlate } from 'slate-react';import { Element } from './components/element';import { Skeleton } from '@mui/material';+const Toolbars = lazy(() => import('./components/toolbar'));+const EditorEditable = () => {- const { readOnly } = useEditorContext();+ const { readOnly, decorateState } = useEditorContext();const editor = useSlate();const codeDecorate = useDecorate(editor);++ const decorate = useCallback(+ ([, path]: NodeEntry): BaseRange[] => {+ const highlightRanges: (Range & {+ class_name: string;+ })[] = [];++ if (!decorateState) return [];++ Object.values(decorateState).forEach((state) => {+ const intersection = Range.intersection(state.range, Editor.range(editor, path));++ if (intersection) {+ highlightRanges.push({+ ...intersection,+ class_name: state.class_name,+ });+ }+ });++ return highlightRanges;+ },+ [editor, decorateState],+ );const renderElement = useCallback((props: RenderElementProps) => {return (- <Suspense fallback={<Skeleton width={'100%'} height={24} />}>+ <Suspense+ fallback={<Skeleton+ width={'100%'}+ height={24}+ />}+ ><Element {...props} /></Suspense>);@@ -36,12 +67,14 @@ const EditorEditable = () => {return (<>+<Editablerole={'textbox'}decorate={(entry: NodeEntry) => {- const decoration = codeDecorate?.(entry);+ const codeDecoration = codeDecorate?.(entry);+ const decoration = decorate(entry);- return decoration || [];+ return [...codeDecoration, ...decoration];}}className={'outline-none mb-36 w-[964px] min-w-0 max-w-full px-6 focus:outline-none'}renderLeaf={Leaf}@@ -53,6 +86,11 @@ const EditorEditable = () => {onCompositionStart={onCompositionStart}onKeyDown={onKeyDown}/>+ {!readOnly &&+ <Suspense>+ <Toolbars />+ </Suspense>+ }</>);};diff --git a/frontend/appflowy_web_app/src/components/editor/EditorContext.tsx b/frontend/appflowy_web_app/src/components/editor/EditorContext.tsxindex ae4d3e7fbf..6a4bd4d524 100644--- a/frontend/appflowy_web_app/src/components/editor/EditorContext.tsx+++ b/frontend/appflowy_web_app/src/components/editor/EditorContext.tsx@@ -5,7 +5,8 @@ import {LoadView,LoadViewMeta,} from '@/application/types';-import { createContext, useContext } from 'react';+import { createContext, useCallback, useContext, useState } from 'react';+import { BaseRange } from 'slate';export interface EditorLayoutStyle {fontLayout: FontLayout;@@ -24,6 +25,11 @@ export enum EditorVariant {app = 'app',}+interface Decorate {+ range: BaseRange;+ class_name: string;+}+export interface EditorContextState {readOnly: boolean;layoutStyle?: EditorLayoutStyle;@@ -38,6 +44,9 @@ export interface EditorContextState {onJumpedBlockId?: () => void;variant?: EditorVariant;onRendered?: () => void;+ decorateState?: Record<string, Decorate>;+ addDecorate?: (range: BaseRange, class_name: string, type: string) => void;+ removeDecorate?: (type: string) => void;}export const EditorContext = createContext<EditorContextState>({@@ -47,7 +56,39 @@ export const EditorContext = createContext<EditorContextState>({});export const EditorContextProvider = ({ children, ...props }: EditorContextState & { children: React.ReactNode }) => {- return <EditorContext.Provider value={props}>{children}</EditorContext.Provider>;+ const [decorateState, setDecorateState] = useState<Record<string, Decorate>>({});++ const addDecorate = useCallback((range: BaseRange, class_name: string, type: string) => {+ setDecorateState((prev) => ({+ ...prev,+ [type]: {+ range,+ class_name,+ },+ }));+ }, []);++ const removeDecorate = useCallback((type: string) => {+ setDecorateState((prev) => {+ if (prev[type] === undefined) {+ return prev;+ }++ const newState = { ...prev };++ delete newState[type];+ return newState;+ });+ }, []);++ return <EditorContext.Provider+ value={{+ ...props,+ decorateState,+ addDecorate,+ removeDecorate,+ }}+ >{children}</EditorContext.Provider>;};export function useEditorContext () {diff --git a/frontend/appflowy_web_app/src/components/editor/__tests__/blocks/Paragraph.cy.tsx b/frontend/appflowy_web_app/src/components/editor/__tests__/blocks/Paragraph.cy.tsxindex a03f002ba7..6fec1402bf 100644--- a/frontend/appflowy_web_app/src/components/editor/__tests__/blocks/Paragraph.cy.tsx+++ b/frontend/appflowy_web_app/src/components/editor/__tests__/blocks/Paragraph.cy.tsx@@ -52,9 +52,15 @@ describe('<Paragraph />', () => {cy.get('[role="textbox"]').should('exist');- cy.get('[role="textbox"]').type('{movetostart}').type('{rightarrow}'.repeat(10))- .type(` New text at the 'world' middle `);- cy.get('[role="textbox"]').type('{movetoend}').type('{leftarrow}'.repeat(6)).type('{backspace}'.repeat(4));+ moveCursor(0, 10);++ cy.get('[role="textbox"]').type(` New text at the 'world' middle `);++ cy.get('[role="textbox"]').selectMultipleText(['bold']);++ cy.wait(50);++ cy.get('[role="textbox"]').type('{backspace}');const expectJSON = [{type: 'paragraph',diff --git a/frontend/appflowy_web_app/src/components/editor/__tests__/mount.tsx b/frontend/appflowy_web_app/src/components/editor/__tests__/mount.tsxindex 8b666cd16f..dac04098ca 100644--- a/frontend/appflowy_web_app/src/components/editor/__tests__/mount.tsx+++ b/frontend/appflowy_web_app/src/components/editor/__tests__/mount.tsx@@ -32,7 +32,7 @@ export const moveToLineStart = (lineIndex: number) => {export const moveCursor = (lineIndex: number, charIndex: number) => {moveToLineStart(lineIndex);// Move the cursor with right arrow key and batch the movement- const batchSize = 5;+ const batchSize = 1;const batches = Math.ceil(charIndex / batchSize);for (let i = 0; i < batches; i++) {@@ -40,7 +40,7 @@ export const moveCursor = (lineIndex: number, charIndex: number) => {cy.get('@targetBlock').type('{rightarrow}'.repeat(remainingMoves))- .wait(50);+ .wait(20);}};diff --git a/frontend/appflowy_web_app/src/components/editor/components/blocks/database/DatabaseBlock.tsx b/frontend/appflowy_web_app/src/components/editor/components/blocks/database/DatabaseBlock.tsxindex 2934067f36..4a84a9622b 100644--- a/frontend/appflowy_web_app/src/components/editor/components/blocks/database/DatabaseBlock.tsx+++ b/frontend/appflowy_web_app/src/components/editor/components/blocks/database/DatabaseBlock.tsx@@ -107,11 +107,15 @@ export const DatabaseBlock = memo(<><div{...attributes}+ contentEditable={false}className={`relative w-full cursor-pointer py-2`}onMouseEnter={() => setIsHovering(true)}onMouseLeave={() => setIsHovering(false)}>- <div ref={ref} className={'absolute left-0 top-0 h-full w-full caret-transparent'}>+ <div+ ref={ref}+ className={'absolute left-0 top-0 h-full w-full caret-transparent'}+ >{children}</div><div@@ -137,7 +141,10 @@ export const DatabaseBlock = memo(/>{isHovering && (<div className={'absolute right-4 top-1'}>- <Tooltip placement={'bottom'} title={t('tooltip.openAsPage')}>+ <Tooltip+ placement={'bottom'}+ title={t('tooltip.openAsPage')}+ ><buttoncolor={'primary'}className={'rounded border border-line-divider bg-bg-body p-1 hover:bg-fill-list-hover'}diff --git a/frontend/appflowy_web_app/src/components/editor/components/blocks/divider/DividerNode.tsx b/frontend/appflowy_web_app/src/components/editor/components/blocks/divider/DividerNode.tsxindex f3dff23aeb..fe558fd3f8 100644--- a/frontend/appflowy_web_app/src/components/editor/components/blocks/divider/DividerNode.tsx+++ b/frontend/appflowy_web_app/src/components/editor/components/blocks/divider/DividerNode.tsx@@ -9,17 +9,25 @@ export const DividerNode = memo(}, [attributes.className]);return (- <div {...attributes} className={className}>- <div contentEditable={false} className={'w-full px-1 py-2'}>+ <div {...attributes} contentEditable={false}+ className={className}+ >+ <div+ contentEditable={false}+ className={'w-full px-1 py-2'}+ ><hr className={'border-line-border'} /></div>- <div ref={ref} className={`absolute h-full w-full caret-transparent`}>+ <div+ ref={ref}+ className={`absolute h-full w-full caret-transparent`}+ >{children}</div></div>);- }- )+ },+ ),);export default DividerNode;diff --git a/frontend/appflowy_web_app/src/components/editor/components/blocks/file/FileBlock.tsx b/frontend/appflowy_web_app/src/components/editor/components/blocks/file/FileBlock.tsxindex ed6c652462..9b772356d0 100644--- a/frontend/appflowy_web_app/src/components/editor/components/blocks/file/FileBlock.tsx+++ b/frontend/appflowy_web_app/src/components/editor/components/blocks/file/FileBlock.tsx@@ -42,6 +42,7 @@ export const FileBlock = memo(return (<div{...attributes}+ contentEditable={false}className={className}onMouseEnter={() => {if (!url) return;@@ -81,7 +82,10 @@ export const FileBlock = memo(/>)}</div>- <div ref={ref} className={`absolute h-full w-full caret-transparent`}>+ <div+ ref={ref}+ className={`absolute h-full w-full caret-transparent`}+ >{children}</div>diff --git a/frontend/appflowy_web_app/src/components/editor/components/blocks/gallery/GalleryBlock.tsx b/frontend/appflowy_web_app/src/components/editor/components/blocks/gallery/GalleryBlock.tsxindex 8b107d276e..cc1c518817 100644--- a/frontend/appflowy_web_app/src/components/editor/components/blocks/gallery/GalleryBlock.tsx+++ b/frontend/appflowy_web_app/src/components/editor/components/blocks/gallery/GalleryBlock.tsx@@ -76,10 +76,13 @@ const GalleryBlock = memo(return (<div- ref={ref} {...attributes} className={className} onMouseEnter={() => {- if (!photos.length) return;- setHovered(true);- }}+ contentEditable={false}+ ref={ref} {...attributes}+ className={className}+ onMouseEnter={() => {+ if (!photos.length) return;+ setHovered(true);+ }}onMouseLeave={() => setHovered(false)}><div className={'absolute left-0 top-0 h-full w-full pointer-events-none'}>@@ -96,7 +99,8 @@ const GalleryBlock = memo(onPreview={(index) => {previewIndexRef.current = index;handleOpenPreview();- }} images={photos}+ }}+ images={photos}/>) : <divclassName={@@ -107,7 +111,11 @@ const GalleryBlock = memo({t('document.plugins.image.addAnImageMobile')}</div>}{hovered &&- <GalleryToolbar onCopy={handleCopy} onDownload={handleDownload} onOpenPreview={handleOpenPreview} />}+ <GalleryToolbar+ onCopy={handleCopy}+ onDownload={handleDownload}+ onOpenPreview={handleOpenPreview}+ />}{openPreview && <Suspense><GalleryPreviewimages={photos}diff --git a/frontend/appflowy_web_app/src/components/editor/components/blocks/image/ImageBlock.tsx b/frontend/appflowy_web_app/src/components/editor/components/blocks/image/ImageBlock.tsxindex 58328241ac..9da50e4230 100644--- a/frontend/appflowy_web_app/src/components/editor/components/blocks/image/ImageBlock.tsx+++ b/frontend/appflowy_web_app/src/components/editor/components/blocks/image/ImageBlock.tsx@@ -34,6 +34,7 @@ export const ImageBlock = memo(<div{...attributes}ref={containerRef}+ contentEditable={false}onMouseEnter={() => {if (!url) return;setShowToolbar(true);@@ -41,7 +42,10 @@ export const ImageBlock = memo(onMouseLeave={() => setShowToolbar(false)}className={`${className || ''} image-block relative w-full cursor-default`}>- <div ref={ref} className={'absolute left-0 top-0 h-full w-full select-none caret-transparent'}>+ <div+ ref={ref}+ className={'absolute left-0 top-0 h-full w-full select-none caret-transparent'}+ >{children}</div><div@@ -49,9 +53,17 @@ export const ImageBlock = memo(className={`flex w-full select-none overflow-hidden ${url ? '' : 'rounded-[8px] border border-line-divider'} ${alignCss}`}>{url ? (- <ImageRender showToolbar={showToolbar} selected={selected} node={node} />+ <ImageRender+ showToolbar={showToolbar}+ selected={selected}+ node={node}+ />) : (- <ImageEmpty node={node} onEscape={onFocusNode} containerRef={containerRef} />+ <ImageEmpty+ node={node}+ onEscape={onFocusNode}+ containerRef={containerRef}+ />)}</div></div>diff --git a/frontend/appflowy_web_app/src/components/editor/components/blocks/link-preview/LinkPreview.tsx b/frontend/appflowy_web_app/src/components/editor/components/blocks/link-preview/LinkPreview.tsxindex 91f36fb02c..f9a962741e 100644--- a/frontend/appflowy_web_app/src/components/editor/components/blocks/link-preview/LinkPreview.tsx+++ b/frontend/appflowy_web_app/src/components/editor/components/blocks/link-preview/LinkPreview.tsx@@ -39,6 +39,7 @@ export const LinkPreview = memo(onClick={() => {window.open(url, '_blank');}}+ contentEditable={false}{...attributes}ref={ref}className={`link-preview-block relative w-full cursor-pointer py-1`}@@ -80,11 +81,14 @@ export const LinkPreview = memo(</>)}</div>- <div ref={ref} className={'absolute left-0 top-0 h-full w-full caret-transparent'}>+ <div+ ref={ref}+ className={'absolute left-0 top-0 h-full w-full caret-transparent'}+ >{children}</div></div>);- })+ }),);export default LinkPreview;diff --git a/frontend/appflowy_web_app/src/components/editor/components/blocks/outline/Outline.tsx b/frontend/appflowy_web_app/src/components/editor/components/blocks/outline/Outline.tsxindex b08ed5090f..af02fbe45c 100644--- a/frontend/appflowy_web_app/src/components/editor/components/blocks/outline/Outline.tsx+++ b/frontend/appflowy_web_app/src/components/editor/components/blocks/outline/Outline.tsx@@ -52,21 +52,29 @@ export const Outline = memo(</div>);},- [jumpToHeading]+ [jumpToHeading],);return (- <div {...attributes} className={`outline-block relative my-2 px-1 ${className || ''}`}>- <div ref={ref} className={'absolute left-0 top-0 select-none caret-transparent'}>+ <div {...attributes} contentEditable={false}+ className={`outline-block relative my-2 px-1 ${className || ''}`}+ >+ <div+ ref={ref}+ className={'absolute left-0 top-0 select-none caret-transparent'}+ >{children}</div>- <div contentEditable={false} className={`flex w-full select-none flex-col`}>+ <div+ contentEditable={false}+ className={`flex w-full select-none flex-col`}+ ><div className={'text-md my-2 font-bold'}>{t('document.outlineBlock.placeholder')}</div>{root.map(renderHeading)}</div></div>);- })+ }),);export default Outline;diff --git a/frontend/appflowy_web_app/src/components/editor/components/leaf/formula/FormulaLeaf.tsx b/frontend/appflowy_web_app/src/components/editor/components/leaf/formula/FormulaLeaf.tsxindex 61c5ea2408..39cdba236b 100644--- a/frontend/appflowy_web_app/src/components/editor/components/leaf/formula/FormulaLeaf.tsx+++ b/frontend/appflowy_web_app/src/components/editor/components/leaf/formula/FormulaLeaf.tsx@@ -1,40 +1,106 @@+import { CustomEditor } from '@/application/slate-yjs/command';+import { EditorMarkFormat } from '@/application/slate-yjs/types';import { KatexMath } from '@/components/_shared/katex-math';+import FormulaPopover from '@/components/editor/components/leaf/formula/FormulaPopover';import { useLeafSelected } from '@/components/editor/components/leaf/leaf.hooks';-import React, { Suspense, useMemo } from 'react';+import { PopoverPosition } from '@mui/material';+import React, { Suspense, useCallback, useMemo, useRef, useState } from 'react';import { Text } from 'slate';-import { useReadOnly } from 'slate-react';+import { ReactEditor, useReadOnly, useSlateStatic } from 'slate-react';function FormulaLeaf ({ formula, text }: {formula: string;text: Text;}) {- const { isSelected, select, isCursorAfter, isCursorBefore } = useLeafSelected(text);+ const ref = useRef<HTMLSpanElement>(null);+ const editor = useSlateStatic();+ const { isSelected, isCursorAfter, isCursorBefore } = useLeafSelected(text);+ const [anchorPosition, setAnchorPosition] = useState<PopoverPosition | undefined>(undefined);+ const open = Boolean(anchorPosition);const readonly = useReadOnly();const className = useMemo(() => {const classList = ['formula-inline', 'relative', 'rounded', 'p-0.5 select-none'];if (readonly) classList.push('cursor-default');else classList.push('cursor-pointer');- if (isSelected) classList.push('selected');+ if (isSelected || open) classList.push('selected');if (isCursorAfter) classList.push('cursor-after');if (isCursorBefore) classList.push('cursor-before');return classList.join(' ');- }, [readonly, isSelected, isCursorAfter, isCursorBefore]);+ }, [open, readonly, isSelected, isCursorAfter, isCursorBefore]);++ const handleClose = useCallback(() => {+ setAnchorPosition(undefined);+ }, []);++ const openPopover = useCallback(() => {+ if (readonly) return;+ const rect = ref.current?.getBoundingClientRect();++ if (!rect) return;++ setAnchorPosition({+ top: rect.top + rect.height,+ left: rect.left + rect.width / 2,+ });+ }, [readonly]);++ const handleDone = useCallback((newFormula: string) => {+ handleClose();+ const path = ReactEditor.findPath(editor, text);++ editor.select(path);+ CustomEditor.addMark(editor, {+ key: EditorMarkFormat.Formula,+ value: newFormula,+ });+ }, [handleClose, editor, text]);++ const handleClear = useCallback(() => {+ handleClose();+ ReactEditor.focus(editor);+ const path = ReactEditor.findPath(editor, text);++ editor.select(path);++ CustomEditor.removeMark(editor, EditorMarkFormat.Formula);++ editor.deleteBackward('character');+ editor.insertText(formula);+ }, [editor, formula, handleClose, text]);return (- <span- onClick={e => {- e.preventDefault();- select();- }}- contentEditable={false}- className={className}- >- <Suspense fallback={formula}>-- <KatexMath latex={formula || ''} isInline />- </Suspense>- </span>+ <>+ <span+ ref={ref}+ onClick={e => {+ e.preventDefault();+ e.stopPropagation();+ openPopover();+ }}+ contentEditable={false}+ className={className}+ >+ <Suspense fallback={formula}>++ <KatexMath+ latex={formula || ''}+ isInline+ />+ </Suspense>+ </span>+ {+ open && <FormulaPopover+ open={open}+ anchorPosition={anchorPosition}+ onClose={handleClose}+ defaultValue={formula}+ onDone={handleDone}+ onClear={handleClear}+ />+ }+ </>+);}diff --git a/frontend/appflowy_web_app/src/components/editor/components/leaf/formula/FormulaPopover.tsx b/frontend/appflowy_web_app/src/components/editor/components/leaf/formula/FormulaPopover.tsxnew file mode 100644index 0000000000..d27ff4b8b7--- /dev/null+++ b/frontend/appflowy_web_app/src/components/editor/components/leaf/formula/FormulaPopover.tsx@@ -0,0 +1,92 @@+import { Popover } from '@/components/_shared/popover';+import { IconButton, PopoverPosition, TextField, Tooltip } from '@mui/material';+import React from 'react';+import { useTranslation } from 'react-i18next';+import { ReactComponent as SelectCheck } from '@/assets/selected.svg';+import { ReactComponent as Clear } from '@/assets/trash.svg';++function FormulaPopover ({+ open,+ onClose,+ defaultValue,+ anchorPosition,+ onDone,+ onClear,+}: {+ open: boolean,+ onClose: () => void;+ defaultValue: string+ anchorPosition?: PopoverPosition;+ onDone: (value: string) => void;+ onClear: () => void;+}) {+ const { t } = useTranslation();+ const [value, setValue] = React.useState(defaultValue);++ return (+ <Popover+ onClose={onClose}+ open={open}+ disableAutoFocus={true}+ disableEnforceFocus={true}+ disableRestoreFocus={false}+ anchorPosition={anchorPosition}+ anchorReference={'anchorPosition'}+ transformOrigin={{+ vertical: 'top',+ horizontal: 'center',+ }}+ >+ <div className={'p-4 flex items-center gap-2'}>+ <TextField+ variant={'standard'}+ size={'small'}+ autoFocus={true}+ value={value}+ spellCheck={false}+ placeholder={'E = mc^2'}+ onChange={(e) => setValue(e.target.value)}+ fullWidth={true}+ onKeyDown={e => {+ if (e.key === 'Enter') {+ onDone(value);+ }++ }}+ />+ <div className={'flex gap-2 items-center justify-end'}>+ <Tooltip+ placement={'top'}+ title={t('button.done')}+ >+ <IconButton+ className={'h-[20px] w-[20px]'}+ size={'small'}+ onClick={() => {++ onDone(value);+ }}+ >+ <SelectCheck className={'text-content-blue-400'} />+ </IconButton>+ </Tooltip>+ <Tooltip+ placement={'top'}+ title={t('button.clear')}+ >+ <IconButton+ className={'h-[20px] w-[20px]'}+ size={'small'}+ color={'error'}+ onClick={onClear}+ >+ <Clear />+ </IconButton>+ </Tooltip>+ </div>+ </div>+ </Popover>+ );+}++export default FormulaPopover;\ No newline at end of filediff --git a/frontend/appflowy_web_app/src/components/editor/components/toolbar/index.tsx b/frontend/appflowy_web_app/src/components/editor/components/toolbar/index.tsxnew file mode 100644index 0000000000..7b97324486--- /dev/null+++ b/frontend/appflowy_web_app/src/components/editor/components/toolbar/index.tsx@@ -0,0 +1,14 @@+import { ElementFallbackRender } from '@/components/error/ElementFallbackRender';+import React from 'react';+import { ErrorBoundary } from 'react-error-boundary';+import { SelectionToolbar } from './selection-toolbar/SelectionToolbar';++function Toolbars () {+ return (+ <ErrorBoundary fallbackRender={ElementFallbackRender}>+ <SelectionToolbar />+ </ErrorBoundary>+ );+}++export default Toolbars;\ No newline at end of filediff --git a/frontend/appflowy_web_app/src/components/editor/components/toolbar/selection-toolbar/SelectionToolbar.hooks.ts b/frontend/appflowy_web_app/src/components/editor/components/toolbar/selection-toolbar/SelectionToolbar.hooks.tsnew file mode 100644index 0000000000..81dfee4dd0--- /dev/null+++ b/frontend/appflowy_web_app/src/components/editor/components/toolbar/selection-toolbar/SelectionToolbar.hooks.ts@@ -0,0 +1,188 @@+import { YjsEditor } from '@/application/slate-yjs';+import { getOffsetPointFromSlateRange } from '@/application/slate-yjs/utils/yjsOperations';+import { getRangeRect, getSelectionPosition } from '@/components/editor/components/toolbar/selection-toolbar/utils';+import { useEditorContext } from '@/components/editor/EditorContext';+import { PopoverPosition } from '@mui/material';+import { debounce } from 'lodash-es';+import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react';+import { Range } from 'slate';+import { ReactEditor, useFocused, useSlate, useSlateStatic } from 'slate-react';++export function useVisible () {+ const editor = useSlate();+ const selection = editor.selection;+ const { addDecorate, removeDecorate } = useEditorContext();+ const [forceShow, setForceShow] = useState<boolean>(false);+ const [isDragging, setDragging] = useState<boolean>(false);++ const focus = useFocused();++ const isExpanded = selection ? Range.isExpanded(selection) : false;++ const visible = useMemo(() => {+ if (forceShow) return true;+ if (!focus) return false;++ return isExpanded && !isDragging;+ }, [focus, forceShow, isExpanded, isDragging]);++ useEffect(() => {+ if (!visible) {+ removeDecorate?.('selection-toolbar');+ return;+ }++ }, [visible, removeDecorate]);++ useEffect(() => {++ const handleMouseDown = () => {+ setDragging(true);+ };++ const handleMouseUp = () => {+ setDragging(false);+ setForceShow(false);+ removeDecorate?.('selection-toolbar');+ };++ document.addEventListener('mousedown', handleMouseDown);++ document.addEventListener('mouseup', handleMouseUp);++ return () => {+ document.removeEventListener('mousedown', handleMouseDown);++ document.removeEventListener('mouseup', handleMouseUp);+ };++ }, [removeDecorate]);++ const handleForceShow = useCallback((show: boolean) => {+ if (show && editor.selection) {+ setForceShow(true);+ addDecorate?.(editor.selection, 'bg-content-blue-100', 'selection-toolbar');+ } else {+ setForceShow(false);+ }+ }, [addDecorate, editor.selection]);++ return {+ visible,+ forceShow: handleForceShow,+ };++}++export function useToolbarPosition () {+ const editor = useSlateStatic();++ const setPosition = useCallback((toolbarEl: HTMLDivElement, position: {+ top: number,+ left: number,+ width: number,+ height: number+ }) => {+ const slateEditorDom = ReactEditor.toDOMNode(editor, editor);++ toolbarEl.style.top = `${position.top + slateEditorDom.offsetTop - toolbarEl.offsetHeight}px`;+ const left = position.left + slateEditorDom.offsetLeft;++ // If toolbar is out of editor, move it to the left edge of the editor+ if (left < 0) {+ toolbarEl.style.left = '0';+ return;+ }++ const right = left + toolbarEl.offsetWidth;++ // If toolbar is out of editor, move the right edge to the right edge of the editor+ if (right > slateEditorDom.offsetWidth) {+ toolbarEl.style.left = `${slateEditorDom.offsetWidth - toolbarEl.offsetWidth}px`;+ return;+ }++ toolbarEl.style.left = `${left}px`;+ }, [editor]);++ const showToolbar = useCallback((toolbarEl: HTMLDivElement) => {+ const position = getSelectionPosition(editor);++ if (position) {+ toolbarEl.style.opacity = '1';+ toolbarEl.style.pointerEvents = 'auto';+ setPosition(toolbarEl, position);+ }+ }, [editor, setPosition]);+ const debounceShow = useMemo(() => debounce(showToolbar, 50), [showToolbar]);+ const hideToolbar = useCallback((toolbarEl: HTMLDivElement) => {+ debounceShow.cancel();+ toolbarEl.style.opacity = '0';+ toolbarEl.style.pointerEvents = 'none';+ }, [debounceShow]);++ return {+ showToolbar: debounceShow,+ hideToolbar,+ };+}++export const SelectionToolbarContext = createContext<{+ visible: boolean;+ forceShow: (forceVisible: boolean) => void;+}>({+ visible: false,+ forceShow: () => undefined,+});++export function useSelectionToolbarContext () {+ return useContext(SelectionToolbarContext);+}++interface RelativeRange {+ offset: number;+ textId: string;+}++export function useToolbarPopover (editor: YjsEditor) {+ const { forceShow } = useSelectionToolbarContext();+ const [anchorPosition, setAnchorPosition] = useState<PopoverPosition | undefined>(undefined);+ const rangeRef = useRef<{ start: RelativeRange; end: RelativeRange } | null>(null);++ const open = Boolean(anchorPosition);++ const handleClose = useCallback(() => {+ setAnchorPosition(undefined);+ forceShow(false);+ }, [forceShow]);++ const openPopover = useCallback(() => {+ if (!editor.selection) return;+ const rect = getRangeRect();++ if (!rect) return;++ try {+ rangeRef.current = {+ start: getOffsetPointFromSlateRange(editor, editor.start(editor.selection)),+ end: getOffsetPointFromSlateRange(editor, editor.end(editor.selection)),+ };+ } catch (e) {+ rangeRef.current = null;+ }++ forceShow(true);++ setAnchorPosition({+ top: rect.top + rect.height,+ left: rect.left + rect.width / 2,+ });+ }, [editor, forceShow]);++ return {+ open,+ anchorPosition,+ handleClose,+ openPopover,+ };+}\ No newline at end of filediff --git a/frontend/appflowy_web_app/src/components/editor/components/toolbar/selection-toolbar/SelectionToolbar.tsx b/frontend/appflowy_web_app/src/components/editor/components/toolbar/selection-toolbar/SelectionToolbar.tsxnew file mode 100644index 0000000000..fd884f3f71--- /dev/null+++ b/frontend/appflowy_web_app/src/components/editor/components/toolbar/selection-toolbar/SelectionToolbar.tsx@@ -0,0 +1,44 @@+import ToolbarActions from '@/components/editor/components/toolbar/selection-toolbar/ToolbarActions';+import { SelectionToolbarContext, useToolbarPosition, useVisible } from './SelectionToolbar.hooks';+import React, { useEffect, useRef } from 'react';++export function SelectionToolbar () {+ const { visible, forceShow } = useVisible();+ const ref = useRef<HTMLDivElement | null>(null);+ const {+ hideToolbar,+ showToolbar,+ } = useToolbarPosition();++ useEffect(() => {+ const el = ref.current;++ if (!el) return;+ if (!visible) {+ hideToolbar(el);+ return;+ }++ showToolbar(el);+ }, [hideToolbar, showToolbar, visible]);++ return (+ <SelectionToolbarContext.Provider value={{ visible, forceShow }}>+ <div+ ref={ref}+ className={+ 'selection-toolbar pointer-events-none absolute z-[100] flex min-h-[32px] w-fit flex-grow items-center rounded-lg bg-[var(--fill-toolbar)] px-2 opacity-0 shadow-lg'+ }+ onMouseDown={(e) => {+ // prevent toolbar from taking focus away from editor+ e.preventDefault();+ e.stopPropagation();+ }}+ >+ <ToolbarActions />+ </div>+ </SelectionToolbarContext.Provider>+ );+}++export default SelectionToolbar;\ No newline at end of filediff --git a/frontend/appflowy_web_app/src/components/editor/components/toolbar/selection-toolbar/SelectionToolbarPopoverContext.tsx b/frontend/appflowy_web_app/src/components/editor/components/toolbar/selection-toolbar/SelectionToolbarPopoverContext.tsxnew file mode 100644index 0000000000..707d204434--- /dev/null+++ b/frontend/appflowy_web_app/src/components/editor/components/toolbar/selection-toolbar/SelectionToolbarPopoverContext.tsx@@ -0,0 +1,66 @@+import { useToolbarPopover } from './SelectionToolbar.hooks';+import React, { createContext, useContext, ReactNode } from 'react';+import { Popover } from '@/components/_shared/popover';+import { YjsEditor } from '@/application/slate-yjs';+import { useSlateStatic } from 'slate-react';++interface SelectionToolbarPopoverContextType {+ open: boolean;+ openPopover: () => void;+ closePopover: () => void;+}++const SelectionToolbarPopoverContext = createContext<SelectionToolbarPopoverContextType | null>(null);++export function useSelectionToolbarPopoverContext () {+ const context = useContext(SelectionToolbarPopoverContext);++ if (!context) {+ throw new Error('useSelectionToolbarPopoverContext must be used within a SelectionToolbarPopoverProvider');+ }++ return context;+}++interface SelectionToolbarPopoverProviderProps {+ children: ReactNode;+ popoverContent: React.ReactNode;+}++export function SelectionToolbarPopoverProvider ({ children, popoverContent }: SelectionToolbarPopoverProviderProps) {+ const editor = useSlateStatic() as YjsEditor;+ const {+ open,+ anchorPosition,+ handleClose,+ openPopover,+ } = useToolbarPopover(editor);++ return (+ <SelectionToolbarPopoverContext.Provider value={{ open, openPopover, closePopover: handleClose }}>+ {children}+ {open && (+ <Popover+ onMouseDown={e => {+ e.preventDefault();+ e.stopPropagation();+ }}+ onMouseUp={e => {+ e.stopPropagation();+ }}+ disableRestoreFocus={false}+ open={open}+ onClose={handleClose}+ anchorPosition={anchorPosition}+ anchorReference={'anchorPosition'}+ transformOrigin={{+ vertical: 'top',+ horizontal: 'center',+ }}+ >+ {popoverContent}+ </Popover>+ )}+ </SelectionToolbarPopoverContext.Provider>+ );+}\ No newline at end of filediff --git a/frontend/appflowy_web_app/src/components/editor/components/toolbar/selection-toolbar/ToolbarActions.tsx b/frontend/appflowy_web_app/src/components/editor/components/toolbar/selection-toolbar/ToolbarActions.tsxnew file mode 100644index 0000000000..dabd6330be--- /dev/null+++ b/frontend/appflowy_web_app/src/components/editor/components/toolbar/selection-toolbar/ToolbarActions.tsx@@ -0,0 +1,111 @@+import { YjsEditor } from '@/application/slate-yjs';+import { getBlockEntry } from '@/application/slate-yjs/utils/yjsOperations';+import { BlockType } from '@/application/types';+import Align from '@/components/editor/components/toolbar/selection-toolbar/actions/Align';+import Bold from '@/components/editor/components/toolbar/selection-toolbar/actions/Bold';+import BulletedList from '@/components/editor/components/toolbar/selection-toolbar/actions/BulletedList';+// import Href from '@/components/editor/components/toolbar/selection-toolbar/actions/Href';+import Color from '@/components/editor/components/toolbar/selection-toolbar/actions/Color';+import Formula from '@/components/editor/components/toolbar/selection-toolbar/actions/Formula';+import Heading from '@/components/editor/components/toolbar/selection-toolbar/actions/Heading';+import InlineCode from '@/components/editor/components/toolbar/selection-toolbar/actions/InlineCode';+import Italic from '@/components/editor/components/toolbar/selection-toolbar/actions/Italic';+import NumberedList from '@/components/editor/components/toolbar/selection-toolbar/actions/NumberedList';+import Quote from '@/components/editor/components/toolbar/selection-toolbar/actions/Quote';+import StrikeThrough from '@/components/editor/components/toolbar/selection-toolbar/actions/StrikeThrough';+import Underline from '@/components/editor/components/toolbar/selection-toolbar/actions/Underline';+import { Divider } from '@mui/material';+import { Editor, Element } from 'slate';+import Paragraph from './actions/Paragraph';+import React, { useMemo } from 'react';+import { useSlate } from 'slate-react';++function ToolbarActions () {+ const editor = useSlate() as YjsEditor;+ const selection = editor.selection;+ const start = useMemo(() => selection ? editor.start(selection) : null, [editor, selection]);+ const end = useMemo(() => selection ? editor.end(selection) : null, [editor, selection]);+ const startBlock = useMemo(() => {+ if (!start) return null;+ try {+ return getBlockEntry(editor, start);+ } catch (e) {+ return null;+ }+ }, [editor, start]);+ const endBlock = useMemo(() => {+ if (!end) return null;+ try {+ return getBlockEntry(editor, end);+ } catch (e) {+ return null;+ }+ }, [editor, end]);++ const isAcrossBlock = useMemo(() => {+ return startBlock?.[0].blockId !== endBlock?.[0].blockId;+ }, [endBlock, startBlock]);++ const isCodeBlock = useMemo(() => {+ if (!start || !end) return false;+ const range = { anchor: start, focus: end };++ const [codeBlock] = editor.nodes({+ at: range,+ match: n => !Editor.isEditor(n) && Element.isElement(n) && n.type === BlockType.CodeBlock,+ });++ return !!codeBlock;+ }, [editor, end, start]);++ const groupTwo = <>+ <Underline />+ <Bold />+ <Italic />+ <StrikeThrough />+ </>;++ const groupOne = <>+ <Paragraph />+ <Heading />+ <Divider+ className={'my-1.5 bg-line-on-toolbar opacity-80'}+ orientation={'vertical'}+ flexItem={true}+ />+ </>;++ const groupThree = <>+ <Quote />+ <BulletedList />+ <NumberedList />+ <Divider+ className={'my-1.5 bg-line-on-toolbar opacity-40'}+ orientation={'vertical'}+ flexItem={true}+ />+ {/*<Href />*/}+ </>;++ const groupFour = <><Align /></>;++ return (+ <div+ className={'flex w-fit flex-grow items-center gap-1'}+ >+ {+ !isAcrossBlock && !isCodeBlock && groupOne+ }+ {groupTwo}+ {!isCodeBlock && <InlineCode />}+ {!isCodeBlock && !isAcrossBlock && <Formula />}+ {+ !isAcrossBlock && !isCodeBlock && groupThree+ }+ {groupFour}+ {!isCodeBlock && <Color />}+ </div>+ );+}++export default ToolbarActions;\ No newline at end of filediff --git a/frontend/appflowy_web_app/src/components/editor/components/toolbar/selection-toolbar/actions/ActionButton.tsx b/frontend/appflowy_web_app/src/components/editor/components/toolbar/selection-toolbar/actions/ActionButton.tsxnew file mode 100644index 0000000000..f10b904f58--- /dev/null+++ b/frontend/appflowy_web_app/src/components/editor/components/toolbar/selection-toolbar/actions/ActionButton.tsx@@ -0,0 +1,35 @@+import React, { forwardRef } from 'react';+import IconButton, { IconButtonProps } from '@mui/material/IconButton';+import { Tooltip } from '@mui/material';++const ActionButton = forwardRef<+ HTMLButtonElement,+ {+ tooltip?: string | React.ReactNode;+ onClick?: (e: React.MouseEvent<HTMLButtonElement>) => void;+ children: React.ReactNode;+ active?: boolean;+ } & IconButtonProps+>(({ tooltip, onClick, disabled, children, active, className, ...props }, ref) => {+ return (+ <Tooltip disableInteractive={true} placement={'top'} title={tooltip}>+ <IconButton+ ref={ref}+ onClick={onClick}+ size={'small'}+ style={{+ color: active ? 'var(--fill-default)' : disabled ? 'var(--line-on-toolbar)' : undefined,+ }}+ disabled={disabled}+ {...props}+ className={`${+ className ?? ''+ } bg-transparent px-1 py-1 text-icon-on-toolbar hover:bg-transparent hover:text-fill-hover`}+ >+ {children}+ </IconButton>+ </Tooltip>+ );+});++export default ActionButton;diff --git a/frontend/appflowy_web_app/src/components/editor/components/toolbar/selection-toolbar/actions/Align.tsx b/frontend/appflowy_web_app/src/components/editor/components/toolbar/selection-toolbar/actions/Align.tsxnew file mode 100644index 0000000000..496e8a303c--- /dev/null+++ b/frontend/appflowy_web_app/src/components/editor/components/toolbar/selection-toolbar/actions/Align.tsx@@ -0,0 +1,139 @@+import { YjsEditor } from '@/application/slate-yjs';+import { CustomEditor } from '@/application/slate-yjs/command';+import { getBlockEntry } from '@/application/slate-yjs/utils/yjsOperations';+import { AlignType, BlockData } from '@/application/types';+import { ReactComponent as AlignCenterSvg } from '@/assets/toolbar_align_center.svg';+import { ReactComponent as AlignLeftSvg } from '@/assets/toolbar_align_left.svg';+import { ReactComponent as AlignRightSvg } from '@/assets/toolbar_align_right.svg';+import { Popover } from '@/components/_shared/popover';+import { PopoverProps } from '@mui/material/Popover';+import React, { useCallback, useRef, useState } from 'react';+import { useTranslation } from 'react-i18next';+import { useSlateStatic } from 'slate-react';+import ActionButton from './ActionButton';++const popoverProps: Partial<PopoverProps> = {+ anchorOrigin: {+ vertical: 'bottom',+ horizontal: 'center',+ },+ transformOrigin: {+ vertical: -8,+ horizontal: 'center',+ },+ slotProps: {+ paper: {+ className: 'bg-[var(--fill-toolbar)] rounded-[6px]',+ },+ },+};++export function Align () {+ const [open, setOpen] = useState(false);+ const ref = useRef<HTMLButtonElement | null>(null);+ const { t } = useTranslation();+ const editor = useSlateStatic() as YjsEditor;+ const getAlign = useCallback(() => {+ try {+ const [node] = getBlockEntry(editor);++ return (node.data as BlockData).align;++ } catch (e) {+ return;+ }++ }, [editor]);++ const handleClose = useCallback(() => {+ setOpen(false);+ }, []);++ const handleOpen = useCallback(() => {+ setOpen(true);+ }, []);++ const activeIcon = useCallback(() => {+ const align = getAlign();++ switch (align) {+ case AlignType.Left:+ return <AlignLeftSvg className={'text-fill-default'} />;+ case 'center':+ return <AlignCenterSvg className={'text-fill-default'} />;+ case 'right':+ return <AlignRightSvg className={'text-fill-default'} />;+ default:+ return <AlignLeftSvg />;+ }+ }, [getAlign]);++ const toggleAlign = useCallback(+ (align: AlignType) => {+ return () => {+ try {+ const [node] = getBlockEntry(editor);++ CustomEditor.setBlockData(editor, node.blockId as string, {+ align,+ });+ handleClose();++ } catch (e) {+ return;+ }++ };+ },+ [editor, handleClose],+ );++ return (+ <>+ <ActionButton+ ref={ref} onClick={(e) => {+ e.preventDefault();+ e.stopPropagation();+ handleOpen();+ }} tooltip={t('document.plugins.optionAction.align')}+ >+ {activeIcon()}+ </ActionButton>+ <Popover+ disableAutoFocus={true}+ disableEnforceFocus={true}+ disableRestoreFocus={true}+ onClose={() => {+ setOpen(false);+ }}+ open={open}+ anchorEl={ref.current}+ {...popoverProps}+ >+ <div className={'flex items-center px-2 h-[32px] justify-center'}>+ <ActionButton+ active={getAlign() === AlignType.Left} tooltip={t('document.plugins.optionAction.left')}+ onClick={toggleAlign(AlignType.Left)}+ >+ <AlignLeftSvg />+ </ActionButton>+ <ActionButton+ active={getAlign() === AlignType.Center} tooltip={t('document.plugins.optionAction.center')}+ onClick={toggleAlign(AlignType.Center)}+ >+ <AlignCenterSvg />+ </ActionButton>+ <ActionButton+ active={getAlign() === AlignType.Right} tooltip={t('document.plugins.optionAction.right')}+ onClick={toggleAlign(AlignType.Right)}+ >+ <AlignRightSvg />+ </ActionButton>+ </div>+ </Popover>+ </>++ );+}++export default Align;diff --git a/frontend/appflowy_web_app/src/components/editor/components/toolbar/selection-toolbar/actions/Bold.tsx b/frontend/appflowy_web_app/src/components/editor/components/toolbar/selection-toolbar/actions/Bold.tsxnew file mode 100644index 0000000000..b4b5a5ca5b--- /dev/null+++ b/frontend/appflowy_web_app/src/components/editor/components/toolbar/selection-toolbar/actions/Bold.tsx@@ -0,0 +1,40 @@+import { YjsEditor } from '@/application/slate-yjs';+import { CustomEditor } from '@/application/slate-yjs/command';+import { EditorMarkFormat } from '@/application/slate-yjs/types';+import ActionButton from '@/components/editor/components/toolbar/selection-toolbar/actions/ActionButton';+import { createHotKeyLabel, HOT_KEY_NAME } from '@/utils/hotkeys';+import React, { useCallback, useMemo } from 'react';+import { useTranslation } from 'react-i18next';+import { useSlateStatic } from 'slate-react';+import { ReactComponent as BoldSvg } from '@/assets/bold.svg';++export function Bold () {+ const { t } = useTranslation();+ const editor = useSlateStatic() as YjsEditor;+ const isActivated = CustomEditor.isMarkActive(editor, EditorMarkFormat.Bold);++ const modifier = useMemo(() => createHotKeyLabel(HOT_KEY_NAME.BOLD), []);+ const onClick = useCallback(() => {+ CustomEditor.toggleMark(editor, {+ key: EditorMarkFormat.Bold,+ value: true,+ });+ }, [editor]);++ return (+ <ActionButton+ onClick={onClick}+ active={isActivated}+ tooltip={+ <>+ <div>{t('toolbar.bold')}</div>+ <div className={'text-xs text-text-caption'}>{modifier}</div>+ </>+ }+ >+ <BoldSvg />+ </ActionButton>+ );+}++export default Bold;diff --git a/frontend/appflowy_web_app/src/components/editor/components/toolbar/selection-toolbar/actions/BulletedList.tsx b/frontend/appflowy_web_app/src/components/editor/components/toolbar/selection-toolbar/actions/BulletedList.tsxnew file mode 100644index 0000000000..1e9700306e--- /dev/null+++ b/frontend/appflowy_web_app/src/components/editor/components/toolbar/selection-toolbar/actions/BulletedList.tsx@@ -0,0 +1,41 @@+import { YjsEditor } from '@/application/slate-yjs';+import { CustomEditor } from '@/application/slate-yjs/command';+import { getBlockEntry } from '@/application/slate-yjs/utils/yjsOperations';+import { BlockType } from '@/application/types';+import React, { useCallback } from 'react';+import ActionButton from './ActionButton';+import { useTranslation } from 'react-i18next';+import { useSlateStatic } from 'slate-react';+import { ReactComponent as BulletedListSvg } from '@/assets/bulleted_list.svg';++export function BulletedList () {+ const { t } = useTranslation();+ const editor = useSlateStatic() as YjsEditor;+ const isActivated = CustomEditor.isBlockActive(editor, BlockType.BulletedListBlock);++ const onClick = useCallback(() => {+ try {+ const [node] = getBlockEntry(editor);++ if (!node) return;++ if (node.type === BlockType.BulletedListBlock) {+ CustomEditor.turnToBlock(editor, node.blockId as string, BlockType.Paragraph, {});+ return;+ }++ CustomEditor.turnToBlock(editor, node.blockId as string, BlockType.BulletedListBlock, {});++ } catch (e) {+ return;+ }+ }, [editor]);++ return (+ <ActionButton active={isActivated} onClick={onClick} tooltip={t('document.plugins.bulletedList')}>+ <BulletedListSvg />+ </ActionButton>+ );+}++export default BulletedList;diff --git a/frontend/appflowy_web_app/src/components/editor/components/toolbar/selection-toolbar/actions/Color.tsx b/frontend/appflowy_web_app/src/components/editor/components/toolbar/selection-toolbar/actions/Color.tsxnew file mode 100644index 0000000000..ca01671300--- /dev/null+++ b/frontend/appflowy_web_app/src/components/editor/components/toolbar/selection-toolbar/actions/Color.tsx@@ -0,0 +1,70 @@+import { YjsEditor } from '@/application/slate-yjs';+import { CustomEditor } from '@/application/slate-yjs/command';+import { EditorMarkFormat } from '@/application/slate-yjs/types';+import { ColorPicker } from '@/components/_shared/color-picker';+import {+ SelectionToolbarPopoverProvider,+ useSelectionToolbarPopoverContext,+} from '@/components/editor/components/toolbar/selection-toolbar/SelectionToolbarPopoverContext';+import React, { useCallback } from 'react';+import ActionButton from './ActionButton';+import { useTranslation } from 'react-i18next';+import { useSlateStatic } from 'slate-react';+import { ReactComponent as ColorSvg } from '@/assets/color_theme.svg';++function ColorButton () {+ const { t } = useTranslation();+ const editor = useSlateStatic() as YjsEditor;+ const { openPopover } = useSelectionToolbarPopoverContext();+ const isActivated = CustomEditor.isMarkActive(editor, EditorMarkFormat.BgColor) || CustomEditor.isMarkActive(editor, EditorMarkFormat.FontColor);++ const onClick = useCallback((e: React.MouseEvent) => {+ e.stopPropagation();+ e.preventDefault();+ openPopover();+ }, [openPopover]);++ return (+ <ActionButton+ onClick={onClick}+ active={isActivated}+ tooltip={t('editor.color')}+ >+ <ColorSvg />+ </ActionButton>+ );+}++function ColorPickerContent () {+ const editor = useSlateStatic() as YjsEditor;+ const { closePopover } = useSelectionToolbarPopoverContext();++ const handlePickedColor = useCallback((format: EditorMarkFormat, color: string) => {+ if (color) {+ CustomEditor.addMark(editor, {+ key: format,+ value: color,+ });+ } else {+ CustomEditor.removeMark(editor, format);+ }+ }, [editor]);++ return (+ <ColorPicker+ disableFocus={true}+ onEscape={closePopover}+ onChange={handlePickedColor}+ />+ );+}++function Color () {+ return (+ <SelectionToolbarPopoverProvider popoverContent={<ColorPickerContent />}>+ <ColorButton />+ </SelectionToolbarPopoverProvider>+ );+}++export default Color;\ No newline at end of filediff --git a/frontend/appflowy_web_app/src/components/editor/components/toolbar/selection-toolbar/actions/Formula.tsx b/frontend/appflowy_web_app/src/components/editor/components/toolbar/selection-toolbar/actions/Formula.tsxnew file mode 100644index 0000000000..cf7e904688--- /dev/null+++ b/frontend/appflowy_web_app/src/components/editor/components/toolbar/selection-toolbar/actions/Formula.tsx@@ -0,0 +1,69 @@+import { YjsEditor } from '@/application/slate-yjs';+import { CustomEditor } from '@/application/slate-yjs/command';+import { EditorMarkFormat } from '@/application/slate-yjs/types';+import ActionButton from '@/components/editor/components/toolbar/selection-toolbar/actions/ActionButton';+import React, { useCallback } from 'react';+import { useTranslation } from 'react-i18next';+import { Transforms, Text, Editor } from 'slate';+import { useSlateStatic } from 'slate-react';+import { ReactComponent as MathSvg } from '@/assets/math.svg';++function Formula () {+ const { t } = useTranslation();+ const editor = useSlateStatic() as YjsEditor;+ const isActivated = CustomEditor.isMarkActive(editor, EditorMarkFormat.Formula);++ const onClick = useCallback(() => {+ const { selection } = editor;++ if (!selection) return;++ if (!isActivated) {+ const start = editor.start(selection);+ const text = editor.string(selection);++ editor.delete();++ editor.insertText('$');+ Transforms.select(editor, {+ anchor: start,+ focus: { path: start.path, offset: start.offset + 1 },+ });+ CustomEditor.addMark(editor, {+ key: EditorMarkFormat.Formula,+ value: text,+ });+ } else {+ const [entry] = editor.nodes({+ at: selection,+ match: n => !Editor.isEditor(n) && Text.isText(n) && n.formula !== undefined,+ });++ if (!entry) return;++ const [node] = entry;+ const formula = (node as unknown as Text).formula || '';++ CustomEditor.removeMark(editor, EditorMarkFormat.Formula);++ editor.collapse({+ edge: 'end',+ });+ editor.deleteBackward('character');+ editor.insertText(formula);+ }++ }, [editor, isActivated]);++ return (+ <ActionButton+ onClick={onClick}+ active={isActivated}+ tooltip={t('document.plugins.createInlineMathEquation')}+ >+ <MathSvg />+ </ActionButton>+ );+}++export default Formula;\ No newline at end of filediff --git a/frontend/appflowy_web_app/src/components/editor/components/toolbar/selection-toolbar/actions/Heading.tsx b/frontend/appflowy_web_app/src/components/editor/components/toolbar/selection-toolbar/actions/Heading.tsxnew file mode 100644index 0000000000..76bcf97247--- /dev/null+++ b/frontend/appflowy_web_app/src/components/editor/components/toolbar/selection-toolbar/actions/Heading.tsx@@ -0,0 +1,155 @@+import { YjsEditor } from '@/application/slate-yjs';+import { CustomEditor } from '@/application/slate-yjs/command';+import { getBlockEntry } from '@/application/slate-yjs/utils/yjsOperations';+import { BlockType, HeadingBlockData } from '@/application/types';+import { Popover } from '@/components/_shared/popover';+import { PopoverProps } from '@mui/material/Popover';+import React, { useCallback, useRef, useState } from 'react';+import ActionButton from './ActionButton';+import { useTranslation } from 'react-i18next';+import { useSlateStatic } from 'slate-react';+import { ReactComponent as Heading1Svg } from '@/assets/h1.svg';+import { ReactComponent as Heading2Svg } from '@/assets/h2.svg';+import { ReactComponent as Heading3Svg } from '@/assets/h3.svg';+import { ReactComponent as Heading4Svg } from '@/assets/h4.svg';+import { ReactComponent as Heading5Svg } from '@/assets/h5.svg';+import { ReactComponent as Heading6Svg } from '@/assets/h6.svg';+import { ReactComponent as RightIcon } from '@/assets/arrow_right.svg';++const popoverProps: Partial<PopoverProps> = {+ anchorOrigin: {+ vertical: 'bottom',+ horizontal: 'center',+ },+ transformOrigin: {+ vertical: -8,+ horizontal: 'center',+ },+ slotProps: {+ paper: {+ className: 'bg-[var(--fill-toolbar)] rounded-[6px]',+ },+ },+};++export function Heading () {+ const { t } = useTranslation();+ const editor = useSlateStatic() as YjsEditor;+ const toHeading = useCallback(+ (level: number) => {++ return () => {+ try {+ const [node] = getBlockEntry(editor);++ if (!node) return;++ if (node.type === BlockType.HeadingBlock && (node.data as HeadingBlockData).level === level) {+ CustomEditor.turnToBlock(editor, node.blockId as string, BlockType.Paragraph, {});+ return;+ }++ CustomEditor.turnToBlock<HeadingBlockData>(editor, node.blockId as string, BlockType.HeadingBlock, { level });++ } catch (e) {+ return;+ }++ };+ },+ [editor],+ );++ const isActivated = useCallback(+ (level: number) => {+ try {+ const [node] = getBlockEntry(editor);++ const isBlock = CustomEditor.isBlockActive(editor, BlockType.HeadingBlock);++ return isBlock && (node.data as HeadingBlockData).level === level;+ } catch (e) {+ return false;+ }++ },+ [editor],+ );++ const getActiveButton = useCallback(() => {+ if (isActivated(1)) {+ return <Heading1Svg className={'text-fill-default'} />;+ }++ if (isActivated(2)) {+ return <Heading2Svg className={'text-fill-default'} />;+ }++ if (isActivated(3)) {+ return <Heading3Svg className={'text-fill-default'} />;+ }++ if (isActivated(4)) {+ return <Heading4Svg className={'text-fill-default'} />;+ }++ if (isActivated(5)) {+ return <Heading5Svg className={'text-fill-default'} />;+ }++ if (isActivated(6)) {+ return <Heading6Svg className={'text-fill-default'} />;+ }++ return <Heading1Svg />;+ }, [isActivated]);++ const [open, setOpen] = useState(false);+ const ref = useRef<HTMLButtonElement | null>(null);++ return (+ <div className={'flex items-center justify-center'}>+ <ActionButton+ ref={ref}+ onClick={(e) => {+ e.preventDefault();+ e.stopPropagation();+ setOpen(true);+ }}+ tooltip={'Heading'}+ >+ <div className={'flex items-center justify-center'}>+ {getActiveButton()}+ <RightIcon className={'transform h-3 w-3 rotate-90 text-icon-on-toolbar opacity-80'} />+ </div>++ </ActionButton>+ <Popover+ disableAutoFocus={true}+ disableEnforceFocus={true}+ disableRestoreFocus={true}+ onClose={() => {+ setOpen(false);+ }}+ open={open}+ anchorEl={ref.current}+ {...popoverProps}+ >+ <div className={'flex items-center px-2 h-[32px] justify-center'}>+ <ActionButton active={isActivated(1)} tooltip={t('editor.heading1')} onClick={toHeading(1)}>+ <Heading1Svg />+ </ActionButton>+ <ActionButton active={isActivated(2)} tooltip={t('editor.heading2')} onClick={toHeading(2)}>+ <Heading2Svg />+ </ActionButton>+ <ActionButton active={isActivated(3)} tooltip={t('editor.heading3')} onClick={toHeading(3)}>+ <Heading3Svg />+ </ActionButton>+ </div>+ </Popover>++ </div>+ );+}++export default Heading;diff --git a/frontend/appflowy_web_app/src/components/editor/components/toolbar/selection-toolbar/actions/Href.tsx b/frontend/appflowy_web_app/src/components/editor/components/toolbar/selection-toolbar/actions/Href.tsxnew file mode 100644index 0000000000..8fe8c3886c--- /dev/null+++ b/frontend/appflowy_web_app/src/components/editor/components/toolbar/selection-toolbar/actions/Href.tsx@@ -0,0 +1,107 @@+import { YjsEditor } from '@/application/slate-yjs';+import { CustomEditor } from '@/application/slate-yjs/command';+import { EditorMarkFormat } from '@/application/slate-yjs/types';+import { Popover } from '@/components/_shared/popover';+import {+ useSelectionToolbarContext,+} from '@/components/editor/components/toolbar/selection-toolbar/SelectionToolbar.hooks';+import { getRangeRect } from '@/components/editor/components/toolbar/selection-toolbar/utils';+import { createHotkey, getModifier, HOT_KEY_NAME } from '@/utils/hotkeys';+import { PopoverPosition } from '@mui/material';+import React, { useCallback, useEffect, useMemo } from 'react';+import ActionButton from './ActionButton';+import { useTranslation } from 'react-i18next';+import { ReactEditor, useSlateStatic } from 'slate-react';+import { ReactComponent as LinkSvg } from '@/assets/link.svg';++export function Href () {+ const { t } = useTranslation();+ const { forceShow } = useSelectionToolbarContext();+ const editor = useSlateStatic() as YjsEditor;+ const hasActivatedInline = CustomEditor.hasMark(editor, EditorMarkFormat.Formula) || CustomEditor.hasMark(editor, EditorMarkFormat.Mention);+ const isActivated = CustomEditor.isMarkActive(editor, EditorMarkFormat.Href);+ const [anchorPosition, setAnchorPosition] = React.useState<undefined | PopoverPosition>(undefined);+ const open = Boolean(anchorPosition);+ const handleClose = useCallback(() => {+ setAnchorPosition(undefined);+ }, []);++ const formatLink = useCallback(() => {+ if (!editor.selection || hasActivatedInline) return;+ const rect = getRangeRect();++ if (!rect) return;+ forceShow(true);++ setAnchorPosition({+ top: rect.top + rect.height,+ left: rect.left + rect.width / 2,+ });+ }, [editor, hasActivatedInline, forceShow]);++ const onClick = useCallback((e: React.MouseEvent) => {+ e.stopPropagation();+ e.preventDefault();+ formatLink();+ }, [formatLink]);++ const tooltip = useMemo(() => {+ const modifier = getModifier();++ return (+ <>+ <div>{t('editor.link')}</div>+ <div className={'text-xs text-text-caption'}>{`${modifier} + K`}</div>+ </>+ );+ }, [t]);++ useEffect(() => {+ const onKeyDown = (e: KeyboardEvent) => {+ if (createHotkey(HOT_KEY_NAME.FORMAT_LINK)(e)) {+ e.preventDefault();+ formatLink();+ }+ };++ const slateDom = ReactEditor.toDOMNode(editor, editor);++ if (!slateDom) return;++ slateDom.addEventListener('keydown', onKeyDown);+ return () => {+ slateDom.removeEventListener('keydown', onKeyDown);+ };+ }, [editor, formatLink]);++ return (+ <>+ <ActionButton+ disabled={hasActivatedInline}+ onClick={onClick}+ active={isActivated}+ tooltip={tooltip}+ >+ <LinkSvg />+ </ActionButton>+ {open && <Popover+ onMouseDown={e => e.stopPropagation()}+ onMouseUp={e => e.stopPropagation()}+ disableRestoreFocus={true}+ open={open}+ onClose={handleClose}+ anchorPosition={anchorPosition}+ anchorReference={'anchorPosition'}+ transformOrigin={{+ vertical: 'top',+ horizontal: 'center',+ }}+ >+ <input />+ </Popover>}++ </>+ );+}++export default Href;diff --git a/frontend/appflowy_web_app/src/components/editor/components/toolbar/selection-toolbar/actions/InlineCode.tsx b/frontend/appflowy_web_app/src/components/editor/components/toolbar/selection-toolbar/actions/InlineCode.tsxnew file mode 100644index 0000000000..c41c641465--- /dev/null+++ b/frontend/appflowy_web_app/src/components/editor/components/toolbar/selection-toolbar/actions/InlineCode.tsx@@ -0,0 +1,39 @@+import { CustomEditor } from '@/application/slate-yjs/command';+import { EditorMarkFormat } from '@/application/slate-yjs/types';+import ActionButton from '@/components/editor/components/toolbar/selection-toolbar/actions/ActionButton';+import { createHotKeyLabel, HOT_KEY_NAME } from '@/utils/hotkeys';+import React, { useCallback, useMemo } from 'react';+import { useTranslation } from 'react-i18next';+import { useSlateStatic } from 'slate-react';+import { ReactComponent as CodeSvg } from '@/assets/inline_code.svg';++export function InlineCode () {+ const { t } = useTranslation();+ const editor = useSlateStatic();+ const isActivated = CustomEditor.isMarkActive(editor, EditorMarkFormat.Code);+ const modifier = useMemo(() => createHotKeyLabel(HOT_KEY_NAME.CODE), []);++ const onClick = useCallback(() => {+ CustomEditor.toggleMark(editor, {+ key: EditorMarkFormat.Code,+ value: true,+ });+ }, [editor]);++ return (+ <ActionButton+ onClick={onClick}+ active={isActivated}+ tooltip={+ <>+ <div>{t('editor.embedCode')}</div>+ <div className={'text-xs text-text-caption'}>{modifier}</div>+ </>+ }+ >+ <CodeSvg />+ </ActionButton>+ );+}++export default InlineCode;diff --git a/frontend/appflowy_web_app/src/components/editor/components/toolbar/selection-toolbar/actions/Italic.tsx b/frontend/appflowy_web_app/src/components/editor/components/toolbar/selection-toolbar/actions/Italic.tsxnew file mode 100644index 0000000000..99c4606bce--- /dev/null+++ b/frontend/appflowy_web_app/src/components/editor/components/toolbar/selection-toolbar/actions/Italic.tsx@@ -0,0 +1,39 @@+import { CustomEditor } from '@/application/slate-yjs/command';+import { EditorMarkFormat } from '@/application/slate-yjs/types';+import ActionButton from '@/components/editor/components/toolbar/selection-toolbar/actions/ActionButton';+import { createHotKeyLabel, HOT_KEY_NAME } from '@/utils/hotkeys';+import React, { useCallback, useMemo } from 'react';+import { useTranslation } from 'react-i18next';+import { useSlateStatic } from 'slate-react';+import { ReactComponent as ItalicSvg } from '@/assets/italic.svg';++export function Italic () {+ const { t } = useTranslation();+ const editor = useSlateStatic();+ const isActivated = CustomEditor.isMarkActive(editor, EditorMarkFormat.Italic);+ const modifier = useMemo(() => createHotKeyLabel(HOT_KEY_NAME.ITALIC), []);++ const onClick = useCallback(() => {+ CustomEditor.toggleMark(editor, {+ key: EditorMarkFormat.Italic,+ value: true,+ });+ }, [editor]);++ return (+ <ActionButton+ onClick={onClick}+ active={isActivated}+ tooltip={+ <>+ <div>{t('toolbar.italic')}</div>+ <div className={'text-xs text-text-caption'}>{modifier}</div>+ </>+ }+ >+ <ItalicSvg />+ </ActionButton>+ );+}++export default Italic;diff --git a/frontend/appflowy_web_app/src/components/editor/components/toolbar/selection-toolbar/actions/NumberedList.tsx b/frontend/appflowy_web_app/src/components/editor/components/toolbar/selection-toolbar/actions/NumberedList.tsxnew file mode 100644index 0000000000..2d6320857d--- /dev/null+++ b/frontend/appflowy_web_app/src/components/editor/components/toolbar/selection-toolbar/actions/NumberedList.tsx@@ -0,0 +1,41 @@+import { YjsEditor } from '@/application/slate-yjs';+import { CustomEditor } from '@/application/slate-yjs/command';+import { getBlockEntry } from '@/application/slate-yjs/utils/yjsOperations';+import { BlockType } from '@/application/types';+import React, { useCallback } from 'react';+import ActionButton from './ActionButton';+import { useTranslation } from 'react-i18next';+import { useSlateStatic } from 'slate-react';+import { ReactComponent as NumberedListSvg } from '@/assets/numbered_list.svg';++export function NumberedList () {+ const { t } = useTranslation();+ const editor = useSlateStatic() as YjsEditor;+ const isActivated = CustomEditor.isBlockActive(editor, BlockType.NumberedListBlock);++ const onClick = useCallback(() => {+ try {+ const [node] = getBlockEntry(editor);++ if (!node) return;++ if (node.type === BlockType.NumberedListBlock) {+ CustomEditor.turnToBlock(editor, node.blockId as string, BlockType.Paragraph, {});+ return;+ }++ CustomEditor.turnToBlock(editor, node.blockId as string, BlockType.NumberedListBlock, {});++ } catch (e) {+ return;+ }+ }, [editor]);++ return (+ <ActionButton active={isActivated} onClick={onClick} tooltip={t('document.plugins.numberedList')}>+ <NumberedListSvg />+ </ActionButton>+ );+}++export default NumberedList;diff --git a/frontend/appflowy_web_app/src/components/editor/components/toolbar/selection-toolbar/actions/Paragraph.tsx b/frontend/appflowy_web_app/src/components/editor/components/toolbar/selection-toolbar/actions/Paragraph.tsxnew file mode 100644index 0000000000..a209e1483e--- /dev/null+++ b/frontend/appflowy_web_app/src/components/editor/components/toolbar/selection-toolbar/actions/Paragraph.tsx@@ -0,0 +1,32 @@+import { YjsEditor } from '@/application/slate-yjs';+import { CustomEditor } from '@/application/slate-yjs/command';+import { getBlockEntry } from '@/application/slate-yjs/utils/yjsOperations';+import { BlockType } from '@/application/types';+import { ReactComponent as ParagraphSvg } from '@/assets/paragraph.svg';+import React, { useCallback } from 'react';+import { useTranslation } from 'react-i18next';+import { useSlateStatic } from 'slate-react';+import ActionButton from './ActionButton';++export function Paragraph () {+ const { t } = useTranslation();+ const editor = useSlateStatic() as YjsEditor;++ const onClick = useCallback(() => {+ const [node] = getBlockEntry(editor);++ if (!node) return;++ CustomEditor.turnToBlock(editor, node.blockId as string, BlockType.Paragraph, {});+ }, [editor]);++ const isActive = CustomEditor.isBlockActive(editor, BlockType.Paragraph);++ return (+ <ActionButton active={isActive} onClick={onClick} tooltip={t('editor.text')}>+ <ParagraphSvg />+ </ActionButton>+ );+}++export default Paragraph;diff --git a/frontend/appflowy_web_app/src/components/editor/components/toolbar/selection-toolbar/actions/Quote.tsx b/frontend/appflowy_web_app/src/components/editor/components/toolbar/selection-toolbar/actions/Quote.tsxnew file mode 100644index 0000000000..a5d49fca9e--- /dev/null+++ b/frontend/appflowy_web_app/src/components/editor/components/toolbar/selection-toolbar/actions/Quote.tsx@@ -0,0 +1,42 @@+import { YjsEditor } from '@/application/slate-yjs';+import { CustomEditor } from '@/application/slate-yjs/command';+import { getBlockEntry } from '@/application/slate-yjs/utils/yjsOperations';+import { BlockType } from '@/application/types';+import React, { useCallback } from 'react';+import ActionButton from './ActionButton';+import { useTranslation } from 'react-i18next';+import { useSlateStatic } from 'slate-react';+import { ReactComponent as QuoteSvg } from '@/assets/quote.svg';++export function Quote () {+ const { t } = useTranslation();+ const editor = useSlateStatic() as YjsEditor;+ const isActivated = CustomEditor.isBlockActive(editor, BlockType.QuoteBlock);++ const onClick = useCallback(() => {+ try {+ const [node] = getBlockEntry(editor);++ if (!node) return;++ if (node.type === BlockType.QuoteBlock) {+ CustomEditor.turnToBlock(editor, node.blockId as string, BlockType.Paragraph, {});+ return;+ }++ CustomEditor.turnToBlock(editor, node.blockId as string, BlockType.QuoteBlock, {});++ } catch (e) {+ return;+ }++ }, [editor]);++ return (+ <ActionButton active={isActivated} onClick={onClick} tooltip={t('editor.quote')}>+ <QuoteSvg />+ </ActionButton>+ );+}++export default Quote;diff --git a/frontend/appflowy_web_app/src/components/editor/components/toolbar/selection-toolbar/actions/StrikeThrough.tsx b/frontend/appflowy_web_app/src/components/editor/components/toolbar/selection-toolbar/actions/StrikeThrough.tsxnew file mode 100644index 0000000000..a72cb90bed--- /dev/null+++ b/frontend/appflowy_web_app/src/components/editor/components/toolbar/selection-toolbar/actions/StrikeThrough.tsx@@ -0,0 +1,39 @@+import { CustomEditor } from '@/application/slate-yjs/command';+import { EditorMarkFormat } from '@/application/slate-yjs/types';+import ActionButton from '@/components/editor/components/toolbar/selection-toolbar/actions/ActionButton';+import { createHotKeyLabel, HOT_KEY_NAME } from '@/utils/hotkeys';+import React, { useCallback, useMemo } from 'react';+import { useTranslation } from 'react-i18next';+import { useSlateStatic } from 'slate-react';+import { ReactComponent as StrikeThroughSvg } from '@/assets/strikethrough.svg';++export function StrikeThrough () {+ const { t } = useTranslation();+ const editor = useSlateStatic();+ const isActivated = CustomEditor.isMarkActive(editor, EditorMarkFormat.StrikeThrough);+ const modifier = useMemo(() => createHotKeyLabel(HOT_KEY_NAME.STRIKETHROUGH), []);++ const onClick = useCallback(() => {+ CustomEditor.toggleMark(editor, {+ key: EditorMarkFormat.StrikeThrough,+ value: true,+ });+ }, [editor]);++ return (+ <ActionButton+ onClick={onClick}+ active={isActivated}+ tooltip={+ <>+ <div>{t('editor.strikethrough')}</div>+ <div className={'text-xs text-text-caption'}>{modifier}</div>+ </>+ }+ >+ <StrikeThroughSvg />+ </ActionButton>+ );+}++export default StrikeThrough;diff --git a/frontend/appflowy_web_app/src/components/editor/components/toolbar/selection-toolbar/actions/Underline.tsx b/frontend/appflowy_web_app/src/components/editor/components/toolbar/selection-toolbar/actions/Underline.tsxnew file mode 100644index 0000000000..0f1c2687da--- /dev/null+++ b/frontend/appflowy_web_app/src/components/editor/components/toolbar/selection-toolbar/actions/Underline.tsx@@ -0,0 +1,39 @@+import { CustomEditor } from '@/application/slate-yjs/command';+import { EditorMarkFormat } from '@/application/slate-yjs/types';+import ActionButton from '@/components/editor/components/toolbar/selection-toolbar/actions/ActionButton';+import { createHotKeyLabel, HOT_KEY_NAME } from '@/utils/hotkeys';+import React, { useCallback, useMemo } from 'react';+import { useTranslation } from 'react-i18next';+import { useSlateStatic } from 'slate-react';+import { ReactComponent as UnderlineSvg } from '@/assets/underline.svg';++export function Underline () {+ const { t } = useTranslation();+ const editor = useSlateStatic();+ const isActivated = CustomEditor.isMarkActive(editor, EditorMarkFormat.Underline);+ const modifier = useMemo(() => createHotKeyLabel(HOT_KEY_NAME.UNDERLINE), []);++ const onClick = useCallback(() => {+ CustomEditor.toggleMark(editor, {+ key: EditorMarkFormat.Underline,+ value: true,+ });+ }, [editor]);++ return (+ <ActionButton+ onClick={onClick}+ active={isActivated}+ tooltip={+ <>+ <div>{t('editor.underline')}</div>+ <div className={'text-xs text-text-caption'}>{modifier}</div>+ </>+ }+ >+ <UnderlineSvg />+ </ActionButton>+ );+}++export default Underline;diff --git a/frontend/appflowy_web_app/src/components/editor/components/toolbar/selection-toolbar/utils.ts b/frontend/appflowy_web_app/src/components/editor/components/toolbar/selection-toolbar/utils.tsnew file mode 100644index 0000000000..4268a638fd--- /dev/null+++ b/frontend/appflowy_web_app/src/components/editor/components/toolbar/selection-toolbar/utils.ts@@ -0,0 +1,57 @@+import { ReactEditor } from 'slate-react';++export function getRangeRect () {+ const domSelection = window.getSelection();+ const rangeCount = domSelection?.rangeCount;++ if (!rangeCount) return null;++ const anchorNode = domSelection.anchorNode;+ const focusNode = domSelection.focusNode;+ const focusOffset = domSelection.focusOffset;+ let domRange = rangeCount > 0 ? domSelection.getRangeAt(0) : undefined;++ if (focusNode && anchorNode && anchorNode.parentElement?.getBoundingClientRect().top !== focusNode.parentElement?.getBoundingClientRect().top) {+ const newRange = document.createRange();++ newRange.setStart(focusNode, focusOffset);++ domRange = newRange;+ }++ return domRange?.getBoundingClientRect();+}++export function getSelectionPosition (editor: ReactEditor) {++ const rect = getRangeRect();++ if (!rect) return null;+ let newRect;++ const domNode = ReactEditor.toDOMNode(editor, editor);+ const domNodeRect = domNode.getBoundingClientRect();++ // the default height of the toolbar is 30px+ const gap = 78;++ if (rect) {+ let relativeDomTop = rect.top - domNodeRect.top;+ const relativeDomLeft = rect.left - domNodeRect.left;++ // if the range is above the window, move the toolbar to the bottom of range+ if (rect.top < gap) {+ relativeDomTop = -domNodeRect.top + gap;+ }++ newRect = {+ top: relativeDomTop,+ left: relativeDomLeft,+ width: rect.width,+ height: rect.height,+ };+ }++ return newRect;+}+diff --git a/frontend/appflowy_web_app/src/components/publish/CollabView.tsx b/frontend/appflowy_web_app/src/components/publish/CollabView.tsxindex 997bde4a56..d6a9a8fbdb 100644--- a/frontend/appflowy_web_app/src/components/publish/CollabView.tsx+++ b/frontend/appflowy_web_app/src/components/publish/CollabView.tsx@@ -39,6 +39,7 @@ function CollabView ({ doc }: CollabViewProps) {}}, [layout]) as React.FC<{doc: YDoc;+ readOnly: boolean;navigateToView?: (viewId: string) => Promise<void>;loadViewMeta?: LoadViewMeta;createRowDoc?: CreateRowDoc;@@ -106,6 +107,7 @@ function CollabView ({ doc }: CollabViewProps) {><Viewdoc={doc}+ readOnly={true}loadViewMeta={loadViewMeta}createRowDoc={createRowDoc}navigateToView={navigateToView}diff --git a/frontend/appflowy_web_app/src/pages/AppPage.tsx b/frontend/appflowy_web_app/src/pages/AppPage.tsxindex 431535b1fc..33b45d3a0b 100644--- a/frontend/appflowy_web_app/src/pages/AppPage.tsx+++ b/frontend/appflowy_web_app/src/pages/AppPage.tsx@@ -2,15 +2,15 @@ import { AppendBreadcrumb, CreateRowDoc, LoadView, LoadViewMeta, ViewLayout, YDoimport Help from '@/components/_shared/help/Help';import { findView } from '@/components/_shared/outline/utils';import CalendarSkeleton from '@/components/_shared/skeleton/CalendarSkeleton';-import GridSkeleton from '@/components/_shared/skeleton/GridSkeleton';import DocumentSkeleton from '@/components/_shared/skeleton/DocumentSkeleton';+import GridSkeleton from '@/components/_shared/skeleton/GridSkeleton';import KanbanSkeleton from '@/components/_shared/skeleton/KanbanSkeleton';import { AppContext, useAppHandlers, useAppOutline, useAppViewId } from '@/components/app/app.hooks';import DatabaseView from '@/components/app/DatabaseView';import { Document } from '@/components/document';import RecordNotFound from '@/components/error/RecordNotFound';import { ViewMetaProps } from '@/components/view-meta';-import React, { lazy, Suspense, memo, useCallback, useEffect, useMemo, useContext } from 'react';+import React, { lazy, memo, Suspense, useCallback, useContext, useEffect, useMemo } from 'react';const ViewHelmet = lazy(() => import('@/components/_shared/helmet/ViewHelmet'));@@ -32,7 +32,10 @@ function AppPage () {const rendered = useContext(AppContext)?.rendered;const helmet = useMemo(() => {- return view && rendered ? <Suspense><ViewHelmet name={view.name} icon={view.icon || undefined} /></Suspense> : null;+ return view && rendered ? <Suspense><ViewHelmet+ name={view.name}+ icon={view.icon || undefined}+ /></Suspense> : null;}, [rendered, view]);const [doc, setDoc] = React.useState<YDoc | undefined>(undefined);@@ -73,6 +76,7 @@ function AppPage () {}}, [view?.layout]) as React.FC<{doc: YDoc;+ readOnly: boolean;navigateToView?: (viewId: string) => Promise<void>;loadViewMeta?: LoadViewMeta;createRowDoc?: CreateRowDoc;@@ -114,9 +118,11 @@ function AppPage () {}, [viewMeta]);const viewDom = useMemo(() => {+return doc && viewMeta && View ? (<Viewdoc={doc}+ readOnly={true}viewMeta={viewMeta}navigateToView={toView}loadViewMeta={loadViewMeta}diff --git a/frontend/appflowy_web_app/vite.config.ts b/frontend/appflowy_web_app/vite.config.tsindex b1e88625e0..1ee7367920 100644--- a/frontend/appflowy_web_app/vite.config.ts+++ b/frontend/appflowy_web_app/vite.config.ts@@ -33,7 +33,7 @@ export default defineConfig({name: 'prefixIds',params: {prefix: (node, { path }) => {- const fileName = path?.split('/').pop()?.split('.')[0];+ const fileName = path?.split('/')?.pop()?.split('.')?.[0];return `${fileName}-`;},},diff --git a/frontend/resources/translations/en.json b/frontend/resources/translations/en.jsonindex e317e5cc61..d6aa564e68 100644--- a/frontend/resources/translations/en.json+++ b/frontend/resources/translations/en.json@@ -2501,7 +2501,12 @@"uploadedAt": "Uploaded on {time}","linkedAt": "Link added on {time}","empty": "Upload or embed a file"- }+ },+ "importNotion": "Import from Notion",+ "import": "Import",+ "importSuccess": "Uploaded successfully",+ "importSuccessMessage": "We'll notify you when the import is complete. After that, you can view your imported pages in the sidebar.",+ "importFailed": "Import failed, please check the file format"},"globalComment": {"comments": "Comments",@@ -2681,19 +2686,21 @@"alreadyProTitle": "You've reached the workspace plan limit","alreadyProMessage": "Ask them to contact <email/> to unlock more members","repeatApproveError": "You've already approved this request",- "ensurePlanLimit": "Ensure the workspace plan limit is not exceeded. If the limit is exceeded, consider <upgrade/> the workspace plan or <download/>."+ "ensurePlanLimit": "Ensure the workspace plan limit is not exceeded. If the limit is exceeded, consider <upgrade/> the workspace plan or <download/>.",+ "requestToJoin": "requested to join",+ "asMember": "as a member"},"upgradePlanModal": {- "title": "Unlock Premium Features",- "message": "You're trying to use a premium feature. Upgrade your plan to access all our powerful tools and capabilities!",+ "title": "Upgrade to Pro",+ "message": "{name} has reached the free member limit. Upgrade to the Pro Plan to invite more members.","upgradeSteps": "How to upgrade your plan on AppFlowy:","step1": "1. Go to Settings","step2": "2. Click on 'Plan'","step3": "3. Select 'Change Plan'","appNote": "Note: ",- "actionButton": "Upgrade Now",+ "actionButton": "Upgrade","downloadLink": "Download App",- "laterButton": "Maybe Later",+ "laterButton": "Later","refreshNote": "After successful upgrade, click <refresh/> to activate your new features.","refresh": "here"}