dumi-theme-lobehub 4.0.1 → 4.1.0

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.
@@ -1,3 +1,4 @@
1
+ /// <reference path="../types/dumi-compat.d.ts" />
1
2
  import type { IApi } from 'dumi';
2
3
  declare const SSRPlugin: (api: IApi) => void;
3
4
  export default SSRPlugin;
@@ -1,4 +1,5 @@
1
1
  /// <reference types="react" />
2
+ /// <reference types="@/types/dumi-compat" />
2
3
  import { useRouteMeta } from 'dumi';
3
4
  type IContentTabs = ReturnType<typeof useRouteMeta>['tabs'];
4
5
  export interface ContentTabsProps {
@@ -1,8 +1,15 @@
1
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
2
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
4
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
5
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
6
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
1
7
  import { ThemeSwitch as ThemeSwitchButton } from '@lobehub/ui';
2
8
  import { usePrefersColor } from 'dumi';
3
- import { memo, useEffect } from 'react';
9
+ import { memo, useCallback, useEffect, useRef, useState } from 'react';
4
10
  import { useThemeStore } from "../../store/useThemeStore";
5
11
  import { jsx as _jsx } from "react/jsx-runtime";
12
+ var DISABLE_TRANSITION_STYLE = '*,*::before,*::after{-webkit-transition:none!important;-moz-transition:none!important;-o-transition:none!important;-ms-transition:none!important;transition:none!important}';
6
13
  var ThemeSwitch = /*#__PURE__*/memo(function () {
7
14
  var themeMode = useThemeStore(function (s) {
8
15
  return s.themeMode;
@@ -11,13 +18,43 @@ var ThemeSwitch = /*#__PURE__*/memo(function () {
11
18
  useEffect(function () {
12
19
  return setColorMode(themeMode);
13
20
  }, [themeMode]);
21
+ var styleRef = useRef(null);
22
+ var timerRef = useRef(null);
23
+ var handleThemeSwitch = useCallback(function (mode) {
24
+ var transitionDisableDuration = 100;
25
+ if (timerRef.current) {
26
+ clearTimeout(timerRef.current);
27
+ }
28
+ if (styleRef.current) {
29
+ styleRef.current.remove();
30
+ }
31
+ var css = document.createElement('style');
32
+ css.append(document.createTextNode(DISABLE_TRANSITION_STYLE));
33
+ document.head.append(css);
34
+ styleRef.current = css;
35
+ useThemeStore.setState({
36
+ themeMode: mode
37
+ });
38
+
39
+ // eslint-disable-next-line @typescript-eslint/no-unused-expressions
40
+ window.getComputedStyle(document.body).opacity;
41
+ timerRef.current = setTimeout(function () {
42
+ if (styleRef.current) {
43
+ styleRef.current.remove();
44
+ styleRef.current = null;
45
+ }
46
+ }, transitionDisableDuration);
47
+ }, []);
48
+ var _useState = useState(false),
49
+ _useState2 = _slicedToArray(_useState, 2),
50
+ isMounted = _useState2[0],
51
+ setIsMounted = _useState2[1];
52
+ useEffect(function () {
53
+ setIsMounted(true);
54
+ }, []);
14
55
  return /*#__PURE__*/_jsx(ThemeSwitchButton, {
15
- onThemeSwitch: function onThemeSwitch(themeMode) {
16
- useThemeStore.setState({
17
- themeMode: themeMode
18
- });
19
- },
56
+ onThemeSwitch: handleThemeSwitch,
20
57
  themeMode: themeMode
21
- });
58
+ }, isMounted ? 'mounted' : 'unmounted');
22
59
  });
23
60
  export default ThemeSwitch;
@@ -1,3 +1,4 @@
1
+ /// <reference types="@/types/dumi-compat" />
1
2
  import { type IPreviewerProps } from 'dumi';
2
3
  import { type FC, type ReactNode } from 'react';
3
4
  export interface PreviewerActionsProps extends IPreviewerProps {
@@ -1,4 +1,5 @@
1
1
  /// <reference types="react" />
2
+ /// <reference types="@/types/dumi-compat" />
2
3
  import { type useSiteSearch } from 'dumi';
3
4
  type ISearchResult = ReturnType<typeof useSiteSearch>['result'];
4
5
  export interface SearchResultProps {
@@ -0,0 +1,37 @@
1
+ declare module 'dumi' {
2
+ import type { IRouteMeta } from 'dumi/dist/client/theme-api/types';
3
+
4
+ export type { ClientLoader, History } from '@umijs/renderer-react';
5
+ export function getRouteMetaById(id: string): IRouteMeta | Promise<IRouteMeta>;
6
+ export {
7
+ createBrowserHistory,
8
+ createHashHistory,
9
+ createMemoryHistory,
10
+ createSearchParams,
11
+ generatePath,
12
+ Helmet,
13
+ HelmetProvider,
14
+ Link,
15
+ matchPath,
16
+ matchRoutes,
17
+ Navigate,
18
+ NavLink,
19
+ resolvePath,
20
+ useLocation,
21
+ useMatch,
22
+ useNavigate,
23
+ useOutlet,
24
+ useOutletContext,
25
+ useParams,
26
+ useResolvedPath,
27
+ useRoutes,
28
+ useSearchParams,
29
+ } from '@umijs/renderer-react';
30
+ export { defineConfig } from 'dumi/dist';
31
+ export * from 'dumi/dist/client/theme-api';
32
+ export type { IApi } from 'dumi/dist/types';
33
+ export { useIntl } from 'react-intl';
34
+ import type { History as RouterHistory } from 'history';
35
+
36
+ export const history: RouterHistory;
37
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dumi-theme-lobehub",
3
- "version": "4.0.1",
3
+ "version": "4.1.0",
4
4
  "description": "dumi-theme-lobehub is a documentation site theme package designed for dumi2. It provides a more beautiful and user-friendly development and reading experience based on @lobehub/ui",
5
5
  "keywords": [
6
6
  "lobehub",