Skip to content

Commit

Permalink
remove rr/remix dep (#106)
Browse files Browse the repository at this point in the history
  • Loading branch information
david-crespo authored Jan 14, 2025
1 parent 3d2f71f commit 033f70e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 160 deletions.
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}`}
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

0 comments on commit 033f70e

Please sign in to comment.