@pingux/astro 2.42.0-alpha.0 → 2.42.0-alpha.1
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/TreeView/TreeView.js +5 -10
- package/lib/cjs/components/TreeView/TreeView.stories.js +3 -169
- package/lib/cjs/components/TreeView/TreeView.test.js +9 -130
- package/lib/cjs/components/TreeView/TreeViewRow.js +3 -5
- package/lib/cjs/components/TreeView/TreeViewSection.js +3 -32
- package/lib/components/TreeView/TreeView.js +5 -10
- package/lib/components/TreeView/TreeView.stories.js +1 -161
- package/lib/components/TreeView/TreeView.test.js +9 -130
- package/lib/components/TreeView/TreeViewRow.js +3 -5
- package/lib/components/TreeView/TreeViewSection.js +5 -34
- package/package.json +1 -1
@@ -9,16 +9,13 @@ _Object$defineProperty(exports, "__esModule", {
|
|
9
9
|
value: true
|
10
10
|
});
|
11
11
|
exports.removeRefFromArrayHelper = exports.onKeyDownSection = exports["default"] = exports.addRefToArrayHelper = void 0;
|
12
|
-
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/slicedToArray"));
|
13
12
|
var _some = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/some"));
|
14
13
|
var _concat = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/concat"));
|
15
14
|
var _filter = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/filter"));
|
16
|
-
var _forEach = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/for-each"));
|
17
15
|
var _map = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/map"));
|
18
16
|
var _from = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/array/from"));
|
19
17
|
var _react = _interopRequireWildcard(require("react"));
|
20
18
|
var _listbox = require("@react-aria/listbox");
|
21
|
-
var _visuallyHidden = require("@react-aria/visually-hidden");
|
22
19
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
23
20
|
var _TreeViewContext = require("../../context/TreeViewContext");
|
24
21
|
var _index2 = require("../../index");
|
@@ -113,8 +110,6 @@ var TreeViewSection = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref)
|
|
113
110
|
var item = props.item,
|
114
111
|
items = props.items,
|
115
112
|
title = props.title,
|
116
|
-
hasChildren = props.hasChildren,
|
117
|
-
loadingNodes = props.loadingNodes,
|
118
113
|
focusManager = props.focusManager,
|
119
114
|
onKeyDown = props.onKeyDown,
|
120
115
|
level = props.level,
|
@@ -122,7 +117,6 @@ var TreeViewSection = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref)
|
|
122
117
|
setSize = props.setSize;
|
123
118
|
var key = item.key;
|
124
119
|
var treeSectionRef = (0, _react.useRef)();
|
125
|
-
|
126
120
|
/* istanbul ignore next */
|
127
121
|
(0, _react.useImperativeHandle)(ref, function () {
|
128
122
|
return treeSectionRef.current;
|
@@ -142,17 +136,6 @@ var TreeViewSection = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref)
|
|
142
136
|
isDisabled = _useOption.isDisabled;
|
143
137
|
var isExpanded = state.expandedKeys.has(key);
|
144
138
|
var isDragging = dragState.isDragging(item.key);
|
145
|
-
var _useState = (0, _react.useState)(),
|
146
|
-
_useState2 = (0, _slicedToArray2["default"])(_useState, 2),
|
147
|
-
loaderState = _useState2[0],
|
148
|
-
setLoaderState = _useState2[1];
|
149
|
-
(0, _react.useEffect)(function () {
|
150
|
-
if (loadingNodes) {
|
151
|
-
(0, _forEach["default"])(loadingNodes).call(loadingNodes, function (loader) {
|
152
|
-
if (loader.node === title) setLoaderState(loader.loadingState);
|
153
|
-
});
|
154
|
-
}
|
155
|
-
}, [loadingNodes, title]);
|
156
139
|
var onKeyDownFunction = function onKeyDownFunction(e) {
|
157
140
|
onKeyDownSection(e, state, key, tree, isSelected, isExpanded, focusManager, flatKeyArray, refArray, pageLength, true);
|
158
141
|
if (onKeyDown) {
|
@@ -183,8 +166,7 @@ var TreeViewSection = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref)
|
|
183
166
|
items: items,
|
184
167
|
isDragging: isDragging,
|
185
168
|
isExpanded: isExpanded,
|
186
|
-
onKeyDown: onKeyDownFunction
|
187
|
-
hasChildren: hasChildren
|
169
|
+
onKeyDown: onKeyDownFunction
|
188
170
|
}), isExpanded && (0, _react2.jsx)(_index2.Box, {
|
189
171
|
role: "rowgroup",
|
190
172
|
key: "".concat(item.key, " ul"),
|
@@ -194,22 +176,13 @@ var TreeViewSection = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref)
|
|
194
176
|
border: 'none'
|
195
177
|
}
|
196
178
|
}
|
197
|
-
}, (0,
|
198
|
-
"aria-live": "polite"
|
199
|
-
}, loaderState === false && (isExpanded && items.length > 0 ? ' Loading successful' : 'Loading unsuccessful')), loaderState ? (0, _react2.jsx)(_index2.Loader, {
|
200
|
-
color: "active",
|
201
|
-
ml: "31px"
|
202
|
-
}) : (0, _map["default"])(_context3 = (0, _from["default"])(items)).call(_context3, function (_item, _index) {
|
179
|
+
}, (0, _map["default"])(_context3 = (0, _from["default"])(items)).call(_context3, function (_item, _index) {
|
203
180
|
var _item$children;
|
204
|
-
return (0, _TreeView.SectionOrItemRender)(
|
205
|
-
// _item.value.items?.length > 0 || _item.value.items,
|
206
|
-
((_item$children = _item.children) === null || _item$children === void 0 ? void 0 : _item$children.length) > 0 || _item.value.items, (0, _react2.jsx)(TreeViewSection, {
|
181
|
+
return (0, _TreeView.SectionOrItemRender)(((_item$children = _item.children) === null || _item$children === void 0 ? void 0 : _item$children.length) > 0, (0, _react2.jsx)(TreeViewSection, {
|
207
182
|
item: _item,
|
208
183
|
items: _item.children,
|
209
184
|
title: _item.value.title,
|
210
185
|
key: _item.value.title,
|
211
|
-
hasChildren: _item.value.items && true,
|
212
|
-
loadingNodes: loadingNodes,
|
213
186
|
focusManager: focusManager,
|
214
187
|
level: level + 1,
|
215
188
|
position: _index,
|
@@ -238,8 +211,6 @@ TreeViewSection.propTypes = {
|
|
238
211
|
key: _propTypes["default"].string
|
239
212
|
}),
|
240
213
|
title: _propTypes["default"].string,
|
241
|
-
hasChildren: _propTypes["default"].bool,
|
242
|
-
loadingNodes: _propTypes["default"].arrayOf(_propTypes["default"].shape({})),
|
243
214
|
focusManager: _propTypes["default"].shape({}),
|
244
215
|
onKeyDown: _propTypes["default"].func,
|
245
216
|
level: _propTypes["default"].number,
|
@@ -12,7 +12,7 @@ import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
|
|
12
12
|
import _objectWithoutProperties from "@babel/runtime-corejs3/helpers/esm/objectWithoutProperties";
|
13
13
|
var _excluded = ["value"],
|
14
14
|
_excluded2 = ["value"],
|
15
|
-
_excluded3 = ["tree", "disabledKeys", "onExpandedChange", "
|
15
|
+
_excluded3 = ["tree", "disabledKeys", "onExpandedChange", "onDragStart", "onDrop", "onKeyDown", "pageLength"];
|
16
16
|
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; }
|
17
17
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context6, _context7; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context6 = ownKeys(Object(source), !0)).call(_context6, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context7 = ownKeys(Object(source))).call(_context7, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
|
18
18
|
import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map";
|
@@ -108,7 +108,6 @@ var TreeView = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
108
108
|
var tree = props.tree,
|
109
109
|
disabledKeys = props.disabledKeys,
|
110
110
|
onExpandedChange = props.onExpandedChange,
|
111
|
-
loadingNodes = props.loadingNodes,
|
112
111
|
onDragStartProp = props.onDragStart,
|
113
112
|
onDropProp = props.onDrop,
|
114
113
|
onKeyDown = props.onKeyDown,
|
@@ -148,14 +147,14 @@ var TreeView = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
148
147
|
var flattenNestedData = function flattenNestedData(_data) {
|
149
148
|
var returnArray = [];
|
150
149
|
var checkItemNesting = function checkItemNesting(item) {
|
151
|
-
var _item$value, _item$
|
152
|
-
if (((_item$value = item.value) === null || _item$value === void 0 || (_item$value = _item$value.children) === null || _item$value === void 0 ? void 0 : _item$value.length) > 0
|
150
|
+
var _item$value, _item$children;
|
151
|
+
if (((_item$value = item.value) === null || _item$value === void 0 || (_item$value = _item$value.children) === null || _item$value === void 0 ? void 0 : _item$value.length) > 0) {
|
153
152
|
return {
|
154
153
|
isTopLevel: true,
|
155
154
|
hasChildren: true
|
156
155
|
};
|
157
156
|
}
|
158
|
-
if (((_item$children = item.children) === null || _item$children === void 0 ? void 0 : _item$children.length) > 0
|
157
|
+
if (((_item$children = item.children) === null || _item$children === void 0 ? void 0 : _item$children.length) > 0) {
|
159
158
|
return {
|
160
159
|
isTopLevel: false,
|
161
160
|
hasChildren: true
|
@@ -353,13 +352,11 @@ var TreeView = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
353
352
|
border: 'none !important'
|
354
353
|
}
|
355
354
|
}, others), ___EmotionJSX(TreeViewWrapper, null, _mapInstanceProperty(_context5 = _Array$from(state.collection)).call(_context5, function (item, index) {
|
356
|
-
return SectionOrItemRender(item.
|
355
|
+
return SectionOrItemRender(item.value.children.length > 0, ___EmotionJSX(TreeViewSection, {
|
357
356
|
item: item,
|
358
357
|
items: item.value.children,
|
359
358
|
title: item.props.title,
|
360
359
|
key: item.props.title,
|
361
|
-
hasChildren: item.props.hasChildren,
|
362
|
-
loadingNodes: loadingNodes,
|
363
360
|
onKeyDown: onKeyDown,
|
364
361
|
level: level + 1,
|
365
362
|
setSize: state.collection.size,
|
@@ -394,8 +391,6 @@ TreeView.propTypes = {
|
|
394
391
|
items: isIterableProp,
|
395
392
|
/** String that describes the treeview when using a screen reader. */
|
396
393
|
'aria-label': PropTypes.string,
|
397
|
-
/** Determines whether the loading indicator is shown for the expanded node. */
|
398
|
-
loadingNodes: PropTypes.arrayOf(PropTypes.shape({})),
|
399
394
|
/** Handler that is called when a key is pressed. */
|
400
395
|
onKeyDown: PropTypes.func,
|
401
396
|
/** Callback that is called when the dragging action starts. */
|
@@ -1,23 +1,5 @@
|
|
1
|
-
import _Object$defineProperty from "@babel/runtime-corejs3/core-js-stable/object/define-property";
|
2
|
-
import _Symbol from "@babel/runtime-corejs3/core-js-stable/symbol";
|
3
|
-
import _Object$create from "@babel/runtime-corejs3/core-js-stable/object/create";
|
4
|
-
import _Object$getPrototypeOf from "@babel/runtime-corejs3/core-js-stable/object/get-prototype-of";
|
5
|
-
import _Object$setPrototypeOf from "@babel/runtime-corejs3/core-js-stable/object/set-prototype-of";
|
6
|
-
import _reverseInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/reverse";
|
7
|
-
import _sliceInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/slice";
|
8
|
-
import _typeof from "@babel/runtime-corejs3/helpers/esm/typeof";
|
9
|
-
import _asyncToGenerator from "@babel/runtime-corejs3/helpers/esm/asyncToGenerator";
|
10
|
-
import _slicedToArray from "@babel/runtime-corejs3/helpers/esm/slicedToArray";
|
11
1
|
import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
|
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) { var _context5; _forEachInstanceProperty(_context5 = ["next", "throw", "return"]).call(_context5, 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 = _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 _context6; 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(_context6 = this.tryEntries).call(_context6, 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; }
|
13
|
-
import _Set from "@babel/runtime-corejs3/core-js-stable/set";
|
14
|
-
import _Promise from "@babel/runtime-corejs3/core-js-stable/promise";
|
15
|
-
import _setTimeout from "@babel/runtime-corejs3/core-js-stable/set-timeout";
|
16
|
-
import _Array$from from "@babel/runtime-corejs3/core-js-stable/array/from";
|
17
|
-
import _concatInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/concat";
|
18
|
-
import _forEachInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/for-each";
|
19
|
-
import _spliceInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/splice";
|
20
|
-
import React, { useEffect, useState } from 'react';
|
2
|
+
import React from 'react';
|
21
3
|
import DocsLayout from '../../../.storybook/storybookDocsLayout';
|
22
4
|
import { Item, TreeView, useTreeData } from '../../index';
|
23
5
|
import TreeViewReadMe from './TreeView.mdx';
|
@@ -84,24 +66,6 @@ var data = [{
|
|
84
66
|
key: 'Single Item',
|
85
67
|
title: 'Single Item'
|
86
68
|
}];
|
87
|
-
var initialAsyncItems = [{
|
88
|
-
title: 'Item1',
|
89
|
-
items: []
|
90
|
-
}, {
|
91
|
-
title: 'Item2',
|
92
|
-
items: []
|
93
|
-
}, {
|
94
|
-
title: 'Item3'
|
95
|
-
}, {
|
96
|
-
title: 'Item4',
|
97
|
-
items: []
|
98
|
-
}, {
|
99
|
-
title: 'Item5',
|
100
|
-
items: []
|
101
|
-
}, {
|
102
|
-
title: 'Item6',
|
103
|
-
items: []
|
104
|
-
}];
|
105
69
|
export var Default = function Default(args) {
|
106
70
|
var tree = useTreeData({
|
107
71
|
initialItems: data,
|
@@ -125,128 +89,4 @@ export var Default = function Default(args) {
|
|
125
89
|
title: (_section$value = section.value) === null || _section$value === void 0 ? void 0 : _section$value.title
|
126
90
|
});
|
127
91
|
});
|
128
|
-
};
|
129
|
-
export var AsyncLoading = function AsyncLoading(args) {
|
130
|
-
var _useState = useState(new _Set([])),
|
131
|
-
_useState2 = _slicedToArray(_useState, 2),
|
132
|
-
expandedKeys = _useState2[0],
|
133
|
-
setExpandedKeys = _useState2[1];
|
134
|
-
var _useState3 = useState(1),
|
135
|
-
_useState4 = _slicedToArray(_useState3, 2),
|
136
|
-
childNode = _useState4[0],
|
137
|
-
setChildNode = _useState4[1];
|
138
|
-
var _useState5 = useState([]),
|
139
|
-
_useState6 = _slicedToArray(_useState5, 2),
|
140
|
-
loadingNodes = _useState6[0],
|
141
|
-
setLoadingNodes = _useState6[1];
|
142
|
-
var getMockData = /*#__PURE__*/function () {
|
143
|
-
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
144
|
-
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
145
|
-
while (1) switch (_context.prev = _context.next) {
|
146
|
-
case 0:
|
147
|
-
setChildNode(childNode + 1);
|
148
|
-
|
149
|
-
// emulate loading state
|
150
|
-
_context.next = 3;
|
151
|
-
return new _Promise(function (resolve) {
|
152
|
-
return _setTimeout(resolve, childNode ? 2000 : 3000);
|
153
|
-
});
|
154
|
-
case 3:
|
155
|
-
return _context.abrupt("return", [{
|
156
|
-
title: "Child Node ".concat(childNode),
|
157
|
-
items: []
|
158
|
-
}, {
|
159
|
-
title: "Single Node ".concat(childNode)
|
160
|
-
}]);
|
161
|
-
case 4:
|
162
|
-
case "end":
|
163
|
-
return _context.stop();
|
164
|
-
}
|
165
|
-
}, _callee);
|
166
|
-
}));
|
167
|
-
return function getMockData() {
|
168
|
-
return _ref.apply(this, arguments);
|
169
|
-
};
|
170
|
-
}();
|
171
|
-
var tree = useTreeData({
|
172
|
-
initialItems: initialAsyncItems,
|
173
|
-
getKey: function getKey(item) {
|
174
|
-
return item.title;
|
175
|
-
},
|
176
|
-
getChildren: function getChildren(item) {
|
177
|
-
return item.items;
|
178
|
-
}
|
179
|
-
});
|
180
|
-
var handleExpand = /*#__PURE__*/function () {
|
181
|
-
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(node) {
|
182
|
-
var _tree$getItem, expandedNode, _context2, list;
|
183
|
-
return _regeneratorRuntime().wrap(function _callee2$(_context3) {
|
184
|
-
while (1) switch (_context3.prev = _context3.next) {
|
185
|
-
case 0:
|
186
|
-
if (!(expandedKeys.size < 0 || expandedKeys.size < node.size)) {
|
187
|
-
_context3.next = 11;
|
188
|
-
break;
|
189
|
-
}
|
190
|
-
expandedNode = _Array$from(node).pop();
|
191
|
-
if (!(((_tree$getItem = tree.getItem(expandedNode)) === null || _tree$getItem === void 0 || (_tree$getItem = _tree$getItem.children) === null || _tree$getItem === void 0 ? void 0 : _tree$getItem.length) <= 0)) {
|
192
|
-
_context3.next = 9;
|
193
|
-
break;
|
194
|
-
}
|
195
|
-
setLoadingNodes(_concatInstanceProperty(_context2 = []).call(_context2, loadingNodes, [{
|
196
|
-
node: expandedNode,
|
197
|
-
loadingState: true
|
198
|
-
}]));
|
199
|
-
_context3.next = 6;
|
200
|
-
return getMockData();
|
201
|
-
case 6:
|
202
|
-
list = _context3.sent;
|
203
|
-
_forEachInstanceProperty(list).call(list, function (item) {
|
204
|
-
tree.insert(expandedNode, 1, item);
|
205
|
-
});
|
206
|
-
setExpandedKeys(node);
|
207
|
-
case 9:
|
208
|
-
_context3.next = 12;
|
209
|
-
break;
|
210
|
-
case 11:
|
211
|
-
if (expandedKeys.size > node.size) {
|
212
|
-
setExpandedKeys(node);
|
213
|
-
}
|
214
|
-
case 12:
|
215
|
-
case "end":
|
216
|
-
return _context3.stop();
|
217
|
-
}
|
218
|
-
}, _callee2);
|
219
|
-
}));
|
220
|
-
return function handleExpand(_x) {
|
221
|
-
return _ref2.apply(this, arguments);
|
222
|
-
};
|
223
|
-
}();
|
224
|
-
useEffect(function () {
|
225
|
-
_forEachInstanceProperty(loadingNodes).call(loadingNodes, function (item, index) {
|
226
|
-
var _tree$getItem2;
|
227
|
-
var isFulfilled = ((_tree$getItem2 = tree.getItem(item.node)) === null || _tree$getItem2 === void 0 || (_tree$getItem2 = _tree$getItem2.children) === null || _tree$getItem2 === void 0 ? void 0 : _tree$getItem2.length) > 0;
|
228
|
-
if (isFulfilled) {
|
229
|
-
var _context4;
|
230
|
-
var tempArray = _concatInstanceProperty(_context4 = []).call(_context4, loadingNodes);
|
231
|
-
_spliceInstanceProperty(tempArray).call(tempArray, index, 1, {
|
232
|
-
node: item.node,
|
233
|
-
loadingState: false
|
234
|
-
});
|
235
|
-
setLoadingNodes(tempArray);
|
236
|
-
}
|
237
|
-
});
|
238
|
-
}, [expandedKeys]);
|
239
|
-
return ___EmotionJSX(TreeView, _extends({}, args, {
|
240
|
-
items: tree.items,
|
241
|
-
tree: tree,
|
242
|
-
onExpandedChange: handleExpand,
|
243
|
-
loadingNodes: loadingNodes
|
244
|
-
}), function (section) {
|
245
|
-
return ___EmotionJSX(Item, {
|
246
|
-
key: section.key,
|
247
|
-
items: section.children,
|
248
|
-
title: section.value.title,
|
249
|
-
hasChildren: section.value.items && true
|
250
|
-
});
|
251
|
-
});
|
252
92
|
};
|
@@ -4,8 +4,8 @@ import _asyncToGenerator from "@babel/runtime-corejs3/helpers/esm/asyncToGenerat
|
|
4
4
|
import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
|
5
5
|
var _context;
|
6
6
|
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; }
|
7
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var
|
8
|
-
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 _context5; _forEachInstanceProperty(_context5 = ["next", "throw", "return"]).call(_context5, 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 = _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 _context6; 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(_context6 = this.tryEntries).call(_context6, 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; }
|
7
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context5, _context6; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context5 = ownKeys(Object(source), !0)).call(_context5, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context6 = ownKeys(Object(source))).call(_context6, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
|
8
|
+
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; _forEachInstanceProperty(_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" }], _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 = _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, _forEachInstanceProperty(_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; }
|
9
9
|
import _Set from "@babel/runtime-corejs3/core-js-stable/set";
|
10
10
|
import _concatInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/concat";
|
11
11
|
import _Object$defineProperty from "@babel/runtime-corejs3/core-js-stable/object/define-property";
|
@@ -153,46 +153,6 @@ var TreeViewComponent = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
153
153
|
});
|
154
154
|
});
|
155
155
|
});
|
156
|
-
var asyncData = [{
|
157
|
-
title: 'Item1',
|
158
|
-
items: []
|
159
|
-
}, {
|
160
|
-
title: 'Item2',
|
161
|
-
items: []
|
162
|
-
}, {
|
163
|
-
title: 'Item3'
|
164
|
-
}, {
|
165
|
-
title: 'Item4',
|
166
|
-
items: []
|
167
|
-
}];
|
168
|
-
var AsyncTreeViewComponent = function AsyncTreeViewComponent(props) {
|
169
|
-
var tree = useTreeData({
|
170
|
-
initialItems: asyncData,
|
171
|
-
getKey: function getKey(item) {
|
172
|
-
return item.title;
|
173
|
-
},
|
174
|
-
getChildren: function getChildren(item) {
|
175
|
-
return item.items;
|
176
|
-
}
|
177
|
-
});
|
178
|
-
var loadingNodes = [];
|
179
|
-
return ___EmotionJSX(TreeView, _extends({}, defaultProps, props, {
|
180
|
-
items: tree.items,
|
181
|
-
tree: tree,
|
182
|
-
isLoading: loadingNodes,
|
183
|
-
"aria-label": "Example Tree"
|
184
|
-
}), function (section) {
|
185
|
-
return ___EmotionJSX(Item, {
|
186
|
-
key: section.key,
|
187
|
-
items: section.children,
|
188
|
-
title: section.key,
|
189
|
-
hasChildren: section.value.items && true,
|
190
|
-
customProp: {
|
191
|
-
testp: 1
|
192
|
-
}
|
193
|
-
});
|
194
|
-
});
|
195
|
-
};
|
196
156
|
TreeViewComponent.propTypes = {
|
197
157
|
data: PropTypes.arrayOf(PropTypes.shape({}))
|
198
158
|
};
|
@@ -348,87 +308,6 @@ test('disabledKeys prop disables items in the tree -- rendering them unclickable
|
|
348
308
|
expect(thisItem).not.toHaveClass('is-selected');
|
349
309
|
expect(thisItem).toHaveAttribute('aria-selected', 'false');
|
350
310
|
});
|
351
|
-
describe('loadingState', function () {
|
352
|
-
test('should not render loader if tree item is not expanded', function () {
|
353
|
-
render(___EmotionJSX(AsyncTreeViewComponent, {
|
354
|
-
loadingNodes: [{
|
355
|
-
node: 'Item2',
|
356
|
-
loadingState: true
|
357
|
-
}]
|
358
|
-
}));
|
359
|
-
expect(screen.queryByRole('alert')).not.toBeInTheDocument();
|
360
|
-
});
|
361
|
-
test('should render loader if tree item is expanded', function () {
|
362
|
-
render(___EmotionJSX(AsyncTreeViewComponent, {
|
363
|
-
loadingNodes: [{
|
364
|
-
node: 'Item1',
|
365
|
-
loadingState: true
|
366
|
-
}]
|
367
|
-
}));
|
368
|
-
var buttons = screen.queryAllByRole('button');
|
369
|
-
userEvent.click(buttons[0]);
|
370
|
-
var listItems = screen.getAllByRole('row');
|
371
|
-
var thisItem = listItems[0];
|
372
|
-
var loader = within(thisItem).getByRole('alert');
|
373
|
-
expect(loader).toBeInTheDocument();
|
374
|
-
});
|
375
|
-
test('should hide loader after children are added to the tree item', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
376
|
-
var buttons;
|
377
|
-
return _regeneratorRuntime().wrap(function _callee$(_context2) {
|
378
|
-
while (1) switch (_context2.prev = _context2.next) {
|
379
|
-
case 0:
|
380
|
-
render(___EmotionJSX(AsyncTreeViewComponent, {
|
381
|
-
loadingNodes: [{
|
382
|
-
node: 'Item1',
|
383
|
-
loadingState: true
|
384
|
-
}]
|
385
|
-
}));
|
386
|
-
buttons = screen.queryAllByRole('button');
|
387
|
-
fireEvent.click(buttons[0]);
|
388
|
-
render(___EmotionJSX(AsyncTreeViewComponent, {
|
389
|
-
loadingNodes: [{
|
390
|
-
node: 'Item1',
|
391
|
-
loadingState: false
|
392
|
-
}]
|
393
|
-
}));
|
394
|
-
fireEvent.click(buttons[0]);
|
395
|
-
expect(screen.queryByRole('alert')).not.toBeInTheDocument();
|
396
|
-
case 6:
|
397
|
-
case "end":
|
398
|
-
return _context2.stop();
|
399
|
-
}
|
400
|
-
}, _callee);
|
401
|
-
})));
|
402
|
-
test('should add loader to item without children and not other expanded items', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
403
|
-
var buttons, loader;
|
404
|
-
return _regeneratorRuntime().wrap(function _callee2$(_context3) {
|
405
|
-
while (1) switch (_context3.prev = _context3.next) {
|
406
|
-
case 0:
|
407
|
-
render(___EmotionJSX(AsyncTreeViewComponent, {
|
408
|
-
loadingNodes: [{
|
409
|
-
node: 'Item1',
|
410
|
-
loadingState: true
|
411
|
-
}, {
|
412
|
-
node: 'Item2',
|
413
|
-
loadingState: true
|
414
|
-
}, {
|
415
|
-
node: 'Item4',
|
416
|
-
loadingState: false
|
417
|
-
}]
|
418
|
-
}));
|
419
|
-
buttons = screen.queryAllByRole('button');
|
420
|
-
userEvent.click(buttons[0]);
|
421
|
-
userEvent.click(buttons[1]);
|
422
|
-
userEvent.click(buttons[2]);
|
423
|
-
loader = screen.getAllByRole('alert');
|
424
|
-
expect(loader).toHaveLength(2);
|
425
|
-
case 7:
|
426
|
-
case "end":
|
427
|
-
return _context3.stop();
|
428
|
-
}
|
429
|
-
}, _callee2);
|
430
|
-
})));
|
431
|
-
});
|
432
311
|
test('displays correct aria attributes', function () {
|
433
312
|
render(___EmotionJSX(TreeViewComponent, {
|
434
313
|
data: data
|
@@ -492,10 +371,10 @@ test('onKeyDown does not call passed in prop call back function', function () {
|
|
492
371
|
userEvent.type(thisItem, '{arrowleft}');
|
493
372
|
expect(callback).not.toHaveBeenCalled();
|
494
373
|
});
|
495
|
-
test('onDragStart calls passed in prop call back function', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
374
|
+
test('onDragStart calls passed in prop call back function', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
496
375
|
var callback, secondCallback, listItems, element, target, dataTransfer;
|
497
|
-
return _regeneratorRuntime().wrap(function
|
498
|
-
while (1) switch (
|
376
|
+
return _regeneratorRuntime().wrap(function _callee$(_context2) {
|
377
|
+
while (1) switch (_context2.prev = _context2.next) {
|
499
378
|
case 0:
|
500
379
|
callback = jest.fn();
|
501
380
|
secondCallback = jest.fn();
|
@@ -534,7 +413,7 @@ test('onDragStart calls passed in prop call back function', /*#__PURE__*/_asyncT
|
|
534
413
|
clientY: 51
|
535
414
|
}));
|
536
415
|
expect(target).toHaveAttribute('data-droptarget', 'true');
|
537
|
-
|
416
|
+
_context2.next = 17;
|
538
417
|
return fireEvent(target, new DragEvent('drop', {
|
539
418
|
dataTransfer: dataTransfer,
|
540
419
|
clientX: 51,
|
@@ -544,7 +423,7 @@ test('onDragStart calls passed in prop call back function', /*#__PURE__*/_asyncT
|
|
544
423
|
act(function () {
|
545
424
|
return jest.runAllTimers();
|
546
425
|
});
|
547
|
-
|
426
|
+
_context2.next = 20;
|
548
427
|
return fireEvent(element, new DragEvent('dragend', {
|
549
428
|
dataTransfer: dataTransfer,
|
550
429
|
clientX: 51,
|
@@ -560,9 +439,9 @@ test('onDragStart calls passed in prop call back function', /*#__PURE__*/_asyncT
|
|
560
439
|
});
|
561
440
|
case 23:
|
562
441
|
case "end":
|
563
|
-
return
|
442
|
+
return _context2.stop();
|
564
443
|
}
|
565
|
-
},
|
444
|
+
}, _callee);
|
566
445
|
})));
|
567
446
|
test('items still render if there is only one provided', function () {
|
568
447
|
var callback = jest.fn();
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
|
2
2
|
import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
|
3
3
|
import _objectWithoutProperties from "@babel/runtime-corejs3/helpers/esm/objectWithoutProperties";
|
4
|
-
var _excluded = ["title", "mainIcon", "lastIcon", "item", "items", "isExpanded", "
|
4
|
+
var _excluded = ["title", "mainIcon", "lastIcon", "item", "items", "isExpanded", "isDragging", "onKeyDown"];
|
5
5
|
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; }
|
6
6
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context2, _context3; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context2 = ownKeys(Object(source), !0)).call(_context2, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context3 = ownKeys(Object(source))).call(_context3, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
|
7
7
|
import _findInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/find";
|
@@ -40,7 +40,6 @@ var TreeViewRow = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
40
40
|
item = props.item,
|
41
41
|
items = props.items,
|
42
42
|
isExpanded = props.isExpanded,
|
43
|
-
hasChildren = props.hasChildren,
|
44
43
|
isDragging = props.isDragging,
|
45
44
|
_onKeyDown = props.onKeyDown,
|
46
45
|
others = _objectWithoutProperties(props, _excluded);
|
@@ -182,7 +181,7 @@ var TreeViewRow = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
182
181
|
onKeyDown: function onKeyDown(e) {
|
183
182
|
_onKeyDown(e);
|
184
183
|
}
|
185
|
-
}), (
|
184
|
+
}), (items === null || items === void 0 ? void 0 : items.length) > 0 && ___EmotionJSX(IconButtonToggle, {
|
186
185
|
onToggle: pressIcon,
|
187
186
|
isToggled: isExpanded,
|
188
187
|
defaultIcon: MenuRight,
|
@@ -235,7 +234,6 @@ TreeViewRow.propTypes = {
|
|
235
234
|
key: PropTypes.string
|
236
235
|
}),
|
237
236
|
mainIcon: PropTypes.elementType,
|
238
|
-
lastIcon: PropTypes.elementType
|
239
|
-
hasChildren: PropTypes.bool
|
237
|
+
lastIcon: PropTypes.elementType
|
240
238
|
};
|
241
239
|
export default TreeViewRow;
|