Skip to content

Commit 41384c8

Browse files
Merge pull request #218 from boostcampwm-2024/be-feature-#199
node, edge, page content 상태 초기화
2 parents 62496a0 + 5bf3c9b commit 41384c8

File tree

11 files changed

+864
-10696
lines changed

11 files changed

+864
-10696
lines changed

apps/backend/src/node/node.service.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ export class NodeService {
111111
relations: ['page'],
112112
select: {
113113
id: true,
114+
x: true,
115+
y: true,
114116
page: {
115117
id: true,
116118
title: true, // content 제외하고 title만 선택

apps/backend/src/yjs/yjs.class.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import * as Y from 'yjs';
2+
3+
// Y.Doc에는 name 컬럼이 없어서 생성했습니다.
4+
export class CustomDoc extends Y.Doc {
5+
name: string;
6+
7+
constructor(name: string) {
8+
super();
9+
this.name = name;
10+
}
11+
}

apps/backend/src/yjs/yjs.schema.ts

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
import { Schema } from 'prosemirror-model';
2+
3+
export const novelEditorSchema = new Schema({
4+
nodes: {
5+
doc: { content: 'block+' }, // 문서 루트 노드
6+
7+
paragraph: {
8+
content: 'text*',
9+
group: 'block',
10+
toDOM: () => ['p', 0],
11+
parseDOM: [{ tag: 'p' }],
12+
},
13+
14+
text: { group: 'inline' }, // 텍스트 노드
15+
16+
taskList: {
17+
content: 'taskItem+',
18+
group: 'block',
19+
toDOM: () => ['ul', 0],
20+
parseDOM: [{ tag: 'ul' }],
21+
},
22+
23+
taskItem: {
24+
content: 'paragraph*',
25+
attrs: { checked: { default: false } },
26+
toDOM: (node) => [
27+
'li',
28+
{ class: node.attrs.checked ? 'checked' : '' },
29+
0,
30+
],
31+
parseDOM: [
32+
{
33+
tag: 'li',
34+
getAttrs(dom) {
35+
return { checked: dom.classList.contains('checked') };
36+
},
37+
},
38+
],
39+
},
40+
41+
heading: {
42+
attrs: { level: { default: 1 } },
43+
content: 'text*',
44+
group: 'block',
45+
toDOM: (node) => [`h${node.attrs.level}`, 0],
46+
parseDOM: [
47+
{ tag: 'h1', attrs: { level: 1 } },
48+
{ tag: 'h2', attrs: { level: 2 } },
49+
{ tag: 'h3', attrs: { level: 3 } },
50+
],
51+
},
52+
53+
bulletList: {
54+
content: 'listItem+',
55+
group: 'block',
56+
attrs: { tight: { default: false } },
57+
toDOM: () => ['ul', 0],
58+
parseDOM: [{ tag: 'ul' }],
59+
},
60+
61+
orderedList: {
62+
content: 'listItem+',
63+
group: 'block',
64+
attrs: { tight: { default: false }, start: { default: 1 } },
65+
toDOM: (node) => ['ol', { start: node.attrs.start }, 0],
66+
parseDOM: [{ tag: 'ol' }],
67+
},
68+
69+
listItem: {
70+
content: 'paragraph*',
71+
toDOM: () => ['li', 0],
72+
parseDOM: [{ tag: 'li' }],
73+
},
74+
75+
codeBlock: {
76+
content: 'text*',
77+
attrs: { language: { default: null } },
78+
toDOM: (node) => ['pre', ['code', { class: node.attrs.language }, 0]],
79+
parseDOM: [
80+
{
81+
tag: 'pre',
82+
getAttrs(dom) {
83+
return { language: dom.getAttribute('class') };
84+
},
85+
},
86+
],
87+
},
88+
89+
blockquote: {
90+
content: 'paragraph+',
91+
group: 'block',
92+
toDOM: () => ['blockquote', 0],
93+
parseDOM: [{ tag: 'blockquote' }],
94+
},
95+
96+
youtube: {
97+
attrs: {
98+
src: {},
99+
start: { default: 0 },
100+
width: { default: 640 },
101+
height: { default: 480 },
102+
},
103+
toDOM: (node) => [
104+
'iframe',
105+
{
106+
src: node.attrs.src,
107+
width: node.attrs.width,
108+
height: node.attrs.height,
109+
frameborder: '0',
110+
allow:
111+
'accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture; web-share',
112+
allowfullscreen: true,
113+
},
114+
],
115+
parseDOM: [
116+
{
117+
tag: 'iframe',
118+
getAttrs(dom) {
119+
return {
120+
src: dom.getAttribute('src'),
121+
width: dom.getAttribute('width'),
122+
height: dom.getAttribute('height'),
123+
};
124+
},
125+
},
126+
],
127+
},
128+
129+
twitter: {
130+
attrs: {
131+
src: {},
132+
},
133+
toDOM: (node) => [
134+
'blockquote',
135+
{ class: 'twitter-tweet' },
136+
['a', { href: node.attrs.src }, 0],
137+
],
138+
parseDOM: [
139+
{
140+
tag: 'blockquote.twitter-tweet',
141+
getAttrs(dom) {
142+
return { src: dom.querySelector('a')?.getAttribute('href') };
143+
},
144+
},
145+
],
146+
},
147+
},
148+
149+
marks: {},
150+
});

0 commit comments

Comments
 (0)