Skip to content

Commit beeadee

Browse files
committed
feat: change editor style
1 parent 98ad1c2 commit beeadee

File tree

14 files changed

+98
-30
lines changed

14 files changed

+98
-30
lines changed

Diff for: apps/book-server/src/graphql/Page.gql

+9
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ type Query {
2929
type Mutation {
3030
create(input: CreatePageInput!): Page @auth
3131
reorder(input: ReorderInput!): Void @auth
32+
update(input: UpdatePageInput!): Page @auth
3233
}
3334

3435
input GetPagesInput {
@@ -54,3 +55,11 @@ input ReorderInput {
5455
parent_url_slug: String
5556
index: Int!
5657
}
58+
59+
input UpdatePageInput {
60+
title: String
61+
body: String
62+
is_deleted: Boolean
63+
page_url_slug: String!
64+
book_url_slug: String!
65+
}

Diff for: apps/book-server/src/graphql/generated.ts

+21
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ export type Mutation = {
6565
create?: Maybe<Page>
6666
deploy?: Maybe<Scalars['Void']['output']>
6767
reorder?: Maybe<Scalars['Void']['output']>
68+
update?: Maybe<Page>
6869
}
6970

7071
export type MutationBuildArgs = {
@@ -83,6 +84,10 @@ export type MutationReorderArgs = {
8384
input: ReorderInput
8485
}
8586

87+
export type MutationUpdateArgs = {
88+
input: UpdatePageInput
89+
}
90+
8691
export type Page = {
8792
body: Scalars['String']['output']
8893
book_id: Scalars['ID']['output']
@@ -149,6 +154,14 @@ export type SubscriptionBookDeployCompletedArgs = {
149154
input: BookIdInput
150155
}
151156

157+
export type UpdatePageInput = {
158+
body?: InputMaybe<Scalars['String']['input']>
159+
book_url_slug: Scalars['String']['input']
160+
is_deleted?: InputMaybe<Scalars['Boolean']['input']>
161+
page_url_slug: Scalars['String']['input']
162+
title?: InputMaybe<Scalars['String']['input']>
163+
}
164+
152165
export type Writer = {
153166
email: Scalars['String']['output']
154167
fk_user_id: Scalars['String']['output']
@@ -260,6 +273,7 @@ export type ResolversTypes = {
260273
String: ResolverTypeWrapper<Scalars['String']['output']>
261274
SubScriptionPayload: ResolverTypeWrapper<SubScriptionPayload>
262275
Subscription: ResolverTypeWrapper<{}>
276+
UpdatePageInput: UpdatePageInput
263277
Void: ResolverTypeWrapper<Scalars['Void']['output']>
264278
Writer: ResolverTypeWrapper<WriterModel>
265279
}
@@ -284,6 +298,7 @@ export type ResolversParentTypes = {
284298
String: Scalars['String']['output']
285299
SubScriptionPayload: SubScriptionPayload
286300
Subscription: {}
301+
UpdatePageInput: UpdatePageInput
287302
Void: Scalars['Void']['output']
288303
Writer: WriterModel
289304
}
@@ -345,6 +360,12 @@ export type MutationResolvers<
345360
ContextType,
346361
RequireFields<MutationReorderArgs, 'input'>
347362
>
363+
update?: Resolver<
364+
Maybe<ResolversTypes['Page']>,
365+
ParentType,
366+
ContextType,
367+
RequireFields<MutationUpdateArgs, 'input'>
368+
>
348369
}
349370

350371
export type PageResolvers<

Diff for: apps/book-server/src/graphql/resolvers/pageResolvers.mts

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const pageResolvers: Resolvers = {
1919
const page = await pageService.create(input, ctx.writer?.id)
2020
return page
2121
},
22+
2223
reorder: async (_, { input }, ctx) => {
2324
const pageService = container.resolve(PageService)
2425
await pageService.reorder(input, ctx.writer?.id)

Diff for: apps/book-server/src/services/PageService/index.mts

+21-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import { ConfilctError } from '@errors/ConfilctError.mjs'
22
import { NotFoundError } from '@errors/NotfoundError.mjs'
33
import { UnauthorizedError } from '@errors/UnauthorizedError.mjs'
4-
import type { CreatePageInput, GetPageInput, ReorderInput } from '@graphql/generated.js'
4+
import type {
5+
CreatePageInput,
6+
GetPageInput,
7+
ReorderInput,
8+
UpdatePageInput,
9+
} from '@graphql/generated.js'
510
import { MongoService } from '@lib/mongo/MongoService.mjs'
611
import { UtilsService } from '@lib/utils/UtilsService.mjs'
712
import { Page, Prisma } from '@packages/database/velog-book-mongo'
@@ -13,6 +18,7 @@ interface Service {
1318
getPages(bookUrlSlug: string, signedWriterId?: string): Promise<Page[]>
1419
getPage(input: GetPageInput, signedWriterId?: string): Promise<Page | null>
1520
create(input: CreatePageInput, signedWriterId?: string): Promise<Page>
21+
update(input: UpdatePageInput, signedWriterId?: string): Promise<Page>
1622
reorder(input: ReorderInput, signedWriterId?: string): Promise<void>
1723
}
1824

@@ -137,8 +143,6 @@ export class PageService implements Service {
137143

138144
const { book_url_slug, page_url_slug } = input
139145

140-
console.log('page_url_slug', page_url_slug)
141-
142146
const book = await this.bookSerivce.findByUrlSlug(book_url_slug)
143147

144148
if (!book) {
@@ -161,7 +165,6 @@ export class PageService implements Service {
161165
where: whereQuery,
162166
})
163167

164-
console.log('page', page?.title)
165168
return page
166169
}
167170

@@ -220,6 +223,20 @@ export class PageService implements Service {
220223
return `${this.utils.removeCodeFromUrlSlug(parent_url_slug)}/${this.utils.escapeForUrl(title).toLowerCase()}-${code}`
221224
}
222225

226+
public async update(input: UpdatePageInput, signedWriterId?: string): Promise<Page> {
227+
if (!signedWriterId) {
228+
throw new UnauthorizedError('Not authorized')
229+
}
230+
231+
const { book_url_slug, page_url_slug, ...whereQuery } = input
232+
233+
const book = await this.bookSerivce.findByUrlSlug(book_url_slug)
234+
235+
if (!book) {
236+
throw new NotFoundError('Not found book')
237+
}
238+
}
239+
223240
public async reorder(input: ReorderInput, signedWriterId?: string): Promise<void> {
224241
if (!signedWriterId) {
225242
throw new UnauthorizedError('Not authorized')

Diff for: apps/book-web/src/layouts/NextraLayout/NextraLayout.tsx

+18-4
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@ function NextraLayout({ children, mdxText }: Props) {
8282
})
8383
getPagesRefetch()
8484
}
85-
window.addEventListener(nextraCustomEventName.addAction, addAction)
85+
window.addEventListener(nextraCustomEventName.addActionEvent, addAction)
8686
return () => {
87-
window.removeEventListener(nextraCustomEventName.addAction, addAction)
87+
window.removeEventListener(nextraCustomEventName.addActionEvent, addAction)
8888
}
8989
})
9090

@@ -106,9 +106,23 @@ function NextraLayout({ children, mdxText }: Props) {
106106
getPagesRefetch()
107107
}
108108

109-
window.addEventListener(nextraCustomEventName.changeItem, changeItem)
109+
window.addEventListener(nextraCustomEventName.changeItemEvent, changeItem)
110110
return () => {
111-
window.removeEventListener(nextraCustomEventName.changeItem, changeItem)
111+
window.removeEventListener(nextraCustomEventName.changeItemEvent, changeItem)
112+
}
113+
}, [])
114+
115+
useEffect(() => {
116+
const saveItemBody = async (e: CustomEventInit<CustomEventDetail['saveItemBodyEvent']>) => {
117+
if (!e.detail) return
118+
const { body } = e.detail
119+
console.log('body!', body)
120+
121+
}
122+
123+
window.addEventListener(nextraCustomEventName.saveItemBodyEvent, saveItemBody)
124+
return () => {
125+
window.removeEventListener(nextraCustomEventName.saveItemBodyEvent, saveItemBody)
112126
}
113127
}, [])
114128

Diff for: packages/database/prisma/velog-book-mongo/schema.prisma

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ model Page {
5858
url_slug String @unique // example /${escapeUrl(${parent.title}/${title}).toLowerCase()}}-${code}
5959
code String @unique
6060
depth Int @default(1) @db.Int // max depth 3
61+
is_deleted Boolean @default(false)
6162
6263
created_at DateTime @default(now())
6364
updated_at DateTime @default(now())

Diff for: packages/nextra-editor/src/components/markdown-editor/toolbar/commands/save.tsx

+12-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import { EditorView, KeyBinding } from '@codemirror/view'
22
import { ToolbarCommand } from './type'
3+
import { CustomEventDetail } from '@/types'
4+
import { nextraCustomEventName } from '@/index'
35

46
export const saveKeymap: KeyBinding = {
57
linux: 'Ctrl-s',
68
win: 'Ctrl-s',
79
mac: 'Meta-s',
810
run: (view) => {
9-
execute(view)
11+
saveExecute(view)
1012
return true
1113
},
1214
preventDefault: true,
@@ -33,13 +35,18 @@ const save: ToolbarCommand = {
3335
<path d="M7 3v4a1 1 0 0 0 1 1h7" />
3436
</svg>
3537
),
36-
execute,
38+
execute: saveExecute,
3739
}
3840

39-
function execute(view: EditorView) {
41+
export function saveExecute(view: EditorView) {
4042
const doc = view.state.doc.toString()
41-
console.log(doc)
42-
console.log('save')
43+
const event = new CustomEvent<CustomEventDetail['saveItemBodyEvent']>(
44+
nextraCustomEventName.saveItemBodyEvent,
45+
{
46+
detail: { body: doc },
47+
},
48+
)
49+
window.dispatchEvent(event)
4350
}
4451

4552
export default save

Diff for: packages/nextra-editor/src/components/markdown-editor/toolbar/toolbar.tsx

-7
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,6 @@ const Toolbar = ({ state, view }: Props) => {
7676
upload({ file, info: { type: 'book', refId: '' } })
7777
}
7878

79-
const onCickSaveButton = () => {
80-
console.log('save')
81-
}
82-
8379
useEffect(() => {
8480
// Handle Uploaded Image
8581
if (uploading) return
@@ -106,9 +102,6 @@ const Toolbar = ({ state, view }: Props) => {
106102
case 'image':
107103
onClickImageButton()
108104
return
109-
case 'save':
110-
onCickSaveButton()
111-
return
112105
default:
113106
onClick(command.execute!)
114107
}

Diff for: packages/nextra-editor/src/components/sidebar/sidebar-controller/add-inputs.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,11 @@ function AddInputs({ type }: Props): ReactElement {
5252
const { parentUrlSlug, bookUrlSlug, index, type } = sidebar.actionInfo
5353
if (type === '') return
5454
const event = new CustomEvent<CustomEventDetail['addActionEvent']>(
55-
nextraCustomEventName.addAction,
55+
nextraCustomEventName.addActionEvent,
5656
{
5757
detail: { title, parentUrlSlug, index, bookUrlSlug, type },
5858
},
5959
)
60-
6160
window.dispatchEvent(event)
6261
}
6362

Diff for: packages/nextra-editor/src/components/sidebar/sortable-tree/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ function SortableTree({ items, sidebarRef, showSidebar, onItemsChanged }: Props)
228228
const newParentItem = findItemDeep(newItems, parentId)
229229

230230
const event = new CustomEvent<CustomEventDetail['changeItemEvent']>(
231-
nextraCustomEventName.changeItem,
231+
nextraCustomEventName.changeItemEvent,
232232
{
233233
detail: {
234234
bookUrlSlug,

Diff for: packages/nextra-editor/src/index.tsx

+6-5
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { useMounted } from './nextra/hooks'
1717
import { SidebarProvider } from './contexts/sidebar'
1818
import MarkdownEditor from './components/markdown-editor'
1919
import { MarkdownEditorProvider, useMarkdownEditor } from './contexts/markdown-editor'
20-
20+
import { CustomEventDetail, MdxCompilerOptions, MdxOptions, SearchResult } from './types'
2121
interface BodyProps {
2222
themeContext: PageTheme
2323
breadcrumb: ReactNode
@@ -236,12 +236,13 @@ export {
236236
LocaleSwitch,
237237
} from './components'
238238

239-
export const nextraCustomEventName = {
240-
addAction: 'addAction',
241-
changeItem: 'changeItem',
239+
export const nextraCustomEventName: Record<keyof CustomEventDetail, string> = {
240+
addActionEvent: 'addActionEvent',
241+
changeItemEvent: 'changeItemEvent',
242+
saveItemBodyEvent: 'saveItemBodyEvent',
242243
}
243244

244-
export { CustomEventDetail, MdxCompilerOptions, MdxOptions, SearchResult } from './types'
245+
export { CustomEventDetail, MdxCompilerOptions, MdxOptions, SearchResult }
245246

246247
export {
247248
attachMeta,

Diff for: packages/nextra-editor/src/nextra/components/code.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export const Code = ({ children, className, ...props }: ComponentProps<'code'>):
66
return (
77
<code
88
className={cn(
9-
'nx-break-words nx-rounded-md nx-border nx-border-black nx-border-opacity-[0.04] nx-bg-black nx-bg-opacity-[0.03] nx-px-[.25em] nx-py-0.5 nx-text-[.9em]',
9+
'nx-break-words nx-rounded-md nx-border nx-border-black nx-border-opacity-[0.04] nx-bg-opacity-[0.03] nx-px-[.25em] nx-py-0.5 nx-text-[.9em]',
1010
'dark:nx-border-white/10 dark:nx-bg-white/10',
1111
hasLineNumbers && '[counter-reset:line]',
1212
className,

Diff for: packages/nextra-editor/src/types.ts

+5
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export type SearchResult = {
2020
export interface CustomEventDetail {
2121
addActionEvent: AddActionEvent
2222
changeItemEvent: ChangeItemEvent
23+
saveItemBodyEvent: SaveItemBodyEvent
2324
}
2425

2526
type AddActionEvent = {
@@ -37,6 +38,10 @@ type ChangeItemEvent = {
3738
index: number
3839
}
3940

41+
type SaveItemBodyEvent = {
42+
body: string
43+
}
44+
4045
// for compiler
4146
export type MdxOptions = LoaderOptions['mdxOptions'] &
4247
Pick<ProcessorOptions, 'jsx' | 'outputFormat'>

Diff for: packages/nextra-editor/style.css

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)