Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions components/src/asciidoc/TableOfContents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import { DirectionRightIcon } from '@/icons/react'
import type { DocumentSection } from '@oxide/react-asciidoc'
import * as Accordion from '@radix-ui/react-accordion'
import { Link } from '@remix-run/react'
import cn from 'classnames'
import { Fragment, useCallback, useEffect, useMemo, useRef, useState } from 'react'

Expand Down Expand Up @@ -272,8 +271,8 @@ export const DesktopOutline = ({
data-level={item.level}
className={cn('mb-0 list-none text-sans-sm', item.level > 2 && 'hidden')}
>
<Link
to={`#${item.id}`}
<a
href={`#${item.id}`}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turns out these are fragment links, so there's no advantage to Link that I know of.

className={cn(
'block border-l py-[4px] pr-4',
activeItem === item.id
Expand All @@ -285,7 +284,7 @@ export const DesktopOutline = ({
}}
>
<span dangerouslySetInnerHTML={{ __html: item.title }} />
</Link>
</a>
</li>
{item.sections && renderToc(item.sections)}
</Fragment>
Expand Down Expand Up @@ -316,8 +315,8 @@ export const SmallScreenOutline = ({
data-level={item.level}
className={cn('list-none text-sans-sm', item.level > 2 && 'hidden')}
>
<Link
to={`#${item.id}`}
<a
href={`#${item.id}`}
onClick={() => setValue('')}
className={cn(
'block border-l py-[4px]',
Expand All @@ -330,7 +329,7 @@ export const SmallScreenOutline = ({
}}
>
<span dangerouslySetInnerHTML={{ __html: item.title }} />
</Link>
</a>
</li>
{item.sections && renderToc(item.sections)}
</Fragment>
Expand Down
22 changes: 18 additions & 4 deletions components/src/asciidoc/use-delegated-links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,28 @@
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*/
import { useNavigate } from '@remix-run/react'
import { useEffect } from 'react'

// copied from React Router, unlikely to change
// https://github.com/remix-run/react-router/blob/7b041811/packages/react-router/lib/router/history.ts#L32-L50
interface Path {
pathname: string
search: string
hash: string
}

// https://github.com/remix-run/react-router/blob/7b041811/packages/react-router/lib/router/history.ts#L101-L105
type To = string | Partial<Path>

// Converts regular AsciiDoc a tags and makes them React Routery
// Added key so that this is reloaded when the user routes from one document to another directly
function useDelegatedReactRouterLinks(nodeRef: React.RefObject<HTMLElement>, key: string) {
const navigate = useNavigate()

function useDelegatedReactRouterLinks(
// this is to avoid a dependency on remix/react router
/** Pass in the result of `useNavigate()` in the calling application. */
navigate: (to: To) => void,
nodeRef: React.RefObject<HTMLElement>,
key: string,
) {
useEffect(() => {
const node = nodeRef.current
const handler = (event: MouseEvent) => {
Expand Down
149 changes: 1 addition & 148 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@
"peerDependencies": {
"@asciidoctor/core": "^3.0.0",
"@oxide/react-asciidoc": "^1.0.0",
"@remix-run/react": "2.15.2",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
Expand Down
Loading