dumi 2.3.0-beta.8 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/compiled/crates/swc_plugin_react_demo.wasm +0 -0
- package/dist/assetParsers/block.d.ts +1 -0
- package/dist/assetParsers/block.js +7 -3
- 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 +14 -0
- package/dist/client/theme-api/useLiveDemo.js +94 -72
- 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/features/compile/index.js +3 -0
- package/dist/features/locales.js +4 -0
- package/dist/features/theme/index.js +22 -6
- package/dist/loaders/markdown/index.js +12 -3
- package/dist/loaders/markdown/transformer/index.d.ts +4 -1
- package/dist/loaders/markdown/transformer/rehypeDemo.d.ts +1 -0
- package/dist/loaders/markdown/transformer/rehypeDemo.js +29 -10
- package/dist/loaders/markdown/transformer/rehypeEnhancedTag.js +12 -2
- package/dist/loaders/markdown/transformer/remarkContainer.js +37 -6
- package/dist/techStacks/utils.d.ts +22 -0
- package/dist/techStacks/utils.js +5 -0
- package/dist/types.d.ts +8 -1
- package/package.json +28 -25
- package/tech-stack-utils.d.ts +4 -2
- package/theme-default/builtins/API/index.d.ts +2 -1
- package/theme-default/builtins/API/index.js +173 -43
- package/theme-default/builtins/API/index.less +47 -0
- package/theme-default/builtins/CodeGroup/index.d.ts +3 -0
- package/theme-default/builtins/CodeGroup/index.js +29 -0
- package/theme-default/builtins/Previewer/index.js +1 -1
- package/theme-default/builtins/SourceCode/index.d.ts +3 -2
- package/theme-default/locales/en-US.json +4 -0
- package/theme-default/locales/zh-CN.json +4 -0
- package/theme-default/slots/ContentFooter/index.js +4 -2
- package/theme-default/slots/ContentFooter/index.less +5 -0
- package/theme-default/slots/PreviewerActions/index.d.ts +6 -1
- package/theme-default/slots/PreviewerActions/index.js +30 -13
- package/theme-default/slots/PreviewerActions/index.less +30 -140
- package/theme-default/slots/Tabs/index.d.ts +6 -0
- package/theme-default/slots/Tabs/index.js +11 -0
- package/theme-default/slots/Tabs/index.less +151 -0
|
@@ -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
|
}
|
|
@@ -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.merge({
|
|
90
|
+
conditionNames: ["require", "node", "import"]
|
|
91
|
+
});
|
|
89
92
|
const loaderBaseOpts = {
|
|
90
93
|
techStacks,
|
|
91
94
|
cwd: api.cwd,
|
package/dist/features/locales.js
CHANGED
|
@@ -151,6 +151,10 @@ const LocalesContainer: FC<{ children: ReactNode }> = (props) => {
|
|
|
151
151
|
api.config.themeConfig.editLink
|
|
152
152
|
)};
|
|
153
153
|
|
|
154
|
+
localeMessages['$internal.api.sourceLink'] = ${JSON.stringify(
|
|
155
|
+
api.config.themeConfig.sourceLink
|
|
156
|
+
)};
|
|
157
|
+
|
|
154
158
|
return createIntl({ locale, messages: localeMessages }, cache);
|
|
155
159
|
}, []);
|
|
156
160
|
const [intl, setIntl] = useState(() => getIntl());
|
|
@@ -161,7 +161,7 @@ var theme_default = (api) => {
|
|
|
161
161
|
return memo;
|
|
162
162
|
});
|
|
163
163
|
api.modifyConfig((memo) => {
|
|
164
|
-
var _a, _b;
|
|
164
|
+
var _a, _b, _c;
|
|
165
165
|
if (localThemeData) {
|
|
166
166
|
themeMapKeys.forEach((key) => {
|
|
167
167
|
Object.values(localThemeData[key] || {}).forEach((item) => {
|
|
@@ -180,7 +180,9 @@ var theme_default = (api) => {
|
|
|
180
180
|
import_path.default.resolve(__dirname, "../../client/theme-api")
|
|
181
181
|
);
|
|
182
182
|
const repoUrl = ((_a = api.pkg.repository) == null ? void 0 : _a.url) || api.pkg.repository;
|
|
183
|
-
|
|
183
|
+
const autoEditLink = (((_b = memo.themeConfig) == null ? void 0 : _b.editLink) ?? true) === true;
|
|
184
|
+
const autoSourceLink = (((_c = memo.themeConfig) == null ? void 0 : _c.sourceLink) ?? true) === true;
|
|
185
|
+
if ((autoEditLink || autoSourceLink) && typeof repoUrl === "string") {
|
|
184
186
|
const hostedGitIns = import_hosted_git_info.default.fromUrl(repoUrl);
|
|
185
187
|
let branch = "";
|
|
186
188
|
try {
|
|
@@ -192,10 +194,24 @@ var theme_default = (api) => {
|
|
|
192
194
|
}
|
|
193
195
|
if (hostedGitIns) {
|
|
194
196
|
memo.themeConfig ?? (memo.themeConfig = {});
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
197
|
+
const directory = api.pkg.repository.directory || "";
|
|
198
|
+
if (autoSourceLink) {
|
|
199
|
+
let anchorPrefix = "L";
|
|
200
|
+
if (hostedGitIns.type.includes("bitbucket")) {
|
|
201
|
+
anchorPrefix = "lines-";
|
|
202
|
+
}
|
|
203
|
+
const sourceLinkTemplate = hostedGitIns.browse(
|
|
204
|
+
`${directory}/{fileName}#${anchorPrefix}{line}`,
|
|
205
|
+
{ committish: branch }
|
|
206
|
+
);
|
|
207
|
+
memo.themeConfig.sourceLink = sourceLinkTemplate;
|
|
208
|
+
}
|
|
209
|
+
if (autoEditLink) {
|
|
210
|
+
memo.themeConfig.editLink = `${hostedGitIns.edit(
|
|
211
|
+
`${directory}/{filename}`,
|
|
212
|
+
{ committish: branch }
|
|
213
|
+
)}`;
|
|
214
|
+
}
|
|
199
215
|
}
|
|
200
216
|
}
|
|
201
217
|
return memo;
|
|
@@ -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 `{
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { IParsedBlockAsset } from "../../../assetParsers/block";
|
|
2
2
|
import type { ILocalesConfig, IRouteMeta } from "../../../client/theme-api/types";
|
|
3
3
|
import type { IApi, IDumiConfig, IDumiTechStack } from "../../../types";
|
|
4
|
+
import { type ResolveOptions } from 'enhanced-resolve';
|
|
4
5
|
import type { IRoute } from 'umi';
|
|
5
6
|
import type { Data } from 'vfile';
|
|
6
7
|
declare module 'hast' {
|
|
@@ -25,6 +26,7 @@ declare module 'vfile' {
|
|
|
25
26
|
renderOpts: {
|
|
26
27
|
type?: string;
|
|
27
28
|
rendererPath?: string;
|
|
29
|
+
preflightPath?: string;
|
|
28
30
|
compilePath?: string;
|
|
29
31
|
};
|
|
30
32
|
} | {
|
|
@@ -33,6 +35,7 @@ declare module 'vfile' {
|
|
|
33
35
|
renderOpts: {
|
|
34
36
|
type?: string;
|
|
35
37
|
rendererPath?: string;
|
|
38
|
+
preflightPath?: string;
|
|
36
39
|
compilePath?: string;
|
|
37
40
|
};
|
|
38
41
|
})[];
|
|
@@ -45,7 +48,7 @@ declare module 'vfile' {
|
|
|
45
48
|
export interface IMdTransformerOptions {
|
|
46
49
|
cwd: string;
|
|
47
50
|
fileAbsPath: string;
|
|
48
|
-
alias:
|
|
51
|
+
alias: ResolveOptions['alias'];
|
|
49
52
|
parentAbsPath?: string;
|
|
50
53
|
techStacks: IDumiTechStack[];
|
|
51
54
|
resolve: IDumiConfig['resolve'];
|
|
@@ -5,6 +5,7 @@ import type { IMdTransformerOptions } from '.';
|
|
|
5
5
|
export declare const DEMO_PROP_VALUE_KEY = "$demo-prop-value-key";
|
|
6
6
|
export declare const DUMI_DEMO_TAG = "DumiDemo";
|
|
7
7
|
export declare const DUMI_DEMO_GRID_TAG = "DumiDemoGrid";
|
|
8
|
+
export declare const SKIP_DEMO_PARSE = "pure";
|
|
8
9
|
type IRehypeDemoOptions = Pick<IMdTransformerOptions, 'techStacks' | 'cwd' | 'fileAbsPath' | 'resolve'> & {
|
|
9
10
|
resolver: typeof sync;
|
|
10
11
|
fileLocaleLessPath: string;
|
|
@@ -32,6 +32,7 @@ __export(rehypeDemo_exports, {
|
|
|
32
32
|
DEMO_PROP_VALUE_KEY: () => DEMO_PROP_VALUE_KEY,
|
|
33
33
|
DUMI_DEMO_GRID_TAG: () => DUMI_DEMO_GRID_TAG,
|
|
34
34
|
DUMI_DEMO_TAG: () => DUMI_DEMO_TAG,
|
|
35
|
+
SKIP_DEMO_PARSE: () => SKIP_DEMO_PARSE,
|
|
35
36
|
default: () => rehypeDemo
|
|
36
37
|
});
|
|
37
38
|
module.exports = __toCommonJS(rehypeDemo_exports);
|
|
@@ -48,6 +49,16 @@ var DEMO_NODE_CONTAINER = "$demo-container";
|
|
|
48
49
|
var DEMO_PROP_VALUE_KEY = "$demo-prop-value-key";
|
|
49
50
|
var DUMI_DEMO_TAG = "DumiDemo";
|
|
50
51
|
var DUMI_DEMO_GRID_TAG = "DumiDemoGrid";
|
|
52
|
+
var SKIP_DEMO_PARSE = "pure";
|
|
53
|
+
var ALWAYS_DEMO_PARSE = "demo";
|
|
54
|
+
var skipDemoRE = new RegExp(
|
|
55
|
+
/** 注意前面有空格 ==> */
|
|
56
|
+
` ${SKIP_DEMO_PARSE}`
|
|
57
|
+
);
|
|
58
|
+
var alwaysDemoRE = new RegExp(
|
|
59
|
+
/** 注意前面有空格 ==> */
|
|
60
|
+
` ${ALWAYS_DEMO_PARSE}`
|
|
61
|
+
);
|
|
51
62
|
(async () => {
|
|
52
63
|
({ visit, SKIP, EXIT } = await import("unist-util-visit"));
|
|
53
64
|
({ toString } = await import("hast-util-to-string"));
|
|
@@ -62,14 +73,18 @@ function getCodeLang(node, opts) {
|
|
|
62
73
|
node.properties.src
|
|
63
74
|
);
|
|
64
75
|
lang = import_path.default.extname(node.properties.src).slice(1);
|
|
65
|
-
} else if (
|
|
66
|
-
//
|
|
67
|
-
|
|
68
|
-
|
|
76
|
+
} else if ([
|
|
77
|
+
// 插件开发者可配置 [SKIP_DEMO_PARSE_SIGN] 表示不解析 demo (优先级最高)
|
|
78
|
+
!Object.prototype.hasOwnProperty.call(node.data ?? {}, SKIP_DEMO_PARSE),
|
|
79
|
+
Array.isArray((_b = node.properties) == null ? void 0 : _b.className),
|
|
80
|
+
// 根据用户配置判断 pure 或者 demo
|
|
81
|
+
opts.resolve.codeBlockMode === "passive" ? alwaysDemoRE.test(String((_c = node.data) == null ? void 0 : _c.meta)) : !skipDemoRE.test(String((_d = node.data) == null ? void 0 : _d.meta))
|
|
69
82
|
// active mode (default)
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
83
|
+
].every(Boolean)) {
|
|
84
|
+
lang = String(node.properties.className[0]).replace(
|
|
85
|
+
"language-",
|
|
86
|
+
""
|
|
87
|
+
);
|
|
73
88
|
}
|
|
74
89
|
return lang;
|
|
75
90
|
}
|
|
@@ -181,6 +196,7 @@ function rehypeDemo(opts) {
|
|
|
181
196
|
refAtomIds: vFile.data.frontmatter.atomId ? [vFile.data.frontmatter.atomId] : [],
|
|
182
197
|
fileAbsPath: "",
|
|
183
198
|
lang: codeNode.data.lang,
|
|
199
|
+
fileLocale: opts.fileLocale,
|
|
184
200
|
entryPointCode: codeType === "external" ? void 0 : codeValue,
|
|
185
201
|
resolver: opts.resolver,
|
|
186
202
|
techStack
|
|
@@ -278,7 +294,8 @@ function rehypeDemo(opts) {
|
|
|
278
294
|
id: asset.id,
|
|
279
295
|
component,
|
|
280
296
|
renderOpts: {
|
|
281
|
-
rendererPath: runtimeOpts == null ? void 0 : runtimeOpts.rendererPath
|
|
297
|
+
rendererPath: runtimeOpts == null ? void 0 : runtimeOpts.rendererPath,
|
|
298
|
+
preflightPath: runtimeOpts == null ? void 0 : runtimeOpts.preflightPath
|
|
282
299
|
}
|
|
283
300
|
};
|
|
284
301
|
}
|
|
@@ -316,7 +333,8 @@ function rehypeDemo(opts) {
|
|
|
316
333
|
) : resolveMap,
|
|
317
334
|
renderOpts: {
|
|
318
335
|
rendererPath: runtimeOpts == null ? void 0 : runtimeOpts.rendererPath,
|
|
319
|
-
compilePath: runtimeOpts == null ? void 0 : runtimeOpts.compilePath
|
|
336
|
+
compilePath: runtimeOpts == null ? void 0 : runtimeOpts.compilePath,
|
|
337
|
+
preflightPath: runtimeOpts == null ? void 0 : runtimeOpts.preflightPath
|
|
320
338
|
}
|
|
321
339
|
};
|
|
322
340
|
}
|
|
@@ -364,5 +382,6 @@ function rehypeDemo(opts) {
|
|
|
364
382
|
0 && (module.exports = {
|
|
365
383
|
DEMO_PROP_VALUE_KEY,
|
|
366
384
|
DUMI_DEMO_GRID_TAG,
|
|
367
|
-
DUMI_DEMO_TAG
|
|
385
|
+
DUMI_DEMO_TAG,
|
|
386
|
+
SKIP_DEMO_PARSE
|
|
368
387
|
});
|
|
@@ -40,10 +40,17 @@ var toString;
|
|
|
40
40
|
({ isElement } = await import("hast-util-is-element"));
|
|
41
41
|
({ toString } = await import("hast-util-to-string"));
|
|
42
42
|
})();
|
|
43
|
+
var rawMetaRE = /\[(.+)\]/;
|
|
44
|
+
function rehypeCodeMeta(meta) {
|
|
45
|
+
if (typeof meta !== "string")
|
|
46
|
+
return {};
|
|
47
|
+
const [title] = (rawMetaRE.exec(meta.trim()) || []).slice(1);
|
|
48
|
+
return { title };
|
|
49
|
+
}
|
|
43
50
|
function rehypeEnhancedTag() {
|
|
44
51
|
return async (tree) => {
|
|
45
52
|
visit(tree, "element", (node, i, parent) => {
|
|
46
|
-
var _a, _b, _c, _d;
|
|
53
|
+
var _a, _b, _c, _d, _e;
|
|
47
54
|
if (node.tagName === "pre" && isElement((_a = node.children) == null ? void 0 : _a[0]) && node.children[0].tagName === "code") {
|
|
48
55
|
const className = ((_b = node.children[0].properties) == null ? void 0 : _b.className) || [];
|
|
49
56
|
const lang = (_c = className.join("").match(/language-(\w+)(?:$| )/)) == null ? void 0 : _c[1];
|
|
@@ -51,7 +58,10 @@ function rehypeEnhancedTag() {
|
|
|
51
58
|
parent.children.splice(i, 1, {
|
|
52
59
|
type: "element",
|
|
53
60
|
tagName: "SourceCode",
|
|
54
|
-
properties: {
|
|
61
|
+
properties: {
|
|
62
|
+
...rehypeCodeMeta((_e = node.children[0].data) == null ? void 0 : _e.meta),
|
|
63
|
+
lang
|
|
64
|
+
},
|
|
55
65
|
data: node.children[0].data,
|
|
56
66
|
JSXAttributes: [
|
|
57
67
|
{
|
|
@@ -32,12 +32,19 @@ __export(remarkContainer_exports, {
|
|
|
32
32
|
default: () => remarkContainer
|
|
33
33
|
});
|
|
34
34
|
module.exports = __toCommonJS(remarkContainer_exports);
|
|
35
|
+
var import_rehypeDemo = require("./rehypeDemo");
|
|
35
36
|
var visit;
|
|
36
37
|
var SKIP;
|
|
38
|
+
var CONTINUE;
|
|
37
39
|
var VALID_CONTAINER_TYPES = ["info", "warning", "success", "error"];
|
|
40
|
+
var CODE_GROUP_SPECIFIER = "code-group";
|
|
38
41
|
(async () => {
|
|
39
|
-
({ visit, SKIP } = await import("unist-util-visit"));
|
|
42
|
+
({ visit, SKIP, CONTINUE } = await import("unist-util-visit"));
|
|
40
43
|
})();
|
|
44
|
+
var transformAttributes = (attributes) => Object.entries(attributes ?? {}).reduce(
|
|
45
|
+
(ret, [name, value]) => `${ret} ${value ? `${name}="${value}"` : name}`,
|
|
46
|
+
""
|
|
47
|
+
);
|
|
41
48
|
function remarkContainer() {
|
|
42
49
|
const data = this.data();
|
|
43
50
|
const micromarkExtensions = data.micromarkExtensions.find(
|
|
@@ -47,11 +54,10 @@ function remarkContainer() {
|
|
|
47
54
|
micromarkExtensions.flow["58"].splice(1, 1);
|
|
48
55
|
return (tree) => {
|
|
49
56
|
visit(tree, (node, i, parent) => {
|
|
50
|
-
if (node.type
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
);
|
|
57
|
+
if (node.type !== "containerDirective")
|
|
58
|
+
return CONTINUE;
|
|
59
|
+
if (VALID_CONTAINER_TYPES.includes(node.name)) {
|
|
60
|
+
const attrs = transformAttributes(node.attributes);
|
|
55
61
|
parent.children.splice(
|
|
56
62
|
i,
|
|
57
63
|
1,
|
|
@@ -67,6 +73,31 @@ function remarkContainer() {
|
|
|
67
73
|
);
|
|
68
74
|
return SKIP;
|
|
69
75
|
}
|
|
76
|
+
if (node.name === CODE_GROUP_SPECIFIER) {
|
|
77
|
+
const codeChildren = node.children.filter(({ type }) => type === "code").map((child) => ({
|
|
78
|
+
...child,
|
|
79
|
+
data: {
|
|
80
|
+
...child.data,
|
|
81
|
+
// dumi 默认会编译有关联技术栈的代码块, 标记为不需要编译
|
|
82
|
+
[import_rehypeDemo.SKIP_DEMO_PARSE]: true
|
|
83
|
+
}
|
|
84
|
+
}));
|
|
85
|
+
parent.children.splice(
|
|
86
|
+
i,
|
|
87
|
+
1,
|
|
88
|
+
{
|
|
89
|
+
type: "html",
|
|
90
|
+
value: `<CodeGroup>`,
|
|
91
|
+
position: node.position
|
|
92
|
+
},
|
|
93
|
+
...codeChildren,
|
|
94
|
+
{
|
|
95
|
+
type: "html",
|
|
96
|
+
value: "</CodeGroup>"
|
|
97
|
+
}
|
|
98
|
+
);
|
|
99
|
+
return SKIP;
|
|
100
|
+
}
|
|
70
101
|
});
|
|
71
102
|
};
|
|
72
103
|
}
|