calcite-flow-TYSEOOST.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. import {
  2. createObserver
  3. } from "./chunk-AVLPSIKF.js";
  4. import {
  5. H,
  6. h,
  7. proxyCustomElement
  8. } from "./chunk-IOZKU7B2.js";
  9. import "./chunk-S5KM4IGW.js";
  10. // node_modules/@esri/calcite-components/dist/components/calcite-flow.js
  11. var CSS = {
  12. frame: "frame",
  13. frameAdvancing: "frame--advancing",
  14. frameRetreating: "frame--retreating"
  15. };
  16. var 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)}}";
  17. var Flow = proxyCustomElement(class extends H {
  18. constructor() {
  19. super();
  20. this.__registerHost();
  21. this.__attachShadow();
  22. this.flowDirection = null;
  23. this.itemCount = 0;
  24. this.items = [];
  25. this.itemMutationObserver = createObserver("mutation", () => this.updateFlowProps());
  26. this.getFlowDirection = (oldFlowItemCount, newFlowItemCount) => {
  27. const allowRetreatingDirection = oldFlowItemCount > 1;
  28. const allowAdvancingDirection = oldFlowItemCount && newFlowItemCount > 1;
  29. if (!allowAdvancingDirection && !allowRetreatingDirection) {
  30. return null;
  31. }
  32. return newFlowItemCount < oldFlowItemCount ? "retreating" : "advancing";
  33. };
  34. this.updateFlowProps = () => {
  35. const { el, items } = this;
  36. 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"));
  37. const oldItemCount = items.length;
  38. const newItemCount = newItems.length;
  39. const activeItem = newItems[newItemCount - 1];
  40. const previousItem = newItems[newItemCount - 2];
  41. if (newItemCount && activeItem) {
  42. newItems.forEach((itemNode) => {
  43. itemNode.showBackButton = itemNode === activeItem && newItemCount > 1;
  44. itemNode.hidden = itemNode !== activeItem;
  45. });
  46. }
  47. if (previousItem) {
  48. previousItem.menuOpen = false;
  49. }
  50. this.items = newItems;
  51. if (oldItemCount !== newItemCount) {
  52. const flowDirection = this.getFlowDirection(oldItemCount, newItemCount);
  53. this.itemCount = newItemCount;
  54. this.flowDirection = flowDirection;
  55. }
  56. };
  57. }
  58. async back() {
  59. const { items } = this;
  60. const lastItem = items[items.length - 1];
  61. if (!lastItem) {
  62. return;
  63. }
  64. const beforeBack = lastItem.beforeBack ? lastItem.beforeBack : () => Promise.resolve();
  65. return beforeBack.call(lastItem).then(() => {
  66. lastItem.remove();
  67. return lastItem;
  68. });
  69. }
  70. connectedCallback() {
  71. var _a;
  72. (_a = this.itemMutationObserver) === null || _a === void 0 ? void 0 : _a.observe(this.el, { childList: true, subtree: true });
  73. this.updateFlowProps();
  74. }
  75. disconnectedCallback() {
  76. var _a;
  77. (_a = this.itemMutationObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
  78. }
  79. handleItemBackClick() {
  80. this.back();
  81. }
  82. render() {
  83. const { flowDirection } = this;
  84. const frameDirectionClasses = {
  85. [CSS.frame]: true,
  86. [CSS.frameAdvancing]: flowDirection === "advancing",
  87. [CSS.frameRetreating]: flowDirection === "retreating"
  88. };
  89. return h("div", { class: frameDirectionClasses }, h("slot", null));
  90. }
  91. get el() {
  92. return this;
  93. }
  94. static get style() {
  95. return flowCss;
  96. }
  97. }, [1, "calcite-flow", {
  98. "flowDirection": [32],
  99. "itemCount": [32],
  100. "items": [32],
  101. "back": [64]
  102. }, [[0, "calciteFlowItemBackClick", "handleItemBackClick"], [0, "calcitePanelBackClick", "handleItemBackClick"]]]);
  103. function defineCustomElement$1() {
  104. if (typeof customElements === "undefined") {
  105. return;
  106. }
  107. const components = ["calcite-flow"];
  108. components.forEach((tagName) => {
  109. switch (tagName) {
  110. case "calcite-flow":
  111. if (!customElements.get(tagName)) {
  112. customElements.define(tagName, Flow);
  113. }
  114. break;
  115. }
  116. });
  117. }
  118. defineCustomElement$1();
  119. var CalciteFlow = Flow;
  120. var defineCustomElement = defineCustomElement$1;
  121. export {
  122. CalciteFlow,
  123. defineCustomElement
  124. };
  125. /*!
  126. * All material copyright ESRI, All Rights Reserved, unless otherwise specified.
  127. * See https://github.com/Esri/calcite-components/blob/master/LICENSE.md for details.
  128. * v1.0.0-beta.97
  129. */
  130. //# sourceMappingURL=calcite-flow-TYSEOOST.js.map