@pingux/astro 2.98.0-alpha.0 → 2.98.0-alpha.2
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/lib/cjs/components/ListBox/ListBox.js +17 -2
- package/lib/cjs/components/ListView/ListView.js +15 -2
- package/lib/cjs/components/ListView/ListView.stories.d.ts +1 -0
- package/lib/cjs/components/ListView/ListView.stories.js +157 -33
- package/lib/cjs/components/ListView/ListView.test.js +171 -77
- package/lib/cjs/components/MultivaluesField/DefaultMultivaluesField.js +14 -1
- package/lib/cjs/components/MultivaluesField/MultivaluesField.stories.js +147 -5
- package/lib/cjs/components/MultivaluesField/MultivaluesField.test.js +104 -16
- package/lib/cjs/hooks/useLoadPrev/index.d.ts +1 -0
- package/lib/cjs/hooks/useLoadPrev/index.js +14 -0
- package/lib/cjs/hooks/useLoadPrev/useLoadPrev.d.ts +2 -0
- package/lib/cjs/hooks/useLoadPrev/useLoadPrev.js +35 -0
- package/lib/cjs/hooks/useLoadPrev/useLoadPrev.test.d.ts +1 -0
- package/lib/cjs/hooks/useLoadPrev/useLoadPrev.test.js +87 -0
- package/lib/cjs/types/listBox.d.ts +3 -1
- package/lib/cjs/types/listView.d.ts +1 -0
- package/lib/cjs/utils/devUtils/constants/loadingStates.js +2 -1
- package/lib/components/ListBox/ListBox.js +17 -2
- package/lib/components/ListView/ListView.js +15 -2
- package/lib/components/ListView/ListView.stories.js +125 -2
- package/lib/components/ListView/ListView.test.js +168 -77
- package/lib/components/MultivaluesField/DefaultMultivaluesField.js +14 -1
- package/lib/components/MultivaluesField/MultivaluesField.stories.js +144 -2
- package/lib/components/MultivaluesField/MultivaluesField.test.js +100 -16
- package/lib/hooks/useLoadPrev/index.js +1 -0
- package/lib/hooks/useLoadPrev/useLoadPrev.js +27 -0
- package/lib/hooks/useLoadPrev/useLoadPrev.test.js +78 -0
- package/lib/utils/devUtils/constants/loadingStates.js +2 -1
- package/package.json +1 -1
@@ -9,18 +9,32 @@ var _forEachInstanceProperty = require("@babel/runtime-corejs3/core-js-stable/in
|
|
9
9
|
var _Object$getOwnPropertyDescriptors = require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors");
|
10
10
|
var _Object$defineProperties = require("@babel/runtime-corejs3/core-js-stable/object/define-properties");
|
11
11
|
var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
|
12
|
+
var _Symbol = require("@babel/runtime-corejs3/core-js-stable/symbol");
|
13
|
+
var _Object$create = require("@babel/runtime-corejs3/core-js-stable/object/create");
|
14
|
+
var _Object$getPrototypeOf = require("@babel/runtime-corejs3/core-js-stable/object/get-prototype-of");
|
15
|
+
var _Object$setPrototypeOf = require("@babel/runtime-corejs3/core-js-stable/object/set-prototype-of");
|
16
|
+
var _Promise2 = require("@babel/runtime-corejs3/core-js-stable/promise");
|
17
|
+
var _reverseInstanceProperty = require("@babel/runtime-corejs3/core-js-stable/instance/reverse");
|
18
|
+
var _sliceInstanceProperty = require("@babel/runtime-corejs3/core-js-stable/instance/slice");
|
12
19
|
var _WeakMap = require("@babel/runtime-corejs3/core-js-stable/weak-map");
|
13
20
|
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
|
14
21
|
_Object$defineProperty(exports, "__esModule", {
|
15
22
|
value: true
|
16
23
|
});
|
17
|
-
exports["default"] = exports.Uncontrolled = exports.ReadOnlyValues = exports.ReadOnlyField = exports.IconSlotsInBadge = exports.Error = exports.DisabledKeys = exports.Default = exports.CustomValues = exports.CustomSize = exports.Controlled = exports.CondensedWithSection = exports.Condensed = void 0;
|
24
|
+
exports["default"] = exports.Uncontrolled = exports.ReadOnlyValues = exports.ReadOnlyField = exports.OnLoadPrev = exports.IconSlotsInBadge = exports.Error = exports.DisabledKeys = exports.Default = exports.CustomValues = exports.CustomSize = exports.Controlled = exports.CondensedWithSection = exports.Condensed = void 0;
|
25
|
+
var _map = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/map"));
|
26
|
+
var _fill = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/fill"));
|
27
|
+
var _promise = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/promise"));
|
28
|
+
var _setTimeout2 = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/set-timeout"));
|
29
|
+
var _concat = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/concat"));
|
30
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/asyncToGenerator"));
|
18
31
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/slicedToArray"));
|
19
32
|
var _extends2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/extends"));
|
20
33
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/defineProperty"));
|
21
34
|
var _react = _interopRequireWildcard(require("react"));
|
22
35
|
var _storybookDocsLayout = _interopRequireDefault(require("../../../.storybook/storybookDocsLayout"));
|
23
36
|
var _index = require("../../index");
|
37
|
+
var _loadingStates = _interopRequireDefault(require("../../utils/devUtils/constants/loadingStates"));
|
24
38
|
var _ariaAttributes = require("../../utils/docUtils/ariaAttributes");
|
25
39
|
var _fieldAttributes = require("../../utils/docUtils/fieldAttributes");
|
26
40
|
var _statusProp = require("../../utils/docUtils/statusProp");
|
@@ -28,8 +42,9 @@ var _MultivaluesField = _interopRequireDefault(require("./MultivaluesField.mdx")
|
|
28
42
|
var _react2 = require("@emotion/react");
|
29
43
|
function _getRequireWildcardCache(nodeInterop) { if (typeof _WeakMap !== "function") return null; var cacheBabelInterop = new _WeakMap(); var cacheNodeInterop = new _WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
30
44
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = _Object$defineProperty && _Object$getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? _Object$getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { _Object$defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
45
|
+
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) { var _context13; _forEachInstanceProperty(_context13 = ["next", "throw", "return"]).call(_context13, 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" }], _forEachInstanceProperty(tryLocsList).call(tryLocsList, 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 = _Promise2); 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 _reverseInstanceProperty(keys).call(keys), 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) { var _context14; if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, _forEachInstanceProperty(_context14 = this.tryEntries).call(_context14, resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+_sliceInstanceProperty(name).call(name, 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; }
|
31
46
|
function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
32
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var
|
47
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context11, _context12; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context11 = ownKeys(Object(source), !0)).call(_context11, function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context12 = ownKeys(Object(source))).call(_context12, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
|
33
48
|
var _default = {
|
34
49
|
title: 'Form/MultivaluesField',
|
35
50
|
component: _index.MultivaluesField,
|
@@ -419,7 +434,7 @@ var Controlled = function Controlled(args) {
|
|
419
434
|
}));
|
420
435
|
};
|
421
436
|
exports.Controlled = Controlled;
|
422
|
-
var
|
437
|
+
var _Error = function Error(args) {
|
423
438
|
var _useState9 = (0, _react.useState)(false),
|
424
439
|
_useState10 = (0, _slicedToArray2["default"])(_useState9, 2),
|
425
440
|
isOpen = _useState10[0],
|
@@ -445,7 +460,7 @@ var Error = function Error(args) {
|
|
445
460
|
}, item.name);
|
446
461
|
}));
|
447
462
|
};
|
448
|
-
exports.Error =
|
463
|
+
exports.Error = _Error;
|
449
464
|
var ReadOnlyField = function ReadOnlyField(args) {
|
450
465
|
var _useState11 = (0, _react.useState)(false),
|
451
466
|
_useState12 = (0, _slicedToArray2["default"])(_useState11, 2),
|
@@ -674,4 +689,131 @@ var CondensedWithSection = function CondensedWithSection(args) {
|
|
674
689
|
});
|
675
690
|
}));
|
676
691
|
};
|
677
|
-
exports.CondensedWithSection = CondensedWithSection;
|
692
|
+
exports.CondensedWithSection = CondensedWithSection;
|
693
|
+
var OnLoadPrev = function OnLoadPrev() {
|
694
|
+
var _context, _context2;
|
695
|
+
var initialItems = (0, _map["default"])(_context = (0, _fill["default"])(_context2 = new Array(10)).call(_context2, {
|
696
|
+
key: 'string',
|
697
|
+
name: 'string'
|
698
|
+
})).call(_context, function (_, index) {
|
699
|
+
return {
|
700
|
+
name: "name: ".concat(index),
|
701
|
+
key: "name: ".concat(index),
|
702
|
+
id: index
|
703
|
+
};
|
704
|
+
});
|
705
|
+
var _useState27 = (0, _react.useState)(0),
|
706
|
+
_useState28 = (0, _slicedToArray2["default"])(_useState27, 2),
|
707
|
+
minNum = _useState28[0],
|
708
|
+
setMinNum = _useState28[1];
|
709
|
+
var _useState29 = (0, _react.useState)(10),
|
710
|
+
_useState30 = (0, _slicedToArray2["default"])(_useState29, 2),
|
711
|
+
maxNum = _useState30[0],
|
712
|
+
setMaxNum = _useState30[1];
|
713
|
+
var _useState31 = (0, _react.useState)(initialItems),
|
714
|
+
_useState32 = (0, _slicedToArray2["default"])(_useState31, 2),
|
715
|
+
listItems = _useState32[0],
|
716
|
+
setListItems = _useState32[1];
|
717
|
+
var _useState33 = (0, _react.useState)(false),
|
718
|
+
_useState34 = (0, _slicedToArray2["default"])(_useState33, 2),
|
719
|
+
isOpen = _useState34[0],
|
720
|
+
setIsOpen = _useState34[1];
|
721
|
+
var _useState35 = (0, _react.useState)(_loadingStates["default"].IDLE),
|
722
|
+
_useState36 = (0, _slicedToArray2["default"])(_useState35, 2),
|
723
|
+
loadingState = _useState36[0],
|
724
|
+
setLoadingState = _useState36[1];
|
725
|
+
var onOpenChange = function onOpenChange() {
|
726
|
+
setIsOpen(true);
|
727
|
+
};
|
728
|
+
var onLoadMore = /*#__PURE__*/function () {
|
729
|
+
var _ref = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
730
|
+
var _context3, _context4, _context5;
|
731
|
+
var newItems;
|
732
|
+
return _regeneratorRuntime().wrap(function _callee$(_context6) {
|
733
|
+
while (1) switch (_context6.prev = _context6.next) {
|
734
|
+
case 0:
|
735
|
+
setLoadingState(_loadingStates["default"].LOADING_MORE);
|
736
|
+
_context6.next = 3;
|
737
|
+
return new _promise["default"](function (resolve) {
|
738
|
+
return (0, _setTimeout2["default"])(resolve, 3000);
|
739
|
+
});
|
740
|
+
case 3:
|
741
|
+
newItems = (0, _map["default"])(_context3 = (0, _fill["default"])(_context4 = new Array(10)).call(_context4, {
|
742
|
+
key: 'string',
|
743
|
+
name: 'string'
|
744
|
+
})).call(_context3, function (_, index) {
|
745
|
+
return {
|
746
|
+
name: "name: ".concat(maxNum + index),
|
747
|
+
key: "name: ".concat(maxNum + index),
|
748
|
+
id: maxNum + index
|
749
|
+
};
|
750
|
+
});
|
751
|
+
setMaxNum(maxNum + 10);
|
752
|
+
setListItems((0, _concat["default"])(_context5 = []).call(_context5, listItems, newItems));
|
753
|
+
setLoadingState(_loadingStates["default"].IDLE);
|
754
|
+
case 7:
|
755
|
+
case "end":
|
756
|
+
return _context6.stop();
|
757
|
+
}
|
758
|
+
}, _callee);
|
759
|
+
}));
|
760
|
+
return function onLoadMore() {
|
761
|
+
return _ref.apply(this, arguments);
|
762
|
+
};
|
763
|
+
}();
|
764
|
+
var onLoadPrev = /*#__PURE__*/function () {
|
765
|
+
var _ref2 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
766
|
+
var _context7, _context8, _context9;
|
767
|
+
var newItems;
|
768
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context10) {
|
769
|
+
while (1) switch (_context10.prev = _context10.next) {
|
770
|
+
case 0:
|
771
|
+
setLoadingState(_loadingStates["default"].LOADING_MORE_PREPEND);
|
772
|
+
_context10.next = 3;
|
773
|
+
return new _promise["default"](function (resolve) {
|
774
|
+
return (0, _setTimeout2["default"])(resolve, 3000);
|
775
|
+
});
|
776
|
+
case 3:
|
777
|
+
newItems = (0, _map["default"])(_context7 = (0, _fill["default"])(_context8 = new Array(10)).call(_context8, {
|
778
|
+
key: 'string',
|
779
|
+
name: 'string'
|
780
|
+
})).call(_context7, function (_, index) {
|
781
|
+
return {
|
782
|
+
name: "name: ".concat(minNum - (index + 1)),
|
783
|
+
key: "name: ".concat(minNum - (index + 1)),
|
784
|
+
id: minNum - (index + 1)
|
785
|
+
};
|
786
|
+
});
|
787
|
+
setMinNum(minNum - 10);
|
788
|
+
setListItems((0, _concat["default"])(_context9 = []).call(_context9, newItems, listItems));
|
789
|
+
setLoadingState(_loadingStates["default"].IDLE);
|
790
|
+
case 7:
|
791
|
+
case "end":
|
792
|
+
return _context10.stop();
|
793
|
+
}
|
794
|
+
}, _callee2);
|
795
|
+
}));
|
796
|
+
return function onLoadPrev() {
|
797
|
+
return _ref2.apply(this, arguments);
|
798
|
+
};
|
799
|
+
}();
|
800
|
+
return (0, _react2.jsx)(_index.OverlayProvider
|
801
|
+
// note: spacing for demo purpose only so that the select list renders in the correct place
|
802
|
+
, {
|
803
|
+
style: setOverlayStyle('bottom', isOpen, '50%', '50%', '20%')
|
804
|
+
}, (0, _react2.jsx)(_index.MultivaluesField, {
|
805
|
+
items: listItems,
|
806
|
+
onOpenChange: onOpenChange,
|
807
|
+
onLoadMore: onLoadMore,
|
808
|
+
onLoadPrev: onLoadPrev,
|
809
|
+
loadingState: loadingState,
|
810
|
+
label: "On Load More & Prev"
|
811
|
+
}, function (item) {
|
812
|
+
return (0, _react2.jsx)(_index.Item, {
|
813
|
+
key: item.key,
|
814
|
+
"data-id": item.name,
|
815
|
+
"aria-label": item.name
|
816
|
+
}, item.name);
|
817
|
+
}));
|
818
|
+
};
|
819
|
+
exports.OnLoadPrev = OnLoadPrev;
|
@@ -10,19 +10,26 @@ var _Object$setPrototypeOf = require("@babel/runtime-corejs3/core-js-stable/obje
|
|
10
10
|
var _Promise = require("@babel/runtime-corejs3/core-js-stable/promise");
|
11
11
|
var _reverseInstanceProperty = require("@babel/runtime-corejs3/core-js-stable/instance/reverse");
|
12
12
|
var _sliceInstanceProperty = require("@babel/runtime-corejs3/core-js-stable/instance/slice");
|
13
|
+
var _WeakMap = require("@babel/runtime-corejs3/core-js-stable/weak-map");
|
14
|
+
var _Object$getOwnPropertyDescriptor = require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor");
|
13
15
|
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
|
16
|
+
var _map = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/map"));
|
17
|
+
var _fill = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/fill"));
|
14
18
|
var _forEach = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/for-each"));
|
15
19
|
var _isArray = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/array/is-array"));
|
16
20
|
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/asyncToGenerator"));
|
21
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/slicedToArray"));
|
17
22
|
var _extends2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/extends"));
|
18
|
-
var _react =
|
23
|
+
var _react = _interopRequireWildcard(require("react"));
|
19
24
|
var _userEvent = _interopRequireDefault(require("@testing-library/user-event"));
|
20
25
|
var _index = require("../../index");
|
21
26
|
var _statuses = _interopRequireDefault(require("../../utils/devUtils/constants/statuses"));
|
22
27
|
var _testWrapper = require("../../utils/testUtils/testWrapper");
|
23
28
|
var _universalComponentTest = require("../../utils/testUtils/universalComponentTest");
|
24
29
|
var _react2 = require("@emotion/react");
|
25
|
-
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) { var _context3; _forEachInstanceProperty2(_context3 = ["next", "throw", "return"]).call(_context3, 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" }], _forEachInstanceProperty2(tryLocsList).call(tryLocsList, 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 _reverseInstanceProperty(keys).call(keys), 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) { var _context4; if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, _forEachInstanceProperty2(_context4 = this.tryEntries).call(_context4, resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+_sliceInstanceProperty(name).call(name, 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; }
|
30
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof _WeakMap !== "function") return null; var cacheBabelInterop = new _WeakMap(); var cacheNodeInterop = new _WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
31
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = _Object$defineProperty && _Object$getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? _Object$getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { _Object$defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
32
|
+
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) { var _context7; _forEachInstanceProperty2(_context7 = ["next", "throw", "return"]).call(_context7, 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" }], _forEachInstanceProperty2(tryLocsList).call(tryLocsList, 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 _reverseInstanceProperty(keys).call(keys), 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) { var _context8; if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, _forEachInstanceProperty2(_context8 = this.tryEntries).call(_context8, resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+_sliceInstanceProperty(name).call(name, 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; }
|
26
33
|
var items = [{
|
27
34
|
id: 1,
|
28
35
|
name: 'Aardvark',
|
@@ -63,6 +70,8 @@ var defaultSectionProps = {
|
|
63
70
|
items: withSection,
|
64
71
|
label: 'Field Label'
|
65
72
|
};
|
73
|
+
var onLoadMoreFunc = jest.fn();
|
74
|
+
var onLoadPrevFunc = jest.fn();
|
66
75
|
var getComponent = function getComponent() {
|
67
76
|
var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
68
77
|
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
@@ -108,6 +117,68 @@ var getSectionsComponent = function getSectionsComponent() {
|
|
108
117
|
});
|
109
118
|
})));
|
110
119
|
};
|
120
|
+
var ComponentOnPrevLoad = function ComponentOnPrevLoad() {
|
121
|
+
var _context, _context2;
|
122
|
+
var initialItems = (0, _map["default"])(_context = (0, _fill["default"])(_context2 = new Array(10)).call(_context2, {
|
123
|
+
key: 'string',
|
124
|
+
name: 'string'
|
125
|
+
})).call(_context, function (_item, index) {
|
126
|
+
return {
|
127
|
+
name: "name: ".concat(index),
|
128
|
+
key: "name: ".concat(index),
|
129
|
+
id: index
|
130
|
+
};
|
131
|
+
});
|
132
|
+
// eslint-disable-next-line no-unused-vars
|
133
|
+
var _useState = (0, _react.useState)(initialItems),
|
134
|
+
_useState2 = (0, _slicedToArray2["default"])(_useState, 2),
|
135
|
+
listItems = _useState2[0],
|
136
|
+
setListItems = _useState2[1];
|
137
|
+
var onLoadMore = /*#__PURE__*/function () {
|
138
|
+
var _ref4 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
139
|
+
return _regeneratorRuntime().wrap(function _callee$(_context3) {
|
140
|
+
while (1) switch (_context3.prev = _context3.next) {
|
141
|
+
case 0:
|
142
|
+
onLoadMoreFunc();
|
143
|
+
case 1:
|
144
|
+
case "end":
|
145
|
+
return _context3.stop();
|
146
|
+
}
|
147
|
+
}, _callee);
|
148
|
+
}));
|
149
|
+
return function onLoadMore() {
|
150
|
+
return _ref4.apply(this, arguments);
|
151
|
+
};
|
152
|
+
}();
|
153
|
+
var onLoadPrev = /*#__PURE__*/function () {
|
154
|
+
var _ref5 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
155
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context4) {
|
156
|
+
while (1) switch (_context4.prev = _context4.next) {
|
157
|
+
case 0:
|
158
|
+
onLoadPrevFunc();
|
159
|
+
case 1:
|
160
|
+
case "end":
|
161
|
+
return _context4.stop();
|
162
|
+
}
|
163
|
+
}, _callee2);
|
164
|
+
}));
|
165
|
+
return function onLoadPrev() {
|
166
|
+
return _ref5.apply(this, arguments);
|
167
|
+
};
|
168
|
+
}();
|
169
|
+
return (0, _react2.jsx)(_index.OverlayProvider, null, (0, _react2.jsx)(_index.MultivaluesField, {
|
170
|
+
items: listItems,
|
171
|
+
label: "Field Label",
|
172
|
+
onLoadMore: onLoadMore,
|
173
|
+
onLoadPrev: onLoadPrev
|
174
|
+
}, function (item) {
|
175
|
+
return (0, _react2.jsx)(_index.Item, {
|
176
|
+
key: item.key,
|
177
|
+
"data-id": item.name,
|
178
|
+
"aria-label": item.name
|
179
|
+
}, item.name);
|
180
|
+
}));
|
181
|
+
};
|
111
182
|
beforeAll(function () {
|
112
183
|
jest.spyOn(window.HTMLElement.prototype, 'clientWidth', 'get').mockImplementation(function () {
|
113
184
|
return 1000;
|
@@ -267,10 +338,10 @@ test('no badges are rendered, if nothing is selected', function () {
|
|
267
338
|
});
|
268
339
|
expect(_testWrapper.screen.queryByRole('presentation')).not.toBeInTheDocument(0);
|
269
340
|
});
|
270
|
-
test('after clicking an option, and then typing a custom input, the listbox remains open and filters the options', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regeneratorRuntime().mark(function
|
341
|
+
test('after clicking an option, and then typing a custom input, the listbox remains open and filters the options', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
|
271
342
|
var input, options, firstOption, value, listbox, filteredOptions;
|
272
|
-
return _regeneratorRuntime().wrap(function
|
273
|
-
while (1) switch (
|
343
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context5) {
|
344
|
+
while (1) switch (_context5.prev = _context5.next) {
|
274
345
|
case 0:
|
275
346
|
getComponent({
|
276
347
|
mode: 'non-restrictive'
|
@@ -284,11 +355,11 @@ test('after clicking an option, and then typing a custom input, the listbox rema
|
|
284
355
|
firstOption.click();
|
285
356
|
});
|
286
357
|
expect(firstOption).not.toBeInTheDocument();
|
287
|
-
|
358
|
+
_context5.next = 10;
|
288
359
|
return _userEvent["default"].clear(input);
|
289
360
|
case 10:
|
290
361
|
value = 'ka';
|
291
|
-
|
362
|
+
_context5.next = 13;
|
292
363
|
return _userEvent["default"].type(input, value);
|
293
364
|
case 13:
|
294
365
|
listbox = _testWrapper.screen.queryByRole('listbox');
|
@@ -297,9 +368,9 @@ test('after clicking an option, and then typing a custom input, the listbox rema
|
|
297
368
|
expect(filteredOptions.length).toBe(1);
|
298
369
|
case 17:
|
299
370
|
case "end":
|
300
|
-
return
|
371
|
+
return _context5.stop();
|
301
372
|
}
|
302
|
-
},
|
373
|
+
}, _callee3);
|
303
374
|
})));
|
304
375
|
test('clicking on delete button deletes selection, and re-adds option to list', function () {
|
305
376
|
getComponent();
|
@@ -401,10 +472,10 @@ test('in non-restrictive mode, a badge gets added if there is only one matching
|
|
401
472
|
expect(badgeContainer).toHaveAttribute('role', 'presentation');
|
402
473
|
expect(firstOption).not.toBeInTheDocument();
|
403
474
|
});
|
404
|
-
test('dropdown with options reappears after entering a custom input', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regeneratorRuntime().mark(function
|
475
|
+
test('dropdown with options reappears after entering a custom input', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
|
405
476
|
var input, value1, value2, listbox, options2;
|
406
|
-
return _regeneratorRuntime().wrap(function
|
407
|
-
while (1) switch (
|
477
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context6) {
|
478
|
+
while (1) switch (_context6.prev = _context6.next) {
|
408
479
|
case 0:
|
409
480
|
getComponent({
|
410
481
|
mode: 'non-restrictive'
|
@@ -414,10 +485,10 @@ test('dropdown with options reappears after entering a custom input', /*#__PURE_
|
|
414
485
|
_userEvent["default"].type(input, value1);
|
415
486
|
expect(_testWrapper.screen.queryByRole('listbox')).not.toBeInTheDocument();
|
416
487
|
value2 = '';
|
417
|
-
|
488
|
+
_context6.next = 8;
|
418
489
|
return _userEvent["default"].clear(input);
|
419
490
|
case 8:
|
420
|
-
|
491
|
+
_context6.next = 10;
|
421
492
|
return _userEvent["default"].type(input, value2);
|
422
493
|
case 10:
|
423
494
|
listbox = _testWrapper.screen.getByRole('listbox');
|
@@ -425,9 +496,9 @@ test('dropdown with options reappears after entering a custom input', /*#__PURE_
|
|
425
496
|
expect(options2.length).toBe(items.length);
|
426
497
|
case 13:
|
427
498
|
case "end":
|
428
|
-
return
|
499
|
+
return _context6.stop();
|
429
500
|
}
|
430
|
-
},
|
501
|
+
}, _callee4);
|
431
502
|
})));
|
432
503
|
test('changing the input value and hitting enter by default do nothing', function () {
|
433
504
|
getComponent();
|
@@ -1032,6 +1103,23 @@ test('should render the separators', function () {
|
|
1032
1103
|
}
|
1033
1104
|
});
|
1034
1105
|
});
|
1106
|
+
test('escape focus delegate calls correct functions if anything else is pressed', function () {
|
1107
|
+
(0, _testWrapper.render)((0, _react2.jsx)(ComponentOnPrevLoad, null));
|
1108
|
+
_userEvent["default"].tab();
|
1109
|
+
var listBox = _testWrapper.screen.getAllByRole('listbox');
|
1110
|
+
_testWrapper.fireEvent.scroll(listBox[0], {
|
1111
|
+
target: {
|
1112
|
+
scrollY: 450
|
1113
|
+
}
|
1114
|
+
});
|
1115
|
+
expect(onLoadMoreFunc).toHaveBeenCalled();
|
1116
|
+
_testWrapper.fireEvent.scroll(listBox[0], {
|
1117
|
+
target: {
|
1118
|
+
scrollY: 0
|
1119
|
+
}
|
1120
|
+
});
|
1121
|
+
expect(onLoadPrevFunc).toHaveBeenCalled();
|
1122
|
+
});
|
1035
1123
|
|
1036
1124
|
// Needs to be added to each components test file
|
1037
1125
|
(0, _universalComponentTest.universalComponentTests)({
|
@@ -0,0 +1 @@
|
|
1
|
+
export { default } from './useLoadPrev';
|
@@ -0,0 +1,14 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
|
4
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
|
5
|
+
_Object$defineProperty(exports, "__esModule", {
|
6
|
+
value: true
|
7
|
+
});
|
8
|
+
_Object$defineProperty(exports, "default", {
|
9
|
+
enumerable: true,
|
10
|
+
get: function get() {
|
11
|
+
return _useLoadPrev["default"];
|
12
|
+
}
|
13
|
+
});
|
14
|
+
var _useLoadPrev = _interopRequireDefault(require("./useLoadPrev"));
|
@@ -0,0 +1,35 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
|
4
|
+
_Object$defineProperty(exports, "__esModule", {
|
5
|
+
value: true
|
6
|
+
});
|
7
|
+
exports["default"] = void 0;
|
8
|
+
var _react = require("react");
|
9
|
+
var _utils = require("@react-aria/utils");
|
10
|
+
var useLoadPrev = function useLoadPrev(props, ref) {
|
11
|
+
var isLoading = props.isLoading,
|
12
|
+
onLoadPrev = props.onLoadPrev,
|
13
|
+
items = props.items;
|
14
|
+
var isLoadingRef = (0, _react.useRef)(isLoading);
|
15
|
+
var prevProps = (0, _react.useRef)(props);
|
16
|
+
var onScroll = (0, _react.useCallback)(function () {
|
17
|
+
if (ref.current && !isLoadingRef.current && onLoadPrev) {
|
18
|
+
var rc = ref.current;
|
19
|
+
var shouldLoadPrev = rc.scrollTop === 0;
|
20
|
+
if (shouldLoadPrev) {
|
21
|
+
isLoadingRef.current = true;
|
22
|
+
onLoadPrev();
|
23
|
+
}
|
24
|
+
}
|
25
|
+
}, [onLoadPrev, ref]);
|
26
|
+
(0, _react.useLayoutEffect)(function () {
|
27
|
+
if (props !== prevProps.current) {
|
28
|
+
isLoadingRef.current = isLoading;
|
29
|
+
prevProps.current = props;
|
30
|
+
}
|
31
|
+
}, [isLoading, onLoadPrev, props, ref, items]);
|
32
|
+
(0, _utils.useEvent)(ref, 'scroll', onScroll);
|
33
|
+
};
|
34
|
+
var _default = useLoadPrev;
|
35
|
+
exports["default"] = _default;
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1,87 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _typeof = require("@babel/runtime-corejs3/helpers/typeof");
|
4
|
+
var _WeakMap = require("@babel/runtime-corejs3/core-js-stable/weak-map");
|
5
|
+
var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
|
6
|
+
var _Object$getOwnPropertyDescriptor = require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor");
|
7
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
|
8
|
+
var _react = _interopRequireWildcard(require("react"));
|
9
|
+
var _react2 = require("@testing-library/react");
|
10
|
+
var _Box = _interopRequireDefault(require("../../components/Box"));
|
11
|
+
var _testWrapper = require("../../utils/testUtils/testWrapper");
|
12
|
+
var _useLoadPrev = _interopRequireDefault(require("./useLoadPrev"));
|
13
|
+
var _react3 = require("@emotion/react");
|
14
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof _WeakMap !== "function") return null; var cacheBabelInterop = new _WeakMap(); var cacheNodeInterop = new _WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
15
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = _Object$defineProperty && _Object$getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? _Object$getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { _Object$defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
16
|
+
var onLoadPrev = jest.fn();
|
17
|
+
var TestComponent = function TestComponent(props) {
|
18
|
+
var items = props.items;
|
19
|
+
var ref = (0, _react.useRef)(null);
|
20
|
+
(0, _useLoadPrev["default"])({
|
21
|
+
isLoading: false,
|
22
|
+
onLoadPrev: onLoadPrev,
|
23
|
+
items: items
|
24
|
+
}, ref);
|
25
|
+
return (0, _react3.jsx)(_Box["default"], {
|
26
|
+
sx: {
|
27
|
+
height: '400px',
|
28
|
+
maxHeight: '400px',
|
29
|
+
overflowY: 'scroll'
|
30
|
+
},
|
31
|
+
"data-testid": "outerbox",
|
32
|
+
ref: ref
|
33
|
+
}, "content", (0, _react3.jsx)(_Box["default"], {
|
34
|
+
sx: {
|
35
|
+
height: '800px',
|
36
|
+
minHeight: '800px'
|
37
|
+
},
|
38
|
+
"data-testid": "innerbox"
|
39
|
+
}, "inner content"));
|
40
|
+
};
|
41
|
+
describe('useLoadPrev', function () {
|
42
|
+
it('onLoadPrev is called when scrolling to the top', function () {
|
43
|
+
var _render = (0, _testWrapper.render)((0, _react3.jsx)(TestComponent, {
|
44
|
+
items: [1, 2, 3, 4]
|
45
|
+
})),
|
46
|
+
rerender = _render.rerender;
|
47
|
+
var listView = _testWrapper.screen.getByTestId('outerbox');
|
48
|
+
_react2.fireEvent.scroll(listView, {
|
49
|
+
target: {
|
50
|
+
scrollY: 450
|
51
|
+
}
|
52
|
+
});
|
53
|
+
_react2.fireEvent.scroll(listView, {
|
54
|
+
target: {
|
55
|
+
scrollY: 0
|
56
|
+
}
|
57
|
+
});
|
58
|
+
expect(onLoadPrev).toHaveBeenCalledTimes(1);
|
59
|
+
// should not call because props have not changed
|
60
|
+
_react2.fireEvent.scroll(listView, {
|
61
|
+
target: {
|
62
|
+
scrollY: 450
|
63
|
+
}
|
64
|
+
});
|
65
|
+
_react2.fireEvent.scroll(listView, {
|
66
|
+
target: {
|
67
|
+
scrollY: 0
|
68
|
+
}
|
69
|
+
});
|
70
|
+
expect(onLoadPrev).toHaveBeenCalledTimes(1);
|
71
|
+
// will call becuase props have changed.
|
72
|
+
rerender((0, _react3.jsx)(TestComponent, {
|
73
|
+
items: [1, 2, 3, 4, 5]
|
74
|
+
}));
|
75
|
+
_react2.fireEvent.scroll(listView, {
|
76
|
+
target: {
|
77
|
+
scrollY: 450
|
78
|
+
}
|
79
|
+
});
|
80
|
+
_react2.fireEvent.scroll(listView, {
|
81
|
+
target: {
|
82
|
+
scrollY: 0
|
83
|
+
}
|
84
|
+
});
|
85
|
+
expect(onLoadPrev).toHaveBeenCalledTimes(2);
|
86
|
+
});
|
87
|
+
});
|