react-terminal-viewer-cicd 2.0.4

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 (99) hide show
  1. package/README.md +181 -0
  2. package/dist/esm/Addon/EventEmiter.d.ts +18 -0
  3. package/dist/esm/Addon/EventEmiter.js +64 -0
  4. package/dist/esm/Addon/HighlightAddon.d.ts +26 -0
  5. package/dist/esm/Addon/HighlightAddon.js +188 -0
  6. package/dist/esm/Addon/SearchAddon.d.ts +140 -0
  7. package/dist/esm/Addon/SearchAddon.js +797 -0
  8. package/dist/esm/Addon/WorkerLog/GlobalContext.d.ts +10 -0
  9. package/dist/esm/Addon/WorkerLog/GlobalContext.js +37 -0
  10. package/dist/esm/Addon/WorkerLog/LimitMap.d.ts +14 -0
  11. package/dist/esm/Addon/WorkerLog/LimitMap.js +54 -0
  12. package/dist/esm/Addon/WorkerLog/LogWorker.d.ts +2 -0
  13. package/dist/esm/Addon/WorkerLog/LogWorker.js +13 -0
  14. package/dist/esm/Addon/WorkerLog/Logs.d.ts +21 -0
  15. package/dist/esm/Addon/WorkerLog/Logs.js +60 -0
  16. package/dist/esm/Addon/WorkerLog/Mark.d.ts +36 -0
  17. package/dist/esm/Addon/WorkerLog/Mark.js +155 -0
  18. package/dist/esm/Addon/WorkerLog/Searcher.d.ts +16 -0
  19. package/dist/esm/Addon/WorkerLog/Searcher.js +88 -0
  20. package/dist/esm/Addon/WorkerLog/WebWokerServer.d.ts +10 -0
  21. package/dist/esm/Addon/WorkerLog/WebWokerServer.js +57 -0
  22. package/dist/esm/Addon/WorkerLog/WebWorkerClient.d.ts +13 -0
  23. package/dist/esm/Addon/WorkerLog/WebWorkerClient.js +83 -0
  24. package/dist/esm/Addon/WorkerLog/log.worker.d.ts +1 -0
  25. package/dist/esm/Addon/WorkerLog/log.worker.js +63 -0
  26. package/dist/esm/Addon/WorkerLog/types.d.ts +18 -0
  27. package/dist/esm/Addon/WorkerLog/types.js +1 -0
  28. package/dist/esm/Addon/useAddon.d.ts +9 -0
  29. package/dist/esm/Addon/useAddon.js +33 -0
  30. package/dist/esm/Hooks/useBatchProcess.d.ts +2 -0
  31. package/dist/esm/Hooks/useBatchProcess.js +47 -0
  32. package/dist/esm/Hooks/useCache.d.ts +31 -0
  33. package/dist/esm/Hooks/useCache.js +206 -0
  34. package/dist/esm/Hooks/useDebounceInput.d.ts +3 -0
  35. package/dist/esm/Hooks/useDebounceInput.js +26 -0
  36. package/dist/esm/Hooks/useLocalStore.d.ts +2 -0
  37. package/dist/esm/Hooks/useLocalStore.js +9 -0
  38. package/dist/esm/Hooks/useRemote.d.ts +30 -0
  39. package/dist/esm/Hooks/useRemote.js +398 -0
  40. package/dist/esm/Hooks/useThrottle.d.ts +2 -0
  41. package/dist/esm/Hooks/useThrottle.js +13 -0
  42. package/dist/esm/Hooks/useWorkerLogs.d.ts +9 -0
  43. package/dist/esm/Hooks/useWorkerLogs.js +162 -0
  44. package/dist/esm/TerminalViewer/index.d.ts +185 -0
  45. package/dist/esm/TerminalViewer/index.js +292 -0
  46. package/dist/esm/TerminalViewer/index.less +17 -0
  47. package/dist/esm/TerminalViewerBody/index.d.ts +87 -0
  48. package/dist/esm/TerminalViewerBody/index.js +248 -0
  49. package/dist/esm/TerminalViewerBody/index.less +51 -0
  50. package/dist/esm/TerminalViewerHeader/index.d.ts +88 -0
  51. package/dist/esm/TerminalViewerHeader/index.js +129 -0
  52. package/dist/esm/TerminalViewerHeader/index.less +143 -0
  53. package/dist/esm/TerminalViewerToolBar/index.d.ts +46 -0
  54. package/dist/esm/TerminalViewerToolBar/index.js +28 -0
  55. package/dist/esm/TerminalViewerToolBar/index.less +32 -0
  56. package/dist/esm/TerminalViewerVirtualDom/index.d.ts +71 -0
  57. package/dist/esm/TerminalViewerVirtualDom/index.js +309 -0
  58. package/dist/esm/TerminalViewerVirtualDom/index.less +68 -0
  59. package/dist/esm/index.d.ts +9 -0
  60. package/dist/esm/index.js +9 -0
  61. package/dist/esm/mock/index.d.ts +12 -0
  62. package/dist/esm/mock/index.js +98 -0
  63. package/dist/esm/types.d.ts +30 -0
  64. package/dist/esm/types.js +1 -0
  65. package/dist/worker/Addon/EventEmiter.d.ts +18 -0
  66. package/dist/worker/Addon/HighlightAddon.d.ts +26 -0
  67. package/dist/worker/Addon/SearchAddon.d.ts +140 -0
  68. package/dist/worker/Addon/WorkerLog/GlobalContext.d.ts +10 -0
  69. package/dist/worker/Addon/WorkerLog/LimitMap.d.ts +14 -0
  70. package/dist/worker/Addon/WorkerLog/LogWorker.d.ts +2 -0
  71. package/dist/worker/Addon/WorkerLog/Logs.d.ts +21 -0
  72. package/dist/worker/Addon/WorkerLog/Mark.d.ts +36 -0
  73. package/dist/worker/Addon/WorkerLog/Searcher.d.ts +16 -0
  74. package/dist/worker/Addon/WorkerLog/WebWokerServer.d.ts +10 -0
  75. package/dist/worker/Addon/WorkerLog/WebWorkerClient.d.ts +13 -0
  76. package/dist/worker/Addon/WorkerLog/log.worker.d.ts +1 -0
  77. package/dist/worker/Addon/WorkerLog/types.d.ts +18 -0
  78. package/dist/worker/Addon/useAddon.d.ts +9 -0
  79. package/dist/worker/Hooks/useBatchProcess.d.ts +2 -0
  80. package/dist/worker/Hooks/useCache.d.ts +31 -0
  81. package/dist/worker/Hooks/useDebounceInput.d.ts +3 -0
  82. package/dist/worker/Hooks/useLocalStore.d.ts +2 -0
  83. package/dist/worker/Hooks/useRemote.d.ts +30 -0
  84. package/dist/worker/Hooks/useRemote.test.d.ts +1 -0
  85. package/dist/worker/Hooks/useThrottle.d.ts +2 -0
  86. package/dist/worker/Hooks/useWorkerLogs.d.ts +9 -0
  87. package/dist/worker/TerminalViewer/index.d.ts +185 -0
  88. package/dist/worker/TerminalViewer/index.test.d.ts +1 -0
  89. package/dist/worker/TerminalViewerBody/index.d.ts +87 -0
  90. package/dist/worker/TerminalViewerBody/index.test.d.ts +1 -0
  91. package/dist/worker/TerminalViewerHeader/index.d.ts +88 -0
  92. package/dist/worker/TerminalViewerToolBar/index.d.ts +46 -0
  93. package/dist/worker/TerminalViewerVirtualDom/index.d.ts +71 -0
  94. package/dist/worker/index.d.ts +9 -0
  95. package/dist/worker/log.worker.js +2 -0
  96. package/dist/worker/log.worker.js.map +1 -0
  97. package/dist/worker/mock/index.d.ts +12 -0
  98. package/dist/worker/types.d.ts +30 -0
  99. package/package.json +97 -0
@@ -0,0 +1,398 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
5
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
6
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
7
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
8
+ 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."); }
9
+ 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); }
10
+ 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; }
11
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
12
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
13
+ 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 new 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.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
14
+ 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); } }
15
+ 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); }); }; }
16
+ import { useEffect, useRef, useState } from 'react';
17
+ import useCache from "./useCache";
18
+ var splitContent = function splitContent(content) {
19
+ var result = [];
20
+ var start = 0;
21
+ var len = content.length;
22
+ var offset = 200 * 8000;
23
+ while (start < len) {
24
+ result.push(content.substr(start, offset));
25
+ start += offset;
26
+ }
27
+ return result;
28
+ };
29
+ var batchProcess = /*#__PURE__*/function () {
30
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(array, callback, canContinue, timerCallback) {
31
+ var index,
32
+ string,
33
+ _args = arguments;
34
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
35
+ while (1) switch (_context.prev = _context.next) {
36
+ case 0:
37
+ index = _args.length > 4 && _args[4] !== undefined ? _args[4] : 0;
38
+ if (!(index > array.length)) {
39
+ _context.next = 3;
40
+ break;
41
+ }
42
+ return _context.abrupt("return", undefined);
43
+ case 3:
44
+ string = array[index];
45
+ _context.next = 6;
46
+ return new Promise(function (resolve) {
47
+ var timer = setTimeout(function () {
48
+ if (window.requestAnimationFrame) {
49
+ window.requestAnimationFrame(function () {
50
+ if (canContinue(timer)) {
51
+ callback(string);
52
+ resolve(true);
53
+ }
54
+ });
55
+ } else if (canContinue(timer)) {
56
+ callback(string);
57
+ resolve(true);
58
+ }
59
+ }, array.length >= 2 ? 300 : 0);
60
+ timerCallback(timer);
61
+ });
62
+ case 6:
63
+ return _context.abrupt("return", batchProcess(array, callback, canContinue, timerCallback, index + 1));
64
+ case 7:
65
+ case "end":
66
+ return _context.stop();
67
+ }
68
+ }, _callee);
69
+ }));
70
+ return function batchProcess(_x, _x2, _x3, _x4) {
71
+ return _ref.apply(this, arguments);
72
+ };
73
+ }();
74
+ export var useSequenceFetch = function useSequenceFetch(fetch, callback, options, cacheOptions) {
75
+ var _ref2 = options !== null && options !== void 0 ? options : {},
76
+ _ref2$retry = _ref2.retry,
77
+ retry = _ref2$retry === void 0 ? 3 : _ref2$retry,
78
+ _ref2$timeout = _ref2.timeout,
79
+ timeout = _ref2$timeout === void 0 ? 5000 : _ref2$timeout,
80
+ cacheKey = _ref2.cacheKey,
81
+ cacheValueKey = _ref2.cacheValueKey;
82
+ var originalJobRef = useRef({
83
+ fetch: fetch,
84
+ retry: typeof retry !== 'undefined' ? retry : 0,
85
+ timeout: 0
86
+ });
87
+ var optionsRef = useRef({
88
+ retry: retry,
89
+ timeout: timeout
90
+ });
91
+ var callbackRef = useRef(callback);
92
+ var useCacheRef = useRef(!!(cacheKey && cacheValueKey));
93
+ var enableCacheRef = useRef(!!(cacheKey && cacheValueKey));
94
+ var fetchRef = useRef(0);
95
+ var timerRef = useRef(-1);
96
+ var _useState = useState(false),
97
+ _useState2 = _slicedToArray(_useState, 2),
98
+ loading = _useState2[0],
99
+ setLoading = _useState2[1];
100
+ var _useCache = useCache(cacheKey, cacheValueKey, cacheOptions),
101
+ store = _useCache.store,
102
+ clearCache = _useCache.clearCache,
103
+ setCache = _useCache.setCache,
104
+ getCache = _useCache.getCache;
105
+ var _useState3 = useState(originalJobRef.current),
106
+ _useState4 = _slicedToArray(_useState3, 2),
107
+ job = _useState4[0],
108
+ setJob = _useState4[1];
109
+ useEffect(function () {
110
+ optionsRef.current = {
111
+ retry: retry,
112
+ timeout: timeout
113
+ };
114
+ callbackRef.current = callback;
115
+ });
116
+ useEffect(function () {
117
+ var execJob = /*#__PURE__*/function () {
118
+ var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
119
+ var cacheResult, resumeJob;
120
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
121
+ while (1) switch (_context3.prev = _context3.next) {
122
+ case 0:
123
+ if (!useCacheRef.current) {
124
+ _context3.next = 10;
125
+ break;
126
+ }
127
+ _context3.next = 3;
128
+ return getCache();
129
+ case 3:
130
+ cacheResult = _context3.sent;
131
+ if (!(typeof callbackRef.current === 'function' && cacheResult.result)) {
132
+ _context3.next = 7;
133
+ break;
134
+ }
135
+ _context3.next = 7;
136
+ return callbackRef.current(cacheResult.result);
137
+ case 7:
138
+ if (!cacheResult.complete && cacheResult.key) {
139
+ resumeJob = typeof (job === null || job === void 0 ? void 0 : job.fetch) === 'function' ? job.fetch(cacheResult.key) : null;
140
+ if (resumeJob) {
141
+ setJob(_objectSpread(_objectSpread({}, optionsRef.current), {}, {
142
+ fetch: function fetch() {
143
+ return resumeJob;
144
+ },
145
+ timeout: 0
146
+ }));
147
+ }
148
+ useCacheRef.current = false;
149
+ }
150
+ _context3.next = 11;
151
+ break;
152
+ case 10:
153
+ timerRef.current = setTimeout(function () {
154
+ var fetchId = fetchRef.current;
155
+ if (typeof (job === null || job === void 0 ? void 0 : job.fetch) === 'function' && Number(job.retry) > 0) {
156
+ setLoading(true);
157
+ job.fetch().then( /*#__PURE__*/function () {
158
+ var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(res) {
159
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
160
+ while (1) switch (_context2.prev = _context2.next) {
161
+ case 0:
162
+ setLoading(false);
163
+ if (!(fetchId !== fetchRef.current || !res)) {
164
+ _context2.next = 3;
165
+ break;
166
+ }
167
+ return _context2.abrupt("return");
168
+ case 3:
169
+ if (!(typeof res.result === 'string' && typeof callbackRef.current === 'function')) {
170
+ _context2.next = 6;
171
+ break;
172
+ }
173
+ _context2.next = 6;
174
+ return callbackRef.current(res.result);
175
+ case 6:
176
+ if (!(typeof res.key !== 'undefined' && enableCacheRef.current)) {
177
+ _context2.next = 9;
178
+ break;
179
+ }
180
+ _context2.next = 9;
181
+ return setCache(res.key, {
182
+ nextKey: res.nextKey,
183
+ result: res.result,
184
+ complete: true
185
+ });
186
+ case 9:
187
+ if (!(typeof res.nextKey !== 'undefined' && enableCacheRef.current)) {
188
+ _context2.next = 12;
189
+ break;
190
+ }
191
+ _context2.next = 12;
192
+ return setCache(res.nextKey, {
193
+ nextKey: undefined,
194
+ result: '',
195
+ complete: false
196
+ });
197
+ case 12:
198
+ if (typeof res.next === 'function') {
199
+ setJob(_objectSpread(_objectSpread({}, optionsRef.current), {}, {
200
+ fetch: res.next
201
+ }));
202
+ }
203
+ case 13:
204
+ case "end":
205
+ return _context2.stop();
206
+ }
207
+ }, _callee2);
208
+ }));
209
+ return function (_x5) {
210
+ return _ref4.apply(this, arguments);
211
+ };
212
+ }()).catch(function (e) {
213
+ // eslint-disable-next-line no-console
214
+ console.error(e);
215
+ setLoading(false);
216
+ setJob(_objectSpread(_objectSpread({}, job), {}, {
217
+ retry: job.retry ? job.retry - 1 : 0
218
+ }));
219
+ }).finally(function () {
220
+ fetchRef.current += 1;
221
+ });
222
+ }
223
+ }, (job === null || job === void 0 ? void 0 : job.timeout) || 0);
224
+ case 11:
225
+ case "end":
226
+ return _context3.stop();
227
+ }
228
+ }, _callee3);
229
+ }));
230
+ return function execJob() {
231
+ return _ref3.apply(this, arguments);
232
+ };
233
+ }();
234
+ execJob();
235
+ }, [setCache, getCache, job]);
236
+ useEffect(function () {
237
+ return function () {
238
+ clearTimeout(timerRef.current);
239
+ };
240
+ }, []);
241
+ return {
242
+ loading: loading,
243
+ setLoading: setLoading,
244
+ refresh: function () {
245
+ var _refresh = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
246
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
247
+ while (1) switch (_context5.prev = _context5.next) {
248
+ case 0:
249
+ fetchRef.current += 1;
250
+ clearTimeout(timerRef.current);
251
+ useCacheRef.current = false;
252
+ setLoading(true);
253
+ _context5.next = 6;
254
+ return clearCache();
255
+ case 6:
256
+ setJob(_objectSpread(_objectSpread({}, originalJobRef.current), {}, {
257
+ fetch: function () {
258
+ var _fetch = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
259
+ var _originalJobRef$curre;
260
+ var _originalJobRef$curre2;
261
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
262
+ while (1) switch (_context4.prev = _context4.next) {
263
+ case 0:
264
+ if (!((_originalJobRef$curre = originalJobRef.current) !== null && _originalJobRef$curre !== void 0 && _originalJobRef$curre.fetch)) {
265
+ _context4.next = 2;
266
+ break;
267
+ }
268
+ return _context4.abrupt("return", (_originalJobRef$curre2 = originalJobRef.current) === null || _originalJobRef$curre2 === void 0 || (_originalJobRef$curre2 = _originalJobRef$curre2.fetch) === null || _originalJobRef$curre2 === void 0 ? void 0 : _originalJobRef$curre2.apply(originalJobRef.current));
269
+ case 2:
270
+ return _context4.abrupt("return", new Promise(function (resolve) {
271
+ resolve({
272
+ result: '',
273
+ next: undefined
274
+ });
275
+ }));
276
+ case 3:
277
+ case "end":
278
+ return _context4.stop();
279
+ }
280
+ }, _callee4);
281
+ }));
282
+ function fetch() {
283
+ return _fetch.apply(this, arguments);
284
+ }
285
+ return fetch;
286
+ }()
287
+ }));
288
+ case 7:
289
+ case "end":
290
+ return _context5.stop();
291
+ }
292
+ }, _callee5);
293
+ }));
294
+ function refresh() {
295
+ return _refresh.apply(this, arguments);
296
+ }
297
+ return refresh;
298
+ }(),
299
+ cacheStore: store
300
+ };
301
+ };
302
+ var useRemote = function useRemote(defaultData, callback, options, cacheOptions) {
303
+ var _ref5 = options !== null && options !== void 0 ? options : {},
304
+ fetch = _ref5.fetch,
305
+ _ref5$timeout = _ref5.timeout,
306
+ timeout = _ref5$timeout === void 0 ? 5000 : _ref5$timeout,
307
+ _ref5$retry = _ref5.retry,
308
+ retry = _ref5$retry === void 0 ? 3 : _ref5$retry,
309
+ cacheKey = _ref5.cacheKey,
310
+ cacheValueKey = _ref5.cacheValueKey,
311
+ enableBatch = _ref5.enableBatch;
312
+ var processTimerRef = useRef(-1);
313
+ var incrementalRef = useRef('');
314
+ var _useState5 = useState(defaultData),
315
+ _useState6 = _slicedToArray(_useState5, 2),
316
+ data = _useState6[0],
317
+ setData = _useState6[1];
318
+ var _useSequenceFetch = useSequenceFetch(fetch, /*#__PURE__*/function () {
319
+ var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(result) {
320
+ var _array;
321
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
322
+ while (1) switch (_context6.prev = _context6.next) {
323
+ case 0:
324
+ setData(function (p) {
325
+ return p + result;
326
+ });
327
+ incrementalRef.current = result;
328
+ if (!(enableBatch === false && callback)) {
329
+ _context6.next = 6;
330
+ break;
331
+ }
332
+ callback(result);
333
+ _context6.next = 10;
334
+ break;
335
+ case 6:
336
+ if (!callback) {
337
+ _context6.next = 10;
338
+ break;
339
+ }
340
+ _array = splitContent(result);
341
+ _context6.next = 10;
342
+ return batchProcess(_array, callback, function (timer) {
343
+ return timer === -1 || timer === processTimerRef.current;
344
+ }, function (timer) {
345
+ processTimerRef.current = timer;
346
+ });
347
+ case 10:
348
+ case "end":
349
+ return _context6.stop();
350
+ }
351
+ }, _callee6);
352
+ }));
353
+ return function (_x6) {
354
+ return _ref6.apply(this, arguments);
355
+ };
356
+ }(), {
357
+ timeout: timeout,
358
+ retry: retry,
359
+ cacheKey: cacheKey,
360
+ cacheValueKey: cacheValueKey
361
+ }, cacheOptions),
362
+ loading = _useSequenceFetch.loading,
363
+ _refresh2 = _useSequenceFetch.refresh,
364
+ cacheStore = _useSequenceFetch.cacheStore;
365
+ useEffect(function () {
366
+ return function () {
367
+ clearInterval(processTimerRef.current);
368
+ };
369
+ }, []);
370
+ return {
371
+ data: data,
372
+ loading: loading,
373
+ cacheStore: cacheStore,
374
+ refresh: function () {
375
+ var _refresh3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
376
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
377
+ while (1) switch (_context7.prev = _context7.next) {
378
+ case 0:
379
+ clearTimeout(processTimerRef.current);
380
+ processTimerRef.current = -1;
381
+ _context7.next = 4;
382
+ return _refresh2();
383
+ case 4:
384
+ setData('');
385
+ case 5:
386
+ case "end":
387
+ return _context7.stop();
388
+ }
389
+ }, _callee7);
390
+ }));
391
+ function refresh() {
392
+ return _refresh3.apply(this, arguments);
393
+ }
394
+ return refresh;
395
+ }()
396
+ };
397
+ };
398
+ export default useRemote;
@@ -0,0 +1,2 @@
1
+ declare const useThrottle: (cb: () => void, delay?: number) => () => void | undefined;
2
+ export default useThrottle;
@@ -0,0 +1,13 @@
1
+ import { useRef, useCallback, useEffect } from 'react';
2
+ import throttle from 'lodash.throttle';
3
+ var useThrottle = function useThrottle(cb) {
4
+ var delay = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1000;
5
+ var cbRef = useRef(cb);
6
+ useEffect(function () {
7
+ cbRef.current = cb;
8
+ });
9
+ return useCallback(function () {
10
+ return throttle(cbRef.current, delay)();
11
+ }, [delay]);
12
+ };
13
+ export default useThrottle;
@@ -0,0 +1,9 @@
1
+ /// <reference types="react" />
2
+ import type { SearchResultCallback, SearcherRef, SearcherResult } from '../Addon/WorkerLog/types';
3
+ export declare const useWorkerLogs: (string: string, changeCallback?: SearchResultCallback) => {
4
+ logs: string[];
5
+ working: boolean;
6
+ searcherRef: import("react").MutableRefObject<SearcherRef | undefined>;
7
+ searcherResult: SearcherResult;
8
+ };
9
+ export default useWorkerLogs;
@@ -0,0 +1,162 @@
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(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
6
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
7
+ /* eslint-disable @typescript-eslint/no-explicit-any */
8
+ import { useEffect, useRef, useState } from 'react';
9
+ import { v4 as uuidv4 } from 'uuid';
10
+ import WebWorkerClient from "../Addon/WorkerLog/WebWorkerClient";
11
+ import globalContext from "../Addon/WorkerLog/GlobalContext";
12
+ import LogWorker from "../Addon/WorkerLog/LogWorker";
13
+ export var useWorkerLogs = function useWorkerLogs(string, changeCallback) {
14
+ var prefixRef = useRef('prefix');
15
+ var _useState = useState([]),
16
+ _useState2 = _slicedToArray(_useState, 2),
17
+ logs = _useState2[0],
18
+ setLogs = _useState2[1];
19
+ var _useState3 = useState(false),
20
+ _useState4 = _slicedToArray(_useState3, 2),
21
+ working = _useState4[0],
22
+ setWorking = _useState4[1];
23
+ var _useState5 = useState({
24
+ count: 0,
25
+ map: {},
26
+ markedKey: 0
27
+ }),
28
+ _useState6 = _slicedToArray(_useState5, 2),
29
+ searcherResult = _useState6[0],
30
+ setSearcherResult = _useState6[1];
31
+ var logIdRef = useRef(0);
32
+ var searchIdRef = useRef(0);
33
+ var searcherRef = useRef(undefined);
34
+ var searcherCallbackRef = useRef();
35
+ var changeCallbackRef = useRef();
36
+ var prevKeyword = useRef('');
37
+ var hlIndexRef = useRef(0);
38
+ useEffect(function () {
39
+ prefixRef.current = uuidv4();
40
+ }, []);
41
+ useEffect(function () {
42
+ changeCallbackRef.current = changeCallback;
43
+ searcherRef.current = {
44
+ findPrevious: function findPrevious(keyword, options) {
45
+ setWorking(true);
46
+ var count = searcherResult.count || 0;
47
+ if (prevKeyword.current !== keyword) {
48
+ hlIndexRef.current = 0;
49
+ count = 0;
50
+ }
51
+ var hlIndex = prevKeyword.current === keyword ? hlIndexRef.current : 0;
52
+ var worker = globalContext.getWorker();
53
+ searchIdRef.current += 1;
54
+ if (count > 0) {
55
+ hlIndex = hlIndex - 1 < 0 ? count - 1 : hlIndex - 1;
56
+ } else {
57
+ hlIndex = 0;
58
+ }
59
+ hlIndexRef.current = hlIndex;
60
+ worker === null || worker === void 0 || worker.send('search-log', {
61
+ id: "".concat(prefixRef.current, "-").concat(logIdRef.current),
62
+ searchId: "".concat(prefixRef.current, "-").concat(searchIdRef.current),
63
+ keyword: keyword,
64
+ hlIndex: hlIndex,
65
+ string: string,
66
+ options: options
67
+ });
68
+ prevKeyword.current = keyword;
69
+ },
70
+ findNext: function findNext(keyword, options) {
71
+ setWorking(true);
72
+ var count = searcherResult.count || 0;
73
+ if (prevKeyword.current !== keyword) {
74
+ hlIndexRef.current = 0;
75
+ count = 0;
76
+ }
77
+ var hlIndex = prevKeyword.current === keyword ? hlIndexRef.current : 0;
78
+ var worker = globalContext.getWorker();
79
+ searchIdRef.current += 1;
80
+ if (count > 0) {
81
+ hlIndex = hlIndex + 1 >= count ? 0 : hlIndex + 1;
82
+ } else {
83
+ hlIndex = 0;
84
+ }
85
+ hlIndexRef.current = hlIndex;
86
+ worker === null || worker === void 0 || worker.send('search-log', {
87
+ id: "".concat(prefixRef.current, "-").concat(logIdRef.current),
88
+ searchId: "".concat(prefixRef.current, "-").concat(searchIdRef.current),
89
+ keyword: keyword,
90
+ hlIndex: hlIndex,
91
+ string: string,
92
+ options: options
93
+ });
94
+ prevKeyword.current = keyword;
95
+ },
96
+ onDidChangeResults: function onDidChangeResults(c) {
97
+ searcherCallbackRef.current = c;
98
+ }
99
+ };
100
+ if (!globalContext.getWorker()) {
101
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
102
+ globalContext.setWorker(new WebWorkerClient(new LogWorker(globalContext.getWorkerPath())));
103
+ }
104
+ });
105
+ useEffect(function () {
106
+ setWorking(true);
107
+ var worker = globalContext.getWorker();
108
+ logIdRef.current += 1;
109
+ worker === null || worker === void 0 || worker.send('highlight-log', {
110
+ id: "".concat(prefixRef.current, "-").concat(logIdRef.current),
111
+ string: string
112
+ });
113
+ }, [string]);
114
+ useEffect(function () {
115
+ var worker = globalContext.getWorker();
116
+ var onHighlightSuccess = function onHighlightSuccess(_ref) {
117
+ var id = _ref.id,
118
+ array = _ref.logs;
119
+ // 需处理 Web Worker 处理不及时的异步问题
120
+ var _ref2 = id.match(/(.*)-(\d)/) || [0, 'prefix', 0],
121
+ _ref3 = _slicedToArray(_ref2, 3),
122
+ prefix = _ref3[1],
123
+ number = _ref3[2];
124
+ if (prefix === prefixRef.current && Number(number) <= logIdRef.current) {
125
+ setWorking(false);
126
+ if ((array === null || array === void 0 ? void 0 : array.length) > 0) {
127
+ setLogs(array);
128
+ }
129
+ }
130
+ };
131
+ var onSearchSuccess = function onSearchSuccess(_ref4) {
132
+ var searchId = _ref4.searchId,
133
+ result = _ref4.searcherResult;
134
+ if (searchId === "".concat(prefixRef.current, "-").concat(searchIdRef.current)) {
135
+ setWorking(false);
136
+ setSearcherResult(result);
137
+ }
138
+ if (typeof changeCallbackRef.current === 'function') {
139
+ changeCallbackRef.current(result);
140
+ }
141
+ if (typeof searcherCallbackRef.current === 'function') {
142
+ searcherCallbackRef.current({
143
+ resultIndex: result.count > 0 ? hlIndexRef.current : 0,
144
+ resultCount: result.count
145
+ });
146
+ }
147
+ };
148
+ worker === null || worker === void 0 || worker.on('highlight-log-success', onHighlightSuccess);
149
+ worker === null || worker === void 0 || worker.on('search-log-success', onSearchSuccess);
150
+ return function () {
151
+ worker === null || worker === void 0 || worker.off('highlight-log-success', onHighlightSuccess);
152
+ worker === null || worker === void 0 || worker.off('search-log-success', onSearchSuccess);
153
+ };
154
+ }, []);
155
+ return {
156
+ logs: logs,
157
+ working: working,
158
+ searcherRef: searcherRef,
159
+ searcherResult: searcherResult
160
+ };
161
+ };
162
+ export default useWorkerLogs;