Skip to content

Commit a65d897

Browse files
authored
refactor(): deprecate web component controllers (#19109)
1 parent 3e63b3c commit a65d897

File tree

71 files changed

+1446
-1472
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+1446
-1472
lines changed
Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,18 @@
1-
import { DOCUMENT } from '@angular/common';
2-
import { Inject, Injectable } from '@angular/core';
1+
import { Injectable } from '@angular/core';
2+
import { menuController } from '@ionic/core';
33

4-
import { proxyMethod } from '../util/util';
5-
6-
const CTRL = 'ion-menu-controller';
74
@Injectable({
85
providedIn: 'root',
96
})
107
export class MenuController {
118

12-
constructor(@Inject(DOCUMENT) private doc: any) {
13-
}
14-
159
/**
1610
* Programmatically open the Menu.
1711
* @param [menuId] Optionally get the menu by its id, or side.
1812
* @return returns a promise when the menu is fully opened
1913
*/
20-
open(menuId?: string): Promise<boolean> {
21-
return proxyMethod(CTRL, this.doc, 'open', menuId);
14+
open(menuId?: string) {
15+
return menuController.open(menuId);
2216
}
2317

2418
/**
@@ -28,8 +22,8 @@ export class MenuController {
2822
* @param [menuId] Optionally get the menu by its id, or side.
2923
* @return returns a promise when the menu is fully closed
3024
*/
31-
close(menuId?: string): Promise<boolean> {
32-
return proxyMethod(CTRL, this.doc, 'close', menuId);
25+
close(menuId?: string) {
26+
return menuController.close(menuId);
3327
}
3428

3529
/**
@@ -38,8 +32,8 @@ export class MenuController {
3832
* @param [menuId] Optionally get the menu by its id, or side.
3933
* @return returns a promise when the menu has been toggled
4034
*/
41-
toggle(menuId?: string): Promise<boolean> {
42-
return proxyMethod(CTRL, this.doc, 'toggle', menuId);
35+
toggle(menuId?: string) {
36+
return menuController.toggle(menuId);
4337
}
4438

4539
/**
@@ -50,8 +44,8 @@ export class MenuController {
5044
* @param [menuId] Optionally get the menu by its id, or side.
5145
* @return Returns the instance of the menu, which is useful for chaining.
5246
*/
53-
enable(shouldEnable: boolean, menuId?: string): Promise<HTMLIonMenuElement> {
54-
return proxyMethod(CTRL, this.doc, 'enable', shouldEnable, menuId);
47+
enable(shouldEnable: boolean, menuId?: string) {
48+
return menuController.enable(shouldEnable, menuId);
5549
}
5650

5751
/**
@@ -61,7 +55,7 @@ export class MenuController {
6155
* @return Returns the instance of the menu, which is useful for chaining.
6256
* @deprecated Use swipeGesture() instead
6357
*/
64-
swipeEnable(shouldEnable: boolean, menuId?: string): Promise<HTMLIonMenuElement> {
58+
swipeEnable(shouldEnable: boolean, menuId?: string) {
6559
console.warn('MenuController.swipeEnable is deprecated. Use MenuController.swipeGesture() instead');
6660
return this.swipeGesture(shouldEnable, menuId);
6761
}
@@ -72,25 +66,25 @@ export class MenuController {
7266
* @param [menuId] Optionally get the menu by its id, or side.
7367
* @return Returns the instance of the menu, which is useful for chaining.
7468
*/
75-
swipeGesture(shouldEnable: boolean, menuId?: string): Promise<HTMLIonMenuElement> {
76-
return proxyMethod(CTRL, this.doc, 'swipeGesture', shouldEnable, menuId);
69+
swipeGesture(shouldEnable: boolean, menuId?: string) {
70+
return menuController.swipeGesture(shouldEnable, menuId);
7771
}
7872

7973
/**
8074
* @param [menuId] Optionally get the menu by its id, or side.
8175
* @return Returns true if the specified menu is currently open, otherwise false.
8276
* If the menuId is not specified, it returns true if ANY menu is currenly open.
8377
*/
84-
isOpen(menuId?: string): Promise<boolean> {
85-
return proxyMethod(CTRL, this.doc, 'isOpen', menuId);
78+
isOpen(menuId?: string) {
79+
return menuController.isOpen(menuId);
8680
}
8781

8882
/**
8983
* @param [menuId] Optionally get the menu by its id, or side.
9084
* @return Returns true if the menu is currently enabled, otherwise false.
9185
*/
92-
isEnabled(menuId?: string): Promise<boolean> {
93-
return proxyMethod(CTRL, this.doc, 'isEnabled', menuId);
86+
isEnabled(menuId?: string) {
87+
return menuController.isEnabled(menuId);
9488
}
9589

9690
/**
@@ -102,21 +96,21 @@ export class MenuController {
10296
* @param [menuId] Optionally get the menu by its id, or side.
10397
* @return Returns the instance of the menu if found, otherwise `null`.
10498
*/
105-
get(menuId?: string): Promise<HTMLIonMenuElement> {
106-
return proxyMethod(CTRL, this.doc, 'get', menuId);
99+
get(menuId?: string) {
100+
return menuController.get(menuId);
107101
}
108102

109103
/**
110104
* @return Returns the instance of the menu already opened, otherwise `null`.
111105
*/
112-
getOpen(): Promise<HTMLIonMenuElement> {
113-
return proxyMethod(CTRL, this.doc, 'getOpen');
106+
getOpen() {
107+
return menuController.getOpen();
114108
}
115109

116110
/**
117111
* @return Returns an array of all menu instances.
118112
*/
119-
getMenus(): Promise<HTMLIonMenuElement[]> {
120-
return proxyMethod(CTRL, this.doc, 'getMenus');
113+
getMenus() {
114+
return menuController.getMenus();
121115
}
122116
}

angular/src/util/util.ts

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { HTMLStencilElement } from '../types/interfaces';
21

32
declare const __zone_symbol__requestAnimationFrame: any;
43
declare const requestAnimationFrame: any;
@@ -12,18 +11,3 @@ export const raf = (h: any) => {
1211
}
1312
return setTimeout(h);
1413
};
15-
16-
export const proxyMethod = (ctrlName: string, doc: Document, methodName: string, ...args: any[]) => {
17-
const controller = ensureElementInBody(ctrlName, doc);
18-
return controller.componentOnReady()
19-
.then(() => (controller as any)[methodName].apply(controller, args));
20-
};
21-
22-
export const ensureElementInBody = (elementName: string, doc: Document) => {
23-
let element = doc.querySelector(elementName);
24-
if (!element) {
25-
element = doc.createElement(elementName);
26-
doc.body.appendChild(element);
27-
}
28-
return element as HTMLStencilElement;
29-
};

core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"tslib": "^1.10.0"
3535
},
3636
"devDependencies": {
37-
"@stencil/core": "1.3.1",
37+
"@stencil/core": "1.3.2",
3838
"@stencil/sass": "1.0.1",
3939
"@types/jest": "24.0.17",
4040
"@types/node": "12.7.1",

core/src/components.d.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import {
3131
ItemReorderEventDetail,
3232
LoadingOptions,
3333
MenuChangeEventDetail,
34-
MenuControllerI,
3534
MenuI,
3635
ModalOptions,
3736
NavComponent,
@@ -1378,7 +1377,6 @@ export namespace Components {
13781377
'type': 'submit' | 'reset' | 'button';
13791378
}
13801379
interface IonMenuController {
1381-
'_getInstance': () => Promise<MenuControllerI>;
13821380
/**
13831381
* Close the menu. If a menu is specified, it will close that menu. If no menu is specified, then it will close any menu that is open. If it does not find any open menus, it will return `false`.
13841382
* @param menu The menuId or side of the menu to close.

core/src/components/action-sheet-controller/action-sheet-controller.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, ComponentInterface, Method } from '@stencil/core';
1+
import { Build, Component, ComponentInterface, Method } from '@stencil/core';
22

33
import { ActionSheetOptions, OverlayController } from '../../interface';
44
import { createOverlay, dismissOverlay, getOverlay } from '../../utils/overlays';
@@ -8,6 +8,14 @@ import { createOverlay, dismissOverlay, getOverlay } from '../../utils/overlays'
88
})
99
export class ActionSheetController implements ComponentInterface, OverlayController {
1010

11+
constructor() {
12+
if (Build.isDev) {
13+
console.warn(`[DEPRECATED][ion-action-sheet-controller] Use the actionSheetController export from @ionic/core:
14+
import { actionSheetController } from '@ionic/core';
15+
const actionSheet = await actionSheetController.create({...});`);
16+
}
17+
}
18+
1119
/**
1220
* Create an action sheet overlay with action sheet options.
1321
*

core/src/components/action-sheet/action-sheet.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Component, ComponentInterface, Element, Event, EventEmitter, Host, Meth
22

33
import { getIonMode } from '../../global/ionic-global';
44
import { ActionSheetButton, AnimationBuilder, CssClassMap, OverlayEventDetail, OverlayInterface } from '../../interface';
5-
import { BACKDROP, dismiss, eventMethod, isCancel, present, safeCall } from '../../utils/overlays';
5+
import { BACKDROP, dismiss, eventMethod, isCancel, prepareOverlay, present, safeCall } from '../../utils/overlays';
66
import { getClassMap } from '../../utils/theme';
77

88
import { iosEnterAnimation } from './animations/ios.enter';
@@ -27,7 +27,7 @@ export class ActionSheet implements ComponentInterface, OverlayInterface {
2727
animation?: any;
2828
mode = getIonMode(this);
2929

30-
@Element() el!: HTMLElement;
30+
@Element() el!: HTMLIonActionSheetElement;
3131

3232
/** @internal */
3333
@Prop() overlayIndex!: number;
@@ -113,6 +113,10 @@ export class ActionSheet implements ComponentInterface, OverlayInterface {
113113
return present(this, 'actionSheetEnter', iosEnterAnimation, mdEnterAnimation);
114114
}
115115

116+
constructor() {
117+
prepareOverlay(this.el);
118+
}
119+
116120
/**
117121
* Dismiss the action sheet overlay after it has been presented.
118122
*

core/src/components/action-sheet/readme.md

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -79,45 +79,45 @@ export class ActionSheetExample {
7979

8080
```javascript
8181
async function presentActionSheet() {
82-
const actionSheetController = document.querySelector('ion-action-sheet-controller');
83-
84-
const actionSheet = await actionSheetController.create({
85-
header: "Albums",
86-
buttons: [{
87-
text: 'Delete',
88-
role: 'destructive',
89-
icon: 'trash',
90-
handler: () => {
91-
console.log('Delete clicked');
92-
}
93-
}, {
94-
text: 'Share',
95-
icon: 'share',
96-
handler: () => {
97-
console.log('Share clicked');
98-
}
99-
}, {
100-
text: 'Play (open modal)',
101-
icon: 'arrow-dropright-circle',
102-
handler: () => {
103-
console.log('Play clicked');
104-
}
105-
}, {
106-
text: 'Favorite',
107-
icon: 'heart',
108-
handler: () => {
109-
console.log('Favorite clicked');
110-
}
111-
}, {
112-
text: 'Cancel',
113-
icon: 'close',
114-
role: 'cancel',
115-
handler: () => {
116-
console.log('Cancel clicked');
117-
}
118-
}]
119-
});
120-
await actionSheet.present();
82+
83+
const actionSheet = document.createElement('ion-action-sheet');
84+
85+
actionSheet.header = "Albums";
86+
actionSheet.buttons = [{
87+
text: 'Delete',
88+
role: 'destructive',
89+
icon: 'trash',
90+
handler: () => {
91+
console.log('Delete clicked');
92+
}
93+
}, {
94+
text: 'Share',
95+
icon: 'share',
96+
handler: () => {
97+
console.log('Share clicked');
98+
}
99+
}, {
100+
text: 'Play (open modal)',
101+
icon: 'arrow-dropright-circle',
102+
handler: () => {
103+
console.log('Play clicked');
104+
}
105+
}, {
106+
text: 'Favorite',
107+
icon: 'heart',
108+
handler: () => {
109+
console.log('Favorite clicked');
110+
}
111+
}, {
112+
text: 'Cancel',
113+
icon: 'close',
114+
role: 'cancel',
115+
handler: () => {
116+
console.log('Cancel clicked');
117+
}
118+
}];
119+
document.body.appendChild(actionSheet);
120+
return actionSheet.present();
121121
}
122122
```
123123

0 commit comments

Comments
 (0)