Skip to content

Commit 98ad1c2

Browse files
committed
fix: css style in nextra-editor
1 parent f9f59d5 commit 98ad1c2

File tree

13 files changed

+229
-220
lines changed

13 files changed

+229
-220
lines changed

apps/book-server/src/services/PageService/index.mts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ export class PageService implements Service {
137137

138138
const { book_url_slug, page_url_slug } = input
139139

140+
console.log('page_url_slug', page_url_slug)
141+
140142
const book = await this.bookSerivce.findByUrlSlug(book_url_slug)
141143

142144
if (!book) {
@@ -147,14 +149,19 @@ export class PageService implements Service {
147149
throw new ConfilctError('Not owner of book')
148150
}
149151

152+
const whereQuery = { book_id: book.id, fk_writer_id: signedWriterId }
153+
154+
if (page_url_slug === '/') {
155+
Object.assign(whereQuery, { parent_id: null, index: 0 })
156+
} else {
157+
Object.assign(whereQuery, { url_slug: page_url_slug })
158+
}
159+
150160
const page = await this.mongo.page.findFirst({
151-
where: {
152-
url_slug: page_url_slug,
153-
book_id: book.id,
154-
fk_writer_id: signedWriterId,
155-
},
161+
where: whereQuery,
156162
})
157163

164+
console.log('page', page?.title)
158165
return page
159166
}
160167

@@ -190,7 +197,7 @@ export class PageService implements Service {
190197
}
191198

192199
const code = this.utils.randomString(8)
193-
const urlSlug = `${this.utils.removeCodeFromUrlSlug(parent_url_slug)}/${this.utils.escapeForUrl(title).toLowerCase()}-${code}`
200+
const urlSlug = this.generateUrlSlug({ parent_url_slug, title, code })
194201

195202
const page = await this.mongo.page.create({
196203
data: {
@@ -209,9 +216,11 @@ export class PageService implements Service {
209216

210217
return page
211218
}
219+
private generateUrlSlug({ parent_url_slug, title, code }: Record<string, string>) {
220+
return `${this.utils.removeCodeFromUrlSlug(parent_url_slug)}/${this.utils.escapeForUrl(title).toLowerCase()}-${code}`
221+
}
212222

213223
public async reorder(input: ReorderInput, signedWriterId?: string): Promise<void> {
214-
console.log('input', input)
215224
if (!signedWriterId) {
216225
throw new UnauthorizedError('Not authorized')
217226
}

packages/nextra-editor/css/editor.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
.nextra-editor-container {
2-
flex: 1;
32
display: none;
43
@media (min-width: 1024px) {
54
display: block;

packages/nextra-editor/css/styles.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ html {
1919
'calt' 1,
2020
'ss01' 1;
2121
-webkit-tap-highlight-color: transparent;
22+
@apply nx-overflow-hidden;
2223
}
2324

2425
body {
Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
import { Menu, Transition } from '@headlessui/react'
2+
import cn from 'clsx'
3+
import { useFSRoute } from '../nextra/hooks'
4+
import { ArrowRightIcon, MenuIcon } from '../nextra/icons'
5+
import type { Item, MenuItem, PageItem } from '../nextra/normalize-pages'
6+
import type { ReactElement, ReactNode } from 'react'
7+
import { useConfig, useMenu } from '../contexts'
8+
import { renderComponent } from '../utils'
9+
import { Anchor } from './anchor'
10+
11+
export type NavBarProps = {
12+
flatDirectories: Item[]
13+
items: (PageItem | MenuItem)[]
14+
}
15+
16+
const classes = {
17+
link: cn('nx-text-sm contrast-more:nx-text-gray-700 contrast-more:dark:nx-text-gray-100'),
18+
active: cn('nx-font-medium nx-subpixel-antialiased'),
19+
inactive: cn(
20+
'nx-text-gray-600 hover:nx-text-gray-800 dark:nx-text-gray-400 dark:hover:nx-text-gray-200',
21+
),
22+
}
23+
24+
function NavbarMenu({
25+
className,
26+
menu,
27+
children,
28+
}: {
29+
className?: string
30+
menu: MenuItem
31+
children: ReactNode
32+
}): ReactElement {
33+
const { items } = menu
34+
const routes = Object.fromEntries((menu.children || []).map((route) => [route.name, route]))
35+
36+
return (
37+
<div className="nx-relative nx-inline-block">
38+
<Menu>
39+
<Menu.Button
40+
className={cn(
41+
className,
42+
'-nx-ml-2 nx-hidden nx-items-center nx-whitespace-nowrap nx-rounded nx-p-2 md:nx-inline-flex',
43+
classes.inactive,
44+
)}
45+
>
46+
{children}
47+
</Menu.Button>
48+
<Transition leave="nx-transition-opacity" leaveFrom="nx-opacity-100" leaveTo="nx-opacity-0">
49+
<Menu.Items className="nx-absolute nx-right-0 nx-z-20 nx-mt-1 nx-max-h-64 nx-min-w-full nx-overflow-auto nx-rounded-md nx-bg-white nx-py-1 nx-text-sm nx-shadow-lg nx-ring-1 nx-ring-black/5 dark:nx-bg-neutral-800 dark:nx-ring-white/20">
50+
{Object.entries(items || {}).map(([key, item]) => (
51+
<Menu.Item key={key}>
52+
<Anchor
53+
href={item.href || routes[key]?.route || menu.route + '/' + key}
54+
className={cn(
55+
'nx-relative nx-hidden nx-w-full nx-select-none nx-whitespace-nowrap nx-text-gray-600 hover:nx-text-gray-900 dark:nx-text-gray-400 dark:hover:nx-text-gray-100 md:nx-inline-block',
56+
'nx-py-1.5 nx-transition-colors ltr:nx-pl-3 ltr:nx-pr-9 rtl:nx-pl-9 rtl:nx-pr-3',
57+
)}
58+
newWindow={item.newWindow}
59+
>
60+
{item.title || key}
61+
</Anchor>
62+
</Menu.Item>
63+
))}
64+
</Menu.Items>
65+
</Transition>
66+
</Menu>
67+
</div>
68+
)
69+
}
70+
71+
export function Header({ flatDirectories, items }: NavBarProps): ReactElement {
72+
const config = useConfig()
73+
const activeRoute = useFSRoute()
74+
const { menu, setMenu } = useMenu()
75+
76+
return (
77+
<div className="nextra-nav-container nx-w-full">
78+
<div
79+
className={cn(
80+
'nextra-nav-container-blur',
81+
'nx-pointer-events-none nx-z-[-1] nx-h-full nx-w-full nx-bg-white dark:nx-bg-dark',
82+
'nx-shadow-[0_2px_4px_rgba(0,0,0,.02),0_1px_0_rgba(0,0,0,.06)] dark:nx-shadow-[0_-1px_0_rgba(255,255,255,.1)_inset]',
83+
'contrast-more:nx-shadow-[0_0_0_1px_#000] contrast-more:dark:nx-shadow-[0_0_0_1px_#fff]',
84+
)}
85+
>
86+
<nav className="nx-mx-auto nx-flex nx-h-[var(--nextra-navbar-height)] nx-max-w-[120rem] nx-items-center nx-justify-end nx-gap-2 nx-pl-[max(env(safe-area-inset-left),1.5rem)] nx-pr-[max(env(safe-area-inset-right),1.5rem)]">
87+
{config.logoLink ? (
88+
<Anchor
89+
href={typeof config.logoLink === 'string' ? config.logoLink : '/'}
90+
className="nx-flex nx-items-center hover:nx-opacity-75 ltr:nx-mr-auto rtl:nx-ml-auto"
91+
>
92+
{renderComponent(config.logo)}
93+
</Anchor>
94+
) : (
95+
<div className="nx-flex nx-items-center ltr:nx-mr-auto rtl:nx-ml-auto">
96+
{renderComponent(config.logo)}
97+
</div>
98+
)}
99+
{items.map((pageOrMenu) => {
100+
if (pageOrMenu.display === 'hidden') return null
101+
102+
if (pageOrMenu.type === 'menu') {
103+
const menu = pageOrMenu as MenuItem
104+
return (
105+
<NavbarMenu
106+
key={menu.title}
107+
className={cn(classes.link, 'nx-flex nx-gap-1', classes.inactive)}
108+
menu={menu}
109+
>
110+
{menu.title}
111+
<ArrowRightIcon
112+
className="nx-h-[18px] nx-min-w-[18px] nx-rounded-sm nx-p-0.5"
113+
pathClassName="nx-origin-center nx-transition-transform nx-rotate-90"
114+
/>
115+
</NavbarMenu>
116+
)
117+
}
118+
119+
const page = pageOrMenu as PageItem
120+
let href = page.href || page.route || '#'
121+
122+
// If it's a directory
123+
if (page.children) {
124+
href = (page.withIndexPage ? page.route : page.firstChildRoute) || href
125+
}
126+
127+
const isActive = page.route === activeRoute || activeRoute.startsWith(page.route + '/')
128+
129+
return (
130+
<Anchor
131+
href={href}
132+
key={href}
133+
className={cn(
134+
classes.link,
135+
'nx-relative -nx-ml-2 nx-hidden nx-whitespace-nowrap nx-p-2 md:nx-inline-block',
136+
!isActive || page.newWindow ? classes.inactive : classes.active,
137+
)}
138+
newWindow={page.newWindow}
139+
aria-current={!page.newWindow && isActive}
140+
>
141+
<span className="nx-absolute nx-inset-x-0 nx-text-center">{page.title}</span>
142+
<span className="nx-invisible nx-font-medium">{page.title}</span>
143+
</Anchor>
144+
)
145+
})}
146+
147+
{renderComponent(config.search.component, {
148+
directories: flatDirectories,
149+
className: 'nx-hidden md:nx-inline-block mx-min-w-[200px]',
150+
})}
151+
152+
{config.project.link ? (
153+
<Anchor className="nx-p-2 nx-text-current" href={config.project.link} newWindow>
154+
{renderComponent(config.project.icon)}
155+
</Anchor>
156+
) : null}
157+
158+
{config.chat.link ? (
159+
<Anchor className="nx-p-2 nx-text-current" href={config.chat.link} newWindow>
160+
{renderComponent(config.chat.icon)}
161+
</Anchor>
162+
) : null}
163+
164+
{renderComponent(config.navbar.extraContent)}
165+
166+
<button
167+
type="button"
168+
aria-label="Menu"
169+
className="nextra-hamburger -nx-mr-2 nx-rounded nx-p-2 active:nx-bg-gray-400/20 md:nx-hidden"
170+
onClick={() => setMenu(!menu)}
171+
>
172+
<MenuIcon className={cn({ open: menu })} />
173+
</button>
174+
</nav>
175+
</div>
176+
</div>
177+
)
178+
}

packages/nextra-editor/src/components/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export { Head } from './head'
99
export { Input } from './input'
1010
export { LocaleSwitch } from './locale-switch'
1111
export { NavLinks } from './nav-links'
12-
export { Navbar } from './navbar'
12+
export { Header } from './Header'
1313
export { NotFoundPage } from './404'
1414
export { Search } from './search'
1515
export { Select } from './select'

packages/nextra-editor/src/components/markdown-editor/hooks/useCodemirror.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,16 @@ export const useCodemirror = (container: RefObject<HTMLElement>, config: Config
4747
minWidth,
4848
maxWidth,
4949
},
50+
'& .cm-editor': {
51+
// height: '100%',
52+
},
5053
'& .cm-scroller': {
54+
width: '100%',
5155
height: '100% !important',
5256
scrollbarWidth: 'thin',
5357
scrollbarColor: 'oklch(55.55% 0 0 / 40%) transparent',
5458
scrollbarGutter: 'stable',
59+
'overflow-x': 'hidden',
5560
},
5661
})
5762

packages/nextra-editor/src/components/markdown-editor/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const MarkdownEditor = () => {
1717
}
1818

1919
return (
20-
<div className={cn('nx-py-4')}>
20+
<>
2121
<Toolbar state={state} view={view} container={container} />
2222
<div onClick={onClick}>
2323
<div
@@ -27,7 +27,7 @@ const MarkdownEditor = () => {
2727
suppressContentEditableWarning={true}
2828
/>
2929
</div>
30-
</div>
30+
</>
3131
)
3232
}
3333

packages/nextra-editor/src/components/markdown-editor/markdown-editor.module.css

Lines changed: 0 additions & 5 deletions
This file was deleted.

packages/nextra-editor/src/components/markdown-editor/toolbar/toolbar.tsx

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -122,18 +122,17 @@ const Toolbar = ({ state, view }: Props) => {
122122
return <ToolbarSeparator key={key} />
123123
}
124124
return (
125-
<div key={key}>
126-
<button
127-
onClick={() => commandMapper(command)}
128-
className={cn(
129-
'nx-h-12 nx-w-12 nx-cursor-pointer',
130-
'nx-flex nx-items-center nx-justify-center',
131-
classes.button,
132-
)}
133-
>
134-
{command.icon}
135-
</button>
136-
</div>
125+
<button
126+
key={key}
127+
onClick={() => commandMapper(command)}
128+
className={cn(
129+
'nx-h-12 nx-w-12 nx-cursor-pointer',
130+
'nx-flex nx-items-center nx-justify-center',
131+
classes.button,
132+
)}
133+
>
134+
{command.icon}
135+
</button>
137136
)
138137
})}
139138
</div>

0 commit comments

Comments
 (0)