dumi-theme-lobehub
Version:
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
104 lines • 5.59 kB
JavaScript
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
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."); }
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); }
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; }
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; } }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
import { ActionIcon, Tabs } from '@lobehub/ui';
import { openCodeSandbox, openStackBlitz, useIntl } from 'dumi';
import { Code, Code2, Codesandbox, MonitorUp, Zap } from 'lucide-react';
import { useState } from 'react';
import SourceCode from "../../builtins/SourceCode";
import { useStyles } from "./style";
import { jsx as _jsx } from "react/jsx-runtime";
import { jsxs as _jsxs } from "react/jsx-runtime";
import { Fragment as _Fragment } from "react/jsx-runtime";
var PreviewerActions = function PreviewerActions(props) {
var _files$activeKey$0$ma, _props$disabledAction, _props$disabledAction2, _props$disabledAction3;
var intl = useIntl();
var files = Object.entries(props.asset.dependencies).filter(function (_ref) {
var _ref2 = _slicedToArray(_ref, 2),
type = _ref2[1].type;
return type === 'FILE';
});
var _useState = useState(0),
_useState2 = _slicedToArray(_useState, 2),
activeKey = _useState2[0],
setActiveKey = _useState2[1];
var _useState3 = useState(props.forceShowCode || props.defaultShowCode),
_useState4 = _slicedToArray(_useState3, 2),
showCode = _useState4[0],
setShowCode = _useState4[1];
var isSingleFile = files.length === 1;
var lang = ((_files$activeKey$0$ma = files[activeKey][0].match(/\.([^.]+)$/)) === null || _files$activeKey$0$ma === void 0 ? void 0 : _files$activeKey$0$ma[1]) || 'text';
var _useStyles = useStyles(),
styles = _useStyles.styles;
return /*#__PURE__*/_jsxs(_Fragment, {
children: [/*#__PURE__*/_jsxs("div", {
className: styles.actionBar,
children: [!((_props$disabledAction = props.disabledActions) !== null && _props$disabledAction !== void 0 && _props$disabledAction.includes('CSB')) && /*#__PURE__*/_jsx(ActionIcon, {
icon: Codesandbox,
onClick: function onClick() {
return openCodeSandbox(props);
},
size: 'small',
title: intl.formatMessage({
id: 'previewer.actions.codesandbox'
})
}), !((_props$disabledAction2 = props.disabledActions) !== null && _props$disabledAction2 !== void 0 && _props$disabledAction2.includes('STACKBLITZ')) && /*#__PURE__*/_jsx(ActionIcon, {
icon: Zap,
onClick: function onClick() {
return openStackBlitz(props);
},
size: 'small',
title: intl.formatMessage({
id: 'previewer.actions.stackblitz'
})
}), !((_props$disabledAction3 = props.disabledActions) !== null && _props$disabledAction3 !== void 0 && _props$disabledAction3.includes('EXTERNAL')) && /*#__PURE__*/_jsx("a", {
href: props.demoUrl,
rel: "noreferrer",
target: "_blank",
children: /*#__PURE__*/_jsx(ActionIcon, {
icon: MonitorUp,
size: 'small',
title: intl.formatMessage({
id: 'previewer.actions.separate'
})
})
}), !props.forceShowCode && /*#__PURE__*/_jsx(ActionIcon, {
icon: showCode ? Code2 : Code,
onClick: function onClick() {
return setShowCode(function (previous) {
return !previous;
});
},
size: 'small',
title: intl.formatMessage({
id: "previewer.actions.code.".concat(showCode ? 'shrink' : 'expand')
})
})]
}), showCode && /*#__PURE__*/_jsxs(_Fragment, {
children: [/*#__PURE__*/_jsx("div", {
className: styles.tabs,
children: !isSingleFile && /*#__PURE__*/_jsx(Tabs, {
activeKey: String(activeKey),
items: files.map(function (_ref3, index) {
var _ref4 = _slicedToArray(_ref3, 1),
filename = _ref4[0];
return {
key: String(index),
label: filename
};
}),
onChange: function onChange(key) {
return setActiveKey(Number(key));
}
})
}), /*#__PURE__*/_jsx(SourceCode, {
lang: lang,
children: files[activeKey][1].value
})]
})]
});
};
export default PreviewerActions;