@pingux/astro 2.41.0 → 2.42.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. package/lib/cjs/components/Card/Card.d.ts +4 -0
  2. package/lib/cjs/components/Card/Card.js +10 -51
  3. package/lib/cjs/components/Card/Card.stories.d.ts +24 -0
  4. package/lib/cjs/components/Card/Card.stories.js +13 -12
  5. package/lib/cjs/components/Card/Card.styles.d.ts +44 -0
  6. package/lib/cjs/components/Card/cardAttributes.d.ts +1 -0
  7. package/lib/cjs/components/Card/cardAttributes.js +33 -0
  8. package/lib/cjs/components/Card/index.d.ts +1 -0
  9. package/lib/cjs/components/TreeView/TreeView.js +10 -5
  10. package/lib/cjs/components/TreeView/TreeView.stories.js +169 -3
  11. package/lib/cjs/components/TreeView/TreeView.test.js +130 -9
  12. package/lib/cjs/components/TreeView/TreeViewRow.js +5 -3
  13. package/lib/cjs/components/TreeView/TreeViewSection.js +32 -3
  14. package/lib/cjs/hooks/useField/useField.d.ts +1 -0
  15. package/lib/cjs/types/box.d.ts +2 -0
  16. package/lib/cjs/types/card.d.ts +5 -0
  17. package/lib/cjs/types/card.js +6 -0
  18. package/lib/cjs/types/index.d.ts +1 -0
  19. package/lib/cjs/types/index.js +21 -10
  20. package/lib/components/Card/Card.js +11 -52
  21. package/lib/components/Card/Card.stories.js +14 -12
  22. package/lib/components/Card/cardAttributes.js +25 -0
  23. package/lib/components/TreeView/TreeView.js +10 -5
  24. package/lib/components/TreeView/TreeView.stories.js +161 -1
  25. package/lib/components/TreeView/TreeView.test.js +130 -9
  26. package/lib/components/TreeView/TreeViewRow.js +5 -3
  27. package/lib/components/TreeView/TreeViewSection.js +34 -5
  28. package/lib/types/card.js +1 -0
  29. package/lib/types/index.js +1 -0
  30. package/package.json +1 -1
@@ -1,10 +1,22 @@
1
+ import _Object$keys from "@babel/runtime-corejs3/core-js-stable/object/keys";
2
+ import _Object$getOwnPropertySymbols from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols";
3
+ import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
4
+ import _Object$getOwnPropertyDescriptor from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor";
5
+ import _forEachInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/for-each";
6
+ import _Object$getOwnPropertyDescriptors from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors";
7
+ import _Object$defineProperties from "@babel/runtime-corejs3/core-js-stable/object/define-properties";
8
+ import _Object$defineProperty from "@babel/runtime-corejs3/core-js-stable/object/define-property";
1
9
  import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
10
+ import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
11
+ 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; }
12
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context, _context2; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context = ownKeys(Object(source), !0)).call(_context, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context2 = ownKeys(Object(source))).call(_context2, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
2
13
  import React from 'react';
3
14
  import { withDesign } from 'storybook-addon-designs';
4
15
  import DocsLayout from '../../../.storybook/storybookDocsLayout';
5
16
  import { Box, Card } from '../../index';
6
- import { FIGMA_LINKS } from '../../utils/designUtils/figmaLinks.ts';
17
+ import { FIGMA_LINKS } from '../../utils/designUtils/figmaLinks';
7
18
  import CardReadme from './Card.mdx';
19
+ import { cardArgTypes } from './cardAttributes';
8
20
  import { jsx as ___EmotionJSX } from "@emotion/react";
9
21
  export default {
10
22
  title: 'Components/Card',
@@ -17,17 +29,7 @@ export default {
17
29
  }
18
30
  }
19
31
  },
20
- argTypes: {
21
- children: {
22
- description: 'Card content.',
23
- table: {
24
- type: {}
25
- },
26
- control: {
27
- type: 'text'
28
- }
29
- }
30
- },
32
+ argTypes: _objectSpread({}, cardArgTypes),
31
33
  args: {
32
34
  children: 'Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Ut at enim nunc. Cras congue consequat odio, ac sodales lacus imperdiet quis. In id ex eu lorem sollicitudin hendrerit feugiat ultrices elit. Curabitur imperdiet libero vitae luctus blandit. Ut ac dignissim tortor. Pellentesque convallis eu metus vitae mollis. Donec sapien felis, laoreet eu egestas eu, blandit quis tellus. Donec luctus suscipit nibh, et tincidunt nisl facilisis ut. Mauris molestie purus at lectus venenatis, ac ultrices felis ultrices.'
33
35
  }
@@ -0,0 +1,25 @@
1
+ import _Object$keys from "@babel/runtime-corejs3/core-js-stable/object/keys";
2
+ import _Object$getOwnPropertySymbols from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols";
3
+ import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
4
+ import _Object$getOwnPropertyDescriptor from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor";
5
+ import _forEachInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/for-each";
6
+ import _Object$getOwnPropertyDescriptors from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors";
7
+ import _Object$defineProperties from "@babel/runtime-corejs3/core-js-stable/object/define-properties";
8
+ import _Object$defineProperty from "@babel/runtime-corejs3/core-js-stable/object/define-property";
9
+ import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
10
+ 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; }
11
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context, _context2; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context = ownKeys(Object(source), !0)).call(_context, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context2 = ownKeys(Object(source))).call(_context2, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
12
+ import { ariaAttributeBaseArgTypes } from '../../utils/docUtils/ariaAttributes';
13
+ import { onHoverArgTypes } from '../../utils/docUtils/hoverProps';
14
+ import { onPressArgTypes } from '../../utils/docUtils/pressAttributes';
15
+ export var cardArgTypes = _objectSpread(_objectSpread(_objectSpread({
16
+ children: {
17
+ description: 'Card content.',
18
+ table: {
19
+ type: {}
20
+ },
21
+ control: {
22
+ type: 'text'
23
+ }
24
+ }
25
+ }, onPressArgTypes), onHoverArgTypes), ariaAttributeBaseArgTypes);
@@ -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", "onDragStart", "onDrop", "onKeyDown", "pageLength"];
15
+ _excluded3 = ["tree", "disabledKeys", "onExpandedChange", "loadingNodes", "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,6 +108,7 @@ 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,
111
112
  onDragStartProp = props.onDragStart,
112
113
  onDropProp = props.onDrop,
113
114
  onKeyDown = props.onKeyDown,
@@ -147,14 +148,14 @@ var TreeView = /*#__PURE__*/forwardRef(function (props, ref) {
147
148
  var flattenNestedData = function flattenNestedData(_data) {
148
149
  var returnArray = [];
149
150
  var checkItemNesting = function checkItemNesting(item) {
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) {
151
+ var _item$value, _item$props, _item$children, _item$value2;
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 || item !== null && item !== void 0 && (_item$props = item.props) !== null && _item$props !== void 0 && _item$props.hasChildren) {
152
153
  return {
153
154
  isTopLevel: true,
154
155
  hasChildren: true
155
156
  };
156
157
  }
157
- if (((_item$children = item.children) === null || _item$children === void 0 ? void 0 : _item$children.length) > 0) {
158
+ if (((_item$children = item.children) === null || _item$children === void 0 ? void 0 : _item$children.length) > 0 || (_item$value2 = item.value) !== null && _item$value2 !== void 0 && _item$value2.items) {
158
159
  return {
159
160
  isTopLevel: false,
160
161
  hasChildren: true
@@ -352,11 +353,13 @@ var TreeView = /*#__PURE__*/forwardRef(function (props, ref) {
352
353
  border: 'none !important'
353
354
  }
354
355
  }, others), ___EmotionJSX(TreeViewWrapper, null, _mapInstanceProperty(_context5 = _Array$from(state.collection)).call(_context5, function (item, index) {
355
- return SectionOrItemRender(item.value.children.length > 0, ___EmotionJSX(TreeViewSection, {
356
+ return SectionOrItemRender(item.props.hasChildren || item.value.children.length > 0, ___EmotionJSX(TreeViewSection, {
356
357
  item: item,
357
358
  items: item.value.children,
358
359
  title: item.props.title,
359
360
  key: item.props.title,
361
+ hasChildren: item.props.hasChildren,
362
+ loadingNodes: loadingNodes,
360
363
  onKeyDown: onKeyDown,
361
364
  level: level + 1,
362
365
  setSize: state.collection.size,
@@ -391,6 +394,8 @@ TreeView.propTypes = {
391
394
  items: isIterableProp,
392
395
  /** String that describes the treeview when using a screen reader. */
393
396
  'aria-label': PropTypes.string,
397
+ /** Determines whether the loading indicator is shown for the expanded node. */
398
+ loadingNodes: PropTypes.arrayOf(PropTypes.shape({})),
394
399
  /** Handler that is called when a key is pressed. */
395
400
  onKeyDown: PropTypes.func,
396
401
  /** Callback that is called when the dragging action starts. */
@@ -1,5 +1,23 @@
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";
1
11
  import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
2
- import React from 'react';
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';
3
21
  import DocsLayout from '../../../.storybook/storybookDocsLayout';
4
22
  import { Item, TreeView, useTreeData } from '../../index';
5
23
  import TreeViewReadMe from './TreeView.mdx';
@@ -66,6 +84,24 @@ var data = [{
66
84
  key: 'Single Item',
67
85
  title: 'Single Item'
68
86
  }];
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
+ }];
69
105
  export var Default = function Default(args) {
70
106
  var tree = useTreeData({
71
107
  initialItems: data,
@@ -89,4 +125,128 @@ export var Default = function Default(args) {
89
125
  title: (_section$value = section.value) === null || _section$value === void 0 ? void 0 : _section$value.title
90
126
  });
91
127
  });
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
+ });
92
252
  };
@@ -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 _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; }
7
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context7, _context8; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context7 = ownKeys(Object(source), !0)).call(_context7, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context8 = ownKeys(Object(source))).call(_context8, 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 _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; }
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,6 +153,46 @@ 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
+ };
156
196
  TreeViewComponent.propTypes = {
157
197
  data: PropTypes.arrayOf(PropTypes.shape({}))
158
198
  };
@@ -308,6 +348,87 @@ test('disabledKeys prop disables items in the tree -- rendering them unclickable
308
348
  expect(thisItem).not.toHaveClass('is-selected');
309
349
  expect(thisItem).toHaveAttribute('aria-selected', 'false');
310
350
  });
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
+ });
311
432
  test('displays correct aria attributes', function () {
312
433
  render(___EmotionJSX(TreeViewComponent, {
313
434
  data: data
@@ -371,10 +492,10 @@ test('onKeyDown does not call passed in prop call back function', function () {
371
492
  userEvent.type(thisItem, '{arrowleft}');
372
493
  expect(callback).not.toHaveBeenCalled();
373
494
  });
374
- test('onDragStart calls passed in prop call back function', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
495
+ test('onDragStart calls passed in prop call back function', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
375
496
  var callback, secondCallback, listItems, element, target, dataTransfer;
376
- return _regeneratorRuntime().wrap(function _callee$(_context2) {
377
- while (1) switch (_context2.prev = _context2.next) {
497
+ return _regeneratorRuntime().wrap(function _callee3$(_context4) {
498
+ while (1) switch (_context4.prev = _context4.next) {
378
499
  case 0:
379
500
  callback = jest.fn();
380
501
  secondCallback = jest.fn();
@@ -413,7 +534,7 @@ test('onDragStart calls passed in prop call back function', /*#__PURE__*/_asyncT
413
534
  clientY: 51
414
535
  }));
415
536
  expect(target).toHaveAttribute('data-droptarget', 'true');
416
- _context2.next = 17;
537
+ _context4.next = 17;
417
538
  return fireEvent(target, new DragEvent('drop', {
418
539
  dataTransfer: dataTransfer,
419
540
  clientX: 51,
@@ -423,7 +544,7 @@ test('onDragStart calls passed in prop call back function', /*#__PURE__*/_asyncT
423
544
  act(function () {
424
545
  return jest.runAllTimers();
425
546
  });
426
- _context2.next = 20;
547
+ _context4.next = 20;
427
548
  return fireEvent(element, new DragEvent('dragend', {
428
549
  dataTransfer: dataTransfer,
429
550
  clientX: 51,
@@ -439,9 +560,9 @@ test('onDragStart calls passed in prop call back function', /*#__PURE__*/_asyncT
439
560
  });
440
561
  case 23:
441
562
  case "end":
442
- return _context2.stop();
563
+ return _context4.stop();
443
564
  }
444
- }, _callee);
565
+ }, _callee3);
445
566
  })));
446
567
  test('items still render if there is only one provided', function () {
447
568
  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", "isDragging", "onKeyDown"];
4
+ var _excluded = ["title", "mainIcon", "lastIcon", "item", "items", "isExpanded", "hasChildren", "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,6 +40,7 @@ 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,
43
44
  isDragging = props.isDragging,
44
45
  _onKeyDown = props.onKeyDown,
45
46
  others = _objectWithoutProperties(props, _excluded);
@@ -181,7 +182,7 @@ var TreeViewRow = /*#__PURE__*/forwardRef(function (props, ref) {
181
182
  onKeyDown: function onKeyDown(e) {
182
183
  _onKeyDown(e);
183
184
  }
184
- }), (items === null || items === void 0 ? void 0 : items.length) > 0 && ___EmotionJSX(IconButtonToggle, {
185
+ }), ((items === null || items === void 0 ? void 0 : items.length) > 0 || hasChildren) && ___EmotionJSX(IconButtonToggle, {
185
186
  onToggle: pressIcon,
186
187
  isToggled: isExpanded,
187
188
  defaultIcon: MenuRight,
@@ -234,6 +235,7 @@ TreeViewRow.propTypes = {
234
235
  key: PropTypes.string
235
236
  }),
236
237
  mainIcon: PropTypes.elementType,
237
- lastIcon: PropTypes.elementType
238
+ lastIcon: PropTypes.elementType,
239
+ hasChildren: PropTypes.bool
238
240
  };
239
241
  export default TreeViewRow;