@redocly/theme 0.4.10 → 0.4.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -70,7 +70,7 @@ function CodeSample(_a) {
70
70
  var rawContent = _a.rawContent, highlighted = _a.highlighted, language = _a.language;
71
71
  var langClassName = language ? "language-".concat(language) : '';
72
72
  var copyCodeSnippet = (0, useDefaultThemeSettings_1.useDefaultThemeSettings)().copyCodeSnippet;
73
- var copyCodeProps = __assign(__assign({}, copyCodeSnippet), defaultCopyCodeSnippet);
73
+ var copyCodeProps = __assign(__assign({}, defaultCopyCodeSnippet), copyCodeSnippet);
74
74
  var _b = __read((0, react_1.useState)(false), 2), isCopied = _b[0], setIsCopied = _b[1];
75
75
  var copyCode = function (code) {
76
76
  ClipboardService_1.ClipboardService.copyCustom(code);
@@ -23,7 +23,7 @@ function useActiveHeading(contentElement, displayedHeaders) {
23
23
  var _a = __read((0, react_1.useState)(undefined), 2), heading = _a[0], setHeading = _a[1];
24
24
  var _b = __read((0, react_1.useState)([]), 2), headingElements = _b[0], setHeadingElements = _b[1];
25
25
  var headingElementsRef = (0, react_1.useRef)({});
26
- var history = (0, react_router_dom_1.useHistory)();
26
+ var location = (0, react_router_dom_1.useLocation)();
27
27
  var getVisibleHeadings = function () {
28
28
  var visibleHeadings = [];
29
29
  for (var key in headingElementsRef.current) {
@@ -72,12 +72,9 @@ function useActiveHeading(contentElement, displayedHeaders) {
72
72
  return;
73
73
  }
74
74
  setHeadingElements(findHeaders(contentElement));
75
- var unlisten = history.listen(function () {
76
- setHeadingElements(findHeaders(contentElement));
77
- });
78
- return function () { return unlisten(); };
75
+ return function () { return setHeadingElements(findHeaders(contentElement)); };
79
76
  // eslint-disable-next-line react-hooks/exhaustive-deps
80
- }, [contentElement]);
77
+ }, [location.pathname, contentElement]);
81
78
  (0, react_1.useEffect)(function () {
82
79
  if (!(headingElements === null || headingElements === void 0 ? void 0 : headingElements.length)) {
83
80
  return;
@@ -21,7 +21,7 @@ var react_1 = require("react");
21
21
  var react_router_dom_1 = require("react-router-dom");
22
22
  function useMobileMenu(initialState) {
23
23
  if (initialState === void 0) { initialState = false; }
24
- var location = (0, react_router_dom_1.useHistory)().location;
24
+ var location = (0, react_router_dom_1.useLocation)();
25
25
  var _a = __read((0, react_1.useState)(initialState), 2), isOpen = _a[0], setIsOpen = _a[1];
26
26
  (0, react_1.useEffect)(function () { return setIsOpen(false); }, [location.pathname]);
27
27
  return [isOpen, setIsOpen];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@redocly/theme",
3
- "version": "0.4.10",
3
+ "version": "0.4.12",
4
4
  "description": "Shared UI components",
5
5
  "author": "team@redocly.com",
6
6
  "license": "SEE LICENSE IN LICENSE",
@@ -11,7 +11,7 @@
11
11
  "prismjs": "^1.28.0",
12
12
  "react": "^17.0.2",
13
13
  "react-dom": "^17.0.2",
14
- "react-router-dom": "^5.3.0",
14
+ "react-router-dom": "^6.4.1",
15
15
  "styled-components": "^5.3.1",
16
16
  "styled-system": "^5.1.5"
17
17
  },
@@ -21,7 +21,7 @@ const defaultCopyCodeSnippet = {
21
21
  export function CodeSample({ rawContent, highlighted, language }: CodeSampleProps): JSX.Element {
22
22
  const langClassName = language ? `language-${language}` : '';
23
23
  const { copyCodeSnippet } = useDefaultThemeSettings();
24
- const copyCodeProps = { ...copyCodeSnippet, ...defaultCopyCodeSnippet };
24
+ const copyCodeProps = { ...defaultCopyCodeSnippet, ...copyCodeSnippet };
25
25
 
26
26
  const [isCopied, setIsCopied] = useState(false);
27
27
 
@@ -1,5 +1,5 @@
1
1
  import { useState, useEffect, useRef, useCallback } from 'react';
2
- import { useHistory } from 'react-router-dom';
2
+ import { useLocation } from 'react-router-dom';
3
3
 
4
4
  export type UseActiveHeadingReturnType = string | undefined;
5
5
 
@@ -15,7 +15,7 @@ export function useActiveHeading(
15
15
  const [headingElements, setHeadingElements] = useState<HTMLElement[]>([]);
16
16
  const headingElementsRef = useRef<HeadingEntry>({});
17
17
 
18
- const history = useHistory();
18
+ const location = useLocation();
19
19
 
20
20
  const getVisibleHeadings = () => {
21
21
  const visibleHeadings: IntersectionObserverEntry[] = [];
@@ -85,13 +85,9 @@ export function useActiveHeading(
85
85
  }
86
86
  setHeadingElements(findHeaders(contentElement));
87
87
 
88
- const unlisten = history.listen(() => {
89
- setHeadingElements(findHeaders(contentElement));
90
- });
91
-
92
- return () => unlisten();
88
+ return () => setHeadingElements(findHeaders(contentElement));
93
89
  // eslint-disable-next-line react-hooks/exhaustive-deps
94
- }, [contentElement]);
90
+ }, [location.pathname, contentElement]);
95
91
 
96
92
  useEffect(() => {
97
93
  if (!headingElements?.length) {
@@ -1,9 +1,9 @@
1
1
  import type { Dispatch, SetStateAction } from 'react';
2
2
  import { useEffect, useState } from 'react';
3
- import { useHistory } from 'react-router-dom';
3
+ import { useLocation } from 'react-router-dom';
4
4
 
5
5
  export function useMobileMenu(initialState = false): [boolean, Dispatch<SetStateAction<boolean>>] {
6
- const { location } = useHistory();
6
+ const location = useLocation();
7
7
  const [isOpen, setIsOpen] = useState(initialState);
8
8
 
9
9
  useEffect(() => setIsOpen(false), [location.pathname]);
@@ -52,7 +52,7 @@ export const withPropsFilter =
52
52
  return <WrappedComponent {...filteredProps} />;
53
53
  };
54
54
 
55
- export interface PortalLinkProps<TState> extends LinkProps<TState> {
55
+ export interface PortalLinkProps<TState> extends LinkProps {
56
56
  activeClassName?: string;
57
57
  activeStyle?: object;
58
58
  onClick?: (event: React.MouseEvent<HTMLAnchorElement>) => void;
@@ -1,7 +1,7 @@
1
1
  import * as React from 'react';
2
2
  import type { LinkProps } from 'react-router-dom';
3
3
  export declare const withPropsFilter: (filterList: string[]) => (WrappedComponent: React.FunctionComponent) => (props: React.PropsWithChildren<object>) => JSX.Element;
4
- export interface PortalLinkProps<TState> extends LinkProps<TState> {
4
+ export interface PortalLinkProps<TState> extends LinkProps {
5
5
  activeClassName?: string;
6
6
  activeStyle?: object;
7
7
  onClick?: (event: React.MouseEvent<HTMLAnchorElement>) => void;