calcite-flow.cjs.entry.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. 'use strict';
  7. Object.defineProperty(exports, '__esModule', { value: true });
  8. const index = require('./index-5c65e149.js');
  9. const observers = require('./observers-d9fdf006.js');
  10. const CSS = {
  11. frame: "frame",
  12. frameAdvancing: "frame--advancing",
  13. frameRetreating: "frame--retreating"
  14. };
  15. 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)}}";
  16. const Flow = class {
  17. constructor(hostRef) {
  18. index.registerInstance(this, hostRef);
  19. this.panelCount = 0;
  20. this.flowDirection = null;
  21. this.panels = [];
  22. this.getFlowDirection = (oldPanelCount, newPanelCount) => {
  23. const allowRetreatingDirection = oldPanelCount > 1;
  24. const allowAdvancingDirection = oldPanelCount && newPanelCount > 1;
  25. if (!allowAdvancingDirection && !allowRetreatingDirection) {
  26. return null;
  27. }
  28. return newPanelCount < oldPanelCount ? "retreating" : "advancing";
  29. };
  30. this.updateFlowProps = () => {
  31. const { panels } = this;
  32. const newPanels = Array.from(this.el.querySelectorAll("calcite-panel"));
  33. const oldPanelCount = panels.length;
  34. const newPanelCount = newPanels.length;
  35. const activePanel = newPanels[newPanelCount - 1];
  36. const previousPanel = newPanels[newPanelCount - 2];
  37. if (newPanelCount && activePanel) {
  38. newPanels.forEach((panelNode) => {
  39. panelNode.showBackButton = newPanelCount > 1;
  40. panelNode.hidden = panelNode !== activePanel;
  41. });
  42. }
  43. if (previousPanel) {
  44. previousPanel.menuOpen = false;
  45. }
  46. this.panels = newPanels;
  47. if (oldPanelCount !== newPanelCount) {
  48. const flowDirection = this.getFlowDirection(oldPanelCount, newPanelCount);
  49. this.panelCount = newPanelCount;
  50. this.flowDirection = flowDirection;
  51. }
  52. };
  53. this.panelItemMutationObserver = observers.createObserver("mutation", this.updateFlowProps);
  54. }
  55. // --------------------------------------------------------------------------
  56. //
  57. // Public Methods
  58. //
  59. // --------------------------------------------------------------------------
  60. /**
  61. * Removes the currently active `calcite-panel`.
  62. */
  63. async back() {
  64. const lastItem = this.el.querySelector("calcite-panel:last-child");
  65. if (!lastItem) {
  66. return;
  67. }
  68. const beforeBack = lastItem.beforeBack
  69. ? lastItem.beforeBack
  70. : () => Promise.resolve();
  71. return beforeBack.call(lastItem).then(() => {
  72. lastItem.remove();
  73. return lastItem;
  74. });
  75. }
  76. // --------------------------------------------------------------------------
  77. //
  78. // Lifecycle
  79. //
  80. // --------------------------------------------------------------------------
  81. connectedCallback() {
  82. var _a;
  83. (_a = this.panelItemMutationObserver) === null || _a === void 0 ? void 0 : _a.observe(this.el, { childList: true, subtree: true });
  84. this.updateFlowProps();
  85. }
  86. disconnectedCallback() {
  87. var _a;
  88. (_a = this.panelItemMutationObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
  89. }
  90. // --------------------------------------------------------------------------
  91. //
  92. // Private Methods
  93. //
  94. // --------------------------------------------------------------------------
  95. handleCalcitePanelBackClick() {
  96. this.back();
  97. }
  98. // --------------------------------------------------------------------------
  99. //
  100. // Render Methods
  101. //
  102. // --------------------------------------------------------------------------
  103. render() {
  104. const { flowDirection, panelCount } = this;
  105. const frameDirectionClasses = {
  106. [CSS.frame]: true,
  107. [CSS.frameAdvancing]: flowDirection === "advancing",
  108. [CSS.frameRetreating]: flowDirection === "retreating"
  109. };
  110. return (index.h("div", { class: frameDirectionClasses, key: panelCount }, index.h("slot", null)));
  111. }
  112. get el() { return index.getElement(this); }
  113. };
  114. Flow.style = flowCss;
  115. exports.calcite_flow = Flow;