dumi 2.3.0-beta.4 → 2.3.0-beta.6
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.
- package/dist/client/theme-api/useRouteMeta.d.ts +1 -1
- package/dist/client/theme-api/useRouteMeta.js +4 -4
- package/dist/templates/meta/exports.ts.tpl +2 -2
- package/package.json +1 -1
- package/theme-default/builtins/SourceCode/index.d.ts +1 -0
- package/theme-default/builtins/SourceCode/index.js +22 -17
- package/theme-default/builtins/SourceCode/index.less +25 -0
- package/theme-default/slots/SourceCodeEditor/index.js +3 -2
- package/theme-default/slots/SourceCodeEditor/index.less +22 -4
|
@@ -8,6 +8,7 @@ import { getRouteMetaById, matchRoutes, useAppData, useLocation, useRouteData }
|
|
|
8
8
|
import { useCallback, useState } from 'react';
|
|
9
9
|
import { useIsomorphicLayoutEffect } from "./utils";
|
|
10
10
|
var cache = new Map();
|
|
11
|
+
var asyncCache = new Map();
|
|
11
12
|
var EMPTY_META = {
|
|
12
13
|
frontmatter: {},
|
|
13
14
|
toc: [],
|
|
@@ -16,7 +17,6 @@ var EMPTY_META = {
|
|
|
16
17
|
var ASYNC_META_PROPS = ['texts'];
|
|
17
18
|
function getCachedRouteMeta(route) {
|
|
18
19
|
var cacheKey = route.id;
|
|
19
|
-
var pendingCacheKey = "".concat(cacheKey, ":pending");
|
|
20
20
|
if (!cache.get(cacheKey)) {
|
|
21
21
|
var _meta$tabs;
|
|
22
22
|
var merge = function merge() {
|
|
@@ -34,15 +34,15 @@ function getCachedRouteMeta(route) {
|
|
|
34
34
|
}));
|
|
35
35
|
var proxyGetter = function proxyGetter(target, prop) {
|
|
36
36
|
if (ASYNC_META_PROPS.includes(prop)) {
|
|
37
|
-
if (!
|
|
37
|
+
if (!asyncCache.get(cacheKey)) {
|
|
38
38
|
// load async meta then replace cache
|
|
39
|
-
|
|
39
|
+
asyncCache.set(cacheKey, getRouteMetaById(route.id).then(function (full) {
|
|
40
40
|
return cache.set(cacheKey, merge(full)).get(cacheKey);
|
|
41
41
|
}));
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
// throw promise to trigger suspense
|
|
45
|
-
throw
|
|
45
|
+
throw asyncCache.get(cacheKey);
|
|
46
46
|
}
|
|
47
47
|
return target[prop];
|
|
48
48
|
};
|
|
@@ -138,8 +138,8 @@ export function getRouteMetaById<T extends { syncOnly?: boolean }>(
|
|
|
138
138
|
id: string,
|
|
139
139
|
opts?: T,
|
|
140
140
|
): T extends { syncOnly: true }
|
|
141
|
-
?
|
|
142
|
-
: Promise<
|
|
141
|
+
? IRouteMeta | undefined
|
|
142
|
+
: Promise<IRouteMeta> | undefined {
|
|
143
143
|
if (filesMeta[id]) {
|
|
144
144
|
const { frontmatter, toc, textGetter, tabs } = filesMeta[id];
|
|
145
145
|
const routeMeta: IRouteMeta = {
|
package/package.json
CHANGED
|
@@ -46,22 +46,7 @@ var SourceCode = function SourceCode(props) {
|
|
|
46
46
|
setText(_text);
|
|
47
47
|
}
|
|
48
48
|
}, [lang, children]);
|
|
49
|
-
|
|
50
|
-
className: "dumi-default-source-code"
|
|
51
|
-
}, /*#__PURE__*/React.createElement(CopyToClipboard, {
|
|
52
|
-
text: text,
|
|
53
|
-
onCopy: function onCopy() {
|
|
54
|
-
setIsCopied(true);
|
|
55
|
-
clearTimeout(timer.current);
|
|
56
|
-
timer.current = window.setTimeout(function () {
|
|
57
|
-
return setIsCopied(false);
|
|
58
|
-
}, 2000);
|
|
59
|
-
}
|
|
60
|
-
}, /*#__PURE__*/React.createElement("button", {
|
|
61
|
-
type: "button",
|
|
62
|
-
className: "dumi-default-source-code-copy",
|
|
63
|
-
"data-copied": isCopied || undefined
|
|
64
|
-
}, isCopied ? /*#__PURE__*/React.createElement(IconCheck, null) : /*#__PURE__*/React.createElement(IconCopy, null))), /*#__PURE__*/React.createElement(Highlight, _extends({}, defaultProps, {
|
|
49
|
+
var code = /*#__PURE__*/React.createElement(Highlight, _extends({}, defaultProps, {
|
|
65
50
|
code: children,
|
|
66
51
|
language: SIMILAR_DSL[lang] || lang,
|
|
67
52
|
theme: undefined
|
|
@@ -102,6 +87,26 @@ var SourceCode = function SourceCode(props) {
|
|
|
102
87
|
);
|
|
103
88
|
})));
|
|
104
89
|
}));
|
|
105
|
-
})
|
|
90
|
+
});
|
|
91
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
92
|
+
className: "dumi-default-source-code"
|
|
93
|
+
}, /*#__PURE__*/React.createElement(CopyToClipboard, {
|
|
94
|
+
text: text,
|
|
95
|
+
onCopy: function onCopy() {
|
|
96
|
+
setIsCopied(true);
|
|
97
|
+
clearTimeout(timer.current);
|
|
98
|
+
timer.current = window.setTimeout(function () {
|
|
99
|
+
return setIsCopied(false);
|
|
100
|
+
}, 2000);
|
|
101
|
+
}
|
|
102
|
+
}, /*#__PURE__*/React.createElement("button", {
|
|
103
|
+
type: "button",
|
|
104
|
+
className: "dumi-default-source-code-copy",
|
|
105
|
+
"data-copied": isCopied || undefined
|
|
106
|
+
}, isCopied ? /*#__PURE__*/React.createElement(IconCheck, null) : /*#__PURE__*/React.createElement(IconCopy, null))), props.textarea ? /*#__PURE__*/React.createElement("div", {
|
|
107
|
+
className: "dumi-default-source-code-scroll-container"
|
|
108
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
109
|
+
className: "dumi-default-source-code-scroll-content"
|
|
110
|
+
}, code, props.textarea)) : code, props.extra);
|
|
106
111
|
};
|
|
107
112
|
export default SourceCode;
|
|
@@ -25,7 +25,32 @@
|
|
|
25
25
|
border-bottom-left-radius: 4px;
|
|
26
26
|
border-bottom-right-radius: 4px;
|
|
27
27
|
|
|
28
|
+
&-scroll-container {
|
|
29
|
+
overflow: auto;
|
|
30
|
+
width: 100%;
|
|
31
|
+
height: 100%;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
&-scroll-content {
|
|
35
|
+
position: relative;
|
|
36
|
+
width: max-content;
|
|
37
|
+
height: max-content;
|
|
38
|
+
min-width: 100%;
|
|
39
|
+
min-height: 100%;
|
|
40
|
+
|
|
41
|
+
> pre.prism-code {
|
|
42
|
+
width: max-content;
|
|
43
|
+
position: relative;
|
|
44
|
+
overflow: visible;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
28
48
|
> pre.prism-code {
|
|
49
|
+
overflow: auto;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
> pre.prism-code,
|
|
53
|
+
&-scroll-content > pre.prism-code {
|
|
29
54
|
margin: 0;
|
|
30
55
|
padding: 18px 24px;
|
|
31
56
|
font-size: 14px;
|
|
@@ -43,7 +43,7 @@ var SourceCodeEditor = function SourceCodeEditor(props) {
|
|
|
43
43
|
className: "dumi-default-source-code-editor",
|
|
44
44
|
ref: elm
|
|
45
45
|
}, /*#__PURE__*/React.createElement(SourceCode, _extends({}, props, {
|
|
46
|
-
|
|
46
|
+
textarea: style && /*#__PURE__*/React.createElement("textarea", {
|
|
47
47
|
className: "dumi-default-source-code-editor-textarea",
|
|
48
48
|
style: style,
|
|
49
49
|
value: code,
|
|
@@ -77,7 +77,8 @@ var SourceCodeEditor = function SourceCodeEditor(props) {
|
|
|
77
77
|
autoComplete: "off",
|
|
78
78
|
autoCorrect: "off",
|
|
79
79
|
autoSave: "off"
|
|
80
|
-
}),
|
|
80
|
+
}),
|
|
81
|
+
extra: style && props.extra
|
|
81
82
|
}), code));
|
|
82
83
|
};
|
|
83
84
|
export default SourceCodeEditor;
|
|
@@ -30,11 +30,7 @@
|
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
&:focus {
|
|
33
|
-
box-shadow: 0 0 0 1px lighten(@c-primary, 20%) inset;
|
|
34
|
-
|
|
35
33
|
@{dark-selector} & {
|
|
36
|
-
box-shadow: 0 0 0 1px darken(@c-primary-dark, 20%) inset;
|
|
37
|
-
|
|
38
34
|
// for firefox because its selection color is not translucent when color-scheme is dark
|
|
39
35
|
&::selection {
|
|
40
36
|
background-color: fade(@c-primary-dark, 30%);
|
|
@@ -42,4 +38,26 @@
|
|
|
42
38
|
}
|
|
43
39
|
}
|
|
44
40
|
}
|
|
41
|
+
|
|
42
|
+
&::after {
|
|
43
|
+
content: '';
|
|
44
|
+
position: absolute;
|
|
45
|
+
z-index: 0;
|
|
46
|
+
top: 0;
|
|
47
|
+
left: 0;
|
|
48
|
+
width: 100%;
|
|
49
|
+
height: 100%;
|
|
50
|
+
border-bottom-left-radius: 3px;
|
|
51
|
+
border-bottom-right-radius: 3px;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
&:focus-within {
|
|
55
|
+
&::after {
|
|
56
|
+
box-shadow: 0 0 0 1px @c-primary inset;
|
|
57
|
+
|
|
58
|
+
@{dark-selector} & {
|
|
59
|
+
box-shadow: 0 0 0 1px @c-primary-dark inset;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
45
63
|
}
|