refactor(): deprecate web component controllers (#19109)

This commit is contained in:
Manu MA
2019-08-27 14:00:45 +02:00
committed by GitHub
parent 3e63b3c2c4
commit a65d897214
71 changed files with 1435 additions and 1461 deletions

View File

@ -28,21 +28,25 @@ export const pickerController = /*@__PURE__*/createController<PickerOptions, HTM
export const popoverController = /*@__PURE__*/createController<PopoverOptions, HTMLIonPopoverElement>('ion-popover');
export const toastController = /*@__PURE__*/createController<ToastOptions, HTMLIonToastElement>('ion-toast');
export const prepareOverlay = <T extends HTMLIonOverlayElement>(el: T) => {
const doc = document;
connectListeners(doc);
const overlayIndex = lastId++;
el.overlayIndex = overlayIndex;
if (!el.hasAttribute('id')) {
el.id = `ion-overlay-${overlayIndex}`;
}
};
export const createOverlay = <T extends HTMLIonOverlayElement>(tagName: string, opts: object | undefined): Promise<T> => {
return customElements.whenDefined(tagName).then(() => {
const doc = document;
const element = doc.createElement(tagName) as HTMLIonOverlayElement;
connectListeners(doc);
element.classList.add('overlay-hidden');
// convert the passed in overlay options into props
// that get passed down into the new overlay
Object.assign(element, opts);
element.classList.add('overlay-hidden');
const overlayIndex = lastId++;
element.overlayIndex = overlayIndex;
if (!element.hasAttribute('id')) {
element.id = `ion-overlay-${overlayIndex}`;
}
// append the overlay element to the document body
getAppRoot(doc).appendChild(element);
@ -95,13 +99,12 @@ export const dismissOverlay = (doc: Document, data: any, role: string | undefine
return overlay.dismiss(data, role);
};
export const getOverlays = (doc: Document, overlayTag?: string): HTMLIonOverlayElement[] => {
const overlays = (Array.from(getAppRoot(doc).children) as HTMLIonOverlayElement[]).filter(c => c.overlayIndex > 0);
if (overlayTag === undefined) {
return overlays;
export const getOverlays = (doc: Document, selector?: string): HTMLIonOverlayElement[] => {
if (selector === undefined) {
selector = 'ion-alert,ion-action-sheet,ion-loading,ion-modal,ion-picker,ion-popover,ion-toast';
}
overlayTag = overlayTag.toUpperCase();
return overlays.filter(c => c.tagName === overlayTag);
return (Array.from(doc.querySelectorAll(selector)) as HTMLIonOverlayElement[])
.filter(c => c.overlayIndex > 0);
};
export const getOverlay = (doc: Document, overlayTag?: string, id?: string): HTMLIonOverlayElement | undefined => {