@haniffalab/cherita-react 0.2.0-dev.2024-02-12.4d768f57 → 0.2.0-dev.2024-02-13.d1d7e6d7
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/dist/components/dotplot/Dotplot.js +104 -129
- package/dist/components/heatmap/Heatmap.js +48 -74
- package/dist/components/matrixplot/Matrixplot.js +59 -87
- package/dist/components/obs-list/ObsList.js +68 -93
- package/dist/components/obsm-list/ObsmList.js +26 -45
- package/dist/components/scatterplot/Legend.js +7 -5
- package/dist/components/scatterplot/Scatterplot.js +103 -198
- package/dist/components/scatterplot/Toolbox.js +14 -24
- package/dist/components/var-list/VarList.js +66 -112
- package/dist/components/violin/Violin.js +48 -77
- package/dist/constants/constants.js +9 -17
- package/dist/context/DatasetContext.js +114 -107
- package/dist/helpers/color.js +18 -21
- package/dist/helpers/map.js +41 -43
- package/dist/helpers/zarr.js +20 -42
- package/dist/index.js +17 -17
- package/dist/utils/LoadingSpinner.js +4 -4
- package/dist/utils/errors.js +22 -21
- package/dist/utils/requests.js +67 -105
- package/package.json +3 -2
package/dist/index.js
CHANGED
|
@@ -5,103 +5,103 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
Object.defineProperty(exports, "DatasetProvider", {
|
|
7
7
|
enumerable: true,
|
|
8
|
-
get: function
|
|
8
|
+
get: function () {
|
|
9
9
|
return _DatasetContext.DatasetProvider;
|
|
10
10
|
}
|
|
11
11
|
});
|
|
12
12
|
Object.defineProperty(exports, "Dotplot", {
|
|
13
13
|
enumerable: true,
|
|
14
|
-
get: function
|
|
14
|
+
get: function () {
|
|
15
15
|
return _Dotplot.Dotplot;
|
|
16
16
|
}
|
|
17
17
|
});
|
|
18
18
|
Object.defineProperty(exports, "DotplotControls", {
|
|
19
19
|
enumerable: true,
|
|
20
|
-
get: function
|
|
20
|
+
get: function () {
|
|
21
21
|
return _Dotplot.DotplotControls;
|
|
22
22
|
}
|
|
23
23
|
});
|
|
24
24
|
Object.defineProperty(exports, "Heatmap", {
|
|
25
25
|
enumerable: true,
|
|
26
|
-
get: function
|
|
26
|
+
get: function () {
|
|
27
27
|
return _Heatmap.Heatmap;
|
|
28
28
|
}
|
|
29
29
|
});
|
|
30
30
|
Object.defineProperty(exports, "HeatmapControls", {
|
|
31
31
|
enumerable: true,
|
|
32
|
-
get: function
|
|
32
|
+
get: function () {
|
|
33
33
|
return _Heatmap.HeatmapControls;
|
|
34
34
|
}
|
|
35
35
|
});
|
|
36
36
|
Object.defineProperty(exports, "Matrixplot", {
|
|
37
37
|
enumerable: true,
|
|
38
|
-
get: function
|
|
38
|
+
get: function () {
|
|
39
39
|
return _Matrixplot.Matrixplot;
|
|
40
40
|
}
|
|
41
41
|
});
|
|
42
42
|
Object.defineProperty(exports, "MatrixplotControls", {
|
|
43
43
|
enumerable: true,
|
|
44
|
-
get: function
|
|
44
|
+
get: function () {
|
|
45
45
|
return _Matrixplot.MatrixplotControls;
|
|
46
46
|
}
|
|
47
47
|
});
|
|
48
48
|
Object.defineProperty(exports, "ObsColsList", {
|
|
49
49
|
enumerable: true,
|
|
50
|
-
get: function
|
|
50
|
+
get: function () {
|
|
51
51
|
return _ObsList.ObsColsList;
|
|
52
52
|
}
|
|
53
53
|
});
|
|
54
54
|
Object.defineProperty(exports, "ObsmKeysList", {
|
|
55
55
|
enumerable: true,
|
|
56
|
-
get: function
|
|
56
|
+
get: function () {
|
|
57
57
|
return _ObsmList.ObsmKeysList;
|
|
58
58
|
}
|
|
59
59
|
});
|
|
60
60
|
Object.defineProperty(exports, "PLOTLY_COLORSCALES", {
|
|
61
61
|
enumerable: true,
|
|
62
|
-
get: function
|
|
62
|
+
get: function () {
|
|
63
63
|
return _constants.PLOTLY_COLORSCALES;
|
|
64
64
|
}
|
|
65
65
|
});
|
|
66
66
|
Object.defineProperty(exports, "SELECTION_MODES", {
|
|
67
67
|
enumerable: true,
|
|
68
|
-
get: function
|
|
68
|
+
get: function () {
|
|
69
69
|
return _constants.SELECTION_MODES;
|
|
70
70
|
}
|
|
71
71
|
});
|
|
72
72
|
Object.defineProperty(exports, "Scatterplot", {
|
|
73
73
|
enumerable: true,
|
|
74
|
-
get: function
|
|
74
|
+
get: function () {
|
|
75
75
|
return _Scatterplot.Scatterplot;
|
|
76
76
|
}
|
|
77
77
|
});
|
|
78
78
|
Object.defineProperty(exports, "ScatterplotControls", {
|
|
79
79
|
enumerable: true,
|
|
80
|
-
get: function
|
|
80
|
+
get: function () {
|
|
81
81
|
return _Scatterplot.ScatterplotControls;
|
|
82
82
|
}
|
|
83
83
|
});
|
|
84
84
|
Object.defineProperty(exports, "VIOLIN_MODES", {
|
|
85
85
|
enumerable: true,
|
|
86
|
-
get: function
|
|
86
|
+
get: function () {
|
|
87
87
|
return _constants.VIOLIN_MODES;
|
|
88
88
|
}
|
|
89
89
|
});
|
|
90
90
|
Object.defineProperty(exports, "VarNamesList", {
|
|
91
91
|
enumerable: true,
|
|
92
|
-
get: function
|
|
92
|
+
get: function () {
|
|
93
93
|
return _VarList.VarNamesList;
|
|
94
94
|
}
|
|
95
95
|
});
|
|
96
96
|
Object.defineProperty(exports, "Violin", {
|
|
97
97
|
enumerable: true,
|
|
98
|
-
get: function
|
|
98
|
+
get: function () {
|
|
99
99
|
return _Violin.Violin;
|
|
100
100
|
}
|
|
101
101
|
});
|
|
102
102
|
Object.defineProperty(exports, "ViolinControls", {
|
|
103
103
|
enumerable: true,
|
|
104
|
-
get: function
|
|
104
|
+
get: function () {
|
|
105
105
|
return _Violin.ViolinControls;
|
|
106
106
|
}
|
|
107
107
|
});
|
|
@@ -7,10 +7,10 @@ exports.LoadingSpinner = LoadingSpinner;
|
|
|
7
7
|
require("bootstrap/dist/css/bootstrap.min.css");
|
|
8
8
|
var _reactBootstrap = require("react-bootstrap");
|
|
9
9
|
function LoadingSpinner(_ref) {
|
|
10
|
-
|
|
11
|
-
type =
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
let {
|
|
11
|
+
type = "icon",
|
|
12
|
+
text = "Loading..."
|
|
13
|
+
} = _ref;
|
|
14
14
|
if (type === "message") {
|
|
15
15
|
return /*#__PURE__*/React.createElement("div", {
|
|
16
16
|
className: " h-100 w-100 d-flex z-1 bg-light opacity-75 position-absolute justify-content-center align-items-center "
|
package/dist/utils/errors.js
CHANGED
|
@@ -4,13 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.parseError = void 0;
|
|
7
|
-
|
|
8
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
9
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
10
|
-
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; }
|
|
11
|
-
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
12
|
-
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
13
|
-
var parseError = function parseError(err) {
|
|
7
|
+
const parseError = err => {
|
|
14
8
|
if (err === DOMException.TIMEOUT_ERR) {
|
|
15
9
|
return {
|
|
16
10
|
message: "Timeout error",
|
|
@@ -19,33 +13,40 @@ var parseError = function parseError(err) {
|
|
|
19
13
|
}
|
|
20
14
|
switch (err === null || err === void 0 ? void 0 : err.name) {
|
|
21
15
|
case "TypeError":
|
|
22
|
-
return
|
|
16
|
+
return {
|
|
17
|
+
...err,
|
|
23
18
|
message: "Failed to fetch data from server"
|
|
24
|
-
}
|
|
19
|
+
};
|
|
25
20
|
case "ReadZarrError":
|
|
26
|
-
return
|
|
21
|
+
return {
|
|
22
|
+
...err,
|
|
27
23
|
message: "Failed to read AnnData-Zarr"
|
|
28
|
-
}
|
|
24
|
+
};
|
|
29
25
|
case "InvalidObs":
|
|
30
|
-
return
|
|
26
|
+
return {
|
|
27
|
+
...err,
|
|
31
28
|
message: "Observation not found in dataset"
|
|
32
|
-
}
|
|
29
|
+
};
|
|
33
30
|
case "InvalidVar":
|
|
34
|
-
return
|
|
31
|
+
return {
|
|
32
|
+
...err,
|
|
35
33
|
message: "Feature not found in dataset"
|
|
36
|
-
}
|
|
34
|
+
};
|
|
37
35
|
case "InvalidKey":
|
|
38
|
-
return
|
|
36
|
+
return {
|
|
37
|
+
...err,
|
|
39
38
|
message: "Key not found in datset"
|
|
40
|
-
}
|
|
39
|
+
};
|
|
41
40
|
case "BadRequest":
|
|
42
|
-
return
|
|
41
|
+
return {
|
|
42
|
+
...err,
|
|
43
43
|
message: "Invalid request to server"
|
|
44
|
-
}
|
|
44
|
+
};
|
|
45
45
|
case "InternalServerError":
|
|
46
|
-
return
|
|
46
|
+
return {
|
|
47
|
+
...err,
|
|
47
48
|
message: "Server error"
|
|
48
|
-
}
|
|
49
|
+
};
|
|
49
50
|
default:
|
|
50
51
|
return err;
|
|
51
52
|
}
|
package/dist/utils/requests.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
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); }
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
@@ -9,117 +8,80 @@ exports.useFetch = exports.useDebouncedFetch = void 0;
|
|
|
9
8
|
var _usehooks = require("@uidotdev/usehooks");
|
|
10
9
|
var _reactQuery = require("@tanstack/react-query");
|
|
11
10
|
var _errors = require("./errors");
|
|
12
|
-
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; }
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
11
|
+
async function fetchData(endpoint, params) {
|
|
12
|
+
let signal = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
13
|
+
let ms = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 300000;
|
|
14
|
+
const apiUrl = process.env.REACT_APP_API_URL;
|
|
15
|
+
const controller = new AbortController();
|
|
16
|
+
const timeout = setTimeout(() => {
|
|
17
|
+
controller.abort(DOMException.TIMEOUT_ERR);
|
|
18
|
+
}, ms || 300000);
|
|
19
|
+
if (signal) signal.addEventListener("abort", () => controller.abort());
|
|
20
|
+
const response = await fetch(new URL(endpoint, apiUrl), {
|
|
21
|
+
method: "POST",
|
|
22
|
+
mode: "cors",
|
|
23
|
+
headers: {
|
|
24
|
+
"Content-Type": "application/json",
|
|
25
|
+
Accept: "application/json"
|
|
26
|
+
},
|
|
27
|
+
body: JSON.stringify(params),
|
|
28
|
+
signal: controller.signal
|
|
29
|
+
}).catch(err => {
|
|
30
|
+
// Manual check as fetch returns an AbortError regardless of the reason set to the signal
|
|
31
|
+
if (controller.signal.aborted && controller.signal.reason === DOMException.TIMEOUT_ERR) {
|
|
32
|
+
throw DOMException.TIMEOUT_ERR;
|
|
33
|
+
}
|
|
34
|
+
throw err;
|
|
35
|
+
}).finally(() => clearTimeout(timeout));
|
|
36
|
+
if (!response.ok) {
|
|
37
|
+
throw await response.json();
|
|
38
|
+
}
|
|
39
|
+
return await response.json();
|
|
22
40
|
}
|
|
23
|
-
function
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
timeout = setTimeout(function () {
|
|
40
|
-
controller.abort(DOMException.TIMEOUT_ERR);
|
|
41
|
-
}, ms || 300000);
|
|
42
|
-
if (signal) signal.addEventListener("abort", function () {
|
|
43
|
-
return controller.abort();
|
|
44
|
-
});
|
|
45
|
-
_context.next = 8;
|
|
46
|
-
return fetch(new URL(endpoint, apiUrl), {
|
|
47
|
-
method: "POST",
|
|
48
|
-
mode: "cors",
|
|
49
|
-
headers: {
|
|
50
|
-
"Content-Type": "application/json",
|
|
51
|
-
Accept: "application/json"
|
|
52
|
-
},
|
|
53
|
-
body: JSON.stringify(params),
|
|
54
|
-
signal: controller.signal
|
|
55
|
-
}).catch(function (err) {
|
|
56
|
-
// Manual check as fetch returns an AbortError regardless of the reason set to the signal
|
|
57
|
-
if (controller.signal.aborted && controller.signal.reason === DOMException.TIMEOUT_ERR) {
|
|
58
|
-
throw DOMException.TIMEOUT_ERR;
|
|
59
|
-
}
|
|
60
|
-
throw err;
|
|
61
|
-
}).finally(function () {
|
|
62
|
-
return clearTimeout(timeout);
|
|
63
|
-
});
|
|
64
|
-
case 8:
|
|
65
|
-
response = _context.sent;
|
|
66
|
-
if (response.ok) {
|
|
67
|
-
_context.next = 13;
|
|
68
|
-
break;
|
|
69
|
-
}
|
|
70
|
-
_context.next = 12;
|
|
71
|
-
return response.json();
|
|
72
|
-
case 12:
|
|
73
|
-
throw _context.sent;
|
|
74
|
-
case 13:
|
|
75
|
-
_context.next = 15;
|
|
76
|
-
return response.json();
|
|
77
|
-
case 15:
|
|
78
|
-
return _context.abrupt("return", _context.sent);
|
|
79
|
-
case 16:
|
|
80
|
-
case "end":
|
|
81
|
-
return _context.stop();
|
|
82
|
-
}
|
|
83
|
-
}, _callee);
|
|
84
|
-
}));
|
|
85
|
-
return _fetchData.apply(this, arguments);
|
|
86
|
-
}
|
|
87
|
-
var useFetch = function useFetch(endpoint, params) {
|
|
88
|
-
var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
89
|
-
var _useQuery = (0, _reactQuery.useQuery)(_objectSpread({
|
|
90
|
-
queryKey: [endpoint, params],
|
|
91
|
-
queryFn: function queryFn(_ref) {
|
|
92
|
-
var signal = _ref.signal;
|
|
93
|
-
return fetchData(endpoint, params, signal);
|
|
94
|
-
}
|
|
95
|
-
}, opts)),
|
|
96
|
-
fetchedData = _useQuery.data,
|
|
97
|
-
isPending = _useQuery.isPending,
|
|
98
|
-
serverError = _useQuery.error;
|
|
41
|
+
const useFetch = function (endpoint, params) {
|
|
42
|
+
let opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
43
|
+
const {
|
|
44
|
+
data: fetchedData,
|
|
45
|
+
isPending,
|
|
46
|
+
error: serverError
|
|
47
|
+
} = (0, _reactQuery.useQuery)({
|
|
48
|
+
queryKey: [endpoint, params],
|
|
49
|
+
queryFn: _ref => {
|
|
50
|
+
let {
|
|
51
|
+
signal
|
|
52
|
+
} = _ref;
|
|
53
|
+
return fetchData(endpoint, params, signal);
|
|
54
|
+
},
|
|
55
|
+
...opts
|
|
56
|
+
});
|
|
99
57
|
return {
|
|
100
|
-
fetchedData
|
|
101
|
-
isPending
|
|
58
|
+
fetchedData,
|
|
59
|
+
isPending,
|
|
102
60
|
serverError: (0, _errors.parseError)(serverError)
|
|
103
61
|
};
|
|
104
62
|
};
|
|
105
63
|
exports.useFetch = useFetch;
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
64
|
+
const useDebouncedFetch = function (endpoint, params) {
|
|
65
|
+
let delay = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 500;
|
|
66
|
+
let opts = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
|
|
67
|
+
const debouncedParams = (0, _usehooks.useDebounce)(params, delay);
|
|
68
|
+
const {
|
|
69
|
+
data: fetchedData,
|
|
70
|
+
isPending,
|
|
71
|
+
error: serverError
|
|
72
|
+
} = (0, _reactQuery.useQuery)({
|
|
73
|
+
queryKey: [endpoint, debouncedParams],
|
|
74
|
+
queryFn: _ref2 => {
|
|
75
|
+
let {
|
|
76
|
+
signal
|
|
77
|
+
} = _ref2;
|
|
78
|
+
return fetchData(endpoint, debouncedParams, signal);
|
|
79
|
+
},
|
|
80
|
+
...opts
|
|
81
|
+
});
|
|
120
82
|
return {
|
|
121
|
-
fetchedData
|
|
122
|
-
isPending
|
|
83
|
+
fetchedData,
|
|
84
|
+
isPending,
|
|
123
85
|
serverError: (0, _errors.parseError)(serverError)
|
|
124
86
|
};
|
|
125
87
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@haniffalab/cherita-react",
|
|
3
|
-
"version": "0.2.0-dev.2024-02-
|
|
3
|
+
"version": "0.2.0-dev.2024-02-13.d1d7e6d7",
|
|
4
4
|
"author": "",
|
|
5
5
|
"license": "",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -40,6 +40,7 @@
|
|
|
40
40
|
"@babel/plugin-proposal-private-property-in-object": "^7.21.11",
|
|
41
41
|
"@babel/preset-env": "^7.22.5",
|
|
42
42
|
"@babel/preset-react": "^7.22.5",
|
|
43
|
+
"babel-plugin-add-module-exports": "^1.0.4",
|
|
43
44
|
"eslint": "^8.42.0",
|
|
44
45
|
"eslint-config-prettier": "^8.8.0",
|
|
45
46
|
"eslint-config-react-app": "^7.0.1"
|
|
@@ -78,5 +79,5 @@
|
|
|
78
79
|
"url": "https://github.com/haniffalab/cherita-react/issues"
|
|
79
80
|
},
|
|
80
81
|
"homepage": "https://github.com/haniffalab/cherita-react#readme",
|
|
81
|
-
"prereleaseSha": "
|
|
82
|
+
"prereleaseSha": "d1d7e6d72d5b183b263e3a0b4ac08ea7f23f0076"
|
|
82
83
|
}
|