ion-loading.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. /*!
  2. * (C) Ionic http://ionicframework.com - MIT License
  3. */
  4. import { proxyCustomElement, HTMLElement, createEvent, h, Host } from '@stencil/core/internal/client';
  5. import { E as ENABLE_HTML_CONTENT_DEFAULT, a as sanitizeDOMString } from './config.js';
  6. import { r as raf } from './helpers.js';
  7. import { c as createLockController } from './lock-controller.js';
  8. import { d as createDelegateController, e as createTriggerController, B as BACKDROP, j as prepareOverlay, k as setOverlayId, f as present, g as dismiss, h as eventMethod } from './overlays.js';
  9. import { g as getClassMap } from './theme.js';
  10. import { c as config } from './index4.js';
  11. import { b as getIonMode } from './ionic-global.js';
  12. import { c as createAnimation } from './animation.js';
  13. import { d as defineCustomElement$3 } from './backdrop.js';
  14. import { d as defineCustomElement$2 } from './spinner.js';
  15. /**
  16. * iOS Loading Enter Animation
  17. */
  18. const iosEnterAnimation = (baseEl) => {
  19. const baseAnimation = createAnimation();
  20. const backdropAnimation = createAnimation();
  21. const wrapperAnimation = createAnimation();
  22. backdropAnimation
  23. .addElement(baseEl.querySelector('ion-backdrop'))
  24. .fromTo('opacity', 0.01, 'var(--backdrop-opacity)')
  25. .beforeStyles({
  26. 'pointer-events': 'none',
  27. })
  28. .afterClearStyles(['pointer-events']);
  29. wrapperAnimation.addElement(baseEl.querySelector('.loading-wrapper')).keyframes([
  30. { offset: 0, opacity: 0.01, transform: 'scale(1.1)' },
  31. { offset: 1, opacity: 1, transform: 'scale(1)' },
  32. ]);
  33. return baseAnimation
  34. .addElement(baseEl)
  35. .easing('ease-in-out')
  36. .duration(200)
  37. .addAnimation([backdropAnimation, wrapperAnimation]);
  38. };
  39. /**
  40. * iOS Loading Leave Animation
  41. */
  42. const iosLeaveAnimation = (baseEl) => {
  43. const baseAnimation = createAnimation();
  44. const backdropAnimation = createAnimation();
  45. const wrapperAnimation = createAnimation();
  46. backdropAnimation.addElement(baseEl.querySelector('ion-backdrop')).fromTo('opacity', 'var(--backdrop-opacity)', 0);
  47. wrapperAnimation.addElement(baseEl.querySelector('.loading-wrapper')).keyframes([
  48. { offset: 0, opacity: 0.99, transform: 'scale(1)' },
  49. { offset: 1, opacity: 0, transform: 'scale(0.9)' },
  50. ]);
  51. return baseAnimation
  52. .addElement(baseEl)
  53. .easing('ease-in-out')
  54. .duration(200)
  55. .addAnimation([backdropAnimation, wrapperAnimation]);
  56. };
  57. /**
  58. * Md Loading Enter Animation
  59. */
  60. const mdEnterAnimation = (baseEl) => {
  61. const baseAnimation = createAnimation();
  62. const backdropAnimation = createAnimation();
  63. const wrapperAnimation = createAnimation();
  64. backdropAnimation
  65. .addElement(baseEl.querySelector('ion-backdrop'))
  66. .fromTo('opacity', 0.01, 'var(--backdrop-opacity)')
  67. .beforeStyles({
  68. 'pointer-events': 'none',
  69. })
  70. .afterClearStyles(['pointer-events']);
  71. wrapperAnimation.addElement(baseEl.querySelector('.loading-wrapper')).keyframes([
  72. { offset: 0, opacity: 0.01, transform: 'scale(1.1)' },
  73. { offset: 1, opacity: 1, transform: 'scale(1)' },
  74. ]);
  75. return baseAnimation
  76. .addElement(baseEl)
  77. .easing('ease-in-out')
  78. .duration(200)
  79. .addAnimation([backdropAnimation, wrapperAnimation]);
  80. };
  81. /**
  82. * Md Loading Leave Animation
  83. */
  84. const mdLeaveAnimation = (baseEl) => {
  85. const baseAnimation = createAnimation();
  86. const backdropAnimation = createAnimation();
  87. const wrapperAnimation = createAnimation();
  88. backdropAnimation.addElement(baseEl.querySelector('ion-backdrop')).fromTo('opacity', 'var(--backdrop-opacity)', 0);
  89. wrapperAnimation.addElement(baseEl.querySelector('.loading-wrapper')).keyframes([
  90. { offset: 0, opacity: 0.99, transform: 'scale(1)' },
  91. { offset: 1, opacity: 0, transform: 'scale(0.9)' },
  92. ]);
  93. return baseAnimation
  94. .addElement(baseEl)
  95. .easing('ease-in-out')
  96. .duration(200)
  97. .addAnimation([backdropAnimation, wrapperAnimation]);
  98. };
  99. const loadingIosCss = ".sc-ion-loading-ios-h{--min-width:auto;--width:auto;--min-height:auto;--height:auto;-moz-osx-font-smoothing:grayscale;-webkit-font-smoothing:antialiased;left:0;right:0;top:0;bottom:0;display:-ms-flexbox;display:flex;position:fixed;-ms-flex-align:center;align-items:center;-ms-flex-pack:center;justify-content:center;outline:none;font-family:var(--ion-font-family, inherit);contain:strict;-ms-touch-action:none;touch-action:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;z-index:1001}.overlay-hidden.sc-ion-loading-ios-h{display:none}.loading-wrapper.sc-ion-loading-ios{display:-ms-flexbox;display:flex;-ms-flex-align:inherit;align-items:inherit;-ms-flex-pack:inherit;justify-content:inherit;width:var(--width);min-width:var(--min-width);max-width:var(--max-width);height:var(--height);min-height:var(--min-height);max-height:var(--max-height);background:var(--background);opacity:0;z-index:10}ion-spinner.sc-ion-loading-ios{color:var(--spinner-color)}.sc-ion-loading-ios-h{--background:var(--ion-overlay-background-color, var(--ion-color-step-100, var(--ion-background-color-step-100, #f9f9f9)));--max-width:270px;--max-height:90%;--spinner-color:var(--ion-color-step-600, var(--ion-text-color-step-400, #666666));--backdrop-opacity:var(--ion-backdrop-opacity, 0.3);color:var(--ion-text-color, #000);font-size:0.875rem}.loading-wrapper.sc-ion-loading-ios{border-radius:8px;-webkit-padding-start:34px;padding-inline-start:34px;-webkit-padding-end:34px;padding-inline-end:34px;padding-top:24px;padding-bottom:24px}@supports ((-webkit-backdrop-filter: blur(0)) or (backdrop-filter: blur(0))){.loading-translucent.sc-ion-loading-ios-h .loading-wrapper.sc-ion-loading-ios{background-color:rgba(var(--ion-background-color-rgb, 255, 255, 255), 0.8);-webkit-backdrop-filter:saturate(180%) blur(20px);backdrop-filter:saturate(180%) blur(20px)}}.loading-content.sc-ion-loading-ios{font-weight:bold}.loading-spinner.sc-ion-loading-ios+.loading-content.sc-ion-loading-ios{-webkit-margin-start:16px;margin-inline-start:16px}";
  100. const IonLoadingIosStyle0 = loadingIosCss;
  101. const loadingMdCss = ".sc-ion-loading-md-h{--min-width:auto;--width:auto;--min-height:auto;--height:auto;-moz-osx-font-smoothing:grayscale;-webkit-font-smoothing:antialiased;left:0;right:0;top:0;bottom:0;display:-ms-flexbox;display:flex;position:fixed;-ms-flex-align:center;align-items:center;-ms-flex-pack:center;justify-content:center;outline:none;font-family:var(--ion-font-family, inherit);contain:strict;-ms-touch-action:none;touch-action:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;z-index:1001}.overlay-hidden.sc-ion-loading-md-h{display:none}.loading-wrapper.sc-ion-loading-md{display:-ms-flexbox;display:flex;-ms-flex-align:inherit;align-items:inherit;-ms-flex-pack:inherit;justify-content:inherit;width:var(--width);min-width:var(--min-width);max-width:var(--max-width);height:var(--height);min-height:var(--min-height);max-height:var(--max-height);background:var(--background);opacity:0;z-index:10}ion-spinner.sc-ion-loading-md{color:var(--spinner-color)}.sc-ion-loading-md-h{--background:var(--ion-color-step-50, var(--ion-background-color-step-50, #f2f2f2));--max-width:280px;--max-height:90%;--spinner-color:var(--ion-color-primary, #0054e9);--backdrop-opacity:var(--ion-backdrop-opacity, 0.32);color:var(--ion-color-step-850, var(--ion-text-color-step-150, #262626));font-size:0.875rem}.loading-wrapper.sc-ion-loading-md{border-radius:2px;-webkit-padding-start:24px;padding-inline-start:24px;-webkit-padding-end:24px;padding-inline-end:24px;padding-top:24px;padding-bottom:24px;-webkit-box-shadow:0 16px 20px rgba(0, 0, 0, 0.4);box-shadow:0 16px 20px rgba(0, 0, 0, 0.4)}.loading-spinner.sc-ion-loading-md+.loading-content.sc-ion-loading-md{-webkit-margin-start:16px;margin-inline-start:16px}";
  102. const IonLoadingMdStyle0 = loadingMdCss;
  103. const Loading = /*@__PURE__*/ proxyCustomElement(class Loading extends HTMLElement {
  104. constructor() {
  105. super();
  106. this.__registerHost();
  107. this.didPresent = createEvent(this, "ionLoadingDidPresent", 7);
  108. this.willPresent = createEvent(this, "ionLoadingWillPresent", 7);
  109. this.willDismiss = createEvent(this, "ionLoadingWillDismiss", 7);
  110. this.didDismiss = createEvent(this, "ionLoadingDidDismiss", 7);
  111. this.didPresentShorthand = createEvent(this, "didPresent", 7);
  112. this.willPresentShorthand = createEvent(this, "willPresent", 7);
  113. this.willDismissShorthand = createEvent(this, "willDismiss", 7);
  114. this.didDismissShorthand = createEvent(this, "didDismiss", 7);
  115. this.delegateController = createDelegateController(this);
  116. this.lockController = createLockController();
  117. this.triggerController = createTriggerController();
  118. this.customHTMLEnabled = config.get('innerHTMLTemplatesEnabled', ENABLE_HTML_CONTENT_DEFAULT);
  119. this.presented = false;
  120. this.onBackdropTap = () => {
  121. this.dismiss(undefined, BACKDROP);
  122. };
  123. this.overlayIndex = undefined;
  124. this.delegate = undefined;
  125. this.hasController = false;
  126. this.keyboardClose = true;
  127. this.enterAnimation = undefined;
  128. this.leaveAnimation = undefined;
  129. this.message = undefined;
  130. this.cssClass = undefined;
  131. this.duration = 0;
  132. this.backdropDismiss = false;
  133. this.showBackdrop = true;
  134. this.spinner = undefined;
  135. this.translucent = false;
  136. this.animated = true;
  137. this.htmlAttributes = undefined;
  138. this.isOpen = false;
  139. this.trigger = undefined;
  140. }
  141. onIsOpenChange(newValue, oldValue) {
  142. if (newValue === true && oldValue === false) {
  143. this.present();
  144. }
  145. else if (newValue === false && oldValue === true) {
  146. this.dismiss();
  147. }
  148. }
  149. triggerChanged() {
  150. const { trigger, el, triggerController } = this;
  151. if (trigger) {
  152. triggerController.addClickListener(el, trigger);
  153. }
  154. }
  155. connectedCallback() {
  156. prepareOverlay(this.el);
  157. this.triggerChanged();
  158. }
  159. componentWillLoad() {
  160. var _a;
  161. if (this.spinner === undefined) {
  162. const mode = getIonMode(this);
  163. this.spinner = config.get('loadingSpinner', config.get('spinner', mode === 'ios' ? 'lines' : 'crescent'));
  164. }
  165. if (!((_a = this.htmlAttributes) === null || _a === void 0 ? void 0 : _a.id)) {
  166. setOverlayId(this.el);
  167. }
  168. }
  169. componentDidLoad() {
  170. /**
  171. * If loading indicator was rendered with isOpen="true"
  172. * then we should open loading indicator immediately.
  173. */
  174. if (this.isOpen === true) {
  175. raf(() => this.present());
  176. }
  177. /**
  178. * When binding values in frameworks such as Angular
  179. * it is possible for the value to be set after the Web Component
  180. * initializes but before the value watcher is set up in Stencil.
  181. * As a result, the watcher callback may not be fired.
  182. * We work around this by manually calling the watcher
  183. * callback when the component has loaded and the watcher
  184. * is configured.
  185. */
  186. this.triggerChanged();
  187. }
  188. disconnectedCallback() {
  189. this.triggerController.removeClickListener();
  190. }
  191. /**
  192. * Present the loading overlay after it has been created.
  193. */
  194. async present() {
  195. const unlock = await this.lockController.lock();
  196. await this.delegateController.attachViewToDom();
  197. await present(this, 'loadingEnter', iosEnterAnimation, mdEnterAnimation);
  198. if (this.duration > 0) {
  199. this.durationTimeout = setTimeout(() => this.dismiss(), this.duration + 10);
  200. }
  201. unlock();
  202. }
  203. /**
  204. * Dismiss the loading overlay after it has been presented.
  205. *
  206. * @param data Any data to emit in the dismiss events.
  207. * @param role The role of the element that is dismissing the loading.
  208. * This can be useful in a button handler for determining which button was
  209. * clicked to dismiss the loading.
  210. * Some examples include: ``"cancel"`, `"destructive"`, "selected"`, and `"backdrop"`.
  211. *
  212. * This is a no-op if the overlay has not been presented yet. If you want
  213. * to remove an overlay from the DOM that was never presented, use the
  214. * [remove](https://developer.mozilla.org/en-US/docs/Web/API/Element/remove) method.
  215. */
  216. async dismiss(data, role) {
  217. const unlock = await this.lockController.lock();
  218. if (this.durationTimeout) {
  219. clearTimeout(this.durationTimeout);
  220. }
  221. const dismissed = await dismiss(this, data, role, 'loadingLeave', iosLeaveAnimation, mdLeaveAnimation);
  222. if (dismissed) {
  223. this.delegateController.removeViewFromDom();
  224. }
  225. unlock();
  226. return dismissed;
  227. }
  228. /**
  229. * Returns a promise that resolves when the loading did dismiss.
  230. */
  231. onDidDismiss() {
  232. return eventMethod(this.el, 'ionLoadingDidDismiss');
  233. }
  234. /**
  235. * Returns a promise that resolves when the loading will dismiss.
  236. */
  237. onWillDismiss() {
  238. return eventMethod(this.el, 'ionLoadingWillDismiss');
  239. }
  240. renderLoadingMessage(msgId) {
  241. const { customHTMLEnabled, message } = this;
  242. if (customHTMLEnabled) {
  243. return h("div", { class: "loading-content", id: msgId, innerHTML: sanitizeDOMString(message) });
  244. }
  245. return (h("div", { class: "loading-content", id: msgId }, message));
  246. }
  247. render() {
  248. const { message, spinner, htmlAttributes, overlayIndex } = this;
  249. const mode = getIonMode(this);
  250. const msgId = `loading-${overlayIndex}-msg`;
  251. /**
  252. * If the message is defined, use that as the label.
  253. * Otherwise, don't set aria-labelledby.
  254. */
  255. const ariaLabelledBy = message !== undefined ? msgId : null;
  256. return (h(Host, Object.assign({ key: 'd6066c8b56b1fe4b597a243a7dab191ef0d21286', role: "dialog", "aria-modal": "true", "aria-labelledby": ariaLabelledBy, tabindex: "-1" }, htmlAttributes, { style: {
  257. zIndex: `${40000 + this.overlayIndex}`,
  258. }, onIonBackdropTap: this.onBackdropTap, class: Object.assign(Object.assign({}, getClassMap(this.cssClass)), { [mode]: true, 'overlay-hidden': true, 'loading-translucent': this.translucent }) }), h("ion-backdrop", { key: '2431eda00a2a3f510f5dfc39b7c7d47c056dfa3d', visible: this.showBackdrop, tappable: this.backdropDismiss }), h("div", { key: 'cf210aaf5e754e4eccdb49cf7ead4647b3f9b2d1', tabindex: "0", "aria-hidden": "true" }), h("div", { key: 'fa9375143d391656d70e181d25b952c77c2fc6ec', class: "loading-wrapper ion-overlay-wrapper" }, spinner && (h("div", { key: '8e4a4ed994f7f62df86b03696ac95162df41f52d', class: "loading-spinner" }, h("ion-spinner", { key: 'e5b323c272d365853ba92bd211e390b4fd4751d2', name: spinner, "aria-hidden": "true" }))), message !== undefined && this.renderLoadingMessage(msgId)), h("div", { key: 'cae35ec8c34800477bff3ebcec8010e632158233', tabindex: "0", "aria-hidden": "true" })));
  259. }
  260. get el() { return this; }
  261. static get watchers() { return {
  262. "isOpen": ["onIsOpenChange"],
  263. "trigger": ["triggerChanged"]
  264. }; }
  265. static get style() { return {
  266. ios: IonLoadingIosStyle0,
  267. md: IonLoadingMdStyle0
  268. }; }
  269. }, [34, "ion-loading", {
  270. "overlayIndex": [2, "overlay-index"],
  271. "delegate": [16],
  272. "hasController": [4, "has-controller"],
  273. "keyboardClose": [4, "keyboard-close"],
  274. "enterAnimation": [16],
  275. "leaveAnimation": [16],
  276. "message": [1],
  277. "cssClass": [1, "css-class"],
  278. "duration": [2],
  279. "backdropDismiss": [4, "backdrop-dismiss"],
  280. "showBackdrop": [4, "show-backdrop"],
  281. "spinner": [1025],
  282. "translucent": [4],
  283. "animated": [4],
  284. "htmlAttributes": [16],
  285. "isOpen": [4, "is-open"],
  286. "trigger": [1],
  287. "present": [64],
  288. "dismiss": [64],
  289. "onDidDismiss": [64],
  290. "onWillDismiss": [64]
  291. }, undefined, {
  292. "isOpen": ["onIsOpenChange"],
  293. "trigger": ["triggerChanged"]
  294. }]);
  295. function defineCustomElement$1() {
  296. if (typeof customElements === "undefined") {
  297. return;
  298. }
  299. const components = ["ion-loading", "ion-backdrop", "ion-spinner"];
  300. components.forEach(tagName => { switch (tagName) {
  301. case "ion-loading":
  302. if (!customElements.get(tagName)) {
  303. customElements.define(tagName, Loading);
  304. }
  305. break;
  306. case "ion-backdrop":
  307. if (!customElements.get(tagName)) {
  308. defineCustomElement$3();
  309. }
  310. break;
  311. case "ion-spinner":
  312. if (!customElements.get(tagName)) {
  313. defineCustomElement$2();
  314. }
  315. break;
  316. } });
  317. }
  318. const IonLoading = Loading;
  319. const defineCustomElement = defineCustomElement$1;
  320. export { IonLoading, defineCustomElement };