-
Notifications
You must be signed in to change notification settings - Fork 254
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: make configuration initial only (#638)
BREAKING CHANGE: Theming.js no longer has getTheme and setTheme methods. Use Configuration.js instead.
- Loading branch information
1 parent
9985634
commit 86ad25b
Showing
103 changed files
with
400 additions
and
2,523 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,149 +1,21 @@ | ||
import CalendarType from "@ui5/webcomponents-core/dist/sap/ui/core/CalendarType.js"; | ||
import getDesigntimePropertyAsArray from "./util/getDesigntimePropertyAsArray.js"; | ||
import { getTheme, setTheme } from "./config/Theme.js"; | ||
import { getNoConflict, setNoConflict } from "./config/NoConflict.js"; | ||
import { getCompactSize } from "./config/CompactSize.js"; | ||
import { getRTL } from "./config/RTL.js"; | ||
import { getLanguage, getSupportedLanguages } from "./config/Language.js"; | ||
import { getCalendarType } from "./config/CalendarType.js"; | ||
|
||
let initialized = false; | ||
|
||
const CONFIGURATION = { | ||
theme: "sap_fiori_3", | ||
rtl: null, | ||
language: null, | ||
compactSize: false, | ||
supportedLanguages: null, | ||
calendarType: null, | ||
derivedRTL: null, | ||
"xx-wc-no-conflict": false, // no URL | ||
}; | ||
|
||
/* General settings */ | ||
const getTheme = () => { | ||
initConfiguration(); | ||
return CONFIGURATION.theme; | ||
}; | ||
|
||
const getRTL = () => { | ||
initConfiguration(); | ||
return CONFIGURATION.rtl; | ||
}; | ||
|
||
const getLanguage = () => { | ||
initConfiguration(); | ||
return CONFIGURATION.language; | ||
}; | ||
|
||
const getCompactSize = () => { | ||
initConfiguration(); | ||
return CONFIGURATION.compactSize; | ||
}; | ||
|
||
const getSupportedLanguages = () => { | ||
return getDesigntimePropertyAsArray("$core-i18n-locales:,ar,bg,ca,cs,da,de,el,en,es,et,fi,fr,hi,hr,hu,it,iw,ja,ko,lt,lv,nl,no,pl,pt,ro,ru,sh,sk,sl,sv,th,tr,uk,vi,zh_CN,zh_TW$"); | ||
}; | ||
|
||
const getWCNoConflict = () => { | ||
initConfiguration(); | ||
return CONFIGURATION["xx-wc-no-conflict"]; | ||
}; | ||
|
||
const _setWCNoConflict = value => { | ||
CONFIGURATION["xx-wc-no-conflict"] = value; | ||
}; | ||
|
||
/* Calendar stuff */ | ||
const getCalendarType = () => { | ||
initConfiguration(); | ||
if (CONFIGURATION.calendarType) { | ||
const type = Object.keys(CalendarType).filter(calType => calType === CONFIGURATION.calendarType)[0]; | ||
|
||
if (type) { | ||
return type; | ||
} | ||
} | ||
|
||
return CalendarType.Gregorian; | ||
}; | ||
|
||
const getOriginInfo = () => {}; | ||
|
||
const getLocale = () => { | ||
initConfiguration(); | ||
return CONFIGURATION.language; | ||
}; | ||
|
||
const _setTheme = themeName => { | ||
CONFIGURATION.theme = themeName; | ||
}; | ||
|
||
const booleanMapping = new Map(); | ||
booleanMapping.set("true", true); | ||
booleanMapping.set("false", false); | ||
|
||
let runtimeConfig = {}; | ||
|
||
const parseConfigurationScript = () => { | ||
const configScript = document.querySelector("[data-id='sap-ui-config']"); | ||
let configJSON; | ||
|
||
if (configScript) { | ||
try { | ||
configJSON = JSON.parse(configScript.innerHTML); | ||
} catch (е) { | ||
console.warn("Incorrect data-sap-ui-config format. Please use JSON"); /* eslint-disable-line */ | ||
} | ||
|
||
if (configJSON) { | ||
runtimeConfig = Object.assign({}, configJSON); | ||
} | ||
} | ||
}; | ||
|
||
const parseURLParameters = () => { | ||
const params = new URLSearchParams(window.location.search); | ||
|
||
params.forEach((value, key) => { | ||
if (!key.startsWith("sap-ui")) { | ||
return; | ||
} | ||
|
||
const lowerCaseValue = value.toLowerCase(); | ||
|
||
const param = key.split("sap-ui-")[1]; | ||
|
||
if (booleanMapping.has(value)) { | ||
value = booleanMapping.get(lowerCaseValue); | ||
} | ||
|
||
runtimeConfig[param] = value; | ||
}); | ||
}; | ||
|
||
const applyConfigurations = () => { | ||
Object.keys(runtimeConfig).forEach(key => { | ||
CONFIGURATION[key] = runtimeConfig[key]; | ||
}); | ||
}; | ||
|
||
const initConfiguration = () => { | ||
if (initialized) { | ||
return; | ||
} | ||
|
||
parseConfigurationScript(); | ||
parseURLParameters(); | ||
applyConfigurations(); | ||
|
||
initialized = true; | ||
}; | ||
const getOriginInfo = () => {}; // needed for the shim | ||
|
||
export { | ||
getTheme, | ||
setTheme, | ||
getNoConflict, | ||
setNoConflict, | ||
getCompactSize, | ||
getRTL, | ||
getLanguage, | ||
getCompactSize, | ||
getWCNoConflict, | ||
getCalendarType, | ||
getLocale, | ||
_setTheme, | ||
_setWCNoConflict, | ||
getSupportedLanguages, | ||
getCalendarType, | ||
getOriginInfo, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
let initialized = false; | ||
|
||
const initialConfig = { | ||
theme: "sap_fiori_3", | ||
rtl: null, | ||
language: null, | ||
compactSize: false, | ||
calendarType: null, | ||
noConflict: false, // no URL | ||
}; | ||
|
||
/* General settings */ | ||
const getTheme = () => { | ||
initConfiguration(); | ||
return initialConfig.theme; | ||
}; | ||
|
||
const getRTL = () => { | ||
initConfiguration(); | ||
return initialConfig.rtl; | ||
}; | ||
|
||
const getLanguage = () => { | ||
initConfiguration(); | ||
return initialConfig.language; | ||
}; | ||
|
||
const getCompactSize = () => { | ||
initConfiguration(); | ||
return initialConfig.compactSize; | ||
}; | ||
|
||
const getNoConflict = () => { | ||
initConfiguration(); | ||
return initialConfig.noConflict; | ||
}; | ||
|
||
const getCalendarType = () => { | ||
initConfiguration(); | ||
return initialConfig.calendarType; | ||
}; | ||
|
||
const booleanMapping = new Map(); | ||
booleanMapping.set("true", true); | ||
booleanMapping.set("false", false); | ||
|
||
let runtimeConfig = {}; | ||
|
||
const parseConfigurationScript = () => { | ||
const configScript = document.querySelector("[data-ui5-config]") || document.querySelector("[data-id='sap-ui-config']"); // for backward compatibility | ||
|
||
let configJSON; | ||
|
||
if (configScript) { | ||
try { | ||
configJSON = JSON.parse(configScript.innerHTML); | ||
} catch (err) { | ||
console.warn("Incorrect data-sap-ui-config format. Please use JSON"); /* eslint-disable-line */ | ||
} | ||
|
||
if (configJSON) { | ||
runtimeConfig = Object.assign({}, configJSON); | ||
} | ||
} | ||
}; | ||
|
||
const parseURLParameters = () => { | ||
const params = new URLSearchParams(window.location.search); | ||
|
||
params.forEach((value, key) => { | ||
if (!key.startsWith("sap-ui")) { | ||
return; | ||
} | ||
|
||
const lowerCaseValue = value.toLowerCase(); | ||
|
||
const param = key.split("sap-ui-")[1]; | ||
|
||
if (booleanMapping.has(value)) { | ||
value = booleanMapping.get(lowerCaseValue); | ||
} | ||
|
||
runtimeConfig[param] = value; | ||
}); | ||
}; | ||
|
||
const applyConfigurations = () => { | ||
Object.keys(runtimeConfig).forEach(key => { | ||
initialConfig[key] = runtimeConfig[key]; | ||
}); | ||
}; | ||
|
||
const initConfiguration = () => { | ||
if (initialized) { | ||
return; | ||
} | ||
|
||
parseConfigurationScript(); | ||
parseURLParameters(); | ||
applyConfigurations(); | ||
|
||
initialized = true; | ||
}; | ||
|
||
export { | ||
getTheme, | ||
getRTL, | ||
getLanguage, | ||
getCompactSize, | ||
getNoConflict, | ||
getCalendarType, | ||
}; |
Oops, something went wrong.