@mouseless/baked 0.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -0
- package/dist/module.d.mts +45 -0
- package/dist/module.json +9 -0
- package/dist/module.mjs +110 -0
- package/dist/runtime/assets/overrides.css +1 -0
- package/dist/runtime/assets/tailwind.css +1 -0
- package/dist/runtime/components/AuthorizedContent.d.vue.ts +10 -0
- package/dist/runtime/components/AuthorizedContent.vue +14 -0
- package/dist/runtime/components/AuthorizedContent.vue.d.ts +10 -0
- package/dist/runtime/components/Bake.d.vue.ts +20 -0
- package/dist/runtime/components/Bake.vue +50 -0
- package/dist/runtime/components/Bake.vue.d.ts +20 -0
- package/dist/runtime/components/BasePersistentPopover.d.vue.ts +178 -0
- package/dist/runtime/components/BasePersistentPopover.vue +41 -0
- package/dist/runtime/components/BasePersistentPopover.vue.d.ts +178 -0
- package/dist/runtime/components/CardLink.d.vue.ts +11 -0
- package/dist/runtime/components/CardLink.vue +57 -0
- package/dist/runtime/components/CardLink.vue.d.ts +11 -0
- package/dist/runtime/components/DataPanel.d.vue.ts +20 -0
- package/dist/runtime/components/DataPanel.vue +138 -0
- package/dist/runtime/components/DataPanel.vue.d.ts +20 -0
- package/dist/runtime/components/DataTable.d.vue.ts +11 -0
- package/dist/runtime/components/DataTable.vue +213 -0
- package/dist/runtime/components/DataTable.vue.d.ts +11 -0
- package/dist/runtime/components/DefaultLayout.d.vue.ts +18 -0
- package/dist/runtime/components/DefaultLayout.vue +44 -0
- package/dist/runtime/components/DefaultLayout.vue.d.ts +18 -0
- package/dist/runtime/components/DeferredTabContent.d.vue.ts +16 -0
- package/dist/runtime/components/DeferredTabContent.vue +23 -0
- package/dist/runtime/components/DeferredTabContent.vue.d.ts +16 -0
- package/dist/runtime/components/Error.d.vue.ts +3 -0
- package/dist/runtime/components/Error.vue +13 -0
- package/dist/runtime/components/Error.vue.d.ts +3 -0
- package/dist/runtime/components/ErrorPage.d.vue.ts +11 -0
- package/dist/runtime/components/ErrorPage.vue +65 -0
- package/dist/runtime/components/ErrorPage.vue.d.ts +11 -0
- package/dist/runtime/components/Filter.d.vue.ts +11 -0
- package/dist/runtime/components/Filter.vue +23 -0
- package/dist/runtime/components/Filter.vue.d.ts +11 -0
- package/dist/runtime/components/Header.d.vue.ts +11 -0
- package/dist/runtime/components/Header.vue +78 -0
- package/dist/runtime/components/Header.vue.d.ts +11 -0
- package/dist/runtime/components/Icon.d.vue.ts +11 -0
- package/dist/runtime/components/Icon.vue +14 -0
- package/dist/runtime/components/Icon.vue.d.ts +11 -0
- package/dist/runtime/components/LanguageSwitcher.d.vue.ts +11 -0
- package/dist/runtime/components/LanguageSwitcher.vue +57 -0
- package/dist/runtime/components/LanguageSwitcher.vue.d.ts +11 -0
- package/dist/runtime/components/Layout.d.vue.ts +10 -0
- package/dist/runtime/components/Layout.vue +38 -0
- package/dist/runtime/components/Layout.vue.d.ts +10 -0
- package/dist/runtime/components/Logo.d.vue.ts +9 -0
- package/dist/runtime/components/Logo.vue +18 -0
- package/dist/runtime/components/Logo.vue.d.ts +9 -0
- package/dist/runtime/components/MenuPage.d.vue.ts +11 -0
- package/dist/runtime/components/MenuPage.vue +93 -0
- package/dist/runtime/components/MenuPage.vue.d.ts +11 -0
- package/dist/runtime/components/Message.d.vue.ts +11 -0
- package/dist/runtime/components/Message.vue +33 -0
- package/dist/runtime/components/Message.vue.d.ts +11 -0
- package/dist/runtime/components/ModalLayout.d.vue.ts +18 -0
- package/dist/runtime/components/ModalLayout.vue +14 -0
- package/dist/runtime/components/ModalLayout.vue.d.ts +18 -0
- package/dist/runtime/components/Money.d.vue.ts +11 -0
- package/dist/runtime/components/Money.vue +27 -0
- package/dist/runtime/components/Money.vue.d.ts +11 -0
- package/dist/runtime/components/NavLink.d.vue.ts +11 -0
- package/dist/runtime/components/NavLink.vue +30 -0
- package/dist/runtime/components/NavLink.vue.d.ts +11 -0
- package/dist/runtime/components/None.d.vue.ts +11 -0
- package/dist/runtime/components/None.vue +25 -0
- package/dist/runtime/components/None.vue.d.ts +11 -0
- package/dist/runtime/components/Number.d.vue.ts +11 -0
- package/dist/runtime/components/Number.vue +27 -0
- package/dist/runtime/components/Number.vue.d.ts +11 -0
- package/dist/runtime/components/Page.d.vue.ts +3 -0
- package/dist/runtime/components/Page.vue +24 -0
- package/dist/runtime/components/Page.vue.d.ts +3 -0
- package/dist/runtime/components/PageTitle.d.vue.ts +22 -0
- package/dist/runtime/components/PageTitle.vue +171 -0
- package/dist/runtime/components/PageTitle.vue.d.ts +22 -0
- package/dist/runtime/components/Parameters.d.vue.ts +11 -0
- package/dist/runtime/components/Parameters.vue +60 -0
- package/dist/runtime/components/Parameters.vue.d.ts +11 -0
- package/dist/runtime/components/PersistentPopover.d.vue.ts +46 -0
- package/dist/runtime/components/PersistentPopover.vue +335 -0
- package/dist/runtime/components/PersistentPopover.vue.d.ts +46 -0
- package/dist/runtime/components/QueryParameters.d.vue.ts +11 -0
- package/dist/runtime/components/QueryParameters.vue +103 -0
- package/dist/runtime/components/QueryParameters.vue.d.ts +11 -0
- package/dist/runtime/components/Rate.d.vue.ts +11 -0
- package/dist/runtime/components/Rate.vue +22 -0
- package/dist/runtime/components/Rate.vue.d.ts +11 -0
- package/dist/runtime/components/ReportPage.d.vue.ts +11 -0
- package/dist/runtime/components/ReportPage.vue +147 -0
- package/dist/runtime/components/ReportPage.vue.d.ts +11 -0
- package/dist/runtime/components/Select.d.vue.ts +11 -0
- package/dist/runtime/components/Select.vue +120 -0
- package/dist/runtime/components/Select.vue.d.ts +11 -0
- package/dist/runtime/components/SelectButton.d.vue.ts +11 -0
- package/dist/runtime/components/SelectButton.vue +94 -0
- package/dist/runtime/components/SelectButton.vue.d.ts +11 -0
- package/dist/runtime/components/SideMenu.d.vue.ts +20 -0
- package/dist/runtime/components/SideMenu.vue +121 -0
- package/dist/runtime/components/SideMenu.vue.d.ts +20 -0
- package/dist/runtime/components/SideMenuItem.d.vue.ts +11 -0
- package/dist/runtime/components/SideMenuItem.vue +33 -0
- package/dist/runtime/components/SideMenuItem.vue.d.ts +11 -0
- package/dist/runtime/components/Text.d.vue.ts +11 -0
- package/dist/runtime/components/Text.vue +36 -0
- package/dist/runtime/components/Text.vue.d.ts +11 -0
- package/dist/runtime/composables/useBreakpoints.d.ts +1 -0
- package/dist/runtime/composables/useBreakpoints.js +48 -0
- package/dist/runtime/composables/useCache.d.ts +13 -0
- package/dist/runtime/composables/useCache.js +60 -0
- package/dist/runtime/composables/useComponentResolver.d.ts +3 -0
- package/dist/runtime/composables/useComponentResolver.js +13 -0
- package/dist/runtime/composables/useComposableResolver.d.ts +3 -0
- package/dist/runtime/composables/useComposableResolver.js +15 -0
- package/dist/runtime/composables/useConditional.d.ts +3 -0
- package/dist/runtime/composables/useConditional.js +15 -0
- package/dist/runtime/composables/useContext.d.ts +15 -0
- package/dist/runtime/composables/useContext.js +60 -0
- package/dist/runtime/composables/useDataFetcher.d.ts +15 -0
- package/dist/runtime/composables/useDataFetcher.js +203 -0
- package/dist/runtime/composables/useFormat.d.ts +16 -0
- package/dist/runtime/composables/useFormat.js +116 -0
- package/dist/runtime/composables/useLayouts.d.ts +3 -0
- package/dist/runtime/composables/useLayouts.js +21 -0
- package/dist/runtime/composables/useLocalization.d.ts +6 -0
- package/dist/runtime/composables/useLocalization.js +34 -0
- package/dist/runtime/composables/useLoginRedirect.d.ts +3 -0
- package/dist/runtime/composables/useLoginRedirect.js +15 -0
- package/dist/runtime/composables/useMutex.d.ts +3 -0
- package/dist/runtime/composables/useMutex.js +26 -0
- package/dist/runtime/composables/useNuxtError.d.ts +3 -0
- package/dist/runtime/composables/useNuxtError.js +13 -0
- package/dist/runtime/composables/useNuxtRoute.d.ts +3 -0
- package/dist/runtime/composables/useNuxtRoute.js +13 -0
- package/dist/runtime/composables/usePages.d.ts +5 -0
- package/dist/runtime/composables/usePages.js +27 -0
- package/dist/runtime/composables/useQuery.d.ts +3 -0
- package/dist/runtime/composables/useQuery.js +13 -0
- package/dist/runtime/composables/useToast.d.ts +1 -0
- package/dist/runtime/composables/useToast.js +5 -0
- package/dist/runtime/composables/useToken.d.ts +11 -0
- package/dist/runtime/composables/useToken.js +99 -0
- package/dist/runtime/composables/useUiStates.d.ts +9 -0
- package/dist/runtime/composables/useUiStates.js +9 -0
- package/dist/runtime/composables/useUnref.d.ts +3 -0
- package/dist/runtime/composables/useUnref.js +109 -0
- package/dist/runtime/plugins/auth.d.ts +2 -0
- package/dist/runtime/plugins/auth.js +81 -0
- package/dist/runtime/plugins/baked.d.ts +10 -0
- package/dist/runtime/plugins/baked.js +50 -0
- package/dist/runtime/plugins/cacheApplication.d.ts +2 -0
- package/dist/runtime/plugins/cacheApplication.js +27 -0
- package/dist/runtime/plugins/cacheUser.d.ts +2 -0
- package/dist/runtime/plugins/cacheUser.js +37 -0
- package/dist/runtime/plugins/errorHandling.d.ts +14 -0
- package/dist/runtime/plugins/errorHandling.js +96 -0
- package/dist/runtime/plugins/fetch.d.ts +2 -0
- package/dist/runtime/plugins/fetch.js +80 -0
- package/dist/runtime/plugins/localization.d.ts +2 -0
- package/dist/runtime/plugins/localization.js +18 -0
- package/dist/runtime/plugins/mutex.d.ts +7 -0
- package/dist/runtime/plugins/mutex.js +15 -0
- package/dist/runtime/plugins/primeVue.d.ts +2 -0
- package/dist/runtime/plugins/primeVue.js +75 -0
- package/dist/runtime/plugins/toast.d.ts +6 -0
- package/dist/runtime/plugins/toast.js +18 -0
- package/dist/runtime/plugins/trailingSlash.d.ts +2 -0
- package/dist/runtime/plugins/trailingSlash.js +18 -0
- package/dist/runtime/server/tsconfig.json +3 -0
- package/dist/types.d.mts +3 -0
- package/package.json +74 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
declare const _default: typeof __VLS_export;
|
|
2
|
+
export default _default;
|
|
3
|
+
declare const __VLS_export: import("vue").DefineComponent<{}, {
|
|
4
|
+
$props: Partial<typeof __VLS_props>;
|
|
5
|
+
item: Record<string, any>;
|
|
6
|
+
path: string;
|
|
7
|
+
}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
8
|
+
declare const __VLS_props: {
|
|
9
|
+
readonly item: Record<string, any>;
|
|
10
|
+
readonly path: string;
|
|
11
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
declare const _default: typeof __VLS_export;
|
|
2
|
+
export default _default;
|
|
3
|
+
declare const __VLS_export: import("vue").DefineComponent<{}, {
|
|
4
|
+
$props: Partial<typeof __VLS_props>;
|
|
5
|
+
schema: any;
|
|
6
|
+
data: any;
|
|
7
|
+
}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
8
|
+
declare const __VLS_props: {
|
|
9
|
+
readonly schema: any;
|
|
10
|
+
readonly data: any;
|
|
11
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<Skeleton
|
|
3
|
+
v-if="loading"
|
|
4
|
+
height="1.5rem"
|
|
5
|
+
/>
|
|
6
|
+
<span
|
|
7
|
+
v-else-if="data"
|
|
8
|
+
v-tooltip.bottom="tooltip"
|
|
9
|
+
>{{ text }}</span>
|
|
10
|
+
<span v-else>-</span>
|
|
11
|
+
</template>
|
|
12
|
+
|
|
13
|
+
<script setup>
|
|
14
|
+
import { computed } from "vue";
|
|
15
|
+
import { Skeleton } from "primevue";
|
|
16
|
+
import { useContext, useFormat } from "#imports";
|
|
17
|
+
const context = useContext();
|
|
18
|
+
const { truncate } = useFormat();
|
|
19
|
+
const { schema, data } = defineProps({
|
|
20
|
+
schema: { type: null, required: true },
|
|
21
|
+
data: { type: null, required: true }
|
|
22
|
+
});
|
|
23
|
+
const { maxLength } = schema;
|
|
24
|
+
const loading = context.injectLoading();
|
|
25
|
+
const lengthIsExceeded = computed(() => maxLength && data.length > maxLength);
|
|
26
|
+
const text = computed(() => lengthIsExceeded.value ? truncate(data, maxLength) : data);
|
|
27
|
+
const tooltip = computed(() => ({
|
|
28
|
+
value: `${data}`,
|
|
29
|
+
disabled: !lengthIsExceeded.value,
|
|
30
|
+
pt: {
|
|
31
|
+
root: {
|
|
32
|
+
style: maxLength ? `min-width: ${maxLength / 4}rem;` : ""
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}));
|
|
36
|
+
</script>
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
declare const _default: typeof __VLS_export;
|
|
2
|
+
export default _default;
|
|
3
|
+
declare const __VLS_export: import("vue").DefineComponent<{}, {
|
|
4
|
+
$props: Partial<typeof __VLS_props>;
|
|
5
|
+
schema: any;
|
|
6
|
+
data: any;
|
|
7
|
+
}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
8
|
+
declare const __VLS_props: {
|
|
9
|
+
readonly schema: any;
|
|
10
|
+
readonly data: any;
|
|
11
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function _default(): {};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { ref, onMounted, onBeforeUnmount } from "vue";
|
|
2
|
+
import { useRuntimeConfig } from "#app";
|
|
3
|
+
|
|
4
|
+
export default function() {
|
|
5
|
+
const { public: { composables: { useBreakpoints: { screens } } } } = useRuntimeConfig();
|
|
6
|
+
|
|
7
|
+
const sizes = Object
|
|
8
|
+
.keys(screens)
|
|
9
|
+
.reduce((result, key) => ({ [key]: removePx(screens[key]), ...result }), {});
|
|
10
|
+
|
|
11
|
+
const refs = {};
|
|
12
|
+
Object.keys(sizes).forEach(key => {
|
|
13
|
+
refs[`is${capitalize(key)}`] = ref(false);
|
|
14
|
+
refs[`isMax${capitalize(key)}`] = ref(false);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
const update = () => {
|
|
18
|
+
const width = globalThis.innerWidth;
|
|
19
|
+
|
|
20
|
+
Object.keys(sizes).forEach(key => {
|
|
21
|
+
refs[`is${capitalize(key)}`].value = width >= sizes[key];
|
|
22
|
+
refs[`isMax${capitalize(key)}`].value = width < sizes[key];
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
onMounted(() => {
|
|
27
|
+
update();
|
|
28
|
+
globalThis.addEventListener("resize", update);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
onBeforeUnmount(() => {
|
|
32
|
+
globalThis.removeEventListener("resize", update);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
function removePx(size) {
|
|
36
|
+
return typeof size === "string"
|
|
37
|
+
? parseInt(size.replace("px", ""), 10)
|
|
38
|
+
: size;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function capitalize(str) {
|
|
42
|
+
if(str.length === 0) { return str; }
|
|
43
|
+
|
|
44
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return refs;
|
|
48
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export default function _default(name: any, { expirationInMinutes }?: {
|
|
2
|
+
expirationInMinutes?: number | undefined;
|
|
3
|
+
}): {
|
|
4
|
+
buildKey: ({ path, query }: {
|
|
5
|
+
path: any;
|
|
6
|
+
query: any;
|
|
7
|
+
}) => any;
|
|
8
|
+
getOrCreate: ({ key, create }: {
|
|
9
|
+
key: any;
|
|
10
|
+
create: any;
|
|
11
|
+
}) => Promise<any>;
|
|
12
|
+
clear: () => void;
|
|
13
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
export default function(name, { expirationInMinutes = 60 } = {}) {
|
|
2
|
+
function buildKey({ path, query }) {
|
|
3
|
+
let result = path;
|
|
4
|
+
if(query) {
|
|
5
|
+
const search = new URLSearchParams(query);
|
|
6
|
+
search.sort();
|
|
7
|
+
result += `?${search}`;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
return result;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function isCacheValid(entry) {
|
|
14
|
+
return Date.now() - entry.createdAt < expirationInMinutes * 60 * 1000;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async function getOrCreate({ key, create }) {
|
|
18
|
+
if(typeof create !== "function") {
|
|
19
|
+
throw new Error("create must be a function");
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
key = `${name}[${key}]`;
|
|
23
|
+
|
|
24
|
+
const cached = localStorage.getItem(key);
|
|
25
|
+
if(cached) {
|
|
26
|
+
const entry = JSON.parse(cached);
|
|
27
|
+
if(isCacheValid(entry)) {
|
|
28
|
+
return entry.data;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const result = await create();
|
|
33
|
+
localStorage.setItem(key, JSON.stringify({
|
|
34
|
+
createdAt: Date.now(),
|
|
35
|
+
data: result
|
|
36
|
+
}));
|
|
37
|
+
|
|
38
|
+
return result;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function clear() {
|
|
42
|
+
const keysToClear = [];
|
|
43
|
+
for(let i = 0; i<localStorage.length; i++) {
|
|
44
|
+
const key = localStorage.key(i);
|
|
45
|
+
if(key.startsWith(name)) {
|
|
46
|
+
keysToClear.push(key);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
for(const key of keysToClear) {
|
|
51
|
+
localStorage.removeItem(key);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return {
|
|
56
|
+
buildKey,
|
|
57
|
+
getOrCreate,
|
|
58
|
+
clear
|
|
59
|
+
};
|
|
60
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { useNuxtApp } from "#app";
|
|
2
|
+
|
|
3
|
+
export default function() {
|
|
4
|
+
const { $composables } = useNuxtApp();
|
|
5
|
+
|
|
6
|
+
function resolve(name) {
|
|
7
|
+
if(!$composables[name]) { throw new Error(`Cannot resolve composable '${name}'`); }
|
|
8
|
+
|
|
9
|
+
return $composables[name]();
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return {
|
|
13
|
+
resolve
|
|
14
|
+
};
|
|
15
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export default function() {
|
|
2
|
+
|
|
3
|
+
function find(conditional, data) {
|
|
4
|
+
const conditions = conditional.conditions.filter(component => data[component.prop] === component.value);
|
|
5
|
+
if(conditions.length > 0) {
|
|
6
|
+
return conditions[0].component;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
return conditional.fallback;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return {
|
|
13
|
+
find
|
|
14
|
+
};
|
|
15
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export default function _default(): {
|
|
2
|
+
injectPath: () => string;
|
|
3
|
+
providePath: (name: any) => void;
|
|
4
|
+
injectDataDescriptor: () => null;
|
|
5
|
+
provideDataDescriptor: (value: any) => void;
|
|
6
|
+
injectData: () => {
|
|
7
|
+
ParentData: null;
|
|
8
|
+
Custom: null;
|
|
9
|
+
};
|
|
10
|
+
provideData: (value: any, key: any) => void;
|
|
11
|
+
injectLoading: () => import("vue").Ref<boolean, boolean>;
|
|
12
|
+
provideLoading: (value: any) => void;
|
|
13
|
+
injectPage: () => any;
|
|
14
|
+
providePage: (value: any) => void;
|
|
15
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { inject, provide, ref } from "vue";
|
|
2
|
+
|
|
3
|
+
export default function() {
|
|
4
|
+
function providePath(name) {
|
|
5
|
+
const path = inject("__bake_path", null);
|
|
6
|
+
provide("__bake_path", path ? `${path}/${name}` : name);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function injectPath() {
|
|
10
|
+
return inject("__bake_path", "");
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function injectDataDescriptor() {
|
|
14
|
+
return inject("__bake_data_descriptor", null);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function provideDataDescriptor(value) {
|
|
18
|
+
return provide("__bake_data_descriptor", value);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function injectData() {
|
|
22
|
+
return {
|
|
23
|
+
ParentData: inject("__bake_injected_data:ParentData", null),
|
|
24
|
+
Custom: inject("__bake_injected_data:Custom", null)
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function provideData(value, key) {
|
|
29
|
+
provide(`__bake_injected_data:${key}`, value);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function injectLoading() {
|
|
33
|
+
return inject("__bake_loading", ref(false));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function provideLoading(value) {
|
|
37
|
+
provide("__bake_loading", value);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function injectPage() {
|
|
41
|
+
return inject("__bake_page");
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function providePage(value) {
|
|
45
|
+
provide("__bake_page", value);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return {
|
|
49
|
+
injectPath,
|
|
50
|
+
providePath,
|
|
51
|
+
injectDataDescriptor,
|
|
52
|
+
provideDataDescriptor,
|
|
53
|
+
injectData,
|
|
54
|
+
provideData,
|
|
55
|
+
injectLoading,
|
|
56
|
+
provideLoading,
|
|
57
|
+
injectPage,
|
|
58
|
+
providePage
|
|
59
|
+
};
|
|
60
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export default function _default(): {
|
|
2
|
+
shouldLoad: (dataType: any) => boolean;
|
|
3
|
+
get: ({ data, injectedData }: {
|
|
4
|
+
data: any;
|
|
5
|
+
injectedData: any;
|
|
6
|
+
}) => any;
|
|
7
|
+
fetch: ({ data, injectedData }: {
|
|
8
|
+
data: any;
|
|
9
|
+
injectedData: any;
|
|
10
|
+
}) => Promise<any>;
|
|
11
|
+
fetchParameters: ({ data, injectedData }: {
|
|
12
|
+
data: any;
|
|
13
|
+
injectedData: any;
|
|
14
|
+
}) => Promise<any>;
|
|
15
|
+
};
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import { useRuntimeConfig } from "#app";
|
|
2
|
+
import { useComposableResolver, useUnref } from "#imports";
|
|
3
|
+
|
|
4
|
+
export default function() {
|
|
5
|
+
const datas = {
|
|
6
|
+
"Composite": Composite({ parentFetch: fetch, parentFetchParameters: fetchParameters }),
|
|
7
|
+
"Computed": Computed(),
|
|
8
|
+
"Injected": Injected(),
|
|
9
|
+
"Inline": Inline(),
|
|
10
|
+
"Remote": Remote({ parentFetch: fetch })
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
function shouldLoad(dataType) {
|
|
14
|
+
return datas[dataType]?.fetch !== undefined;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function get({ data, injectedData }) {
|
|
18
|
+
const type = data?.type;
|
|
19
|
+
if(!type) { return null; }
|
|
20
|
+
if(!datas[type]) { return null; }
|
|
21
|
+
if(!datas[type].get) { return null; }
|
|
22
|
+
|
|
23
|
+
return datas[type].get({ data, injectedData });
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async function fetch({ data, injectedData }) {
|
|
27
|
+
const fetcher = datas[data?.type];
|
|
28
|
+
if(!fetcher) { throw new Error(`${data?.type} is not a valid data type`); }
|
|
29
|
+
|
|
30
|
+
return fetcher.get
|
|
31
|
+
? fetcher.get({ data, injectedData })
|
|
32
|
+
: await fetcher.fetch({ data, injectedData });
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
async function fetchParameters({ data, injectedData }) {
|
|
36
|
+
const fetcher = datas[data?.type];
|
|
37
|
+
|
|
38
|
+
return fetcher?.fetchParameters
|
|
39
|
+
? fetcher.fetchParameters({ data, injectedData })
|
|
40
|
+
: [];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return {
|
|
44
|
+
shouldLoad,
|
|
45
|
+
get,
|
|
46
|
+
fetch,
|
|
47
|
+
fetchParameters
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function Composite({ parentFetch, parentFetchParameters }) {
|
|
52
|
+
const unref = useUnref();
|
|
53
|
+
|
|
54
|
+
async function fetch({ data, injectedData }) {
|
|
55
|
+
const result = {};
|
|
56
|
+
|
|
57
|
+
for(const part of data.parts) {
|
|
58
|
+
Object.assign(
|
|
59
|
+
result,
|
|
60
|
+
unref.deepUnref(await parentFetch({ data: part, injectedData }))
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return result;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
async function fetchParameters({ data, injectedData }) {
|
|
68
|
+
const result = [];
|
|
69
|
+
|
|
70
|
+
for(const part of data.parts) {
|
|
71
|
+
result.push(
|
|
72
|
+
...unref.deepUnref(await parentFetchParameters({ data: part, injectedData }))
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return result;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return {
|
|
80
|
+
fetch,
|
|
81
|
+
fetchParameters
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function Computed() {
|
|
86
|
+
const composableResolver = useComposableResolver();
|
|
87
|
+
|
|
88
|
+
async function fetch({ data }) {
|
|
89
|
+
const composable = (await composableResolver.resolve(data.composable)).default();
|
|
90
|
+
|
|
91
|
+
if(composable.compute) {
|
|
92
|
+
return composable.compute(...(data.args || []));
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if(composable.computeAsync) {
|
|
96
|
+
return await composable.computeAsync(...(data.args || []));
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
throw new Error("Data composable should have either `compute` or `computeAsync`");
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function fetchParameters({ data }) {
|
|
103
|
+
return data.args;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return {
|
|
107
|
+
fetch,
|
|
108
|
+
fetchParameters
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function Injected() {
|
|
113
|
+
function get({ data, injectedData }) {
|
|
114
|
+
const result = injectedData[data.key];
|
|
115
|
+
|
|
116
|
+
if(!data.prop) { return result; }
|
|
117
|
+
|
|
118
|
+
return result.value?.[data.prop];
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return {
|
|
122
|
+
get
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function Inline() {
|
|
127
|
+
function get({ data }) {
|
|
128
|
+
return data.value;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return {
|
|
132
|
+
get
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function Remote({ parentFetch }) {
|
|
137
|
+
const { public: { composables } } = useRuntimeConfig();
|
|
138
|
+
const unref = useUnref();
|
|
139
|
+
|
|
140
|
+
async function fetch({ data, injectedData }) {
|
|
141
|
+
const baseURL = composables.useDataFetcher.baseURL;
|
|
142
|
+
const headers = await fetchHeaders({ data, injectedData });
|
|
143
|
+
const query = await fetchQuery({ data, injectedData });
|
|
144
|
+
|
|
145
|
+
const options = { baseURL, headers: headers, query: query };
|
|
146
|
+
if(data.attributes) {
|
|
147
|
+
options.attributes = data.attributes;
|
|
148
|
+
}
|
|
149
|
+
const retry = composables?.useDataFetcher?.retry ?? false;
|
|
150
|
+
|
|
151
|
+
if(retry) {
|
|
152
|
+
return await fetchWithRetry(data.path, options, retry);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return await $fetch(data.path, { ...options, retry: false });
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
async function fetchHeaders({ data, injectedData }) {
|
|
159
|
+
return data.headers
|
|
160
|
+
? unref.deepUnref(await parentFetch({ data: data.headers, injectedData }))
|
|
161
|
+
: { };
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
async function fetchQuery({ data, injectedData }) {
|
|
165
|
+
return data.query
|
|
166
|
+
? unref.deepUnref(await parentFetch({ data: data.query, injectedData }))
|
|
167
|
+
: { };
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
async function fetchParameters(options) {
|
|
171
|
+
return Object.values(await fetchQuery(options));
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
async function fetchWithRetry(url, options,
|
|
175
|
+
{ maxRetry = Number.MAX_VALUE, delay = 200 } = { }
|
|
176
|
+
) {
|
|
177
|
+
let lastError = null;
|
|
178
|
+
for(let i = -1; i < maxRetry; i++) { // i starts at -1 to allow for the first attempt
|
|
179
|
+
try {
|
|
180
|
+
return await $fetch(url, { ...options, retry: false });
|
|
181
|
+
} catch (error) {
|
|
182
|
+
lastError = error;
|
|
183
|
+
|
|
184
|
+
if(error.response) { // server is up and returned and error
|
|
185
|
+
break;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
await wait(delay);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
throw lastError;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function wait(ms) {
|
|
196
|
+
return new Promise(resolve => setTimeout(resolve, ms));
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
return {
|
|
200
|
+
fetch,
|
|
201
|
+
fetchParameters
|
|
202
|
+
};
|
|
203
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export default function _default(): {
|
|
2
|
+
asClasses: (path: any, prefix?: string) => any;
|
|
3
|
+
asCurrency: (value: any, { shorten, shortenThousands }?: {}) => "-" | {
|
|
4
|
+
shortened: boolean;
|
|
5
|
+
toString: () => string;
|
|
6
|
+
};
|
|
7
|
+
asDecimal: (value: any) => any;
|
|
8
|
+
asMonth: (date: any) => any;
|
|
9
|
+
asNumber: (value: any, { shorten, shortenThousands, formatOptions }?: {}) => "-" | {
|
|
10
|
+
shortened: boolean;
|
|
11
|
+
toString: () => string;
|
|
12
|
+
};
|
|
13
|
+
asPercentage: (value: any) => any;
|
|
14
|
+
format: (formatString: any, args: any) => any;
|
|
15
|
+
truncate: (value: any, length: any) => any;
|
|
16
|
+
};
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { useRuntimeConfig } from "#app";
|
|
2
|
+
import { useLocalization } from "#imports";
|
|
3
|
+
|
|
4
|
+
export default function() {
|
|
5
|
+
const { locale: currentLocale, localize: lc } = useLocalization({ group: "useFormat" });
|
|
6
|
+
const { public: { composables } } = useRuntimeConfig();
|
|
7
|
+
|
|
8
|
+
const locale = currentLocale.value || "en";
|
|
9
|
+
const currency = composables?.useFormat?.currency || "USD";
|
|
10
|
+
const B = lc("suffix.B"); // billions
|
|
11
|
+
const M = lc("suffix.M"); // millions
|
|
12
|
+
const K = lc("suffix.K"); // thousands
|
|
13
|
+
|
|
14
|
+
const STAGES = [
|
|
15
|
+
{ threshold: 1_000_000_000, divisor: 1_000_000_000, suffix: B, fraction: true },
|
|
16
|
+
{ threshold: 1_000_000, divisor: 1_000_000, suffix: M, fraction: true },
|
|
17
|
+
{ threshold: 1_000, divisor: 1_000, suffix: K, fraction: true },
|
|
18
|
+
{ threshold: 999.9999, divisor: 1, suffix: "", fraction: false },
|
|
19
|
+
{ threshold: Number.MIN_VALUE, divisor: 1, suffix: "", fraction: true }
|
|
20
|
+
];
|
|
21
|
+
|
|
22
|
+
function asClasses(path,
|
|
23
|
+
prefix = "b--"
|
|
24
|
+
) {
|
|
25
|
+
return path.split("/")
|
|
26
|
+
.filter(item => item.length > 0)
|
|
27
|
+
.map(item => `${prefix}${item}`);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function asCurrency(value,
|
|
31
|
+
{ shorten, shortenThousands } = { }
|
|
32
|
+
) {
|
|
33
|
+
return asNumber(value, {
|
|
34
|
+
shorten,
|
|
35
|
+
shortenThousands,
|
|
36
|
+
formatOptions: {
|
|
37
|
+
style: "currency",
|
|
38
|
+
currency
|
|
39
|
+
}
|
|
40
|
+
}) ;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function asDecimal(value) {
|
|
44
|
+
value ||= "-";
|
|
45
|
+
|
|
46
|
+
return value.toLocaleString(locale, { style: "decimal", maximumFractionDigits: 2 });
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function asMonth(date) {
|
|
50
|
+
return date.toLocaleString(locale, { month: "long" });
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function asNumber(value,
|
|
54
|
+
{ shorten, shortenThousands, formatOptions } = { }
|
|
55
|
+
) {
|
|
56
|
+
if(!value) { return "-"; }
|
|
57
|
+
|
|
58
|
+
shorten ??= true;
|
|
59
|
+
shortenThousands ??= false;
|
|
60
|
+
formatOptions ??= { };
|
|
61
|
+
|
|
62
|
+
const stage = shorten
|
|
63
|
+
? STAGES.find(s => (shortenThousands || s.threshold !== 1_000) && Math.abs(value) >= s.threshold) ?? STAGES[STAGES.length - 1]
|
|
64
|
+
: STAGES[STAGES.length - 1];
|
|
65
|
+
const shownValue = value / stage.divisor;
|
|
66
|
+
|
|
67
|
+
const fractionDigitCount = stage.fraction ? 2 : 0;
|
|
68
|
+
const formattedResult = shownValue.toLocaleString(locale, {
|
|
69
|
+
maximumFractionDigits: fractionDigitCount,
|
|
70
|
+
trailingZeroDisplay: "stripIfInteger",
|
|
71
|
+
...formatOptions
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
return {
|
|
75
|
+
shortened: stage.suffix !== "",
|
|
76
|
+
toString: () => formattedResult + stage.suffix
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function asPercentage(value) {
|
|
81
|
+
value ||= "-";
|
|
82
|
+
|
|
83
|
+
return value.toLocaleString(locale, { style: "percent", maximumFractionDigits: 2 });
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function format(formatString, args) {
|
|
87
|
+
// TODO: this format call is temporary, final design should handle path
|
|
88
|
+
// variables using name, not index, e.g., /test/{0} -> /test/{id}
|
|
89
|
+
return formatString.replace(/(\{\{\d\}\}|\{\d\})/g, part => {
|
|
90
|
+
if(part.substring(0, 2) === "{{") { return part; } // escape
|
|
91
|
+
|
|
92
|
+
const index = parseInt(part.match(/\d/)[0]);
|
|
93
|
+
|
|
94
|
+
return args[index];
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function truncate(value, length) {
|
|
99
|
+
if(!value || !length || value.length <= length - 3) {
|
|
100
|
+
return value;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return value.substring(0, length - 3).concat("...");
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return {
|
|
107
|
+
asClasses,
|
|
108
|
+
asCurrency,
|
|
109
|
+
asDecimal,
|
|
110
|
+
asMonth,
|
|
111
|
+
asNumber,
|
|
112
|
+
asPercentage,
|
|
113
|
+
format,
|
|
114
|
+
truncate
|
|
115
|
+
};
|
|
116
|
+
};
|