dumi 2.3.0-rc.0 → 2.3.1
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 -2
- package/dist/client/pages/Demo/index.js +12 -6
- package/dist/client/theme-api/DumiDemo/index.js +6 -3
- package/dist/client/theme-api/types.d.ts +9 -0
- package/dist/client/theme-api/useLiveDemo.js +108 -81
- package/dist/client/theme-api/useRenderer.d.ts +10 -3
- package/dist/client/theme-api/useRenderer.js +72 -39
- package/dist/client/theme-api/utils.d.ts +4 -3
- package/dist/client/theme-api/utils.js +36 -0
- package/dist/constants.d.ts +1 -0
- package/dist/constants.js +8 -0
- package/dist/features/compile/index.js +3 -0
- package/dist/loaders/markdown/index.js +12 -3
- package/dist/loaders/markdown/transformer/index.d.ts +2 -0
- package/dist/loaders/markdown/transformer/rehypeDemo.js +4 -2
- package/dist/types.d.ts +5 -0
- package/package.json +4 -4
- package/theme-default/slots/ContentFooter/index.js +4 -2
- package/theme-default/slots/ContentFooter/index.less +5 -0
|
Binary file
|
|
@@ -83,7 +83,7 @@ async function parseBlockAsset(opts) {
|
|
|
83
83
|
type: "NPM",
|
|
84
84
|
value: pkg.version
|
|
85
85
|
};
|
|
86
|
-
result.resolveMap[args.path] =
|
|
86
|
+
result.resolveMap[args.path] = args.path;
|
|
87
87
|
}
|
|
88
88
|
return { path: args.path, external: true };
|
|
89
89
|
}
|
|
@@ -148,7 +148,7 @@ async function parseBlockAsset(opts) {
|
|
|
148
148
|
result.frontmatter = frontmatter;
|
|
149
149
|
}
|
|
150
150
|
}
|
|
151
|
-
if (!isEntryPoint || !opts.entryPointCode) {
|
|
151
|
+
if (opts.techStack.runtimeOpts && (!isEntryPoint || !opts.entryPointCode)) {
|
|
152
152
|
result.resolveMap[filename] = args.path;
|
|
153
153
|
}
|
|
154
154
|
return {
|
|
@@ -3,17 +3,23 @@ import { createElement, useEffect } from 'react';
|
|
|
3
3
|
import { useRenderer } from "../../theme-api/useRenderer";
|
|
4
4
|
import "./index.less";
|
|
5
5
|
var DemoRenderPage = function DemoRenderPage() {
|
|
6
|
-
var
|
|
7
|
-
|
|
6
|
+
var params = useParams();
|
|
7
|
+
var id = params.id;
|
|
8
8
|
var demo = useDemo(id);
|
|
9
|
-
var
|
|
9
|
+
var _useRenderer = useRenderer({
|
|
10
|
+
id: id,
|
|
11
|
+
component: demo.component,
|
|
12
|
+
renderOpts: demo.renderOpts
|
|
13
|
+
}),
|
|
14
|
+
canvasRef = _useRenderer.canvasRef;
|
|
10
15
|
var _ref = demo || {},
|
|
11
16
|
component = _ref.component,
|
|
12
17
|
renderOpts = _ref.renderOpts;
|
|
13
18
|
var _useLiveDemo = useLiveDemo(id),
|
|
14
19
|
liveDemoNode = _useLiveDemo.node,
|
|
15
20
|
setSource = _useLiveDemo.setSource,
|
|
16
|
-
liveDemoError = _useLiveDemo.error
|
|
21
|
+
liveDemoError = _useLiveDemo.error,
|
|
22
|
+
loading = _useLiveDemo.loading;
|
|
17
23
|
var finalNode = liveDemoNode || (renderOpts !== null && renderOpts !== void 0 && renderOpts.renderer ? /*#__PURE__*/createElement('div', {
|
|
18
24
|
ref: canvasRef
|
|
19
25
|
}) : component && /*#__PURE__*/createElement(component));
|
|
@@ -33,7 +39,7 @@ var DemoRenderPage = function DemoRenderPage() {
|
|
|
33
39
|
|
|
34
40
|
// notify parent window that compile done
|
|
35
41
|
useEffect(function () {
|
|
36
|
-
if (
|
|
42
|
+
if (!loading && (liveDemoError || liveDemoNode)) {
|
|
37
43
|
window.postMessage({
|
|
38
44
|
type: 'dumi.liveDemo.compileDone',
|
|
39
45
|
value: {
|
|
@@ -41,7 +47,7 @@ var DemoRenderPage = function DemoRenderPage() {
|
|
|
41
47
|
}
|
|
42
48
|
});
|
|
43
49
|
}
|
|
44
|
-
}, [liveDemoNode,
|
|
50
|
+
}, [liveDemoError, liveDemoNode, loading]);
|
|
45
51
|
return finalNode;
|
|
46
52
|
};
|
|
47
53
|
export default DemoRenderPage;
|
|
@@ -15,9 +15,12 @@ var InternalDumiDemo = function InternalDumiDemo(props) {
|
|
|
15
15
|
var component = demo.component,
|
|
16
16
|
asset = demo.asset,
|
|
17
17
|
renderOpts = demo.renderOpts;
|
|
18
|
-
var
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
var _useRenderer = useRenderer({
|
|
19
|
+
id: id,
|
|
20
|
+
renderOpts: demo.renderOpts,
|
|
21
|
+
component: demo.component
|
|
22
|
+
}),
|
|
23
|
+
canvasRef = _useRenderer.canvasRef;
|
|
21
24
|
|
|
22
25
|
// hide debug demo in production
|
|
23
26
|
if (process.env.NODE_ENV === 'production' && props.previewerProps.debug) return null;
|
|
@@ -233,6 +233,7 @@ export type IDemoCompileFn = (code: string, opts: {
|
|
|
233
233
|
filename: string;
|
|
234
234
|
}) => Promise<string>;
|
|
235
235
|
export type IDemoCancelableFn = (canvas: HTMLElement, component: AgnosticComponentModule) => (() => void) | Promise<() => void>;
|
|
236
|
+
export type IDemoPreflightFn = (component: AgnosticComponentModule) => Promise<void>;
|
|
236
237
|
export type IDemoData = {
|
|
237
238
|
component: ReactComponentType | AgnosticComponentType;
|
|
238
239
|
asset: IPreviewerProps['asset'];
|
|
@@ -243,7 +244,15 @@ export type IDemoData = {
|
|
|
243
244
|
* provide a runtime compile function for compile demo code for live preview
|
|
244
245
|
*/
|
|
245
246
|
compile?: IDemoCompileFn;
|
|
247
|
+
/**
|
|
248
|
+
* Component rendering function, used to manage the creation and unmount of components
|
|
249
|
+
*/
|
|
246
250
|
renderer?: IDemoCancelableFn;
|
|
251
|
+
/**
|
|
252
|
+
* Used to detect initialization errors of components in advance
|
|
253
|
+
* (if there is an error, the component will not be mounted)
|
|
254
|
+
*/
|
|
255
|
+
preflight?: IDemoPreflightFn;
|
|
247
256
|
};
|
|
248
257
|
};
|
|
249
258
|
export {};
|
|
@@ -2,22 +2,19 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
|
|
|
2
2
|
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) keys.push(key); return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, catch: function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
|
|
3
3
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
4
4
|
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
5
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
6
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
7
|
-
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
8
|
-
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
9
|
-
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
10
5
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
11
6
|
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."); }
|
|
12
7
|
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); }
|
|
13
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; }
|
|
14
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; } }
|
|
15
10
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
11
|
+
import { SHOULD_SKIP_LIVEDEMO_ERROR } from "../../constants";
|
|
16
12
|
import { useDemo } from 'dumi';
|
|
17
13
|
import throttle from 'lodash.throttle';
|
|
18
14
|
import { createElement, useCallback, useRef, useState } from 'react';
|
|
19
15
|
import DemoErrorBoundary from "./DumiDemo/DemoErrorBoundary";
|
|
20
16
|
import { useRenderer } from "./useRenderer";
|
|
17
|
+
import { getAgnosticComponentModule } from "./utils";
|
|
21
18
|
var THROTTLE_WAIT = 500;
|
|
22
19
|
function evalCommonJS(js, _ref) {
|
|
23
20
|
var module = _ref.module,
|
|
@@ -33,40 +30,38 @@ export var useLiveDemo = function useLiveDemo(id, opts) {
|
|
|
33
30
|
setLoading = _useState2[1];
|
|
34
31
|
var loadingTimer = useRef();
|
|
35
32
|
var taskToken = useRef();
|
|
33
|
+
function resetLoadingStatus() {
|
|
34
|
+
clearTimeout(loadingTimer.current);
|
|
35
|
+
setLoading(false);
|
|
36
|
+
}
|
|
36
37
|
var _demo$context = demo.context,
|
|
37
38
|
context = _demo$context === void 0 ? {} : _demo$context,
|
|
38
39
|
asset = demo.asset,
|
|
39
40
|
renderOpts = demo.renderOpts;
|
|
40
|
-
var _useState3 = useState(),
|
|
41
|
+
var _useState3 = useState(null),
|
|
41
42
|
_useState4 = _slicedToArray(_useState3, 2),
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
var
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
43
|
+
error = _useState4[0],
|
|
44
|
+
setError = _useState4[1];
|
|
45
|
+
var _useRenderer = useRenderer({
|
|
46
|
+
id: id,
|
|
47
|
+
renderOpts: demo.renderOpts,
|
|
48
|
+
onResolved: function onResolved() {
|
|
49
|
+
resetLoadingStatus();
|
|
50
|
+
}
|
|
51
|
+
}),
|
|
52
|
+
ref = _useRenderer.canvasRef,
|
|
53
|
+
setComponent = _useRenderer.setComponent;
|
|
51
54
|
var _useState5 = useState(),
|
|
52
55
|
_useState6 = _slicedToArray(_useState5, 2),
|
|
53
56
|
demoNode = _useState6[0],
|
|
54
57
|
setDemoNode = _useState6[1];
|
|
55
|
-
var _useState7 = useState(null),
|
|
56
|
-
_useState8 = _slicedToArray(_useState7, 2),
|
|
57
|
-
error = _useState8[0],
|
|
58
|
-
setError = _useState8[1];
|
|
59
58
|
var setSource = useCallback(throttle( /*#__PURE__*/function () {
|
|
60
59
|
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(source) {
|
|
61
60
|
var _opts$containerRef;
|
|
62
|
-
var
|
|
61
|
+
var iframeWindow, entryFileName, liveRequire, token, entryFileCode, liveExports, liveModule, component, renderToStaticMarkupDeferred, _liveExports, _liveModule, newDemoNode, oError, shouldSkipError;
|
|
63
62
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
64
63
|
while (1) switch (_context.prev = _context.next) {
|
|
65
64
|
case 0:
|
|
66
|
-
resetLoadingStatus = function _resetLoadingStatus() {
|
|
67
|
-
clearTimeout(loadingTimer.current);
|
|
68
|
-
setLoading(false);
|
|
69
|
-
};
|
|
70
65
|
// set loading status if still compiling after 499ms
|
|
71
66
|
loadingTimer.current = window.setTimeout(function () {
|
|
72
67
|
setLoading(true);
|
|
@@ -74,11 +69,11 @@ export var useLiveDemo = function useLiveDemo(id, opts) {
|
|
|
74
69
|
// make sure timer be fired before next throttle
|
|
75
70
|
THROTTLE_WAIT - 1);
|
|
76
71
|
if (!(opts !== null && opts !== void 0 && opts.iframe && opts !== null && opts !== void 0 && (_opts$containerRef = opts.containerRef) !== null && _opts$containerRef !== void 0 && _opts$containerRef.current)) {
|
|
77
|
-
_context.next =
|
|
72
|
+
_context.next = 7;
|
|
78
73
|
break;
|
|
79
74
|
}
|
|
80
75
|
iframeWindow = opts.containerRef.current.querySelector('iframe').contentWindow;
|
|
81
|
-
_context.next =
|
|
76
|
+
_context.next = 5;
|
|
82
77
|
return new Promise(function (resolve) {
|
|
83
78
|
var handler = function handler(ev) {
|
|
84
79
|
if (ev.data.type.startsWith('dumi.liveDemo.compileDone')) {
|
|
@@ -93,86 +88,103 @@ export var useLiveDemo = function useLiveDemo(id, opts) {
|
|
|
93
88
|
value: source
|
|
94
89
|
});
|
|
95
90
|
});
|
|
96
|
-
case
|
|
97
|
-
_context.next =
|
|
91
|
+
case 5:
|
|
92
|
+
_context.next = 74;
|
|
98
93
|
break;
|
|
99
|
-
case
|
|
94
|
+
case 7:
|
|
100
95
|
entryFileName = Object.keys(asset.dependencies).find(function (k) {
|
|
101
96
|
return asset.dependencies[k].type === 'FILE';
|
|
102
|
-
});
|
|
103
|
-
|
|
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) {
|
|
104
101
|
if (v in context) return context[v];
|
|
105
102
|
throw new Error("Cannot find module: ".concat(v));
|
|
106
103
|
};
|
|
107
104
|
token = taskToken.current = Math.random();
|
|
108
105
|
entryFileCode = source[entryFileName];
|
|
109
106
|
if (!(renderOpts !== null && renderOpts !== void 0 && renderOpts.compile)) {
|
|
110
|
-
_context.next =
|
|
107
|
+
_context.next = 23;
|
|
111
108
|
break;
|
|
112
109
|
}
|
|
113
|
-
_context.prev =
|
|
114
|
-
_context.next =
|
|
110
|
+
_context.prev = 12;
|
|
111
|
+
_context.next = 15;
|
|
115
112
|
return renderOpts.compile(entryFileCode, {
|
|
116
113
|
filename: entryFileName
|
|
117
114
|
});
|
|
118
|
-
case
|
|
115
|
+
case 15:
|
|
119
116
|
entryFileCode = _context.sent;
|
|
120
|
-
_context.next =
|
|
117
|
+
_context.next = 23;
|
|
121
118
|
break;
|
|
122
|
-
case
|
|
123
|
-
_context.prev =
|
|
124
|
-
_context.t0 = _context["catch"](
|
|
119
|
+
case 18:
|
|
120
|
+
_context.prev = 18;
|
|
121
|
+
_context.t0 = _context["catch"](12);
|
|
125
122
|
setError(_context.t0);
|
|
126
123
|
resetLoadingStatus();
|
|
127
124
|
return _context.abrupt("return");
|
|
128
|
-
case
|
|
125
|
+
case 23:
|
|
129
126
|
if (!(renderOpts !== null && renderOpts !== void 0 && renderOpts.renderer && renderOpts !== null && renderOpts !== void 0 && renderOpts.compile)) {
|
|
130
|
-
_context.next =
|
|
127
|
+
_context.next = 44;
|
|
131
128
|
break;
|
|
132
129
|
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
130
|
+
_context.prev = 24;
|
|
131
|
+
liveExports = {};
|
|
132
|
+
liveModule = {
|
|
133
|
+
exports: liveExports
|
|
134
|
+
};
|
|
135
|
+
evalCommonJS(entryFileCode, {
|
|
136
|
+
exports: liveExports,
|
|
137
|
+
module: liveModule,
|
|
138
|
+
require: liveRequire
|
|
139
|
+
});
|
|
140
|
+
_context.next = 30;
|
|
141
|
+
return getAgnosticComponentModule(liveExports);
|
|
142
|
+
case 30:
|
|
143
|
+
component = _context.sent;
|
|
144
|
+
if (!renderOpts.preflight) {
|
|
145
|
+
_context.next = 34;
|
|
146
|
+
break;
|
|
150
147
|
}
|
|
148
|
+
_context.next = 34;
|
|
149
|
+
return renderOpts.preflight(component);
|
|
150
|
+
case 34:
|
|
151
|
+
setComponent(component);
|
|
152
|
+
setDemoNode( /*#__PURE__*/createElement('div', {
|
|
153
|
+
ref: ref
|
|
154
|
+
}));
|
|
155
|
+
setError(null);
|
|
156
|
+
_context.next = 43;
|
|
157
|
+
break;
|
|
158
|
+
case 39:
|
|
159
|
+
_context.prev = 39;
|
|
160
|
+
_context.t1 = _context["catch"](24);
|
|
161
|
+
setError(_context.t1);
|
|
151
162
|
resetLoadingStatus();
|
|
163
|
+
case 43:
|
|
152
164
|
return _context.abrupt("return");
|
|
153
|
-
case
|
|
154
|
-
_context.prev =
|
|
165
|
+
case 44:
|
|
166
|
+
_context.prev = 44;
|
|
155
167
|
// load renderToStaticMarkup in async way
|
|
156
168
|
renderToStaticMarkupDeferred = import('react-dom/server').then(function (_ref3) {
|
|
157
169
|
var renderToStaticMarkup = _ref3.renderToStaticMarkup;
|
|
158
170
|
return renderToStaticMarkup;
|
|
159
171
|
}); // skip current task if another task is running
|
|
160
172
|
if (!(token !== taskToken.current)) {
|
|
161
|
-
_context.next =
|
|
173
|
+
_context.next = 48;
|
|
162
174
|
break;
|
|
163
175
|
}
|
|
164
176
|
return _context.abrupt("return");
|
|
165
|
-
case
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
exports:
|
|
177
|
+
case 48:
|
|
178
|
+
_liveExports = {};
|
|
179
|
+
_liveModule = {
|
|
180
|
+
exports: _liveExports
|
|
169
181
|
}; // initial component with fake runtime
|
|
170
182
|
evalCommonJS(entryFileCode, {
|
|
171
|
-
exports:
|
|
172
|
-
module:
|
|
173
|
-
require:
|
|
183
|
+
exports: _liveExports,
|
|
184
|
+
module: _liveModule,
|
|
185
|
+
require: liveRequire
|
|
174
186
|
});
|
|
175
|
-
newDemoNode = /*#__PURE__*/createElement(DemoErrorBoundary, null, /*#__PURE__*/createElement(
|
|
187
|
+
newDemoNode = /*#__PURE__*/createElement(DemoErrorBoundary, null, /*#__PURE__*/createElement(_liveExports.default));
|
|
176
188
|
oError = console.error; // hijack console.error to avoid useLayoutEffect error
|
|
177
189
|
console.error = function () {
|
|
178
190
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
@@ -182,29 +194,44 @@ export var useLiveDemo = function useLiveDemo(id, opts) {
|
|
|
182
194
|
};
|
|
183
195
|
|
|
184
196
|
// check component is able to render, to avoid show react overlay error
|
|
185
|
-
_context.
|
|
197
|
+
_context.prev = 54;
|
|
198
|
+
_context.next = 57;
|
|
186
199
|
return renderToStaticMarkupDeferred;
|
|
187
|
-
case
|
|
188
|
-
_context.
|
|
189
|
-
(0, _context.
|
|
200
|
+
case 57:
|
|
201
|
+
_context.t2 = _context.sent;
|
|
202
|
+
(0, _context.t2)(newDemoNode);
|
|
203
|
+
_context.next = 66;
|
|
204
|
+
break;
|
|
205
|
+
case 61:
|
|
206
|
+
_context.prev = 61;
|
|
207
|
+
_context.t3 = _context["catch"](54);
|
|
208
|
+
shouldSkipError = SHOULD_SKIP_LIVEDEMO_ERROR.some(function (e) {
|
|
209
|
+
return _context.t3.message.includes(e);
|
|
210
|
+
});
|
|
211
|
+
if (shouldSkipError) {
|
|
212
|
+
_context.next = 66;
|
|
213
|
+
break;
|
|
214
|
+
}
|
|
215
|
+
throw _context.t3;
|
|
216
|
+
case 66:
|
|
190
217
|
console.error = oError;
|
|
191
218
|
|
|
192
219
|
// set new demo node with passing source
|
|
193
220
|
setDemoNode(newDemoNode);
|
|
194
221
|
setError(null);
|
|
195
|
-
_context.next =
|
|
222
|
+
_context.next = 74;
|
|
196
223
|
break;
|
|
197
|
-
case
|
|
198
|
-
_context.prev =
|
|
199
|
-
_context.
|
|
200
|
-
setError(_context.
|
|
201
|
-
case
|
|
224
|
+
case 71:
|
|
225
|
+
_context.prev = 71;
|
|
226
|
+
_context.t4 = _context["catch"](44);
|
|
227
|
+
setError(_context.t4);
|
|
228
|
+
case 74:
|
|
202
229
|
resetLoadingStatus();
|
|
203
|
-
case
|
|
230
|
+
case 75:
|
|
204
231
|
case "end":
|
|
205
232
|
return _context.stop();
|
|
206
233
|
}
|
|
207
|
-
}, _callee, null, [[
|
|
234
|
+
}, _callee, null, [[12, 18], [24, 39], [44, 71], [54, 61]]);
|
|
208
235
|
}));
|
|
209
236
|
return function (_x2) {
|
|
210
237
|
return _ref2.apply(this, arguments);
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import type { IDemoData } from './types';
|
|
3
|
-
export
|
|
2
|
+
import type { AgnosticComponentType, IDemoData } from './types';
|
|
3
|
+
export interface UseRendererOptions {
|
|
4
4
|
id: string;
|
|
5
|
-
|
|
5
|
+
component?: AgnosticComponentType;
|
|
6
|
+
renderOpts: IDemoData['renderOpts'];
|
|
7
|
+
onResolved?: () => void;
|
|
8
|
+
}
|
|
9
|
+
export declare const useRenderer: ({ id, component, renderOpts, onResolved, }: UseRendererOptions) => {
|
|
10
|
+
canvasRef: import("react").RefObject<HTMLDivElement>;
|
|
11
|
+
setComponent: import("react").Dispatch<import("react").SetStateAction<AgnosticComponentType | null>>;
|
|
12
|
+
};
|
|
@@ -2,22 +2,41 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
|
|
|
2
2
|
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) keys.push(key); return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, catch: function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
|
|
3
3
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
4
4
|
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
5
|
-
|
|
5
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
6
|
+
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."); }
|
|
7
|
+
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); }
|
|
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
|
+
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
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
11
|
+
import { useEffect, useRef, useState } from 'react';
|
|
12
|
+
import { getAgnosticComponentModule } from "./utils";
|
|
13
|
+
|
|
6
14
|
// maintain all the mounted instance
|
|
7
15
|
var map = new Map();
|
|
8
16
|
export var useRenderer = function useRenderer(_ref) {
|
|
9
17
|
var id = _ref.id,
|
|
10
18
|
component = _ref.component,
|
|
11
|
-
renderOpts = _ref.renderOpts
|
|
19
|
+
renderOpts = _ref.renderOpts,
|
|
20
|
+
onResolved = _ref.onResolved;
|
|
21
|
+
var _useState = useState(component ? getAgnosticComponentModule(component) : null),
|
|
22
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
23
|
+
deferedComponent = _useState2[0],
|
|
24
|
+
setComponent = _useState2[1];
|
|
12
25
|
var canvasRef = useRef(null);
|
|
13
26
|
var teardownRef = useRef(function () {});
|
|
14
|
-
var
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
27
|
+
var prevCanvas = useRef(canvasRef.current);
|
|
28
|
+
var resolving = useRef(false);
|
|
29
|
+
if (prevCanvas.current !== canvasRef.current) {
|
|
30
|
+
if (prevCanvas.current === null) {
|
|
31
|
+
// When first render, component maintained by the parent component userRenderer may be removed.
|
|
32
|
+
// The hosted element should be added back
|
|
33
|
+
var handler = map.get(id);
|
|
34
|
+
if (handler !== null && handler !== void 0 && handler.teardown && handler !== null && handler !== void 0 && handler.hostElement && canvasRef.current) {
|
|
35
|
+
canvasRef.current.appendChild(handler.hostElement);
|
|
36
|
+
teardownRef.current = handler.teardown;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
prevCanvas.current = canvasRef.current;
|
|
21
40
|
}
|
|
22
41
|
var renderer = renderOpts === null || renderOpts === void 0 ? void 0 : renderOpts.renderer;
|
|
23
42
|
useEffect(function () {
|
|
@@ -26,63 +45,77 @@ export var useRenderer = function useRenderer(_ref) {
|
|
|
26
45
|
}
|
|
27
46
|
function _resolveRender() {
|
|
28
47
|
_resolveRender = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
29
|
-
var
|
|
30
|
-
var module, teardown;
|
|
48
|
+
var legacyHandler, legacyTeardown, comp, hostElement, _legacyHandler$hostEl, teardown;
|
|
31
49
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
32
50
|
while (1) switch (_context.prev = _context.next) {
|
|
33
51
|
case 0:
|
|
34
|
-
if (!(!canvasRef.current || !renderer || !
|
|
52
|
+
if (!(!canvasRef.current || !renderer || !deferedComponent)) {
|
|
35
53
|
_context.next = 2;
|
|
36
54
|
break;
|
|
37
55
|
}
|
|
38
56
|
return _context.abrupt("return");
|
|
39
57
|
case 2:
|
|
40
|
-
|
|
41
|
-
|
|
58
|
+
legacyHandler = map.get(id);
|
|
59
|
+
if (!resolving.current) {
|
|
60
|
+
_context.next = 5;
|
|
42
61
|
break;
|
|
43
62
|
}
|
|
44
63
|
return _context.abrupt("return");
|
|
45
|
-
case
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
_context.next =
|
|
56
|
-
|
|
57
|
-
case
|
|
58
|
-
_context.t0 = component;
|
|
59
|
-
case 12:
|
|
60
|
-
module = _context.t0;
|
|
61
|
-
module = (_module$default = module.default) !== null && _module$default !== void 0 ? _module$default : module;
|
|
62
|
-
_context.next = 16;
|
|
63
|
-
return renderer(canvasRef.current, module);
|
|
64
|
-
case 16:
|
|
64
|
+
case 5:
|
|
65
|
+
resolving.current = true;
|
|
66
|
+
legacyTeardown = legacyHandler === null || legacyHandler === void 0 ? void 0 : legacyHandler.teardown;
|
|
67
|
+
_context.next = 9;
|
|
68
|
+
return deferedComponent;
|
|
69
|
+
case 9:
|
|
70
|
+
comp = _context.sent;
|
|
71
|
+
hostElement = document.createElement('div');
|
|
72
|
+
_context.prev = 11;
|
|
73
|
+
canvasRef.current.appendChild(hostElement);
|
|
74
|
+
_context.next = 15;
|
|
75
|
+
return renderer(hostElement, comp);
|
|
76
|
+
case 15:
|
|
65
77
|
teardown = _context.sent;
|
|
78
|
+
legacyTeardown === null || legacyTeardown === void 0 ? void 0 : legacyTeardown();
|
|
79
|
+
legacyHandler === null || legacyHandler === void 0 ? void 0 : (_legacyHandler$hostEl = legacyHandler.hostElement) === null || _legacyHandler$hostEl === void 0 ? void 0 : _legacyHandler$hostEl.remove();
|
|
66
80
|
// remove instance when react component is unmounted
|
|
67
81
|
teardownRef.current = function () {
|
|
68
82
|
teardown();
|
|
83
|
+
hostElement.remove();
|
|
69
84
|
map.delete(id);
|
|
70
85
|
};
|
|
71
|
-
map.set(id,
|
|
72
|
-
|
|
86
|
+
map.set(id, {
|
|
87
|
+
teardown: teardownRef.current,
|
|
88
|
+
hostElement: hostElement
|
|
89
|
+
});
|
|
90
|
+
_context.next = 26;
|
|
91
|
+
break;
|
|
92
|
+
case 22:
|
|
93
|
+
_context.prev = 22;
|
|
94
|
+
_context.t0 = _context["catch"](11);
|
|
95
|
+
hostElement.remove();
|
|
96
|
+
throw _context.t0;
|
|
97
|
+
case 26:
|
|
98
|
+
_context.prev = 26;
|
|
99
|
+
resolving.current = false;
|
|
100
|
+
onResolved === null || onResolved === void 0 ? void 0 : onResolved();
|
|
101
|
+
return _context.finish(26);
|
|
102
|
+
case 30:
|
|
73
103
|
case "end":
|
|
74
104
|
return _context.stop();
|
|
75
105
|
}
|
|
76
|
-
}, _callee);
|
|
106
|
+
}, _callee, null, [[11, 22, 26, 30]]);
|
|
77
107
|
}));
|
|
78
108
|
return _resolveRender.apply(this, arguments);
|
|
79
109
|
}
|
|
80
110
|
resolveRender();
|
|
81
|
-
}, [canvasRef.current,
|
|
111
|
+
}, [canvasRef.current, deferedComponent, renderer]);
|
|
82
112
|
useEffect(function () {
|
|
83
113
|
return function () {
|
|
84
114
|
return teardownRef.current();
|
|
85
115
|
};
|
|
86
116
|
}, []);
|
|
87
|
-
return
|
|
117
|
+
return {
|
|
118
|
+
canvasRef: canvasRef,
|
|
119
|
+
setComponent: setComponent
|
|
120
|
+
};
|
|
88
121
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PluginManager } from 'dumi';
|
|
2
|
-
import {
|
|
3
|
-
import type { ILocale, INav, INavItem, IRouteMeta, IRoutesById, IUserNavValue } from './types';
|
|
2
|
+
import { useLayoutEffect } from 'react';
|
|
3
|
+
import type { AgnosticComponentModule, IDemoData, ILocale, INav, INavItem, IRouteMeta, IRoutesById, IUserNavValue } from './types';
|
|
4
4
|
/**
|
|
5
5
|
* private instance, do not use it in your code
|
|
6
6
|
*/
|
|
@@ -13,7 +13,7 @@ export declare const useLocaleDocRoutes: () => IRoutesById;
|
|
|
13
13
|
* @returns code string
|
|
14
14
|
*/
|
|
15
15
|
export declare const genReactRenderCode: (version: string) => string;
|
|
16
|
-
export declare const useIsomorphicLayoutEffect: typeof
|
|
16
|
+
export declare const useIsomorphicLayoutEffect: typeof useLayoutEffect;
|
|
17
17
|
/**
|
|
18
18
|
* common comparer for sidebar/nav items
|
|
19
19
|
*/
|
|
@@ -28,3 +28,4 @@ export declare const useRouteDataComparer: <T extends {
|
|
|
28
28
|
*/
|
|
29
29
|
export declare const pickRouteSortMeta: (original: Partial<Pick<INavItem, 'order' | 'title'>>, field: 'nav' | 'nav.second' | 'group', fm: IRouteMeta['frontmatter']) => Partial<Pick<INavItem, "title" | "order">>;
|
|
30
30
|
export declare function getLocaleNav(nav: IUserNavValue | INav, locale: ILocale): import("./types").IUserNavItems;
|
|
31
|
+
export declare function getAgnosticComponentModule(component: IDemoData['component']): Promise<AgnosticComponentModule>;
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) keys.push(key); return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, catch: function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
|
|
2
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
3
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
1
4
|
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
2
5
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
3
6
|
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."); }
|
|
@@ -96,4 +99,37 @@ export var pickRouteSortMeta = function pickRouteSortMeta(original, field, fm) {
|
|
|
96
99
|
};
|
|
97
100
|
export function getLocaleNav(nav, locale) {
|
|
98
101
|
return Array.isArray(nav) ? nav : nav[locale.id];
|
|
102
|
+
}
|
|
103
|
+
export function getAgnosticComponentModule(_x2) {
|
|
104
|
+
return _getAgnosticComponentModule.apply(this, arguments);
|
|
105
|
+
}
|
|
106
|
+
function _getAgnosticComponentModule() {
|
|
107
|
+
_getAgnosticComponentModule = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(component) {
|
|
108
|
+
var _mod$default;
|
|
109
|
+
var mod;
|
|
110
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
111
|
+
while (1) switch (_context.prev = _context.next) {
|
|
112
|
+
case 0:
|
|
113
|
+
if (!(component instanceof Promise)) {
|
|
114
|
+
_context.next = 6;
|
|
115
|
+
break;
|
|
116
|
+
}
|
|
117
|
+
_context.next = 3;
|
|
118
|
+
return component;
|
|
119
|
+
case 3:
|
|
120
|
+
_context.t0 = _context.sent;
|
|
121
|
+
_context.next = 7;
|
|
122
|
+
break;
|
|
123
|
+
case 6:
|
|
124
|
+
_context.t0 = component;
|
|
125
|
+
case 7:
|
|
126
|
+
mod = _context.t0;
|
|
127
|
+
return _context.abrupt("return", (_mod$default = mod.default) !== null && _mod$default !== void 0 ? _mod$default : mod);
|
|
128
|
+
case 9:
|
|
129
|
+
case "end":
|
|
130
|
+
return _context.stop();
|
|
131
|
+
}
|
|
132
|
+
}, _callee);
|
|
133
|
+
}));
|
|
134
|
+
return _getAgnosticComponentModule.apply(this, arguments);
|
|
99
135
|
}
|
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,6 +86,9 @@ 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.byDependency.set("commonjs", {
|
|
90
|
+
conditionNames: ["require", "node", "import"]
|
|
91
|
+
});
|
|
89
92
|
const loaderBaseOpts = {
|
|
90
93
|
techStacks,
|
|
91
94
|
cwd: api.cwd,
|
|
@@ -35,13 +35,16 @@ module.exports = __toCommonJS(markdown_exports);
|
|
|
35
35
|
var import_tabs = require("../../features/tabs");
|
|
36
36
|
var import_utils = require("../../utils");
|
|
37
37
|
var import_fs = __toESM(require("fs"));
|
|
38
|
+
var import_path = __toESM(require("path"));
|
|
38
39
|
var import_plugin_utils = require("umi/plugin-utils");
|
|
39
40
|
var import_transformer = __toESM(require("./transformer"));
|
|
40
41
|
var import_rehypeText = require("./transformer/rehypeText");
|
|
41
42
|
function getDemoSourceFiles(demos = []) {
|
|
42
43
|
return demos.reduce((ret, demo) => {
|
|
43
44
|
if ("resolveMap" in demo) {
|
|
44
|
-
ret.push(
|
|
45
|
+
ret.push(
|
|
46
|
+
...Object.values(demo.resolveMap).filter((p) => import_path.default.isAbsolute(p))
|
|
47
|
+
);
|
|
45
48
|
}
|
|
46
49
|
return ret;
|
|
47
50
|
}, []);
|
|
@@ -114,11 +117,11 @@ export const demos = {
|
|
|
114
117
|
return "undefined";
|
|
115
118
|
const entryFileName = Object.keys(this.asset.dependencies)[0];
|
|
116
119
|
const context = Object.entries(this.resolveMap).reduce(
|
|
117
|
-
(acc, [key,
|
|
120
|
+
(acc, [key, path2]) => ({
|
|
118
121
|
...acc,
|
|
119
122
|
// omit entry file
|
|
120
123
|
...key !== entryFileName ? {
|
|
121
|
-
[key]: `{{{require('${
|
|
124
|
+
[key]: `{{{require('${path2}')}}}`
|
|
122
125
|
} : {}
|
|
123
126
|
}),
|
|
124
127
|
{}
|
|
@@ -145,6 +148,12 @@ export const demos = {
|
|
|
145
148
|
renderOpts.rendererPath
|
|
146
149
|
)}')).default,`);
|
|
147
150
|
}
|
|
151
|
+
if (renderOpts.preflightPath) {
|
|
152
|
+
propertyArray.push(`
|
|
153
|
+
preflight: (await import('${(0, import_plugin_utils.winPath)(
|
|
154
|
+
renderOpts.preflightPath
|
|
155
|
+
)}')).default,`);
|
|
156
|
+
}
|
|
148
157
|
if (propertyArray.length === 0)
|
|
149
158
|
return "undefined";
|
|
150
159
|
return `{
|
|
@@ -26,6 +26,7 @@ declare module 'vfile' {
|
|
|
26
26
|
renderOpts: {
|
|
27
27
|
type?: string;
|
|
28
28
|
rendererPath?: string;
|
|
29
|
+
preflightPath?: string;
|
|
29
30
|
compilePath?: string;
|
|
30
31
|
};
|
|
31
32
|
} | {
|
|
@@ -34,6 +35,7 @@ declare module 'vfile' {
|
|
|
34
35
|
renderOpts: {
|
|
35
36
|
type?: string;
|
|
36
37
|
rendererPath?: string;
|
|
38
|
+
preflightPath?: string;
|
|
37
39
|
compilePath?: string;
|
|
38
40
|
};
|
|
39
41
|
})[];
|
|
@@ -294,7 +294,8 @@ function rehypeDemo(opts) {
|
|
|
294
294
|
id: asset.id,
|
|
295
295
|
component,
|
|
296
296
|
renderOpts: {
|
|
297
|
-
rendererPath: runtimeOpts == null ? void 0 : runtimeOpts.rendererPath
|
|
297
|
+
rendererPath: runtimeOpts == null ? void 0 : runtimeOpts.rendererPath,
|
|
298
|
+
preflightPath: runtimeOpts == null ? void 0 : runtimeOpts.preflightPath
|
|
298
299
|
}
|
|
299
300
|
};
|
|
300
301
|
}
|
|
@@ -332,7 +333,8 @@ function rehypeDemo(opts) {
|
|
|
332
333
|
) : resolveMap,
|
|
333
334
|
renderOpts: {
|
|
334
335
|
rendererPath: runtimeOpts == null ? void 0 : runtimeOpts.rendererPath,
|
|
335
|
-
compilePath: runtimeOpts == null ? void 0 : runtimeOpts.compilePath
|
|
336
|
+
compilePath: runtimeOpts == null ? void 0 : runtimeOpts.compilePath,
|
|
337
|
+
preflightPath: runtimeOpts == null ? void 0 : runtimeOpts.preflightPath
|
|
336
338
|
}
|
|
337
339
|
};
|
|
338
340
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -58,6 +58,11 @@ export type IDumiTechStackOnBlockLoadArgs = OnLoadArgs & {
|
|
|
58
58
|
filename: string;
|
|
59
59
|
};
|
|
60
60
|
export interface IDumiTechStackRuntimeOpts {
|
|
61
|
+
/**
|
|
62
|
+
* Component detection function path,
|
|
63
|
+
* used to detect errors that occur from application creation to component mounting.
|
|
64
|
+
*/
|
|
65
|
+
preflightPath?: string;
|
|
61
66
|
/**
|
|
62
67
|
* path of the cancelable{@link IDemoCancelableFn} function
|
|
63
68
|
* that manipulate(mount/unmount) third-party framework component
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dumi",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.1",
|
|
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",
|
|
@@ -163,7 +163,7 @@
|
|
|
163
163
|
"typescript": "~5.0.4",
|
|
164
164
|
"vitest": "^0.33.0",
|
|
165
165
|
"zx": "^7.2.3",
|
|
166
|
-
"dumi-theme-mobile": "2.3.0
|
|
166
|
+
"dumi-theme-mobile": "2.3.0"
|
|
167
167
|
},
|
|
168
168
|
"peerDependencies": {
|
|
169
169
|
"react": ">=16.8",
|
|
@@ -64,9 +64,11 @@ var ContentFooter = function ContentFooter() {
|
|
|
64
64
|
}, [showLastUpdated]);
|
|
65
65
|
return /*#__PURE__*/React.createElement("footer", {
|
|
66
66
|
className: "dumi-default-content-footer"
|
|
67
|
-
}, /*#__PURE__*/React.createElement("dl", null, showLastUpdated && /*#__PURE__*/React.createElement("dd", null, /*#__PURE__*/React.createElement(IconClock, null), /*#__PURE__*/React.createElement(
|
|
67
|
+
}, /*#__PURE__*/React.createElement("dl", null, showLastUpdated && /*#__PURE__*/React.createElement("dd", null, /*#__PURE__*/React.createElement(IconClock, null), /*#__PURE__*/React.createElement("span", {
|
|
68
|
+
className: "dumi-default-mobile-hidden"
|
|
69
|
+
}, /*#__PURE__*/React.createElement(FormattedMessage, {
|
|
68
70
|
id: "content.footer.last.updated"
|
|
69
|
-
}), /*#__PURE__*/React.createElement("time", {
|
|
71
|
+
})), /*#__PURE__*/React.createElement("time", {
|
|
70
72
|
dateTime: isoLastUpdated
|
|
71
73
|
}, lastUpdated)), showEditLink && /*#__PURE__*/React.createElement("dd", null, /*#__PURE__*/React.createElement("a", {
|
|
72
74
|
target: "_blank",
|