dumi 2.3.0-alpha.9 → 2.3.0-beta.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.
Files changed (86) hide show
  1. package/dist/assetParsers/block.d.ts +7 -1
  2. package/dist/assetParsers/block.js +14 -6
  3. package/dist/client/pages/Demo/index.js +19 -5
  4. package/dist/client/pages/Loading.d.ts +1 -0
  5. package/dist/client/pages/Loading.js +2 -0
  6. package/dist/client/theme-api/DumiDemo/index.js +4 -4
  7. package/dist/client/theme-api/{context/index.d.ts → context.d.ts} +4 -12
  8. package/dist/client/theme-api/context.js +16 -0
  9. package/dist/client/theme-api/index.d.ts +2 -3
  10. package/dist/client/theme-api/index.js +2 -3
  11. package/dist/client/theme-api/types.d.ts +6 -4
  12. package/dist/client/theme-api/useLiveDemo.d.ts +6 -0
  13. package/dist/client/theme-api/useLiveDemo.js +70 -0
  14. package/dist/client/theme-api/useRouteMeta.js +73 -20
  15. package/dist/client/theme-api/useSiteSearch/index.d.ts +1 -1
  16. package/dist/client/theme-api/useSiteSearch/index.js +20 -48
  17. package/dist/client/theme-api/useSiteSearch/useSearchData.d.ts +9 -6
  18. package/dist/client/theme-api/useSiteSearch/useSearchData.js +55 -60
  19. package/dist/client/theme-api/useTabMeta.js +1 -1
  20. package/dist/client/theme-api/utils.d.ts +10 -0
  21. package/dist/client/theme-api/utils.js +25 -0
  22. package/dist/constants.d.ts +0 -1
  23. package/dist/constants.js +0 -4
  24. package/dist/features/compile/index.js +11 -18
  25. package/dist/features/exports.js +3 -3
  26. package/dist/features/meta.js +12 -31
  27. package/dist/features/theme/index.js +8 -5
  28. package/dist/loaders/markdown/index.d.ts +1 -7
  29. package/dist/loaders/markdown/index.js +39 -113
  30. package/dist/loaders/markdown/transformer/index.d.ts +1 -1
  31. package/dist/loaders/markdown/transformer/rehypeDemo.js +8 -2
  32. package/dist/loaders/page/index.js +1 -3
  33. package/dist/preset.js +1 -2
  34. package/dist/templates/ContextWrapper.ts.tpl +2 -10
  35. package/dist/templates/meta/exports.ts.tpl +160 -0
  36. package/dist/templates/meta/index.ts.tpl +26 -0
  37. package/dist/templates/{meta-runtime.ts.tpl → meta/runtime.ts.tpl} +11 -22
  38. package/dist/types.d.ts +2 -2
  39. package/index.d.ts +1 -4
  40. package/package.json +2 -1
  41. package/theme-default/builtins/Previewer/index.d.ts +1 -1
  42. package/theme-default/builtins/Previewer/index.js +35 -33
  43. package/theme-default/builtins/Previewer/index.less +34 -0
  44. package/theme-default/builtins/SourceCode/index.d.ts +2 -1
  45. package/theme-default/builtins/SourceCode/index.js +3 -3
  46. package/theme-default/builtins/SourceCode/index.less +1 -0
  47. package/theme-default/locales/en-US.json +2 -0
  48. package/theme-default/locales/zh-CN.json +2 -0
  49. package/theme-default/slots/Loading/index.d.ts +5 -0
  50. package/theme-default/slots/Loading/index.js +18 -0
  51. package/theme-default/slots/Loading/index.less +20 -0
  52. package/theme-default/slots/PreviewerActions/index.d.ts +7 -1
  53. package/theme-default/slots/PreviewerActions/index.js +49 -6
  54. package/theme-default/slots/PreviewerActions/index.less +58 -14
  55. package/theme-default/slots/SearchBar/Mask.js +1 -1
  56. package/theme-default/slots/SearchBar/index.js +1 -1
  57. package/theme-default/slots/SearchResult/index.js +1 -10
  58. package/theme-default/slots/SourceCodeEditor/index.d.ts +18 -0
  59. package/theme-default/slots/SourceCodeEditor/index.js +106 -0
  60. package/theme-default/slots/SourceCodeEditor/index.less +45 -0
  61. package/dist/client/theme-api/context/index.js +0 -50
  62. package/dist/client/theme-api/context/use.d.ts +0 -10
  63. package/dist/client/theme-api/context/use.js +0 -25
  64. package/dist/client/theme-api/evalCode.d.ts +0 -2
  65. package/dist/client/theme-api/evalCode.js +0 -17
  66. package/dist/client/theme-api/live/LiveProvider.d.ts +0 -16
  67. package/dist/client/theme-api/live/LiveProvider.js +0 -74
  68. package/dist/client/theme-api/live/index.d.ts +0 -3
  69. package/dist/client/theme-api/live/index.js +0 -3
  70. package/dist/client/theme-api/live/useDemoScopes.d.ts +0 -2
  71. package/dist/client/theme-api/live/useDemoScopes.js +0 -15
  72. package/dist/features/live.d.ts +0 -3
  73. package/dist/features/live.js +0 -74
  74. package/dist/templates/live/demo-scopes.ts.tpl +0 -22
  75. package/dist/templates/live/disabled.ts.tpl +0 -1
  76. package/dist/templates/meta-demos.ts.tpl +0 -34
  77. package/dist/templates/meta-frontmatter.ts.tpl +0 -9
  78. package/dist/templates/meta-route.ts.tpl +0 -43
  79. package/dist/templates/meta-search.ts.tpl +0 -41
  80. package/theme-default/slots/LiveDemo/index.d.ts +0 -3
  81. package/theme-default/slots/LiveDemo/index.js +0 -8
  82. package/theme-default/slots/LiveEditor/index.d.ts +0 -4
  83. package/theme-default/slots/LiveEditor/index.js +0 -20
  84. package/theme-default/slots/LiveError/index.d.ts +0 -4
  85. package/theme-default/slots/LiveError/index.js +0 -15
  86. package/theme-default/slots/LiveError/index.less +0 -22
@@ -0,0 +1,45 @@
1
+ @import (reference) '../../styles/variables.less';
2
+
3
+ .@{prefix}-source-code-editor {
4
+ position: relative;
5
+
6
+ &-textarea {
7
+ position: absolute;
8
+ z-index: 1;
9
+ display: block;
10
+ top: 0;
11
+ left: 0;
12
+ width: 100%;
13
+ height: 100%;
14
+ color: transparent;
15
+ caret-color: @c-text;
16
+ overflow-wrap: normal;
17
+ white-space: pre;
18
+ box-sizing: border-box;
19
+ background: transparent;
20
+ opacity: 1;
21
+ border: 0;
22
+ resize: none;
23
+ outline: none;
24
+ overflow: hidden;
25
+ border-bottom-left-radius: 3px;
26
+ border-bottom-right-radius: 3px;
27
+
28
+ @{dark-selector} & {
29
+ caret-color: @c-text-dark;
30
+ }
31
+
32
+ &:focus {
33
+ box-shadow: 0 0 0 1px lighten(@c-primary, 20%) inset;
34
+
35
+ @{dark-selector} & {
36
+ box-shadow: 0 0 0 1px darken(@c-primary-dark, 20%) inset;
37
+
38
+ // for firefox because its selection color is not translucent when color-scheme is dark
39
+ &::selection {
40
+ background-color: fade(@c-primary-dark, 30%);
41
+ }
42
+ }
43
+ }
44
+ }
45
+ }
@@ -1,50 +0,0 @@
1
- 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
- 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
- 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
- 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
- import { createContext, useContext } from 'react';
6
- import use from "./use";
7
- export var SiteContext = /*#__PURE__*/createContext({
8
- pkg: {},
9
- historyType: 'browser',
10
- entryExports: {},
11
- demos: {},
12
- components: {},
13
- locales: [],
14
- themeConfig: {},
15
- loading: false,
16
- setLoading: function setLoading() {},
17
- _2_level_nav_available: true,
18
- getDemoById: function () {
19
- var _getDemoById = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
20
- return _regeneratorRuntime().wrap(function _callee$(_context) {
21
- while (1) switch (_context.prev = _context.next) {
22
- case 0:
23
- return _context.abrupt("return", null);
24
- case 1:
25
- case "end":
26
- return _context.stop();
27
- }
28
- }, _callee);
29
- }));
30
- function getDemoById() {
31
- return _getDemoById.apply(this, arguments);
32
- }
33
- return getDemoById;
34
- }(),
35
- tabs: []
36
- });
37
- export var useSiteData = function useSiteData() {
38
- return useContext(SiteContext);
39
- };
40
- var cache = new Map();
41
-
42
- // Async load demo data
43
- export function useDemoData(demoId) {
44
- var _useSiteData = useSiteData(),
45
- getDemoById = _useSiteData.getDemoById;
46
- if (!cache.has(demoId)) {
47
- cache.set(demoId, getDemoById(demoId));
48
- }
49
- return use(cache.get(demoId));
50
- }
@@ -1,10 +0,0 @@
1
- type ReactPromise<T> = Promise<T> & {
2
- status?: 'pending' | 'fulfilled' | 'rejected';
3
- value?: T;
4
- reason?: any;
5
- };
6
- /**
7
- * @private Internal usage. Safe to remove
8
- */
9
- export default function use<T>(promise: ReactPromise<T>): T;
10
- export {};
@@ -1,25 +0,0 @@
1
- // Copy from React official demo.
2
- // This will be replace if React release new version of use hooks
3
-
4
- /**
5
- * @private Internal usage. Safe to remove
6
- */
7
- export default function use(promise) {
8
- if (promise.status === 'fulfilled') {
9
- return promise.value;
10
- } else if (promise.status === 'rejected') {
11
- throw promise.reason;
12
- } else if (promise.status === 'pending') {
13
- throw promise;
14
- } else {
15
- promise.status = 'pending';
16
- promise.then(function (result) {
17
- promise.status = 'fulfilled';
18
- promise.value = result;
19
- }, function (reason) {
20
- promise.status = 'rejected';
21
- promise.reason = reason;
22
- });
23
- throw promise;
24
- }
25
- }
@@ -1,2 +0,0 @@
1
- import type { ComponentType } from 'react';
2
- export declare const evalCode: (code: string, scope: any) => ComponentType;
@@ -1,17 +0,0 @@
1
- function _construct(Parent, args, Class) { if (_isNativeReflectConstruct()) { _construct = Reflect.construct.bind(); } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); }
2
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
3
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
4
- function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
5
- function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
6
- 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); }
7
- function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
8
- function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
9
- 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; }
10
- export var evalCode = function evalCode(code, scope) {
11
- var scopeKeys = Object.keys(scope);
12
- var scopeValues = scopeKeys.map(function (key) {
13
- return scope[key];
14
- });
15
- var importReg = /import[\S\s]*?from.*;/g;
16
- return _construct(Function, scopeKeys.concat([code.replace(importReg, '').replace('export default', 'return').trim()])).apply(void 0, _toConsumableArray(scopeValues));
17
- };
@@ -1,16 +0,0 @@
1
- import React, { FC } from 'react';
2
- type LiveContextProps = {
3
- enabled: boolean;
4
- code: string;
5
- onCodeChange: (code: string) => void;
6
- demo: React.ReactNode;
7
- error: string;
8
- };
9
- export declare const LiveContext: React.Context<LiveContextProps>;
10
- export type LiveProviderProps = {
11
- initialCode: string;
12
- demoId: string;
13
- children: React.ReactElement;
14
- };
15
- export declare const LiveProvider: FC<LiveProviderProps>;
16
- export default LiveProvider;
@@ -1,74 +0,0 @@
1
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
2
- 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."); }
3
- 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); }
4
- 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; }
5
- 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; } }
6
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
7
- import { evalCode } from 'dumi';
8
- import React, { useMemo, useState } from 'react';
9
- import ReactDOM from 'react-dom/server';
10
- import { transform } from 'sucrase';
11
- import { useDemoScopes } from "./useDemoScopes";
12
- export var LiveContext = /*#__PURE__*/React.createContext({
13
- enabled: false,
14
- code: '',
15
- onCodeChange: function onCodeChange() {},
16
- demo: null,
17
- error: ''
18
- });
19
- var transformCode = function transformCode(code, scopes) {
20
- if (!scopes) {
21
- return /*#__PURE__*/React.createElement(React.Fragment, null);
22
- }
23
- var Comp = evalCode(transform(code, {
24
- transforms: ['typescript', 'jsx']
25
- }).code, scopes);
26
- return /*#__PURE__*/React.createElement(Comp, null);
27
- };
28
- export var LiveProvider = function LiveProvider(_ref) {
29
- var initialCode = _ref.initialCode,
30
- demoId = _ref.demoId,
31
- children = _ref.children;
32
- var scopes = useDemoScopes(demoId);
33
- var _useState = useState(initialCode),
34
- _useState2 = _slicedToArray(_useState, 2),
35
- code = _useState2[0],
36
- setCode = _useState2[1];
37
- var _useState3 = useState(function () {
38
- return transformCode(code, scopes);
39
- }),
40
- _useState4 = _slicedToArray(_useState3, 2),
41
- demo = _useState4[0],
42
- setDemo = _useState4[1];
43
- var _useState5 = useState(''),
44
- _useState6 = _slicedToArray(_useState5, 2),
45
- error = _useState6[0],
46
- setError = _useState6[1];
47
- var onCodeChange = function onCodeChange(newCode) {
48
- setCode(newCode);
49
- try {
50
- var liveDemo = transformCode(newCode, scopes);
51
- ReactDOM.renderToString(liveDemo);
52
- setDemo(liveDemo);
53
- setError('');
54
- } catch (e) {
55
- setError(e.message);
56
- }
57
- };
58
- var contextValue = useMemo(function () {
59
- return {
60
- error: error,
61
- enabled: scopes !== null,
62
- demo: demo,
63
- code: code,
64
- onCodeChange: onCodeChange
65
- };
66
- }, [code, scopes, demo, error]);
67
- if (!scopes) {
68
- return children;
69
- }
70
- return /*#__PURE__*/React.createElement(LiveContext.Provider, {
71
- value: contextValue
72
- }, children);
73
- };
74
- export default LiveProvider;
@@ -1,3 +0,0 @@
1
- import LiveProvider, { LiveContext } from './LiveProvider';
2
- import { isLiveEnabled } from './useDemoScopes';
3
- export { LiveProvider, LiveContext, isLiveEnabled };
@@ -1,3 +0,0 @@
1
- import LiveProvider, { LiveContext } from "./LiveProvider";
2
- import { isLiveEnabled } from "./useDemoScopes";
3
- export { LiveProvider, LiveContext, isLiveEnabled };
@@ -1,2 +0,0 @@
1
- export declare const useDemoScopes: (id: string) => any;
2
- export declare const isLiveEnabled: () => boolean;
@@ -1,15 +0,0 @@
1
- import { getDemoScopesById } from 'dumi';
2
- import use from "../context/use";
3
- var cache = new Map();
4
- export var useDemoScopes = function useDemoScopes(id) {
5
- if (!getDemoScopesById) {
6
- return null;
7
- }
8
- if (!cache.has(id)) {
9
- cache.set(id, getDemoScopesById(id));
10
- }
11
- return use(cache.get(id));
12
- };
13
- export var isLiveEnabled = function isLiveEnabled() {
14
- return !!getDemoScopesById;
15
- };
@@ -1,3 +0,0 @@
1
- import { IApi } from 'umi';
2
- declare const _default: (api: IApi) => void;
3
- export default _default;
@@ -1,74 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: true });
8
- };
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
16
- };
17
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
-
19
- // src/features/live.ts
20
- var live_exports = {};
21
- __export(live_exports, {
22
- default: () => live_default
23
- });
24
- module.exports = __toCommonJS(live_exports);
25
- var import_constants = require("../constants");
26
- var import_tabs = require("./tabs");
27
- var import_path = require("path");
28
- var import_plugin_utils = require("umi/plugin-utils");
29
- var live_default = (api) => {
30
- const mdFiles = [];
31
- api.describe({
32
- key: "live",
33
- config: {
34
- schema(joi) {
35
- return joi.boolean();
36
- }
37
- },
38
- enableBy: api.EnableBy.register
39
- });
40
- api.register({
41
- key: "modifyRoutes",
42
- // make sure it is called last
43
- stage: Infinity,
44
- fn: (routes) => {
45
- mdFiles.length = 0;
46
- Object.values(routes).forEach((route) => {
47
- if (!route.isLayout && !/\*|:/.test(route.path) && route.file && !(0, import_tabs.isTabRouteFile)(route.file) && route.file.endsWith(".md")) {
48
- mdFiles.push({
49
- index: mdFiles.length,
50
- file: (0, import_plugin_utils.winPath)(route.file),
51
- id: route.id
52
- });
53
- }
54
- });
55
- return routes;
56
- }
57
- });
58
- api.onGenerateFiles(async () => {
59
- api.writeTmpFile({
60
- noPluginDir: true,
61
- path: "dumi/live/demo-scopes.ts",
62
- tplPath: (0, import_plugin_utils.winPath)(
63
- (0, import_path.join)(
64
- import_constants.TEMPLATES_DIR,
65
- "live",
66
- !!api.config.live ? "demo-scopes.ts.tpl" : "disabled.ts.tpl"
67
- )
68
- ),
69
- context: {
70
- metaFiles: mdFiles
71
- }
72
- });
73
- });
74
- };
@@ -1,22 +0,0 @@
1
- {{#metaFiles}}
2
- import { scopeIndex as scpi{{{index}}} } from '{{{file}}}?type=scope-index';
3
- {{/metaFiles}}
4
-
5
- const scopeIndexes: Record<string, { ids: string[], getter: () => Promise<any> }> = {
6
- {{#metaFiles}}
7
- ...scpi{{{index}}},
8
- {{/metaFiles}}
9
- };
10
-
11
- /** Async to load demo by id */
12
- export const getDemoScopesById = async (id: string) => {
13
- const getter = scopeIndexes[id];
14
-
15
- if (!getter) {
16
- return {};
17
- }
18
-
19
- const { scopes }: any = await getter() || {};
20
-
21
- return scopes?.[id] || {};
22
- };
@@ -1 +0,0 @@
1
- export const getDemoScopesById = null;
@@ -1,34 +0,0 @@
1
- {{#metaFiles}}
2
- import { demoIndex as dmi{{{index}}} } from '{{{file}}}?type=demo-index';
3
- {{/metaFiles}}
4
-
5
- export const demoIndexes: Record<string, { ids: string[], getter: () => Promise<any> }> = {
6
- {{#metaFiles}}
7
- '{{{id}}}': dmi{{{index}}},
8
- {{/metaFiles}}
9
- };
10
-
11
- // Convert the demoIndex to a key-value pairs: <demoId, getter>
12
- const demoIdMap = Object.keys(demoIndexes).reduce((total, current) => {
13
- const demoIndex = demoIndexes[current];
14
- const { ids, getter } = demoIndex;
15
-
16
- ids.forEach((id) => {
17
- total[id] = getter;
18
- });
19
-
20
- return total;
21
- }, {});
22
-
23
- /** Async to load demo by id */
24
- export const getDemoById = async (id: string) => {
25
- const getter = demoIdMap[id];
26
-
27
- if (!getter) {
28
- return null;
29
- }
30
-
31
- const { demos }: any = await getter() || {};
32
-
33
- return demos?.[id];
34
- };
@@ -1,9 +0,0 @@
1
- {{#metaFiles}}
2
- import { frontmatter as fm{{{index}}} } from '{{{file}}}?type=frontmatter';
3
- {{/metaFiles}}
4
-
5
- export const filesFrontmatter = {
6
- {{#metaFiles}}
7
- '{{{id}}}': fm{{{index}}},
8
- {{/metaFiles}}
9
- }
@@ -1,43 +0,0 @@
1
- import { tabs } from './tabs';
2
- import { filesFrontmatter } from './frontmatter';
3
-
4
- const files = {
5
- {{#metaFiles}}
6
- '{{{id}}}': {
7
- textGetter: () => import({{{chunkName}}}'{{{file}}}?type=text'),
8
- {{#tabs}}
9
- tabs: {{{tabs}}},
10
- {{/tabs}}
11
- },
12
- {{/metaFiles}}
13
- };
14
-
15
- export const getRouteMetaById = async (id: string) => {
16
- const file = files[id];
17
-
18
- if (!file) {
19
- return null;
20
- }
21
-
22
- const text = await file.textGetter();
23
- const frontmatter = filesFrontmatter[id];
24
-
25
- const tabsMeta = file.tabs && await Promise.all(file.tabs.map(async (tab) => {
26
- const meta = await getRouteMetaById(tab) ?? {
27
- frontmatter: { title: tabs[tab].title },
28
- toc: [],
29
- texts: [],
30
- };
31
- return {
32
- ...tabs[tab],
33
- meta,
34
- }
35
- }));
36
-
37
- return {
38
- texts: text?.texts,
39
- toc: text?.toc,
40
- frontmatter,
41
- tabs: tabsMeta,
42
- };
43
- }
@@ -1,41 +0,0 @@
1
- // This will bundle all the site demos and meta data into one file
2
- // which should only async load on search
3
- import { getRouteMetaById } from './route-meta';
4
- import { demoIndexes } from './demos';
5
- import { filesFrontmatter } from './frontmatter';
6
-
7
- // generate demos data in runtime, for reuse route.id to reduce bundle size
8
- export const demos = {};
9
-
10
- /** @private Internal usage. Safe to refactor. */
11
- export async function loadFilesMeta(idList: string[]) {
12
- const metaMap: Record<string, any> = {};
13
-
14
- {{#metaFiles}}
15
- if (idList.includes('{{{id}}}')) {
16
- metaMap['{{{id}}}'] = async () => {
17
- const routeMeta = await getRouteMetaById('{{{id}}}');
18
- const demo = await demoIndexes['{{{id}}}']?.getter() || {};
19
- return {
20
- frontmatter: filesFrontmatter['{{{id}}}'] ?? {},
21
- toc: routeMeta?.toc ?? [],
22
- texts: routeMeta?.texts ?? [],
23
- tabs: routeMeta?.tabs ?? [],
24
- demos: demo?.demos ?? {},
25
- };
26
- };
27
- }
28
- {{/metaFiles}}
29
-
30
- // Wait for all meta data to be loaded
31
- const metaList = await Promise.all(Object.entries(metaMap).map(([id, getter]) => getter()));
32
-
33
- // Merge into filesMeta
34
- const filesMeta = {};
35
-
36
- Object.entries(metaMap).forEach(([id], index) => {
37
- filesMeta[id] = metaList[index];
38
- });
39
-
40
- return filesMeta;
41
- }
@@ -1,3 +0,0 @@
1
- import { FC } from 'react';
2
- declare const LiveDemo: FC;
3
- export default LiveDemo;
@@ -1,8 +0,0 @@
1
- import { LiveContext } from 'dumi';
2
- import React, { useContext } from 'react';
3
- var LiveDemo = function LiveDemo() {
4
- var _useContext = useContext(LiveContext),
5
- demo = _useContext.demo;
6
- return /*#__PURE__*/React.createElement(React.Fragment, null, demo);
7
- };
8
- export default LiveDemo;
@@ -1,4 +0,0 @@
1
- import { ComponentProps, FC } from 'react';
2
- import Editor from 'react-simple-code-editor';
3
- declare const LiveEditor: FC<ComponentProps<typeof Editor>>;
4
- export default LiveEditor;
@@ -1,20 +0,0 @@
1
- function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
- import { LiveContext } from 'dumi';
3
- import { highlight, languages } from 'prismjs';
4
- import React, { useContext } from 'react';
5
- import Editor from 'react-simple-code-editor';
6
- var LiveEditor = function LiveEditor(props) {
7
- var _props$highlight, _props$padding;
8
- var _useContext = useContext(LiveContext),
9
- code = _useContext.code,
10
- onCodeChange = _useContext.onCodeChange;
11
- return /*#__PURE__*/React.createElement(Editor, _extends({}, props, {
12
- value: code,
13
- onValueChange: onCodeChange,
14
- highlight: (_props$highlight = props.highlight) !== null && _props$highlight !== void 0 ? _props$highlight : function (code) {
15
- return highlight(code, languages.js, 'tsx');
16
- },
17
- padding: (_props$padding = props.padding) !== null && _props$padding !== void 0 ? _props$padding : 20
18
- }));
19
- };
20
- export default LiveEditor;
@@ -1,4 +0,0 @@
1
- import { FC } from 'react';
2
- import './index.less';
3
- declare const LiveError: FC;
4
- export default LiveError;
@@ -1,15 +0,0 @@
1
- import { ReactComponent as IconError } from '@ant-design/icons-svg/inline-svg/filled/close-circle.svg';
2
- import { LiveContext } from 'dumi';
3
- import React, { useContext } from 'react';
4
- import "./index.less";
5
- var LiveError = function LiveError() {
6
- var _useContext = useContext(LiveContext),
7
- error = _useContext.error;
8
- if (!error) {
9
- return null;
10
- }
11
- return /*#__PURE__*/React.createElement("pre", {
12
- className: 'dumi-default-live-error'
13
- }, /*#__PURE__*/React.createElement(IconError, null), error);
14
- };
15
- export default LiveError;
@@ -1,22 +0,0 @@
1
- @import (reference) '../../styles/variables.less';
2
-
3
- .dumi-default-live-error {
4
- @color: darken(desaturate(@c-error, 20%), 1%);
5
-
6
- white-space: break-spaces;
7
- background: lighten(@c-error, 51%);
8
- color: @color;
9
- padding: 12px 20px;
10
- margin: 0;
11
- border-radius: 0 0 4px 4px;
12
- display: flex;
13
- align-items: flex-start;
14
- gap: 8px;
15
- line-height: 16px;
16
-
17
- > svg {
18
- fill: currentcolor;
19
- width: 16px;
20
- flex: none;
21
- }
22
- }