diff --git a/CHANGELOG.md b/CHANGELOG.md index bc464c7d..2644c2e7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ # Changelog +## v1.11.0 + +_19 nov 2024_ + +- Added support for splitting up translation file per language +- Added hasFocus property to ComponentBase type +- Fixed issue with alpha during router transitions + + ## v1.10.1 _15 nov 2024_ @@ -7,6 +16,7 @@ _15 nov 2024_ - Upgraded to renderer 2.7.1 - Added documentation on Router + ## v1.10.0 _8 nov 2024_ diff --git a/index.d.ts b/index.d.ts index 2fbe2933..bdbe35be 100644 --- a/index.d.ts +++ b/index.d.ts @@ -149,6 +149,11 @@ declare module '@lightningjs/blits' { } export type ComponentBase = { + /** + * Check if a component has focus + */ + hasFocus: boolean, + /** * Listen to events emitted by other components */ diff --git a/package-lock.json b/package-lock.json index fd1856f3..59bd4126 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@lightningjs/blits", - "version": "1.10.1", + "version": "1.11.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@lightningjs/blits", - "version": "1.10.1", + "version": "1.11.0", "license": "Apache-2.0", "dependencies": { "@lightningjs/msdf-generator": "^1.1.0", diff --git a/package.json b/package.json index ccce1df4..c8afe771 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@lightningjs/blits", - "version": "1.10.1", + "version": "1.11.0", "description": "Blits: The Lightning 3 App Development Framework", "bin": "bin/index.js", "exports": { diff --git a/src/plugins/language.js b/src/plugins/language.js index 63e50a85..ec2ae02b 100644 --- a/src/plugins/language.js +++ b/src/plugins/language.js @@ -37,22 +37,45 @@ export default { ) const setLanguage = (language) => { - // define the dictionary - dictionary = translations[language] || {} - // set the current language in the reactive state - state.language = language - - // warnings - if (Object.keys(translations).length === 0) { - Log.warn( - 'No translations loaded. Please load a file with translations or specify a translations object manually' - ) - } - if (language in translations === false) { - Log.warn(`Language ${language} not available in the loaded translations`) + const warningMsg = + Object.keys(translations).length === 0 + ? 'No translations loaded. Please load a file with translations or specify a translations object manually' + : language in translations === false + ? `Language ${language} not available in the loaded translations` + : false + if (warningMsg) { + Log.warn(warningMsg) + // set the current language in the reactive state + state.language = language + } else { + setDict(language).then(() => { + state.language = language + }) } } + const setDict = (language) => { + return new Promise((resolve) => { + const translationObj = translations[language] + if (typeof translationObj === 'object') { + dictionary = translationObj + resolve() + } else if (typeof translationObj === 'string') { + fetchJson(translationObj) + .then((result) => { + // save the translations for this language (to prevent loading twice) + translations[language] = result + // define the dictionary + dictionary = result + resolve() + }) + .catch((e) => { + Log.error(e) + }) + } + }) + } + const loadLanguageFile = (filePath) => { return fetchJson(filePath) .then((result) => { @@ -65,8 +88,9 @@ export default { const setTranslations = (translationsObject) => { translations = translationsObject - dictionary = translations[state.language] || {} - state.loaded++ + setDict(state.language).then(() => { + state.loaded++ + }) } if ('file' in options) { diff --git a/src/router/router.js b/src/router/router.js index 93d0b2f9..6e4f3476 100644 --- a/src/router/router.js +++ b/src/router/router.js @@ -168,6 +168,25 @@ export const navigate = async function () { } } else { holder = view[symbols.holder] + + // Check, whether cached view holder's alpha prop is exists in transition or not + let hasAlphaProp = false + if (route.transition.before) { + if (Array.isArray(route.transition.before)) { + for (let i = 0; i < route.transition.before.length; i++) { + if (route.transition.before[i].prop === 'alpha') { + hasAlphaProp = true + break + } + } + } else if (route.transition.before.prop === 'alpha') { + hasAlphaProp = true + } + } + // set holder alpha when alpha prop is not exists in route transition + if (hasAlphaProp === false) { + holder.set('alpha', 1) + } } this[symbols.children].push(view)