Skip to content

Commit 61e494d

Browse files
authored
Merge pull request #37 from duylongpro99/development
feat: margin document
2 parents 549b897 + 0b1b1c1 commit 61e494d

File tree

6 files changed

+28
-5
lines changed

6 files changed

+28
-5
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
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

49
A real-time collaborative document editor built with modern web technologies, offering a seamless writing and collaboration experience.

liveblocks.config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff 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

src/app/document/[documentId]/(ruler)/rulers.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { useMutation, useStorage } from "@liveblocks/react/suspense";
12
import React, { useRef, useState } from "react";
23
import { Marker } from "./markers";
34

@@ -8,8 +9,15 @@ const MINIMUM_SPACE = 100;
89
const INITIAL_MG = 56;
910

1011
export 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);

src/app/document/[documentId]/avatar.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import Image from "next/image";
21
import React from "react";
32

43
const SIZE = 36;

src/app/document/[documentId]/editor.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,14 @@ import ResizeImage from "tiptap-extension-resize-image";
2121
import { FontSizeExtension } from "@/extensions/font-size";
2222
import { LineHeightExtension } from "@/extensions/line-height";
2323
import { useLiveblocksExtension } from "@liveblocks/react-tiptap";
24+
import { useStorage } from "@liveblocks/react/suspense";
2425
import TextStyle from "@tiptap/extension-text-style";
2526
import { Ruler } from "./(ruler)/rulers";
2627
import { Threads } from "./threads";
2728

2829
export 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
},

src/app/document/[documentId]/room.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff 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
>

0 commit comments

Comments
 (0)