mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
Issue number: internal --------- ## What is the current behavior? - `LogLevel` throws error `Error: Cannot access ambient const enums when 'isolatedModules' is enabled` - Several existing console warns and errors are not calling the function that respects the `logLevel` config ## What is the new behavior? - Remove `const` from the `enum` to work with `isolatedModules` - Update `console.warn`s to `printIonWarning` - Update `console.error`s to `printIonError` ## Does this introduce a breaking change? - [ ] Yes - [x] No ## Other information Dev build: `8.5.5-dev.11744729748.174bf7e0` --------- Co-authored-by: Brandy Smith <6577830+brandyscarney@users.noreply.github.com>
81 lines
2.3 KiB
TypeScript
81 lines
2.3 KiB
TypeScript
import { getMode, setMode } from '@stencil/core';
|
|
import { printIonWarning } from '@utils/logging';
|
|
|
|
import type { IonicConfig, Mode } from '../interface';
|
|
import { isPlatform, setupPlatforms } from '../utils/platform';
|
|
|
|
import { config, configFromSession, configFromURL, saveConfig } from './config';
|
|
|
|
// TODO(FW-2832): types
|
|
|
|
let defaultMode: Mode;
|
|
|
|
export const getIonMode = (ref?: any): Mode => {
|
|
return (ref && getMode(ref)) || defaultMode;
|
|
};
|
|
|
|
export const initialize = (userConfig: IonicConfig = {}) => {
|
|
if (typeof (window as any) === 'undefined') {
|
|
return;
|
|
}
|
|
|
|
const doc = window.document;
|
|
const win = window;
|
|
const Ionic = ((win as any).Ionic = (win as any).Ionic || {});
|
|
|
|
// create the Ionic.config from raw config object (if it exists)
|
|
// and convert Ionic.config into a ConfigApi that has a get() fn
|
|
const configObj = {
|
|
...configFromSession(win),
|
|
persistConfig: false,
|
|
...Ionic.config,
|
|
...configFromURL(win),
|
|
...userConfig,
|
|
};
|
|
|
|
config.reset(configObj);
|
|
if (config.getBoolean('persistConfig')) {
|
|
saveConfig(win, configObj);
|
|
}
|
|
|
|
// Setup platforms
|
|
setupPlatforms(win);
|
|
|
|
// first see if the mode was set as an attribute on <html>
|
|
// which could have been set by the user, or by pre-rendering
|
|
// otherwise get the mode via config settings, and fallback to md
|
|
Ionic.config = config;
|
|
Ionic.mode = defaultMode = config.get(
|
|
'mode',
|
|
doc.documentElement.getAttribute('mode') || (isPlatform(win, 'ios') ? 'ios' : 'md')
|
|
);
|
|
config.set('mode', defaultMode);
|
|
doc.documentElement.setAttribute('mode', defaultMode);
|
|
doc.documentElement.classList.add(defaultMode);
|
|
|
|
if (config.getBoolean('_testing')) {
|
|
config.set('animated', false);
|
|
}
|
|
|
|
const isIonicElement = (elm: any) => elm.tagName?.startsWith('ION-');
|
|
|
|
const isAllowedIonicModeValue = (elmMode: string) => ['ios', 'md'].includes(elmMode);
|
|
|
|
setMode((elm: any) => {
|
|
while (elm) {
|
|
const elmMode = (elm as any).mode || elm.getAttribute('mode');
|
|
if (elmMode) {
|
|
if (isAllowedIonicModeValue(elmMode)) {
|
|
return elmMode;
|
|
} else if (isIonicElement(elm)) {
|
|
printIonWarning('Invalid ionic mode: "' + elmMode + '", expected: "ios" or "md"');
|
|
}
|
|
}
|
|
elm = elm.parentElement;
|
|
}
|
|
return defaultMode;
|
|
});
|
|
};
|
|
|
|
export default initialize;
|