diff --git a/core/src/global/config.ts b/core/src/global/config.ts index 44c2d21fa4..37b994351f 100644 --- a/core/src/global/config.ts +++ b/core/src/global/config.ts @@ -1,52 +1,4 @@ -import { Mode } from '../interface'; - -export interface IonicConfig { - /** - * The mode determines which platform styles to use. - * Possible values are: `"ios"` or `"md"`. - */ - mode?: Mode; - persistConfig?: boolean; - - inputShims?: boolean; - backButtonIcon?: string; - backButtonText?: string; - spinner?: string; - loadingSpinner?: string; - menuIcon?: string; - animated?: boolean; - pickerSpinner?: string; - refreshingIcon?: string; - refreshingSpinner?: string; - menuType?: string; - scrollPadding?: string; - inputBlurring?: string; - scrollAssist?: boolean; - hideCaretOnScroll?: string; - infiniteLoadingSpinner?: string; - keyboardHeight?: number; - swipeBackEnabled?: boolean; - - tabbarPlacement?: string; - tabbarLayout?: string; - tabbarHighlight?: boolean; - - actionSheetEnter?: string; - alertEnter?: string; - loadingEnter?: string; - modalEnter?: string; - popoverEnter?: string; - toastEnter?: string; - pickerEnter?: string; - - actionSheetLeave?: string; - alertLeave?: string; - loadingLeave?: string; - modalLeave?: string; - popoverLeave?: string; - toastLeave?: string; - pickerLeave?: string; -} +import { IonicConfig } from '../interface'; export class Config { @@ -81,3 +33,43 @@ export class Config { this.m.set(key, value); } } + +const IONIC_PREFIX = 'ionic:'; +const IONIC_SESSION_KEY = 'ionic-persist-config'; + +export function configFromSession(): any { + try { + const configStr = window.sessionStorage.getItem(IONIC_SESSION_KEY); + return configStr !== null ? JSON.parse(configStr) : {}; + } catch { + return {}; + } +} + +export function saveConfig(config: any) { + try { + window.sessionStorage.setItem(IONIC_SESSION_KEY, JSON.stringify(config)); + } catch { + return; + } +} + +export function configFromURL() { + const config: any = {}; + const win = window; + win.location.search.slice(1) + .split('&') + .map(entry => entry.split('=')) + .map(([key, value]) => [decodeURIComponent(key), decodeURIComponent(value)]) + .filter(([key]) => startsWith(key, IONIC_PREFIX)) + .map(([key, value]) => [key.slice(IONIC_PREFIX.length), value]) + .forEach(([key, value]) => { + config[key] = value; + }); + + return config; +} + +function startsWith(input: string, search: string): boolean { + return input.substr(0, search.length) === search; +} diff --git a/core/src/global/ionic-global.ts b/core/src/global/ionic-global.ts index e2034576e3..1858e2b140 100644 --- a/core/src/global/ionic-global.ts +++ b/core/src/global/ionic-global.ts @@ -1,9 +1,8 @@ import 'ionicons'; -import { configFromSession, configFromURL, saveConfig } from '../utils/config'; import { isPlatform, setupPlatforms } from '../utils/platform'; -import { Config } from './config'; +import { Config, configFromSession, configFromURL, saveConfig } from './config'; const win = window; const Ionic = (win as any)['Ionic'] = (win as any)['Ionic'] || {}; diff --git a/core/src/index.ts b/core/src/index.ts index 08bb5550e5..c8883f2599 100644 --- a/core/src/index.ts +++ b/core/src/index.ts @@ -9,8 +9,5 @@ export const enum ViewLifecycle { } // util functions -export * from './utils/helpers'; -export * from './utils/haptic'; -export * from './utils/framework-delegate'; export * from './utils/platform'; export * from './utils/config'; diff --git a/core/src/interface.d.ts b/core/src/interface.d.ts index 27b889e25d..88bafe1816 100644 --- a/core/src/interface.d.ts +++ b/core/src/interface.d.ts @@ -44,6 +44,11 @@ export type BackButtonEvent = CustomEvent<{ register(priority: number, handler: () => Promise | void): void; }> +export interface FrameworkDelegate { + attachViewToDom(container: any, component: any, propsOrDataObj?: any, cssClasses?: string[]): Promise; + removeViewFromDom(container: any, component: any): Promise; +} + declare global { interface StencilGlobalHTMLAttributes { // for ion-menu and ion-split-pane diff --git a/core/src/utils/config.ts b/core/src/utils/config.ts index 3561c07278..34a56cca3a 100644 --- a/core/src/utils/config.ts +++ b/core/src/utils/config.ts @@ -1,4 +1,52 @@ -import { IonicConfig } from '../interface'; +import { Mode } from '../interface'; + +export interface IonicConfig { + /** + * The mode determines which platform styles to use. + * Possible values are: `"ios"` or `"md"`. + */ + mode?: Mode; + persistConfig?: boolean; + + inputShims?: boolean; + backButtonIcon?: string; + backButtonText?: string; + spinner?: string; + loadingSpinner?: string; + menuIcon?: string; + animated?: boolean; + pickerSpinner?: string; + refreshingIcon?: string; + refreshingSpinner?: string; + menuType?: string; + scrollPadding?: string; + inputBlurring?: string; + scrollAssist?: boolean; + hideCaretOnScroll?: string; + infiniteLoadingSpinner?: string; + keyboardHeight?: number; + swipeBackEnabled?: boolean; + + tabbarPlacement?: string; + tabbarLayout?: string; + tabbarHighlight?: boolean; + + actionSheetEnter?: string; + alertEnter?: string; + loadingEnter?: string; + modalEnter?: string; + popoverEnter?: string; + toastEnter?: string; + pickerEnter?: string; + + actionSheetLeave?: string; + alertLeave?: string; + loadingLeave?: string; + modalLeave?: string; + popoverLeave?: string; + toastLeave?: string; + pickerLeave?: string; +} export function setupConfig(config: IonicConfig) { const win = window as any; @@ -14,43 +62,3 @@ export function setupConfig(config: IonicConfig) { }; return win.Ionic.config; } - -const IONIC_PREFIX = 'ionic:'; -const IONIC_SESSION_KEY = 'ionic-persist-config'; - -export function configFromSession(): any { - try { - const configStr = window.sessionStorage.getItem(IONIC_SESSION_KEY); - return configStr !== null ? JSON.parse(configStr) : {}; - } catch { - return {}; - } -} - -export function saveConfig(config: any) { - try { - window.sessionStorage.setItem(IONIC_SESSION_KEY, JSON.stringify(config)); - } catch { - return; - } -} - -export function configFromURL() { - const config: any = {}; - const win = window; - win.location.search.slice(1) - .split('&') - .map(entry => entry.split('=')) - .map(([key, value]) => [decodeURIComponent(key), decodeURIComponent(value)]) - .filter(([key]) => startsWith(key, IONIC_PREFIX)) - .map(([key, value]) => [key.slice(IONIC_PREFIX.length), value]) - .forEach(([key, value]) => { - config[key] = value; - }); - - return config; -} - -function startsWith(input: string, search: string): boolean { - return input.substr(0, search.length) === search; -} diff --git a/core/src/utils/framework-delegate.ts b/core/src/utils/framework-delegate.ts index daf91c5031..05734dc36f 100644 --- a/core/src/utils/framework-delegate.ts +++ b/core/src/utils/framework-delegate.ts @@ -1,9 +1,4 @@ -import { ComponentRef } from '../interface'; - -export interface FrameworkDelegate { - attachViewToDom(container: any, component: any, propsOrDataObj?: any, cssClasses?: string[]): Promise; - removeViewFromDom(container: any, component: any): Promise; -} +import { ComponentRef, FrameworkDelegate } from '../interface'; export async function attachComponent( delegate: FrameworkDelegate | undefined,