migrate mobile ui utils to typescript
This commit is contained in:
+1
-1
@@ -27,7 +27,7 @@ import { getTheme, isEnableAnimate } from '@/lib/settings.ts';
|
||||
import { initMapProvider } from '@/lib/map/index.ts';
|
||||
import { isUserLogined, isUserUnlocked } from '@/lib/userstate.ts';
|
||||
import { setExpenseAndIncomeAmountColor } from '@/lib/ui/common.ts';
|
||||
import { isModalShowing, setAppFontSize } from '@/lib/ui/mobile.js';
|
||||
import { isModalShowing, setAppFontSize } from '@/lib/ui/mobile.ts';
|
||||
|
||||
const { tt, getCurrentLanguageInfo, setLanguage, initLocale } = useI18n();
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ import { useI18n } from '@/locales/helpers.ts';
|
||||
import type { ColorValue, ColorInfo } from '@/core/color.ts';
|
||||
import { arrayContainsFieldValue } from '@/lib/common.ts';
|
||||
import { getColorsInRows } from '@/lib/color.ts';
|
||||
import { scrollToSelectedItem } from '@/lib/ui/mobile.js';
|
||||
import { scrollToSelectedItem } from '@/lib/ui/mobile.ts';
|
||||
|
||||
const props = defineProps<{
|
||||
modelValue: ColorValue;
|
||||
|
||||
@@ -64,7 +64,7 @@ import {
|
||||
getTimeValues,
|
||||
getCombinedDateAndTimeValues
|
||||
} from '@/lib/datetime.ts';
|
||||
import { createInlinePicker } from '@/lib/ui/mobile.js';
|
||||
import { createInlinePicker } from '@/lib/ui/mobile.ts';
|
||||
|
||||
export default {
|
||||
props: [
|
||||
|
||||
@@ -36,7 +36,7 @@ import { useI18n } from '@/locales/helpers.ts';
|
||||
import type { IconInfo, IconInfoWithId } from '@/core/icon.ts';
|
||||
import { arrayContainsFieldValue } from '@/lib/common.ts';
|
||||
import { getIconsInRows } from '@/lib/icon.ts';
|
||||
import { scrollToSelectedItem } from '@/lib/ui/mobile.js';
|
||||
import { scrollToSelectedItem } from '@/lib/ui/mobile.ts';
|
||||
|
||||
const props = defineProps<{
|
||||
modelValue: string;
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { scrollToSelectedItem } from '@/lib/ui/mobile.js';
|
||||
import { scrollToSelectedItem } from '@/lib/ui/mobile.ts';
|
||||
|
||||
export default {
|
||||
props: [
|
||||
|
||||
@@ -69,7 +69,7 @@
|
||||
import { type Ref, ref, computed } from 'vue';
|
||||
|
||||
import { useI18n } from '@/locales/helper.js';
|
||||
import { useI18nUIComponents } from '@/lib/ui/mobile.js';
|
||||
import { useI18nUIComponents } from '@/lib/ui/mobile.ts';
|
||||
import { useUserStore } from '@/stores/user.ts';
|
||||
|
||||
import { ALL_CURRENCIES } from '@/consts/currency.ts';
|
||||
|
||||
@@ -70,7 +70,7 @@ import { useUserStore } from '@/stores/user.ts';
|
||||
|
||||
import { ScheduledTemplateFrequencyType } from '@/core/template.ts';
|
||||
import { sortNumbersArray } from '@/lib/common.ts';
|
||||
import { scrollToSelectedItem } from '@/lib/ui/mobile.js';
|
||||
import { scrollToSelectedItem } from '@/lib/ui/mobile.ts';
|
||||
|
||||
export default {
|
||||
props: [
|
||||
|
||||
@@ -80,7 +80,7 @@ import { mapStores } from 'pinia';
|
||||
import { useTransactionTagsStore } from '@/stores/transactionTag.js';
|
||||
|
||||
import { copyArrayTo } from '@/lib/common.ts';
|
||||
import { scrollToSelectedItem } from '@/lib/ui/mobile.js';
|
||||
import { scrollToSelectedItem } from '@/lib/ui/mobile.ts';
|
||||
|
||||
export default {
|
||||
props: [
|
||||
|
||||
@@ -42,7 +42,7 @@
|
||||
|
||||
<script>
|
||||
import { isArray } from '@/lib/common.ts';
|
||||
import { scrollToSelectedItem } from '@/lib/ui/mobile.js';
|
||||
import { scrollToSelectedItem } from '@/lib/ui/mobile.ts';
|
||||
|
||||
export default {
|
||||
props: [
|
||||
|
||||
@@ -66,7 +66,7 @@ import {
|
||||
getItemByKeyValue,
|
||||
getPrimaryValueBySecondaryValue
|
||||
} from '@/lib/common.ts';
|
||||
import { scrollToSelectedItem } from '@/lib/ui/mobile.js';
|
||||
import { scrollToSelectedItem } from '@/lib/ui/mobile.ts';
|
||||
|
||||
export default {
|
||||
props: [
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
import { autoChangeTextareaSize } from '@/lib/ui/mobile.js';
|
||||
|
||||
export default {
|
||||
mounted(el) {
|
||||
autoChangeTextareaSize(el);
|
||||
},
|
||||
updated(el) {
|
||||
autoChangeTextareaSize(el);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import { autoChangeTextareaSize } from '@/lib/ui/mobile.ts';
|
||||
|
||||
export default {
|
||||
mounted(el: HTMLElement): void {
|
||||
autoChangeTextareaSize(el);
|
||||
},
|
||||
updated(el: HTMLElement): void {
|
||||
autoChangeTextareaSize(el);
|
||||
}
|
||||
}
|
||||
@@ -133,6 +133,16 @@ export function isObjectEmpty(obj: object): boolean {
|
||||
return true;
|
||||
}
|
||||
|
||||
export function getNumberValue(value: unknown, defaultValue: number): number {
|
||||
if (isString(value)) {
|
||||
return parseInt(value as string, 10);
|
||||
} else if (isNumber(value)) {
|
||||
return value as number;
|
||||
} else {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
export function sortNumbersArray(array: number[]): number[] {
|
||||
return array.sort(function (num1, num2) {
|
||||
return num1 - num2;
|
||||
|
||||
@@ -1,12 +1,26 @@
|
||||
import { useI18n as useVueI18n } from 'vue-i18n';
|
||||
import { f7, f7ready } from 'framework7-vue';
|
||||
import type { Dialog, Picker, Router } from 'framework7/types';
|
||||
|
||||
import { FontSize, FONT_SIZE_PREVIEW_CLASSNAME_PREFIX } from '@/core/font.ts';
|
||||
import { translateError } from '@/locales/helper';
|
||||
|
||||
import { getNumberValue } from '../common.ts';
|
||||
import { isEnableAnimate } from '../settings.ts';
|
||||
// @ts-expect-error the above file is migrating to ts
|
||||
import { translateError } from '@/locales/helper.js';
|
||||
|
||||
export function showAlert(message, confirmCallback, translateFn) {
|
||||
interface Framework7Dom {
|
||||
length: number;
|
||||
[index: number]: Element;
|
||||
find: (selector?: string) => Framework7Dom;
|
||||
offset(): { top: number; left: number };
|
||||
scrollTop(position: number, duration?: number, callback?: () => void): Framework7Dom;
|
||||
outerHeight(includeMargin?: boolean): number;
|
||||
css(property: string): string | number;
|
||||
}
|
||||
|
||||
type TranslateFunction = (message: string) => string;
|
||||
|
||||
export function showAlert(message: string, confirmCallback: (dialog: Dialog.Dialog, e: Event) => void, translateFn: TranslateFunction): void {
|
||||
f7ready((f7) => {
|
||||
f7.dialog.create({
|
||||
title: translateFn('global.app.title'),
|
||||
@@ -22,7 +36,7 @@ export function showAlert(message, confirmCallback, translateFn) {
|
||||
});
|
||||
}
|
||||
|
||||
export function showConfirm(message, confirmCallback, cancelCallback, translateFn) {
|
||||
export function showConfirm(message: string, confirmCallback: (dialog: Dialog.Dialog, e: Event) => void, cancelCallback: (dialog: Dialog.Dialog, e: Event) => void, translateFn: TranslateFunction): void {
|
||||
f7ready((f7) => {
|
||||
f7.dialog.create({
|
||||
title: translateFn('global.app.title'),
|
||||
@@ -42,7 +56,7 @@ export function showConfirm(message, confirmCallback, cancelCallback, translateF
|
||||
});
|
||||
}
|
||||
|
||||
export function showToast(message, timeout, translateFn) {
|
||||
export function showToast(message: string, timeout: number, translateFn: TranslateFunction):void {
|
||||
f7ready((f7) => {
|
||||
f7.toast.create({
|
||||
text: translateError(message, translateFn),
|
||||
@@ -52,7 +66,7 @@ export function showToast(message, timeout, translateFn) {
|
||||
});
|
||||
}
|
||||
|
||||
export function showLoading(delayConditionFunc, delayMills) {
|
||||
export function showLoading(delayConditionFunc: () => boolean, delayMills: number): void {
|
||||
if (!delayConditionFunc) {
|
||||
f7ready((f7) => {
|
||||
return f7.preloader.show();
|
||||
@@ -75,7 +89,7 @@ export function hideLoading() {
|
||||
});
|
||||
}
|
||||
|
||||
export function createInlinePicker(containerEl, inputEl, cols, value, events) {
|
||||
export function createInlinePicker(containerEl: HTMLElement, inputEl: HTMLElement, cols: Picker.ColumnParameters[], value: unknown[], events?: { change: (picker: Picker.Picker, value: unknown, displayValue: unknown) => void }): Picker.Picker {
|
||||
return f7.picker.create({
|
||||
containerEl: containerEl,
|
||||
inputEl: inputEl,
|
||||
@@ -87,7 +101,8 @@ export function createInlinePicker(containerEl, inputEl, cols, value, events) {
|
||||
});
|
||||
}
|
||||
|
||||
export function routeBackOnError(f7router, errorPropertyName) {
|
||||
export function routeBackOnError(f7router: Router.Router, errorPropertyName: string): void {
|
||||
// @ts-expect-error vue SFC would be migrated to composition API and this function would be removed in the future
|
||||
const self = this;
|
||||
const router = f7router;
|
||||
|
||||
@@ -106,28 +121,24 @@ export function routeBackOnError(f7router, errorPropertyName) {
|
||||
});
|
||||
}
|
||||
|
||||
export function elements(selector) {
|
||||
return f7.$(selector);
|
||||
}
|
||||
|
||||
export function isModalShowing() {
|
||||
export function isModalShowing(): number {
|
||||
return f7.$('.modal-in').length;
|
||||
}
|
||||
|
||||
export function onSwipeoutDeleted(domId, callback) {
|
||||
export function onSwipeoutDeleted(domId: string, callback: () => void): void {
|
||||
f7.swipeout.delete(f7.$('#' + domId), callback);
|
||||
}
|
||||
|
||||
export function autoChangeTextareaSize(el) {
|
||||
f7.$(el).find('textarea').each(el => {
|
||||
el.scrollTop = 0;
|
||||
el.style.height = '';
|
||||
el.style.height = el.scrollHeight + 'px';
|
||||
export function autoChangeTextareaSize(el: HTMLElement): void {
|
||||
f7.$(el).find('textarea').each((child: HTMLElement) => {
|
||||
child.scrollTop = 0;
|
||||
child.style.height = '';
|
||||
child.style.height = child.scrollHeight + 'px';
|
||||
});
|
||||
}
|
||||
|
||||
export function setAppFontSize(type) {
|
||||
const htmlElement = elements('html');
|
||||
export function setAppFontSize(type: number): void {
|
||||
const htmlElement = f7.$('html');
|
||||
const allFontSizes = FontSize.values();
|
||||
|
||||
for (let i = 0; i < allFontSizes.length; i++) {
|
||||
@@ -143,7 +154,7 @@ export function setAppFontSize(type) {
|
||||
}
|
||||
}
|
||||
|
||||
export function getFontSizePreviewClassName(type) {
|
||||
export function getFontSizePreviewClassName(type: number): string {
|
||||
const allFontSizes = FontSize.values();
|
||||
|
||||
for (let i = 0; i < allFontSizes.length; i++) {
|
||||
@@ -157,7 +168,7 @@ export function getFontSizePreviewClassName(type) {
|
||||
return FONT_SIZE_PREVIEW_CLASSNAME_PREFIX + FontSize.Default.className;
|
||||
}
|
||||
|
||||
export function scrollToSelectedItem(parentEl, containerSelector, selectedItemSelector) {
|
||||
export function scrollToSelectedItem(parentEl: Framework7Dom, containerSelector: string, selectedItemSelector: string): void {
|
||||
if (!parentEl || !parentEl.length) {
|
||||
return;
|
||||
}
|
||||
@@ -169,16 +180,18 @@ export function scrollToSelectedItem(parentEl, containerSelector, selectedItemSe
|
||||
return;
|
||||
}
|
||||
|
||||
let targetPos = selectedItem.offset().top - container.offset().top - parseInt(container.css('padding-top'), 10)
|
||||
const containerPaddingTop = getNumberValue(container.css('padding-top'), 0);
|
||||
|
||||
let targetPos = selectedItem.offset().top - container.offset().top - containerPaddingTop
|
||||
- (container.outerHeight() - selectedItem.outerHeight()) / 2;
|
||||
|
||||
if (selectedItem.length > 1) {
|
||||
let firstSelectedItem = elements(selectedItem[0]);
|
||||
let lastSelectedItem = elements(selectedItem[selectedItem.length - 1]);
|
||||
const firstSelectedItem = f7.$(selectedItem[0]);
|
||||
const lastSelectedItem = f7.$(selectedItem[selectedItem.length - 1]);
|
||||
|
||||
let firstSelectedItemInTop = firstSelectedItem.offset().top - container.offset().top - parseInt(container.css('padding-top'), 10);
|
||||
let lastSelectedItemInTop = lastSelectedItem.offset().top - container.offset().top - parseInt(container.css('padding-top'), 10);
|
||||
let lastSelectedItemInBottom = lastSelectedItem.offset().top - container.offset().top - parseInt(container.css('padding-top'), 10)
|
||||
const firstSelectedItemInTop = firstSelectedItem.offset().top - container.offset().top - containerPaddingTop;
|
||||
const lastSelectedItemInTop = lastSelectedItem.offset().top - container.offset().top - containerPaddingTop;
|
||||
const lastSelectedItemInBottom = lastSelectedItem.offset().top - container.offset().top - containerPaddingTop
|
||||
- (container.outerHeight() - firstSelectedItem.outerHeight());
|
||||
|
||||
targetPos = (firstSelectedItemInTop + lastSelectedItemInBottom) / 2;
|
||||
@@ -199,8 +212,8 @@ export function useI18nUIComponents() {
|
||||
const i18nGlobal = useVueI18n();
|
||||
|
||||
return {
|
||||
showAlert: (message, confirmCallback) => showAlert(message, confirmCallback, i18nGlobal.t),
|
||||
showConfirm: (message, confirmCallback, cancelCallback) => showConfirm(message, confirmCallback, cancelCallback, i18nGlobal.t),
|
||||
showToast: (message, timeout) => showToast(message, timeout, i18nGlobal.t)
|
||||
};
|
||||
showAlert: (message: string, confirmCallback: (dialog: Dialog.Dialog, e: Event) => void) => showAlert(message, confirmCallback, i18nGlobal.t),
|
||||
showConfirm: (message: string, confirmCallback: (dialog: Dialog.Dialog, e: Event) => void, cancelCallback: (dialog: Dialog.Dialog, e: Event) => void): void => showConfirm(message, confirmCallback, cancelCallback, i18nGlobal.t),
|
||||
showToast: (message: string, timeout: number): void => showToast(message, timeout, i18nGlobal.t)
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -92,7 +92,7 @@ import {
|
||||
showLoading,
|
||||
hideLoading,
|
||||
routeBackOnError
|
||||
} from '@/lib/ui/mobile.js';
|
||||
} from '@/lib/ui/mobile.ts';
|
||||
|
||||
import PinCodeInput from '@/components/common/PinCodeInput.vue';
|
||||
import MapView from '@/components/common/MapView.vue';
|
||||
@@ -117,7 +117,7 @@ import MapSheet from '@/components/mobile/MapSheet.vue';
|
||||
import TransactionTagSelectionSheet from '@/components/mobile/TransactionTagSelectionSheet.vue';
|
||||
import ScheduleFrequencySheet from '@/components/mobile/ScheduleFrequencySheet.vue';
|
||||
|
||||
import TextareaAutoSize from '@/directives/mobile/textareaAutoSize.js';
|
||||
import TextareaAutoSize from '@/directives/mobile/textareaAutoSize.ts';
|
||||
|
||||
import '@/styles/mobile/global.css';
|
||||
import '@/styles/mobile/font-size-default.css';
|
||||
|
||||
@@ -197,7 +197,7 @@ import {
|
||||
} from '@/lib/server_settings.ts';
|
||||
import { getDesktopVersionPath } from '@/lib/version.ts';
|
||||
import { setExpenseAndIncomeAmountColor } from '@/lib/ui/common.ts';
|
||||
import { isModalShowing } from '@/lib/ui/mobile.js';
|
||||
import { isModalShowing } from '@/lib/ui/mobile.ts';
|
||||
|
||||
export default {
|
||||
props: [
|
||||
|
||||
@@ -83,7 +83,7 @@ import {
|
||||
getWebAuthnCredentialId
|
||||
} from '@/lib/userstate.ts';
|
||||
import { setExpenseAndIncomeAmountColor } from '@/lib/ui/common.ts';
|
||||
import { isModalShowing } from '@/lib/ui/mobile.js';
|
||||
import { isModalShowing } from '@/lib/ui/mobile.ts';
|
||||
|
||||
export default {
|
||||
props: [
|
||||
|
||||
@@ -181,7 +181,7 @@ import { useAccountsStore } from '@/stores/account.js';
|
||||
import { useExchangeRatesStore } from '@/stores/exchangeRates.ts';
|
||||
|
||||
import { AccountType, AccountCategory } from '@/core/account.ts';
|
||||
import { onSwipeoutDeleted } from '@/lib/ui/mobile.js';
|
||||
import { onSwipeoutDeleted } from '@/lib/ui/mobile.ts';
|
||||
|
||||
export default {
|
||||
props: [
|
||||
|
||||
@@ -96,7 +96,7 @@ import {
|
||||
getFirstShowingId,
|
||||
getLastShowingId
|
||||
} from '@/lib/category.js';
|
||||
import { onSwipeoutDeleted } from '@/lib/ui/mobile.js';
|
||||
import { onSwipeoutDeleted } from '@/lib/ui/mobile.ts';
|
||||
|
||||
export default {
|
||||
props: [
|
||||
|
||||
@@ -118,7 +118,7 @@ import { useUserStore } from '@/stores/user.ts';
|
||||
|
||||
import { FontSize } from '@/core/font.ts';
|
||||
import { getCurrentUnixTime, getDay, getDayOfWeekName } from '@/lib/datetime.ts';
|
||||
import { setAppFontSize, getFontSizePreviewClassName } from '@/lib/ui/mobile.js';
|
||||
import { setAppFontSize, getFontSizePreviewClassName } from '@/lib/ui/mobile.ts';
|
||||
|
||||
export default {
|
||||
props: [
|
||||
|
||||
@@ -349,7 +349,7 @@ import {
|
||||
getDateTypeByDateRange,
|
||||
getDateRangeByDateType
|
||||
} from '@/lib/datetime.ts';
|
||||
import { scrollToSelectedItem } from '@/lib/ui/mobile.js';
|
||||
import { scrollToSelectedItem } from '@/lib/ui/mobile.ts';
|
||||
|
||||
export default {
|
||||
props: [
|
||||
|
||||
@@ -152,7 +152,7 @@ import {
|
||||
getFirstShowingId,
|
||||
getLastShowingId
|
||||
} from '@/lib/tag.js';
|
||||
import { onSwipeoutDeleted } from '@/lib/ui/mobile.js';
|
||||
import { onSwipeoutDeleted } from '@/lib/ui/mobile.ts';
|
||||
|
||||
export default {
|
||||
props: [
|
||||
|
||||
@@ -95,7 +95,7 @@ import {
|
||||
getFirstShowingId,
|
||||
getLastShowingId
|
||||
} from '@/lib/template.js';
|
||||
import { onSwipeoutDeleted } from '@/lib/ui/mobile.js';
|
||||
import { onSwipeoutDeleted } from '@/lib/ui/mobile.ts';
|
||||
|
||||
export default {
|
||||
props: [
|
||||
|
||||
@@ -551,7 +551,7 @@ import {
|
||||
import { categoryTypeToTransactionType, transactionTypeToCategoryType } from '@/lib/category.js';
|
||||
import { getUnifiedSelectedAccountsCurrencyOrDefaultCurrency } from '@/lib/account.js';
|
||||
import { getTransactionDisplayAmount } from '@/lib/transaction.js';
|
||||
import { onSwipeoutDeleted, scrollToSelectedItem } from '@/lib/ui/mobile.js';
|
||||
import { onSwipeoutDeleted, scrollToSelectedItem } from '@/lib/ui/mobile.ts';
|
||||
|
||||
export default {
|
||||
props: [
|
||||
|
||||
@@ -50,7 +50,7 @@ import { useTokensStore } from '@/stores/token.ts';
|
||||
import { isEquals } from '@/lib/common.ts';
|
||||
import { parseSessionInfo } from '@/lib/session.ts';
|
||||
|
||||
import { onSwipeoutDeleted } from '@/lib/ui/mobile.js';
|
||||
import { onSwipeoutDeleted } from '@/lib/ui/mobile.ts';
|
||||
|
||||
export default {
|
||||
props: [
|
||||
|
||||
Reference in New Issue
Block a user