Skip to content

Commit

Permalink
Merge branch 'develop' into feat/support-russian-language
Browse files Browse the repository at this point in the history
  • Loading branch information
eugenepro2 authored Nov 23, 2024
2 parents e964e68 + 96b8963 commit a1ad3d3
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 31 deletions.
5 changes: 5 additions & 0 deletions .changeset/spotty-eagles-tie.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@medusajs/admin-vite-plugin": patch
---

fix(admin-vite-plugin): Move @babel/types to dependencies from devDependencies to make it compatible with Yarn PnP
2 changes: 1 addition & 1 deletion packages/admin/admin-vite-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
"test:watch": "vitest"
},
"devDependencies": {
"@babel/types": "7.25.6",
"@types/node": "^20.10.4",
"tsup": "8.0.1",
"typescript": "5.3.3",
Expand All @@ -40,6 +39,7 @@
"dependencies": {
"@babel/parser": "7.25.6",
"@babel/traverse": "7.25.6",
"@babel/types": "7.25.6",
"@medusajs/admin-shared": "2.0.4",
"chokidar": "3.5.3",
"fdir": "6.1.1",
Expand Down
18 changes: 5 additions & 13 deletions www/packages/docs-ui/src/components/Heading/H2/index.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,19 @@
"use client"

import clsx from "clsx"
import React, { useMemo } from "react"
import React from "react"
import { CopyButton, Link } from "@/components"
import { useIsBrowser } from "../../../providers"
import { usePathname } from "next/navigation"
import { useHeadingUrl } from "../../.."

type H2Props = React.HTMLAttributes<HTMLHeadingElement> & {
id?: string
passRef?: React.RefObject<HTMLHeadingElement | null>
}

export const H2 = ({ className, children, passRef, ...props }: H2Props) => {
const { isBrowser } = useIsBrowser()
const pathname = usePathname()
const copyText = useMemo(() => {
const hash = `#${props.id}`
if (!isBrowser) {
return hash
}

return `${window.location.origin}${pathname}${hash}`
}, [props.id, isBrowser, pathname])
const copyText = useHeadingUrl({
id: props.id || "",
})
return (
<h2
className={clsx(
Expand Down
20 changes: 3 additions & 17 deletions www/packages/docs-ui/src/components/Heading/H3/index.tsx
Original file line number Diff line number Diff line change
@@ -1,30 +1,16 @@
"use client"

import clsx from "clsx"
import React, { useMemo } from "react"
import React from "react"
import { CopyButton, Link } from "@/components"
import { useIsBrowser } from "../../../providers"
import { useHeadingUrl } from "../../.."

type H3Props = React.HTMLAttributes<HTMLHeadingElement> & {
id?: string
}

export const H3 = ({ className, children, ...props }: H3Props) => {
const { isBrowser } = useIsBrowser()
const copyText = useMemo(() => {
const url = `#${props.id}`
if (!isBrowser) {
return url
}

const hashIndex = window.location.href.indexOf("#")
return (
window.location.href.substring(
0,
hashIndex !== -1 ? hashIndex : window.location.href.length
) + url
)
}, [props.id, isBrowser])
const copyText = useHeadingUrl({ id: props.id || "" })
return (
<h3
className={clsx(
Expand Down
1 change: 1 addition & 0 deletions www/packages/docs-ui/src/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export * from "./use-click-outside"
export * from "./use-collapsible"
export * from "./use-collapsible-code-lines"
export * from "./use-copy"
export * from "./use-heading-url"
export * from "./use-current-learning-path"
export * from "./use-is-external-link"
export * from "./use-keyboard-shortcut"
Expand Down
32 changes: 32 additions & 0 deletions www/packages/docs-ui/src/hooks/use-heading-url/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"use client"

import { usePathname } from "next/navigation"
import { useIsBrowser, useSiteConfig } from "../../providers"
import { useMemo } from "react"

type useHeadingUrlProps = {
id: string
}

export const useHeadingUrl = ({ id }: useHeadingUrlProps) => {
const { isBrowser } = useIsBrowser()
const {
config: { basePath },
} = useSiteConfig()
const pathname = usePathname()
const headingUrl = useMemo(() => {
const hash = `#${id}`
if (!isBrowser) {
return hash
}

const url = `${window.location.origin}${basePath}${pathname}`.replace(
/\/$/,
""
)

return `${url}${hash}`
}, [id, isBrowser, pathname])

return headingUrl
}

0 comments on commit a1ad3d3

Please sign in to comment.