dumi 2.3.0 → 2.3.2
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/compiled/crates/swc_plugin_react_demo.wasm +0 -0
- package/dist/assetParsers/block.js +2 -1
- package/dist/client/theme-api/useLiveDemo.js +23 -18
- package/dist/constants.d.ts +1 -0
- package/dist/constants.js +8 -0
- package/dist/features/compile/index.js +1 -1
- package/package.json +3 -3
- package/theme-default/slots/Toc/index.js +14 -1
|
Binary file
|
|
@@ -83,7 +83,8 @@ async function parseBlockAsset(opts) {
|
|
|
83
83
|
type: "NPM",
|
|
84
84
|
value: pkg.version
|
|
85
85
|
};
|
|
86
|
-
|
|
86
|
+
if (opts.techStack.runtimeOpts)
|
|
87
|
+
result.resolveMap[args.path] = args.path;
|
|
87
88
|
}
|
|
88
89
|
return { path: args.path, external: true };
|
|
89
90
|
}
|
|
@@ -8,6 +8,7 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
|
|
|
8
8
|
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; }
|
|
9
9
|
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
|
|
10
10
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
11
|
+
import { SHOULD_SKIP_LIVEDEMO_ERROR } from "../../constants";
|
|
11
12
|
import { useDemo } from 'dumi';
|
|
12
13
|
import throttle from 'lodash.throttle';
|
|
13
14
|
import { createElement, useCallback, useRef, useState } from 'react';
|
|
@@ -57,7 +58,7 @@ export var useLiveDemo = function useLiveDemo(id, opts) {
|
|
|
57
58
|
var setSource = useCallback(throttle( /*#__PURE__*/function () {
|
|
58
59
|
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(source) {
|
|
59
60
|
var _opts$containerRef;
|
|
60
|
-
var iframeWindow, entryFileName,
|
|
61
|
+
var iframeWindow, entryFileName, liveRequire, token, entryFileCode, liveExports, liveModule, component, renderToStaticMarkupDeferred, _liveExports, _liveModule, newDemoNode, oError, shouldSkipError;
|
|
61
62
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
62
63
|
while (1) switch (_context.prev = _context.next) {
|
|
63
64
|
case 0:
|
|
@@ -93,8 +94,10 @@ export var useLiveDemo = function useLiveDemo(id, opts) {
|
|
|
93
94
|
case 7:
|
|
94
95
|
entryFileName = Object.keys(asset.dependencies).find(function (k) {
|
|
95
96
|
return asset.dependencies[k].type === 'FILE';
|
|
96
|
-
});
|
|
97
|
-
|
|
97
|
+
}); // why not require?
|
|
98
|
+
// https://github.com/airbnb/babel-plugin-dynamic-import-node/blob/a68388870de822183218515a1adbb3e8d7fa9486/src/utils.js#L24
|
|
99
|
+
// if just use require, local variable will overwrite __webpack__require__ in the template method
|
|
100
|
+
liveRequire = function liveRequire(v) {
|
|
98
101
|
if (v in context) return context[v];
|
|
99
102
|
throw new Error("Cannot find module: ".concat(v));
|
|
100
103
|
};
|
|
@@ -125,17 +128,17 @@ export var useLiveDemo = function useLiveDemo(id, opts) {
|
|
|
125
128
|
break;
|
|
126
129
|
}
|
|
127
130
|
_context.prev = 24;
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
exports:
|
|
131
|
+
liveExports = {};
|
|
132
|
+
liveModule = {
|
|
133
|
+
exports: liveExports
|
|
131
134
|
};
|
|
132
135
|
evalCommonJS(entryFileCode, {
|
|
133
|
-
exports:
|
|
134
|
-
module:
|
|
135
|
-
require:
|
|
136
|
+
exports: liveExports,
|
|
137
|
+
module: liveModule,
|
|
138
|
+
require: liveRequire
|
|
136
139
|
});
|
|
137
140
|
_context.next = 30;
|
|
138
|
-
return getAgnosticComponentModule(
|
|
141
|
+
return getAgnosticComponentModule(liveExports);
|
|
139
142
|
case 30:
|
|
140
143
|
component = _context.sent;
|
|
141
144
|
if (!renderOpts.preflight) {
|
|
@@ -172,16 +175,16 @@ export var useLiveDemo = function useLiveDemo(id, opts) {
|
|
|
172
175
|
}
|
|
173
176
|
return _context.abrupt("return");
|
|
174
177
|
case 48:
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
exports:
|
|
178
|
+
_liveExports = {};
|
|
179
|
+
_liveModule = {
|
|
180
|
+
exports: _liveExports
|
|
178
181
|
}; // initial component with fake runtime
|
|
179
182
|
evalCommonJS(entryFileCode, {
|
|
180
|
-
exports:
|
|
181
|
-
module:
|
|
182
|
-
require:
|
|
183
|
+
exports: _liveExports,
|
|
184
|
+
module: _liveModule,
|
|
185
|
+
require: liveRequire
|
|
183
186
|
});
|
|
184
|
-
newDemoNode = /*#__PURE__*/createElement(DemoErrorBoundary, null, /*#__PURE__*/createElement(
|
|
187
|
+
newDemoNode = /*#__PURE__*/createElement(DemoErrorBoundary, null, /*#__PURE__*/createElement(_liveExports.default));
|
|
185
188
|
oError = console.error; // hijack console.error to avoid useLayoutEffect error
|
|
186
189
|
console.error = function () {
|
|
187
190
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
@@ -202,7 +205,9 @@ export var useLiveDemo = function useLiveDemo(id, opts) {
|
|
|
202
205
|
case 61:
|
|
203
206
|
_context.prev = 61;
|
|
204
207
|
_context.t3 = _context["catch"](54);
|
|
205
|
-
shouldSkipError =
|
|
208
|
+
shouldSkipError = SHOULD_SKIP_LIVEDEMO_ERROR.some(function (e) {
|
|
209
|
+
return _context.t3.message.includes(e);
|
|
210
|
+
});
|
|
206
211
|
if (shouldSkipError) {
|
|
207
212
|
_context.next = 66;
|
|
208
213
|
break;
|
package/dist/constants.d.ts
CHANGED
|
@@ -20,3 +20,4 @@ export declare const VERSION_2_DEPRECATE_SOFT_BREAKS = "^2.2.0";
|
|
|
20
20
|
export declare const DEFAULT_DEMO_MODULE_EXTENSIONS: string[];
|
|
21
21
|
export declare const DEFAULT_DEMO_PLAIN_TEXT_EXTENSIONS: string[];
|
|
22
22
|
export declare const FS_CACHE_DIR = "node_modules/.cache/dumi";
|
|
23
|
+
export declare const SHOULD_SKIP_LIVEDEMO_ERROR: string[];
|
package/dist/constants.js
CHANGED
|
@@ -28,6 +28,7 @@ __export(constants_exports, {
|
|
|
28
28
|
PICKED_PKG_FIELDS: () => PICKED_PKG_FIELDS,
|
|
29
29
|
PREFERS_COLOR_ATTR: () => PREFERS_COLOR_ATTR,
|
|
30
30
|
PREFERS_COLOR_LS_KEY: () => PREFERS_COLOR_LS_KEY,
|
|
31
|
+
SHOULD_SKIP_LIVEDEMO_ERROR: () => SHOULD_SKIP_LIVEDEMO_ERROR,
|
|
31
32
|
SP_ROUTE_PREFIX: () => SP_ROUTE_PREFIX,
|
|
32
33
|
THEME_PREFIX: () => THEME_PREFIX,
|
|
33
34
|
USELESS_TMP_FILES: () => USELESS_TMP_FILES,
|
|
@@ -64,6 +65,12 @@ var DEFAULT_DEMO_PLAIN_TEXT_EXTENSIONS = [
|
|
|
64
65
|
".json"
|
|
65
66
|
];
|
|
66
67
|
var FS_CACHE_DIR = "node_modules/.cache/dumi";
|
|
68
|
+
var SHOULD_SKIP_LIVEDEMO_ERROR = [
|
|
69
|
+
"Unable to find node on an unmounted component",
|
|
70
|
+
"#188",
|
|
71
|
+
"Portals are not currently supported by the server renderer",
|
|
72
|
+
"#257"
|
|
73
|
+
];
|
|
67
74
|
// Annotate the CommonJS export names for ESM import in node:
|
|
68
75
|
0 && (module.exports = {
|
|
69
76
|
DEFAULT_DEMO_MODULE_EXTENSIONS,
|
|
@@ -75,6 +82,7 @@ var FS_CACHE_DIR = "node_modules/.cache/dumi";
|
|
|
75
82
|
PICKED_PKG_FIELDS,
|
|
76
83
|
PREFERS_COLOR_ATTR,
|
|
77
84
|
PREFERS_COLOR_LS_KEY,
|
|
85
|
+
SHOULD_SKIP_LIVEDEMO_ERROR,
|
|
78
86
|
SP_ROUTE_PREFIX,
|
|
79
87
|
THEME_PREFIX,
|
|
80
88
|
USELESS_TMP_FILES,
|
|
@@ -86,7 +86,7 @@ var compile_default = (api) => {
|
|
|
86
86
|
api.chainWebpack(async (memo) => {
|
|
87
87
|
const babelInUmi = memo.module.rule("src").use("babel-loader").entries();
|
|
88
88
|
const loaderPath = require.resolve("../../loaders/markdown");
|
|
89
|
-
memo.resolve.
|
|
89
|
+
memo.resolve.byDependency.set("commonjs", {
|
|
90
90
|
conditionNames: ["require", "node", "import"]
|
|
91
91
|
});
|
|
92
92
|
const loaderBaseOpts = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dumi",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.2",
|
|
4
4
|
"description": "📖 Documentation Generator of React Component",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"generator",
|
|
@@ -75,7 +75,6 @@
|
|
|
75
75
|
"copy-to-clipboard": "^3.3.3",
|
|
76
76
|
"deepmerge": "^4.3.1",
|
|
77
77
|
"dumi-afx-deps": "^1.0.0-alpha.19",
|
|
78
|
-
"dumi-assets-types": "2.0.0-alpha.0",
|
|
79
78
|
"enhanced-resolve": "^5.15.0",
|
|
80
79
|
"estree-util-to-js": "^1.2.0",
|
|
81
80
|
"estree-util-visit": "^1.2.1",
|
|
@@ -126,7 +125,8 @@
|
|
|
126
125
|
"unist-util-visit-parents": "^5.1.3",
|
|
127
126
|
"url": "^0.11.1",
|
|
128
127
|
"v8-compile-cache": "2.3.0",
|
|
129
|
-
"vfile": "^5.3.7"
|
|
128
|
+
"vfile": "^5.3.7",
|
|
129
|
+
"dumi-assets-types": "2.3.0"
|
|
130
130
|
},
|
|
131
131
|
"devDependencies": {
|
|
132
132
|
"@commitlint/cli": "^17.6.7",
|
|
@@ -23,6 +23,10 @@ var Toc = function Toc() {
|
|
|
23
23
|
_useState2 = _slicedToArray(_useState, 2),
|
|
24
24
|
sectionRefs = _useState2[0],
|
|
25
25
|
setSectionRefs = _useState2[1];
|
|
26
|
+
var _useState3 = useState(0),
|
|
27
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
28
|
+
headerHeight = _useState4[0],
|
|
29
|
+
setHeaderHeight = _useState4[1];
|
|
26
30
|
var memoToc = React.useMemo(function () {
|
|
27
31
|
var toc = meta.toc;
|
|
28
32
|
if (tabMeta) {
|
|
@@ -47,8 +51,17 @@ var Toc = function Toc() {
|
|
|
47
51
|
setSectionRefs(refs);
|
|
48
52
|
}
|
|
49
53
|
}, [pathname, search, loading, memoToc]);
|
|
54
|
+
useEffect(function () {
|
|
55
|
+
if (sectionRefs.length > 0) {
|
|
56
|
+
// find the header height, and set it to scrollspy offset
|
|
57
|
+
// because the header is sticky, so we need to set the offset to avoid the active item is hidden by the header
|
|
58
|
+
var header = document.querySelector('.dumi-default-header');
|
|
59
|
+
setHeaderHeight(header ? header.clientHeight : 0);
|
|
60
|
+
}
|
|
61
|
+
}, [sectionRefs]);
|
|
50
62
|
return sectionRefs.length ? /*#__PURE__*/React.createElement(ScrollSpy, {
|
|
51
|
-
sectionRefs: sectionRefs
|
|
63
|
+
sectionRefs: sectionRefs,
|
|
64
|
+
offset: -headerHeight
|
|
52
65
|
}, function (_ref3) {
|
|
53
66
|
var currentElementIndexInViewport = _ref3.currentElementIndexInViewport;
|
|
54
67
|
// for keep prev item active when no item in viewport
|