File tree Expand file tree Collapse file tree 6 files changed +28
-5
lines changed
src/app/document/[documentId] Expand file tree Collapse file tree 6 files changed +28
-5
lines changed Original file line number Diff line number Diff line change 11# Thanks AI support me to write readme - haha
2+ # Wanna try?
3+ Go
4+ ``` markdown
5+ [ https://v0-new-project-d2azd6z3jcc.vercel.app/ ] ( https://v0-new-project-d2azd6z3jcc.vercel.app/ )
6+ ```
27# Write Document - Collaborative Document Editor
38
49A real-time collaborative document editor built with modern web technologies, offering a seamless writing and collaboration experience.
Original file line number Diff line number Diff line change @@ -12,6 +12,8 @@ declare global {
1212 Storage : {
1313 // Example, a conflict-free list
1414 // animals: LiveList<string>;
15+ leftMg : number ;
16+ rightMg : number ;
1517 } ;
1618
1719 // Custom user info set when authenticating with a secret key
Original file line number Diff line number Diff line change 1+ import { useMutation , useStorage } from "@liveblocks/react/suspense" ;
12import React , { useRef , useState } from "react" ;
23import { Marker } from "./markers" ;
34
@@ -8,8 +9,15 @@ const MINIMUM_SPACE = 100;
89const INITIAL_MG = 56 ;
910
1011export const Ruler : React . FC = ( ) => {
11- const [ leftMg , setLeftMg ] = useState ( INITIAL_MG ) ;
12- const [ rightMg , setRightMg ] = useState ( INITIAL_MG ) ;
12+ const leftMg = useStorage ( ( root ) => root . leftMg ) ?? INITIAL_MG ;
13+ const rightMg = useStorage ( ( root ) => root . rightMg ) ?? INITIAL_MG ;
14+ const setLeftMg = useMutation ( ( { storage } , position ) => {
15+ storage . set ( "leftMg" , position ) ;
16+ } , [ ] ) ;
17+
18+ const setRightMg = useMutation ( ( { storage } , position ) => {
19+ storage . set ( "rightMg" , position ) ;
20+ } , [ ] ) ;
1321
1422 const [ isDraggingLeft , setIsDraggingLeft ] = useState ( false ) ;
1523 const [ isDraggingRight , setIsDraggingRight ] = useState ( false ) ;
Original file line number Diff line number Diff line change 1- import Image from "next/image" ;
21import React from "react" ;
32
43const SIZE = 36 ;
Original file line number Diff line number Diff line change @@ -21,11 +21,14 @@ import ResizeImage from "tiptap-extension-resize-image";
2121import { FontSizeExtension } from "@/extensions/font-size" ;
2222import { LineHeightExtension } from "@/extensions/line-height" ;
2323import { useLiveblocksExtension } from "@liveblocks/react-tiptap" ;
24+ import { useStorage } from "@liveblocks/react/suspense" ;
2425import TextStyle from "@tiptap/extension-text-style" ;
2526import { Ruler } from "./(ruler)/rulers" ;
2627import { Threads } from "./threads" ;
2728
2829export const Editor : React . FC = ( ) => {
30+ const leftMg = useStorage ( ( root ) => root . leftMg ) ;
31+ const rightMg = useStorage ( ( root ) => root . rightMg ) ;
2932 const { setEditor } = useEditorStore ( ) ;
3033 const liveblocks = useLiveblocksExtension ( ) ;
3134
@@ -57,7 +60,7 @@ export const Editor: React.FC = () => {
5760 } ,
5861 editorProps : {
5962 attributes : {
60- style : " padding-left: 56px ; padding-right: 56px;" ,
63+ style : ` padding-left: ${ leftMg ?? 56 } px ; padding-right: ${ rightMg ?? 56 } px;` ,
6164 class :
6265 "focus:outline-none print:border-0 bg-white border-[#c7c7c7] flex flex-col min-h-[1054px] w-[816px] pt-10 pr-14 pb-10 cursor-text" ,
6366 } ,
Original file line number Diff line number Diff line change @@ -79,7 +79,13 @@ export function Room({ children }: { children: ReactNode }) {
7979 } ) ;
8080 } }
8181 >
82- < RoomProvider id = { params . documentId } >
82+ < RoomProvider
83+ id = { params . documentId }
84+ initialStorage = { {
85+ leftMg : 56 ,
86+ rightMg : 56 ,
87+ } }
88+ >
8389 < ClientSideSuspense
8490 fallback = { < FullscreenLoader label = "Document loading..." /> }
8591 >
You can’t perform that action at this time.
0 commit comments