calcite-flow.entry.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*!
  2. * All material copyright ESRI, All Rights Reserved, unless otherwise specified.
  3. * See https://github.com/Esri/calcite-components/blob/master/LICENSE.md for details.
  4. * v1.0.0-beta.97
  5. */
  6. import { r as registerInstance, h, g as getElement } from './index-1f9b54dc.js';
  7. import { c as createObserver } from './observers-9f44e9b3.js';
  8. const CSS = {
  9. frame: "frame",
  10. frameAdvancing: "frame--advancing",
  11. frameRetreating: "frame--retreating"
  12. };
  13. const flowCss = "@keyframes in{0%{opacity:0}100%{opacity:1}}@keyframes in-down{0%{opacity:0;transform:translate3D(0, -5px, 0)}100%{opacity:1;transform:translate3D(0, 0, 0)}}@keyframes in-up{0%{opacity:0;transform:translate3D(0, 5px, 0)}100%{opacity:1;transform:translate3D(0, 0, 0)}}@keyframes in-scale{0%{opacity:0;transform:scale3D(0.95, 0.95, 1)}100%{opacity:1;transform:scale3D(1, 1, 1)}}:root{--calcite-animation-timing:calc(150ms * var(--calcite-internal-duration-factor));--calcite-internal-duration-factor:var(--calcite-duration-factor, 1);--calcite-internal-animation-timing-fast:calc(100ms * var(--calcite-internal-duration-factor));--calcite-internal-animation-timing-medium:calc(200ms * var(--calcite-internal-duration-factor));--calcite-internal-animation-timing-slow:calc(300ms * var(--calcite-internal-duration-factor))}.calcite-animate{opacity:0;animation-fill-mode:both;animation-duration:var(--calcite-animation-timing)}.calcite-animate__in{animation-name:in}.calcite-animate__in-down{animation-name:in-down}.calcite-animate__in-up{animation-name:in-up}.calcite-animate__in-scale{animation-name:in-scale}@media (prefers-reduced-motion: reduce){:root{--calcite-internal-duration-factor:0.01}}:host{box-sizing:border-box;background-color:var(--calcite-ui-foreground-1);color:var(--calcite-ui-text-2);font-size:var(--calcite-font-size--1)}:host *{box-sizing:border-box}:root{--calcite-floating-ui-transition:var(--calcite-animation-timing)}:host([hidden]){display:none}:host{position:relative;display:flex;inline-size:100%;flex:1 1 auto;align-items:stretch;overflow:hidden;background-color:transparent}:host .frame{position:relative;margin:0px;display:flex;inline-size:100%;flex:1 1 auto;flex-direction:column;align-items:stretch;padding:0px}:host ::slotted(calcite-flow-item),:host ::slotted(calcite-panel){block-size:100%}:host ::slotted(.calcite-match-height:last-child){display:flex;flex:1 1 auto;overflow:hidden}:host .frame--advancing{animation:calcite-frame-advance var(--calcite-animation-timing)}:host .frame--retreating{animation:calcite-frame-retreat var(--calcite-animation-timing)}@keyframes calcite-frame-advance{0%{--tw-bg-opacity:0.5;transform:translate3d(50px, 0, 0)}100%{--tw-bg-opacity:1;transform:translate3d(0, 0, 0)}}@keyframes calcite-frame-retreat{0%{--tw-bg-opacity:0.5;transform:translate3d(-50px, 0, 0)}100%{--tw-bg-opacity:1;transform:translate3d(0, 0, 0)}}";
  14. const Flow = class {
  15. constructor(hostRef) {
  16. registerInstance(this, hostRef);
  17. this.flowDirection = null;
  18. this.itemCount = 0;
  19. this.items = [];
  20. this.itemMutationObserver = createObserver("mutation", () => this.updateFlowProps());
  21. this.getFlowDirection = (oldFlowItemCount, newFlowItemCount) => {
  22. const allowRetreatingDirection = oldFlowItemCount > 1;
  23. const allowAdvancingDirection = oldFlowItemCount && newFlowItemCount > 1;
  24. if (!allowAdvancingDirection && !allowRetreatingDirection) {
  25. return null;
  26. }
  27. return newFlowItemCount < oldFlowItemCount ? "retreating" : "advancing";
  28. };
  29. this.updateFlowProps = () => {
  30. const { el, items } = this;
  31. const newItems = Array.from(el.querySelectorAll("calcite-flow-item, calcite-panel")).filter((flowItem) => !flowItem.matches("calcite-flow-item calcite-flow-item, calcite-panel calcite-panel"));
  32. const oldItemCount = items.length;
  33. const newItemCount = newItems.length;
  34. const activeItem = newItems[newItemCount - 1];
  35. const previousItem = newItems[newItemCount - 2];
  36. if (newItemCount && activeItem) {
  37. newItems.forEach((itemNode) => {
  38. itemNode.showBackButton = itemNode === activeItem && newItemCount > 1;
  39. itemNode.hidden = itemNode !== activeItem;
  40. });
  41. }
  42. if (previousItem) {
  43. previousItem.menuOpen = false;
  44. }
  45. this.items = newItems;
  46. if (oldItemCount !== newItemCount) {
  47. const flowDirection = this.getFlowDirection(oldItemCount, newItemCount);
  48. this.itemCount = newItemCount;
  49. this.flowDirection = flowDirection;
  50. }
  51. };
  52. }
  53. // --------------------------------------------------------------------------
  54. //
  55. // Public Methods
  56. //
  57. // --------------------------------------------------------------------------
  58. /**
  59. * Removes the currently active `calcite-flow-item` or `calcite-panel`.
  60. */
  61. async back() {
  62. const { items } = this;
  63. const lastItem = items[items.length - 1];
  64. if (!lastItem) {
  65. return;
  66. }
  67. const beforeBack = lastItem.beforeBack
  68. ? lastItem.beforeBack
  69. : () => Promise.resolve();
  70. return beforeBack.call(lastItem).then(() => {
  71. lastItem.remove();
  72. return lastItem;
  73. });
  74. }
  75. // --------------------------------------------------------------------------
  76. //
  77. // Lifecycle
  78. //
  79. // --------------------------------------------------------------------------
  80. connectedCallback() {
  81. var _a;
  82. (_a = this.itemMutationObserver) === null || _a === void 0 ? void 0 : _a.observe(this.el, { childList: true, subtree: true });
  83. this.updateFlowProps();
  84. }
  85. disconnectedCallback() {
  86. var _a;
  87. (_a = this.itemMutationObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
  88. }
  89. // --------------------------------------------------------------------------
  90. //
  91. // Private Methods
  92. //
  93. // --------------------------------------------------------------------------
  94. handleItemBackClick() {
  95. this.back();
  96. }
  97. // --------------------------------------------------------------------------
  98. //
  99. // Render Methods
  100. //
  101. // --------------------------------------------------------------------------
  102. render() {
  103. const { flowDirection } = this;
  104. const frameDirectionClasses = {
  105. [CSS.frame]: true,
  106. [CSS.frameAdvancing]: flowDirection === "advancing",
  107. [CSS.frameRetreating]: flowDirection === "retreating"
  108. };
  109. return (h("div", { class: frameDirectionClasses }, h("slot", null)));
  110. }
  111. get el() { return getElement(this); }
  112. };
  113. Flow.style = flowCss;
  114. export { Flow as calcite_flow };