mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-11-09 16:16:41 +08:00
refactor(all): updating to newest stencil apis (#18578)
* chore(): update ionicons * refactor(all): updating to newest stencil apis * fix lint issues * more changes * moreee * fix treeshaking * fix config * fix checkbox * fix stuff * chore(): update ionicons * fix linting errors
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
import { Component, ComponentInterface, Element, Event, EventEmitter, Listen, Method, Prop, QueueApi } from '@stencil/core';
|
||||
import { Component, ComponentInterface, Element, Event, EventEmitter, Listen, Method, Prop } from '@stencil/core';
|
||||
|
||||
import { BackButtonEvent, Config, RouteChain, RouterDirection, RouterEventDetail } from '../../interface';
|
||||
import { BackButtonEvent, RouteChain, RouterDirection, RouterEventDetail } from '../../interface';
|
||||
import { debounce } from '../../utils/helpers';
|
||||
|
||||
import { ROUTER_INTENT_BACK, ROUTER_INTENT_FORWARD, ROUTER_INTENT_NONE } from './utils/constants';
|
||||
@ -23,10 +23,6 @@ export class Router implements ComponentInterface {
|
||||
|
||||
@Element() el!: HTMLElement;
|
||||
|
||||
@Prop({ context: 'config' }) config!: Config;
|
||||
@Prop({ context: 'queue' }) queue!: QueueApi;
|
||||
@Prop({ context: 'window' }) win!: Window;
|
||||
|
||||
/**
|
||||
* By default `ion-router` will match the routes at the root path ("/").
|
||||
* That can be changed when
|
||||
@ -62,15 +58,15 @@ export class Router implements ComponentInterface {
|
||||
|
||||
async componentWillLoad() {
|
||||
console.debug('[ion-router] router will load');
|
||||
await waitUntilNavNode(this.win);
|
||||
await waitUntilNavNode();
|
||||
console.debug('[ion-router] found nav');
|
||||
|
||||
await this.onRoutesChanged();
|
||||
}
|
||||
|
||||
componentDidLoad() {
|
||||
this.win.addEventListener('ionRouteRedirectChanged', debounce(this.onRedirectChanged.bind(this), 10));
|
||||
this.win.addEventListener('ionRouteDataChanged', debounce(this.onRoutesChanged.bind(this), 100));
|
||||
window.addEventListener('ionRouteRedirectChanged', debounce(this.onRedirectChanged.bind(this), 10));
|
||||
window.addEventListener('ionRouteDataChanged', debounce(this.onRoutesChanged.bind(this), 100));
|
||||
}
|
||||
|
||||
@Listen('popstate', { target: 'window' })
|
||||
@ -95,7 +91,7 @@ export class Router implements ComponentInterface {
|
||||
@Method()
|
||||
push(url: string, direction: RouterDirection = 'forward') {
|
||||
if (url.startsWith('.')) {
|
||||
url = (new URL(url, this.win.location.href)).pathname;
|
||||
url = (new URL(url, window.location.href)).pathname;
|
||||
}
|
||||
console.debug('[ion-router] URL pushed -> updating nav', url, direction);
|
||||
|
||||
@ -109,7 +105,7 @@ export class Router implements ComponentInterface {
|
||||
*/
|
||||
@Method()
|
||||
back() {
|
||||
this.win.history.back();
|
||||
window.history.back();
|
||||
return Promise.resolve(this.waitPromise);
|
||||
}
|
||||
|
||||
@ -129,7 +125,7 @@ export class Router implements ComponentInterface {
|
||||
console.warn('[ion-router] router is busy, navChanged was cancelled');
|
||||
return false;
|
||||
}
|
||||
const { ids, outlet } = await readNavState(this.win.document.body);
|
||||
const { ids, outlet } = await readNavState(window.document.body);
|
||||
const routes = readRoutes(this.el);
|
||||
const chain = routerIDsToChain(ids, routes);
|
||||
if (!chain) {
|
||||
@ -162,7 +158,7 @@ export class Router implements ComponentInterface {
|
||||
}
|
||||
|
||||
private historyDirection() {
|
||||
const win = this.win;
|
||||
const win = window;
|
||||
|
||||
if (win.history.state === null) {
|
||||
this.state++;
|
||||
@ -207,7 +203,7 @@ export class Router implements ComponentInterface {
|
||||
}
|
||||
|
||||
// write DOM give
|
||||
return this.safeWriteNavState(this.win.document.body, chain, direction, path, redirectFrom);
|
||||
return this.safeWriteNavState(document.body, chain, direction, path, redirectFrom);
|
||||
}
|
||||
|
||||
private async safeWriteNavState(
|
||||
@ -270,11 +266,11 @@ export class Router implements ComponentInterface {
|
||||
|
||||
private setPath(path: string[], direction: RouterDirection) {
|
||||
this.state++;
|
||||
writePath(this.win.history, this.root, this.useHash, path, direction, this.state);
|
||||
writePath(window.history, this.root, this.useHash, path, direction, this.state);
|
||||
}
|
||||
|
||||
private getPath(): string[] | null {
|
||||
return readPath(this.win.location, this.root, this.useHash);
|
||||
return readPath(window.location, this.root, this.useHash);
|
||||
}
|
||||
|
||||
private routeChangeEvent(path: string[], redirectFromPath: string[] | null): RouterEventDetail | null {
|
||||
|
||||
@ -67,12 +67,12 @@ export async function readNavState(root: HTMLElement | undefined) {
|
||||
return { ids, outlet };
|
||||
}
|
||||
|
||||
export function waitUntilNavNode(win: Window) {
|
||||
if (searchNavNode(win.document.body)) {
|
||||
export function waitUntilNavNode() {
|
||||
if (searchNavNode(document.body)) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
return new Promise(resolve => {
|
||||
win.addEventListener('ionNavWillLoad', resolve, { once: true });
|
||||
window.addEventListener('ionNavWillLoad', resolve, { once: true });
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user