mirror of
https://github.com/Funkoala14/knowledgebase_law.git
synced 2025-06-09 04:38:15 +08:00
158 lines
16 KiB
JavaScript
158 lines
16 KiB
JavaScript
|
import _typeof from "@babel/runtime/helpers/typeof";
|
||
|
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
||
|
import _extends from "@babel/runtime/helpers/extends";
|
||
|
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
||
|
import _createClass from "@babel/runtime/helpers/createClass";
|
||
|
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
|
||
|
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
|
||
|
import _inherits from "@babel/runtime/helpers/inherits";
|
||
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
||
|
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 e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator["return"] && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.aft
|
||
|
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
||
|
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
||
|
import React from 'react';
|
||
|
import highlight from './highlight';
|
||
|
export default (function (options) {
|
||
|
var _ReactAsyncHighlighter;
|
||
|
var loader = options.loader,
|
||
|
isLanguageRegistered = options.isLanguageRegistered,
|
||
|
registerLanguage = options.registerLanguage,
|
||
|
languageLoaders = options.languageLoaders,
|
||
|
noAsyncLoadingLanguages = options.noAsyncLoadingLanguages;
|
||
|
var ReactAsyncHighlighter = /*#__PURE__*/function (_React$PureComponent) {
|
||
|
function ReactAsyncHighlighter() {
|
||
|
_classCallCheck(this, ReactAsyncHighlighter);
|
||
|
return _callSuper(this, ReactAsyncHighlighter, arguments);
|
||
|
}
|
||
|
_inherits(ReactAsyncHighlighter, _React$PureComponent);
|
||
|
return _createClass(ReactAsyncHighlighter, [{
|
||
|
key: "componentDidUpdate",
|
||
|
value: function componentDidUpdate() {
|
||
|
if (!ReactAsyncHighlighter.isRegistered(this.props.language) && languageLoaders) {
|
||
|
this.loadLanguage();
|
||
|
}
|
||
|
}
|
||
|
}, {
|
||
|
key: "componentDidMount",
|
||
|
value: function componentDidMount() {
|
||
|
var _this = this;
|
||
|
if (!ReactAsyncHighlighter.astGeneratorPromise) {
|
||
|
ReactAsyncHighlighter.loadAstGenerator();
|
||
|
}
|
||
|
if (!ReactAsyncHighlighter.astGenerator) {
|
||
|
ReactAsyncHighlighter.astGeneratorPromise.then(function () {
|
||
|
_this.forceUpdate();
|
||
|
});
|
||
|
}
|
||
|
if (!ReactAsyncHighlighter.isRegistered(this.props.language) && languageLoaders) {
|
||
|
this.loadLanguage();
|
||
|
}
|
||
|
}
|
||
|
}, {
|
||
|
key: "loadLanguage",
|
||
|
value: function loadLanguage() {
|
||
|
var _this2 = this;
|
||
|
var language = this.props.language;
|
||
|
if (language === 'text') {
|
||
|
return;
|
||
|
}
|
||
|
ReactAsyncHighlighter.loadLanguage(language).then(function () {
|
||
|
return _this2.forceUpdate();
|
||
|
})["catch"](function () {});
|
||
|
}
|
||
|
}, {
|
||
|
key: "normalizeLanguage",
|
||
|
value: function normalizeLanguage(language) {
|
||
|
return ReactAsyncHighlighter.isSupportedLanguage(language) ? language : 'text';
|
||
|
}
|
||
|
}, {
|
||
|
key: "render",
|
||
|
value: function render() {
|
||
|
return /*#__PURE__*/React.createElement(ReactAsyncHighlighter.highlightInstance, _extends({}, this.props, {
|
||
|
language: this.normalizeLanguage(this.props.language),
|
||
|
astGenerator: ReactAsyncHighlighter.astGenerator
|
||
|
}));
|
||
|
}
|
||
|
}], [{
|
||
|
key: "preload",
|
||
|
value: function preload() {
|
||
|
return ReactAsyncHighlighter.loadAstGenerator();
|
||
|
}
|
||
|
}, {
|
||
|
key: "loadLanguage",
|
||
|
value: function () {
|
||
|
var _loadLanguage = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(language) {
|
||
|
var languageLoader;
|
||
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
||
|
while (1) switch (_context.prev = _context.next) {
|
||
|
case 0:
|
||
|
languageLoader = languageLoaders[language];
|
||
|
if (!(typeof languageLoader === 'function')) {
|
||
|
_context.next = 5;
|
||
|
break;
|
||
|
}
|
||
|
return _context.abrupt("return", languageLoader(ReactAsyncHighlighter.registerLanguage));
|
||
|
case 5:
|
||
|
throw new Error("Language ".concat(language, " not supported"));
|
||
|
case 6:
|
||
|
case "end":
|
||
|
return _context.stop();
|
||
|
}
|
||
|
}, _callee);
|
||
|
}));
|
||
|
function loadLanguage(_x) {
|
||
|
return _loadLanguage.apply(this, arguments);
|
||
|
}
|
||
|
return loadLanguage;
|
||
|
}()
|
||
|
}, {
|
||
|
key: "isSupportedLanguage",
|
||
|
value: function isSupportedLanguage(language) {
|
||
|
return ReactAsyncHighlighter.isRegistered(language) || typeof languageLoaders[language] === 'function';
|
||
|
}
|
||
|
}, {
|
||
|
key: "loadAstGenerator",
|
||
|
value: function loadAstGenerator() {
|
||
|
ReactAsyncHighlighter.astGeneratorPromise = loader().then(function (astGenerator) {
|
||
|
ReactAsyncHighlighter.astGenerator = astGenerator;
|
||
|
if (registerLanguage) {
|
||
|
ReactAsyncHighlighter.languages.forEach(function (language, name) {
|
||
|
return registerLanguage(astGenerator, name, language);
|
||
|
});
|
||
|
}
|
||
|
});
|
||
|
return ReactAsyncHighlighter.astGeneratorPromise;
|
||
|
}
|
||
|
}]);
|
||
|
}(React.PureComponent);
|
||
|
_ReactAsyncHighlighter = ReactAsyncHighlighter;
|
||
|
_defineProperty(ReactAsyncHighlighter, "astGenerator", null);
|
||
|
_defineProperty(ReactAsyncHighlighter, "highlightInstance", highlight(null, {}));
|
||
|
_defineProperty(ReactAsyncHighlighter, "astGeneratorPromise", null);
|
||
|
_defineProperty(ReactAsyncHighlighter, "languages", new Map());
|
||
|
_defineProperty(ReactAsyncHighlighter, "supportedLanguages", options.supportedLanguages || Object.keys(languageLoaders || {}));
|
||
|
_defineProperty(ReactAsyncHighlighter, "isRegistered", function (language) {
|
||
|
if (noAsyncLoadingLanguages) {
|
||
|
return true;
|
||
|
}
|
||
|
if (!registerLanguage) {
|
||
|
throw new Error("Current syntax highlighter doesn't support registration of languages");
|
||
|
}
|
||
|
if (!_ReactAsyncHighlighter.astGenerator) {
|
||
|
// Ast generator not available yet, but language will be registered once it is.
|
||
|
return _ReactAsyncHighlighter.languages.has(language);
|
||
|
}
|
||
|
return isLanguageRegistered(_ReactAsyncHighlighter.astGenerator, language);
|
||
|
});
|
||
|
_defineProperty(ReactAsyncHighlighter, "registerLanguage", function (name, language) {
|
||
|
if (!registerLanguage) {
|
||
|
throw new Error("Current syntax highlighter doesn't support registration of languages");
|
||
|
}
|
||
|
if (_ReactAsyncHighlighter.astGenerator) {
|
||
|
return registerLanguage(_ReactAsyncHighlighter.astGenerator, name, language);
|
||
|
} else {
|
||
|
_ReactAsyncHighlighter.languages.set(name, language);
|
||
|
}
|
||
|
});
|
||
|
return ReactAsyncHighlighter;
|
||
|
});
|