ion-split-pane.cjs.entry.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*!
  2. * (C) Ionic http://ionicframework.com - MIT License
  3. */
  4. 'use strict';
  5. Object.defineProperty(exports, '__esModule', { value: true });
  6. const index = require('./index-2e236a04.js');
  7. const index$1 = require('./index-cc858e97.js');
  8. const ionicGlobal = require('./ionic-global-6dea5a96.js');
  9. const splitPaneIosCss = ":host{--side-width:100%;left:0;right:0;top:0;bottom:0;display:-ms-flexbox;display:flex;position:absolute;-ms-flex-direction:row;flex-direction:row;-ms-flex-wrap:nowrap;flex-wrap:nowrap;contain:strict}:host(.split-pane-visible) ::slotted(.split-pane-main){left:0;right:0;top:0;bottom:0;position:relative;-ms-flex:1;flex:1;-webkit-box-shadow:none;box-shadow:none;overflow:hidden;z-index:0}::slotted(.split-pane-side:not(ion-menu)){display:none}:host{--border:0.55px solid var(--ion-item-border-color, var(--ion-border-color, var(--ion-color-step-250, var(--ion-background-color-step-250, #c8c7cc))));--side-min-width:270px;--side-max-width:28%}";
  10. const IonSplitPaneIosStyle0 = splitPaneIosCss;
  11. const splitPaneMdCss = ":host{--side-width:100%;left:0;right:0;top:0;bottom:0;display:-ms-flexbox;display:flex;position:absolute;-ms-flex-direction:row;flex-direction:row;-ms-flex-wrap:nowrap;flex-wrap:nowrap;contain:strict}:host(.split-pane-visible) ::slotted(.split-pane-main){left:0;right:0;top:0;bottom:0;position:relative;-ms-flex:1;flex:1;-webkit-box-shadow:none;box-shadow:none;overflow:hidden;z-index:0}::slotted(.split-pane-side:not(ion-menu)){display:none}:host{--border:1px solid var(--ion-item-border-color, var(--ion-border-color, var(--ion-color-step-150, var(--ion-background-color-step-150, rgba(0, 0, 0, 0.13)))));--side-min-width:270px;--side-max-width:28%}";
  12. const IonSplitPaneMdStyle0 = splitPaneMdCss;
  13. // TODO(FW-2832): types
  14. const SPLIT_PANE_MAIN = 'split-pane-main';
  15. const SPLIT_PANE_SIDE = 'split-pane-side';
  16. const QUERY = {
  17. xs: '(min-width: 0px)',
  18. sm: '(min-width: 576px)',
  19. md: '(min-width: 768px)',
  20. lg: '(min-width: 992px)',
  21. xl: '(min-width: 1200px)',
  22. never: '',
  23. };
  24. const SplitPane = class {
  25. constructor(hostRef) {
  26. index.registerInstance(this, hostRef);
  27. this.ionSplitPaneVisible = index.createEvent(this, "ionSplitPaneVisible", 7);
  28. this.visible = false;
  29. this.contentId = undefined;
  30. this.disabled = false;
  31. this.when = QUERY['lg'];
  32. }
  33. visibleChanged(visible) {
  34. this.ionSplitPaneVisible.emit({ visible });
  35. }
  36. /**
  37. * @internal
  38. */
  39. async isVisible() {
  40. return Promise.resolve(this.visible);
  41. }
  42. async connectedCallback() {
  43. // TODO: connectedCallback is fired in CE build
  44. // before WC is defined. This needs to be fixed in Stencil.
  45. if (typeof customElements !== 'undefined' && customElements != null) {
  46. await customElements.whenDefined('ion-split-pane');
  47. }
  48. this.styleMainElement();
  49. this.updateState();
  50. }
  51. disconnectedCallback() {
  52. if (this.rmL) {
  53. this.rmL();
  54. this.rmL = undefined;
  55. }
  56. }
  57. updateState() {
  58. if (this.rmL) {
  59. this.rmL();
  60. this.rmL = undefined;
  61. }
  62. // Check if the split-pane is disabled
  63. if (this.disabled) {
  64. this.visible = false;
  65. return;
  66. }
  67. // When query is a boolean
  68. const query = this.when;
  69. if (typeof query === 'boolean') {
  70. this.visible = query;
  71. return;
  72. }
  73. // When query is a string, let's find first if it is a shortcut
  74. const mediaQuery = QUERY[query] || query;
  75. // Media query is empty or null, we hide it
  76. if (mediaQuery.length === 0) {
  77. this.visible = false;
  78. return;
  79. }
  80. // Listen on media query
  81. const callback = (q) => {
  82. this.visible = q.matches;
  83. };
  84. const mediaList = window.matchMedia(mediaQuery);
  85. // TODO FW-5869
  86. mediaList.addListener(callback);
  87. this.rmL = () => mediaList.removeListener(callback);
  88. this.visible = mediaList.matches;
  89. }
  90. /**
  91. * Attempt to find the main content
  92. * element inside of the split pane.
  93. * If found, set it as the main node.
  94. *
  95. * We assume that the main node
  96. * is available in the DOM on split
  97. * pane load.
  98. */
  99. styleMainElement() {
  100. const contentId = this.contentId;
  101. const children = this.el.children;
  102. const nu = this.el.childElementCount;
  103. let foundMain = false;
  104. for (let i = 0; i < nu; i++) {
  105. const child = children[i];
  106. const isMain = contentId !== undefined && child.id === contentId;
  107. if (isMain) {
  108. if (foundMain) {
  109. index$1.printIonWarning('[ion-split-pane] - Cannot have more than one main node.');
  110. return;
  111. }
  112. else {
  113. setPaneClass(child, isMain);
  114. foundMain = true;
  115. }
  116. }
  117. }
  118. if (!foundMain) {
  119. index$1.printIonWarning('[ion-split-pane] - Does not have a specified main node.');
  120. }
  121. }
  122. render() {
  123. const mode = ionicGlobal.getIonMode(this);
  124. return (index.h(index.Host, { key: '098801b5a318e2fc6913fb0d9079b1552927b99b', class: {
  125. [mode]: true,
  126. // Used internally for styling
  127. [`split-pane-${mode}`]: true,
  128. 'split-pane-visible': this.visible,
  129. } }, index.h("slot", { key: '8cbc6a942ecba54fc3c62027d46917db067b65c8' })));
  130. }
  131. get el() { return index.getElement(this); }
  132. static get watchers() { return {
  133. "visible": ["visibleChanged"],
  134. "disabled": ["updateState"],
  135. "when": ["updateState"]
  136. }; }
  137. };
  138. const setPaneClass = (el, isMain) => {
  139. let toAdd;
  140. let toRemove;
  141. if (isMain) {
  142. toAdd = SPLIT_PANE_MAIN;
  143. toRemove = SPLIT_PANE_SIDE;
  144. }
  145. else {
  146. toAdd = SPLIT_PANE_SIDE;
  147. toRemove = SPLIT_PANE_MAIN;
  148. }
  149. const classList = el.classList;
  150. classList.add(toAdd);
  151. classList.remove(toRemove);
  152. };
  153. SplitPane.style = {
  154. ios: IonSplitPaneIosStyle0,
  155. md: IonSplitPaneMdStyle0
  156. };
  157. exports.ion_split_pane = SplitPane;