calcite-flow.entry.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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.82
  5. */
  6. import { r as registerInstance, h, g as getElement } from './index-8ece2564.js';
  7. import { c as createObserver } from './observers-b198f831.js';
  8. const CSS = {
  9. frame: "frame",
  10. frameAdvancing: "frame--advancing",
  11. frameRetreating: "frame--retreating"
  12. };
  13. const flowCss = "@-webkit-keyframes in{0%{opacity:0}100%{opacity:1}}@keyframes in{0%{opacity:0}100%{opacity:1}}@-webkit-keyframes in-down{0%{opacity:0;-webkit-transform:translate3D(0, -5px, 0);transform:translate3D(0, -5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@keyframes in-down{0%{opacity:0;-webkit-transform:translate3D(0, -5px, 0);transform:translate3D(0, -5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@-webkit-keyframes in-up{0%{opacity:0;-webkit-transform:translate3D(0, 5px, 0);transform:translate3D(0, 5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@keyframes in-up{0%{opacity:0;-webkit-transform:translate3D(0, 5px, 0);transform:translate3D(0, 5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@-webkit-keyframes in-scale{0%{opacity:0;-webkit-transform:scale3D(0.95, 0.95, 1);transform:scale3D(0.95, 0.95, 1)}100%{opacity:1;-webkit-transform:scale3D(1, 1, 1);transform:scale3D(1, 1, 1)}}@keyframes in-scale{0%{opacity:0;-webkit-transform:scale3D(0.95, 0.95, 1);transform:scale3D(0.95, 0.95, 1)}100%{opacity:1;-webkit-transform:scale3D(1, 1, 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;-webkit-animation-fill-mode:both;animation-fill-mode:both;-webkit-animation-duration:var(--calcite-animation-timing);animation-duration:var(--calcite-animation-timing)}.calcite-animate__in{-webkit-animation-name:in;animation-name:in}.calcite-animate__in-down{-webkit-animation-name:in-down;animation-name:in-down}.calcite-animate__in-up{-webkit-animation-name:in-up;animation-name:in-up}.calcite-animate__in-scale{-webkit-animation-name:in-scale;animation-name:in-scale}:host{-webkit-box-sizing:border-box;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 *{-webkit-box-sizing:border-box;box-sizing:border-box}:root{--calcite-popper-transition:var(--calcite-animation-timing)}:host([hidden]){display:none}:host{position:relative;display:-ms-flexbox;display:flex;width:100%;-ms-flex:1 1 auto;flex:1 1 auto;-ms-flex-align:stretch;align-items:stretch;overflow:hidden;background-color:transparent}:host .frame{position:relative;margin:0px;display:-ms-flexbox;display:flex;width:100%;-ms-flex:1 1 auto;flex:1 1 auto;-ms-flex-direction:column;flex-direction:column;-ms-flex-align:stretch;align-items:stretch;padding:0px}:host ::slotted(calcite-panel){height:100%}:host ::slotted(.calcite-match-height:last-child){display:-ms-flexbox;display:flex;-ms-flex:1 1 auto;flex:1 1 auto;overflow:hidden}:host .frame--advancing{-webkit-animation:calcite-frame-advance var(--calcite-animation-timing);animation:calcite-frame-advance var(--calcite-animation-timing)}:host .frame--retreating{-webkit-animation:calcite-frame-retreat var(--calcite-animation-timing);animation:calcite-frame-retreat var(--calcite-animation-timing)}@-webkit-keyframes calcite-frame-advance{0%{--tw-bg-opacity:0.5;-webkit-transform:translate3d(50px, 0, 0);transform:translate3d(50px, 0, 0)}100%{--tw-bg-opacity:1;-webkit-transform:translate3d(0, 0, 0);transform:translate3d(0, 0, 0)}}@keyframes calcite-frame-advance{0%{--tw-bg-opacity:0.5;-webkit-transform:translate3d(50px, 0, 0);transform:translate3d(50px, 0, 0)}100%{--tw-bg-opacity:1;-webkit-transform:translate3d(0, 0, 0);transform:translate3d(0, 0, 0)}}@-webkit-keyframes calcite-frame-retreat{0%{--tw-bg-opacity:0.5;-webkit-transform:translate3d(-50px, 0, 0);transform:translate3d(-50px, 0, 0)}100%{--tw-bg-opacity:1;-webkit-transform:translate3d(0, 0, 0);transform:translate3d(0, 0, 0)}}@keyframes calcite-frame-retreat{0%{--tw-bg-opacity:0.5;-webkit-transform:translate3d(-50px, 0, 0);transform:translate3d(-50px, 0, 0)}100%{--tw-bg-opacity:1;-webkit-transform:translate3d(0, 0, 0);transform:translate3d(0, 0, 0)}}";
  14. const Flow = class {
  15. constructor(hostRef) {
  16. registerInstance(this, hostRef);
  17. this.panelCount = 0;
  18. this.flowDirection = null;
  19. this.panels = [];
  20. this.getFlowDirection = (oldPanelCount, newPanelCount) => {
  21. const allowRetreatingDirection = oldPanelCount > 1;
  22. const allowAdvancingDirection = oldPanelCount && newPanelCount > 1;
  23. if (!allowAdvancingDirection && !allowRetreatingDirection) {
  24. return null;
  25. }
  26. return newPanelCount < oldPanelCount ? "retreating" : "advancing";
  27. };
  28. this.updateFlowProps = () => {
  29. const { panels } = this;
  30. const newPanels = Array.from(this.el.querySelectorAll("calcite-panel"));
  31. const oldPanelCount = panels.length;
  32. const newPanelCount = newPanels.length;
  33. const activePanel = newPanels[newPanelCount - 1];
  34. const previousPanel = newPanels[newPanelCount - 2];
  35. if (newPanelCount && activePanel) {
  36. newPanels.forEach((panelNode) => {
  37. panelNode.showBackButton = newPanelCount > 1;
  38. panelNode.hidden = panelNode !== activePanel;
  39. });
  40. }
  41. if (previousPanel) {
  42. previousPanel.menuOpen = false;
  43. }
  44. this.panels = newPanels;
  45. if (oldPanelCount !== newPanelCount) {
  46. const flowDirection = this.getFlowDirection(oldPanelCount, newPanelCount);
  47. this.panelCount = newPanelCount;
  48. this.flowDirection = flowDirection;
  49. }
  50. };
  51. this.panelItemMutationObserver = createObserver("mutation", this.updateFlowProps);
  52. }
  53. // --------------------------------------------------------------------------
  54. //
  55. // Public Methods
  56. //
  57. // --------------------------------------------------------------------------
  58. /**
  59. * Removes the currently active `calcite-panel`.
  60. */
  61. async back() {
  62. const lastItem = this.el.querySelector("calcite-panel:last-child");
  63. if (!lastItem) {
  64. return;
  65. }
  66. const beforeBack = lastItem.beforeBack
  67. ? lastItem.beforeBack
  68. : () => Promise.resolve();
  69. return beforeBack.call(lastItem).then(() => {
  70. lastItem.remove();
  71. return lastItem;
  72. });
  73. }
  74. // --------------------------------------------------------------------------
  75. //
  76. // Lifecycle
  77. //
  78. // --------------------------------------------------------------------------
  79. connectedCallback() {
  80. var _a;
  81. (_a = this.panelItemMutationObserver) === null || _a === void 0 ? void 0 : _a.observe(this.el, { childList: true, subtree: true });
  82. this.updateFlowProps();
  83. }
  84. disconnectedCallback() {
  85. var _a;
  86. (_a = this.panelItemMutationObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
  87. }
  88. // --------------------------------------------------------------------------
  89. //
  90. // Private Methods
  91. //
  92. // --------------------------------------------------------------------------
  93. handleCalcitePanelBackClick() {
  94. this.back();
  95. }
  96. // --------------------------------------------------------------------------
  97. //
  98. // Render Methods
  99. //
  100. // --------------------------------------------------------------------------
  101. render() {
  102. const { flowDirection, panelCount } = this;
  103. const frameDirectionClasses = {
  104. [CSS.frame]: true,
  105. [CSS.frameAdvancing]: flowDirection === "advancing",
  106. [CSS.frameRetreating]: flowDirection === "retreating"
  107. };
  108. return (h("div", { class: frameDirectionClasses, key: panelCount }, h("slot", null)));
  109. }
  110. get el() { return getElement(this); }
  111. };
  112. Flow.style = flowCss;
  113. export { Flow as calcite_flow };