Skip to content

Commit b97fe6c

Browse files
committed
fix: prefer ofetch
1 parent 96edb0e commit b97fe6c

File tree

21 files changed

+359
-318
lines changed

21 files changed

+359
-318
lines changed

packages/common-types/src/plugin.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,9 @@ export interface iPluginOptions<ComponentType = unknown> {
108108
*/
109109
country?: string;
110110
/**
111-
* Countries API base endpoint (full URL)
111+
* Countries API base endpoint
112+
*
113+
* Pathname or full URL (With pathname)
112114
*
113115
* If using nuxt, get better performance with the module
114116
* @see https://www.npmjs.com/package/nuxt-countries-api

packages/components-vue/src/components/base/Action.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
3535
const props = defineProps<iActionProps>();
3636
37-
const xamuOptions = inject<iPluginOptions>("xamu");
37+
const { routerComponent } = inject<iPluginOptions>("xamu") || {};
3838
const { getModifierClasses: GMC } = useHelpers(useUtils);
3939
4040
const currentTag = computed(() => {
@@ -44,7 +44,7 @@
4444
});
4545
4646
const actionComponent = computed(() => {
47-
return (props.to && xamuOptions?.routerComponent) || currentTag.value;
47+
return (props.to && routerComponent) || currentTag.value;
4848
});
4949
5050
/**

packages/components-vue/src/components/base/Img.vue

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
</template>
44

55
<script setup lang="ts">
6-
import { type PropType, computed, inject } from "vue";
6+
import { type PropType, inject } from "vue";
77
88
import type { iPluginOptions } from "@open-xamu-co/ui-common-types";
99
@@ -41,7 +41,5 @@
4141
},
4242
});
4343
44-
const xamuOptions = inject<iPluginOptions<vComponent>>("xamu");
45-
46-
const imageComponent = computed(() => xamuOptions?.imageComponent || "img");
44+
const { imageComponent = "img" } = inject<iPluginOptions<vComponent>>("xamu") || {};
4745
</script>

packages/components-vue/src/components/icon/Fa.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@
3939
4040
const props = defineProps<iIconFaProps>();
4141
42-
const xamuOptions = inject<iPluginOptions>("xamu");
42+
const { fontAwesomePro } = inject<iPluginOptions>("xamu") || {};
4343
4444
const regular = computed(() => {
45-
return props.forceRegular || (xamuOptions?.fontAwesomePro && props.regular);
45+
return props.forceRegular || (fontAwesomePro && props.regular);
4646
});
4747
4848
/**

packages/components-vue/src/components/loader/ContentFetch.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@
102102
const emit = defineEmits(["refresh"]);
103103
104104
const { logger } = useHelpers(useUtils);
105-
const xamuOptions = inject<iVuePluginOptions>("xamu");
106-
const useAsyncData: typeof useAsyncDataFn = xamuOptions?.asyncDataFn ?? useAsyncDataFn;
105+
const { internals } = inject<iVuePluginOptions>("xamu") || {};
106+
const useAsyncData: typeof useAsyncDataFn = internals?.useAsyncData ?? useAsyncDataFn;
107107
108108
const firstLoad = ref(false);
109109
const hydrated = ref(false);

packages/components-vue/src/components/pagination/Content.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@
120120
});
121121
const emit = defineEmits(["refresh", "hasContent"]);
122122
123-
const xamuOptions = inject<iPluginOptions>("xamu");
123+
const { first: defaultFirst } = inject<iPluginOptions>("xamu") || {};
124124
const router = getCurrentInstance()?.appContext.config.globalProperties.$router;
125125
126126
/**
@@ -134,7 +134,7 @@
134134
};
135135
const propsPagination = ref<iPagination>({
136136
orderBy: props.orderBy,
137-
first: props.first ?? xamuOptions?.first,
137+
first: props.first ?? defaultFirst,
138138
at: props.at,
139139
});
140140
const routePagination = computed<iPagination>(() => {

packages/components-vue/src/components/pagination/Simple.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
const emit = defineEmits(["update:model-value"]);
9494
const props = defineProps<iPaginationSimpleProps<T, C>>();
9595
96-
const xamuOptions = inject<iPluginOptions>("xamu");
96+
const { first: defaultFirst } = inject<iPluginOptions>("xamu") || {};
9797
const { t } = useHelpers(useI18n);
9898
9999
/**
@@ -110,7 +110,7 @@
110110
* PaginationSimple first model
111111
*/
112112
const firstModel = computed({
113-
get: () => props.modelValue?.first ?? xamuOptions?.first,
113+
get: () => props.modelValue?.first ?? defaultFirst,
114114
set(first) {
115115
emit("update:model-value", { ...props.modelValue, first });
116116
},

packages/components-vue/src/components/slider/Simple.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@
139139
intervalDuration: 7000,
140140
});
141141
142-
const xamuOptions = inject<iPluginOptions>("xamu");
142+
const { disableAutoAnimate } = inject<iPluginOptions>("xamu") || {};
143143
const { t } = useHelpers(useI18n);
144144
const { isBrowser } = useHelpers(useUtils);
145145
@@ -154,7 +154,7 @@
154154
const childCount = ref(0);
155155
156156
const allowAutoAnimate = computed<boolean>(() => {
157-
return !xamuOptions?.disableAutoAnimate && props.animate;
157+
return !disableAutoAnimate && props.animate;
158158
});
159159
160160
const sliderTag = computed(() => {

packages/components-vue/src/components/value/Simple.vue

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -161,13 +161,10 @@
161161
162162
const props = defineProps<iValueSimpleProps<P>>();
163163
164-
const xamuOptions = inject<iPluginOptions>("xamu");
164+
const { lang = "en", country = "US", imageHosts = [] } = inject<iPluginOptions>("xamu") || {};
165165
const { t } = useHelpers(useI18n);
166166
167167
const locale = computed(() => {
168-
const lang = xamuOptions?.lang || "en";
169-
const country = xamuOptions?.country || "US";
170-
171168
return `${lang}-${country}`;
172169
});
173170
@@ -181,10 +178,10 @@
181178
const [firstPart] = url.split("?");
182179
183180
// host is required
184-
if (isURL(firstPart) && xamuOptions?.imageHosts?.length) {
181+
if (isURL(firstPart) && imageHosts.length) {
185182
const url = new URL(firstPart);
186183
187-
if (xamuOptions.imageHosts.includes(url.host)) return true;
184+
if (imageHosts.includes(url.host)) return true;
188185
}
189186
190187
return /\.(jpg|jpeg|png|webp|avif|gif|svg)$/.test(firstPart);
Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { type Ref, inject, onMounted, onBeforeUnmount, ref } from "vue";
1+
import { type Ref, onMounted, onBeforeUnmount, ref } from "vue";
22

3-
import type { iPluginOptions } from "@open-xamu-co/ui-common-types";
43
import { useUtils } from "@open-xamu-co/ui-common-helpers";
54

65
import { useHelpers } from "../composables/utils";
@@ -21,44 +20,46 @@ function matchMedia(size?: number) {
2120
* @composable
2221
*/
2322
export default function useBrowser() {
24-
const { mediaQueryPixels } = inject<iPluginOptions>("xamu") || {};
25-
const { isBrowser } = useHelpers(useUtils);
23+
return useHelpers((xo) => {
24+
const { mediaQueryPixels } = xo;
25+
const { isBrowser } = useUtils(xo);
2626

27-
// Viewports
28-
const laptopMqRange = ref<boolean>(false);
29-
const tabletMqRange = ref<boolean>(false);
30-
const mobileMqRange = ref<boolean>(false);
31-
// Viewport listeners
32-
const laptopMQHandler = MQHandler(laptopMqRange);
33-
const tabletMQHandler = MQHandler(tabletMqRange);
34-
const mobileMQHandler = MQHandler(mobileMqRange);
27+
// Viewports
28+
const laptopMqRange = ref<boolean>(false);
29+
const tabletMqRange = ref<boolean>(false);
30+
const mobileMqRange = ref<boolean>(false);
31+
// Viewport listeners
32+
const laptopMQHandler = MQHandler(laptopMqRange);
33+
const tabletMQHandler = MQHandler(tabletMqRange);
34+
const mobileMQHandler = MQHandler(mobileMqRange);
3535

36-
// lifecycle, listeners only work on browser
37-
if (isBrowser) {
38-
// Define MQlist
39-
const laptopMQList = matchMedia(mediaQueryPixels?.laptop ?? 1080);
40-
const tabletMQList = matchMedia(mediaQueryPixels?.tablet ?? 768);
41-
const mobileMQList = matchMedia(mediaQueryPixels?.mobile ?? 576);
36+
// lifecycle, listeners only work on browser
37+
if (isBrowser) {
38+
// Define MQlist
39+
const laptopMQList = matchMedia(mediaQueryPixels?.laptop ?? 1080);
40+
const tabletMQList = matchMedia(mediaQueryPixels?.tablet ?? 768);
41+
const mobileMQList = matchMedia(mediaQueryPixels?.mobile ?? 576);
4242

43-
onMounted(() => {
44-
// Mount listeners
45-
laptopMQList.addEventListener("change", laptopMQHandler, true);
46-
tabletMQList.addEventListener("change", tabletMQHandler, true);
47-
mobileMQList.addEventListener("change", mobileMQHandler, true);
43+
onMounted(() => {
44+
// Mount listeners
45+
laptopMQList.addEventListener("change", laptopMQHandler, true);
46+
tabletMQList.addEventListener("change", tabletMQHandler, true);
47+
mobileMQList.addEventListener("change", mobileMQHandler, true);
4848

49-
// Set initial values
50-
laptopMQHandler(laptopMQList);
51-
tabletMQHandler(tabletMQList);
52-
mobileMQHandler(mobileMQList);
53-
});
49+
// Set initial values
50+
laptopMQHandler(laptopMQList);
51+
tabletMQHandler(tabletMQList);
52+
mobileMQHandler(mobileMQList);
53+
});
5454

55-
onBeforeUnmount(() => {
56-
// Unmount listeners
57-
laptopMQList.removeEventListener("change", laptopMQHandler, true);
58-
tabletMQList.removeEventListener("change", tabletMQHandler, true);
59-
mobileMQList.removeEventListener("change", mobileMQHandler, true);
60-
});
61-
}
55+
onBeforeUnmount(() => {
56+
// Unmount listeners
57+
laptopMQList.removeEventListener("change", laptopMQHandler, true);
58+
tabletMQList.removeEventListener("change", tabletMQHandler, true);
59+
mobileMQList.removeEventListener("change", mobileMQHandler, true);
60+
});
61+
}
6262

63-
return { laptopMqRange, tabletMqRange, mobileMqRange };
63+
return { laptopMqRange, tabletMqRange, mobileMqRange };
64+
});
6465
}

0 commit comments

Comments
 (0)