nuxt-glorious 0.7.9-7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. package/README.md +29 -0
  2. package/dist/module.cjs +5 -0
  3. package/dist/module.d.mts +7 -0
  4. package/dist/module.d.ts +7 -0
  5. package/dist/module.json +5 -0
  6. package/dist/module.mjs +93 -0
  7. package/dist/runtime/assets/icons/glorious-arrow.svg +3 -0
  8. package/dist/runtime/assets/icons/glorious-check-fill.svg +10 -0
  9. package/dist/runtime/assets/icons/glorious-x.svg +3 -0
  10. package/dist/runtime/assets/style/components/buttons.css +88 -0
  11. package/dist/runtime/assets/style/components/drawer.css +55 -0
  12. package/dist/runtime/assets/style/components/dropdown.css +18 -0
  13. package/dist/runtime/assets/style/components/editor.css +4 -0
  14. package/dist/runtime/assets/style/components/file.css +65 -0
  15. package/dist/runtime/assets/style/components/input.css +91 -0
  16. package/dist/runtime/assets/style/components/modal.css +46 -0
  17. package/dist/runtime/assets/style/components/paginate.css +17 -0
  18. package/dist/runtime/assets/style/components/select.css +54 -0
  19. package/dist/runtime/assets/style/components/tab.css +9 -0
  20. package/dist/runtime/assets/style/components/textarea.css +64 -0
  21. package/dist/runtime/components/G/Breadcrump.vue +41 -0
  22. package/dist/runtime/components/G/Button.vue +163 -0
  23. package/dist/runtime/components/G/CountDown.vue +65 -0
  24. package/dist/runtime/components/G/Drawer.vue +80 -0
  25. package/dist/runtime/components/G/Dropdown.vue +63 -0
  26. package/dist/runtime/components/G/File.vue +142 -0
  27. package/dist/runtime/components/G/Icon/index.vue +142 -0
  28. package/dist/runtime/components/G/Input.vue +269 -0
  29. package/dist/runtime/components/G/IntersectionObserve.vue +22 -0
  30. package/dist/runtime/components/G/Loading.vue +35 -0
  31. package/dist/runtime/components/G/Modal.vue +92 -0
  32. package/dist/runtime/components/G/Paginate.vue +130 -0
  33. package/dist/runtime/components/G/Radio.vue +38 -0
  34. package/dist/runtime/components/G/Select.vue +145 -0
  35. package/dist/runtime/components/G/Tab.vue +57 -0
  36. package/dist/runtime/components/G/Wizard.vue +123 -0
  37. package/dist/runtime/components/G/textarea.vue +141 -0
  38. package/dist/runtime/composables/useGloriousAppSetting.d.ts +11 -0
  39. package/dist/runtime/composables/useGloriousAppSetting.mjs +37 -0
  40. package/dist/runtime/composables/useGloriousFetch.d.ts +13 -0
  41. package/dist/runtime/composables/useGloriousFetch.mjs +107 -0
  42. package/dist/runtime/composables/useGloriousHead.d.ts +8 -0
  43. package/dist/runtime/composables/useGloriousHead.mjs +33 -0
  44. package/dist/runtime/middlewares/Auth.d.ts +2 -0
  45. package/dist/runtime/middlewares/Auth.mjs +37 -0
  46. package/dist/runtime/middlewares/AuthStrategy.d.ts +2 -0
  47. package/dist/runtime/middlewares/AuthStrategy.mjs +17 -0
  48. package/dist/runtime/plugins/Drawer.d.ts +2 -0
  49. package/dist/runtime/plugins/Drawer.mjs +35 -0
  50. package/dist/runtime/plugins/Modal.d.ts +2 -0
  51. package/dist/runtime/plugins/Modal.mjs +38 -0
  52. package/dist/runtime/plugins/TailwindColor.d.ts +6 -0
  53. package/dist/runtime/plugins/TailwindColor.mjs +10 -0
  54. package/dist/runtime/plugins/glorious-app-setting.d.ts +2 -0
  55. package/dist/runtime/plugins/glorious-app-setting.mjs +11 -0
  56. package/dist/runtime/plugins/shortcut-key.d.ts +2 -0
  57. package/dist/runtime/plugins/shortcut-key.mjs +11 -0
  58. package/dist/runtime/stores/GloriousStore.d.ts +9 -0
  59. package/dist/runtime/stores/GloriousStore.mjs +88 -0
  60. package/dist/types.d.mts +16 -0
  61. package/dist/types.d.ts +16 -0
  62. package/package.json +53 -0
@@ -0,0 +1,38 @@
1
+ <script lang="ts" setup>
2
+ const props = defineProps({
3
+ name: {
4
+ required: false,
5
+ default: "radio",
6
+ type: String,
7
+ },
8
+ value: {
9
+ required: false,
10
+ default: "radio",
11
+ type: [String, Number, null],
12
+ },
13
+ modelValue: {
14
+ required: false,
15
+ default: "",
16
+ type: [String, Number, null],
17
+ },
18
+ checked: {
19
+ required: false,
20
+ default: false,
21
+ type: Boolean,
22
+ },
23
+ });
24
+
25
+ const emits: any = defineEmits(["update:modelValue"]);
26
+ </script>
27
+
28
+ <template>
29
+ <div>
30
+ <input
31
+ type="radio"
32
+ :name="props.name"
33
+ :value="props.value"
34
+ @click="emits('update:modelValue', props.value)"
35
+ :checked="props.checked"
36
+ />
37
+ </div>
38
+ </template>
@@ -0,0 +1,145 @@
1
+ <script lang="ts" setup>
2
+ import { GloriousStore, ref, watch } from "#imports";
3
+ const props = defineProps({
4
+ modelValue: {
5
+ required: false,
6
+ default: null,
7
+ type: [String, Number],
8
+ },
9
+ options: {
10
+ required: true,
11
+ default: [],
12
+ type: Array<object>,
13
+ },
14
+ color: {
15
+ required: false,
16
+ default: "primary",
17
+ type: String,
18
+ },
19
+ size: {
20
+ required: false,
21
+ default: "md",
22
+ type: String,
23
+ },
24
+ title: {
25
+ required: false,
26
+ default: "",
27
+ type: String,
28
+ },
29
+ error: {
30
+ required: false,
31
+ default: "|",
32
+ type: String,
33
+ },
34
+ disabled: {
35
+ required: false,
36
+ default: false,
37
+ type: Boolean,
38
+ },
39
+ placeholder: {
40
+ required: false,
41
+ default: "",
42
+ type: String,
43
+ },
44
+ });
45
+ const selectValue = ref(null);
46
+ const emits = defineEmits(["update:modelValue"]);
47
+ watch(
48
+ () => selectValue.value,
49
+ () => {
50
+ emits("update:modelValue", selectValue.value);
51
+ }
52
+ );
53
+
54
+ const gs: any = GloriousStore();
55
+ const error: any = props.error.split("|");
56
+
57
+ // -------------------------------------- init value
58
+ selectValue.value = props.modelValue;
59
+ watch(
60
+ () => props.modelValue,
61
+ () => {
62
+ selectValue.value = props.modelValue;
63
+ }
64
+ );
65
+ </script>
66
+
67
+ <template>
68
+ <div class="flex flex-col">
69
+ <span class="text-[14px] font-medium text-gray-500">{{ props.title }}</span>
70
+ <select
71
+ v-model="selectValue"
72
+ aria-label="glorious select"
73
+ :disabled="props.disabled"
74
+ :class="[`glorious-select-${props.color}`, props.size]"
75
+ >
76
+ <option
77
+ v-for="(item, index) in props.options"
78
+ :key="index"
79
+ :value="item.value"
80
+ >
81
+ {{ item.text }}
82
+ </option>
83
+ </select>
84
+ <span v-if="gs.forms[error[0]]?.errors[error[1]]" class="text-red-500">
85
+ {{ gs.forms[error[0]].errors[error[1]][0] }}
86
+ </span>
87
+ </div>
88
+ </template>
89
+
90
+ <style>
91
+ .xl.glorious-select-orange, .xl.glorious-select-blue, .xl.glorious-select-gray, .xl.glorious-select-red, .xl.glorious-select-primary {
92
+ @apply py-[0.657rem];
93
+ }
94
+ .lg.glorious-select-orange, .lg.glorious-select-blue, .lg.glorious-select-gray, .lg.glorious-select-red, .lg.glorious-select-primary {
95
+ @apply py-[0.532rem];
96
+ }
97
+ .md.glorious-select-orange, .md.glorious-select-blue, .md.glorious-select-gray, .md.glorious-select-red, .md.glorious-select-primary {
98
+ @apply py-[0.407rem];
99
+ }
100
+ .sm.glorious-select-orange, .sm.glorious-select-blue, .sm.glorious-select-gray, .sm.glorious-select-red, .sm.glorious-select-primary {
101
+ @apply py-[0.282rem];
102
+ }
103
+ .xsm.glorious-select-orange, .xsm.glorious-select-blue, .xsm.glorious-select-gray, .xsm.glorious-select-red, .xsm.glorious-select-primary {
104
+ @apply py-[0.157rem];
105
+ }
106
+
107
+ .glorious-select-orange:focus-visible, .glorious-select-blue:focus-visible, .glorious-select-gray:focus-visible, .glorious-select-red:focus-visible, .glorious-select-primary:focus-visible {
108
+ @apply outline-none ring-2;
109
+ }
110
+
111
+ .glorious-select-primary {
112
+ @apply rounded-md ring-1 ring-green-500 px-3 text-gray-500 text-[14px];
113
+ }
114
+ .glorious-select-primary:disabled {
115
+ @apply cursor-not-allowed;
116
+ }
117
+
118
+ .glorious-select-red {
119
+ @apply rounded-md ring-1 ring-red-500 px-3;
120
+ }
121
+ .glorious-select-red:disabled {
122
+ @apply cursor-not-allowed;
123
+ }
124
+
125
+ .glorious-select-gray {
126
+ @apply rounded-md ring-1 ring-gray-500 px-3;
127
+ }
128
+ .glorious-select-gray:disabled {
129
+ @apply cursor-not-allowed;
130
+ }
131
+
132
+ .glorious-select-blue {
133
+ @apply rounded-md ring-1 ring-blue-500 px-3;
134
+ }
135
+ .glorious-select-blue:disabled {
136
+ @apply cursor-not-allowed;
137
+ }
138
+
139
+ .glorious-select-orange {
140
+ @apply rounded-md ring-1 ring-orange-500 px-3;
141
+ }
142
+ .glorious-select-orange:disabled {
143
+ @apply cursor-not-allowed;
144
+ }
145
+ </style>
@@ -0,0 +1,57 @@
1
+ <script lang="ts" setup>
2
+ interface itemsType {
3
+ active: boolean;
4
+ text: string;
5
+ key: string;
6
+ }
7
+
8
+ const props = defineProps({
9
+ items: {
10
+ required: true,
11
+ default: [],
12
+ type: Array<itemsType>,
13
+ },
14
+ modelValue: {
15
+ required: true,
16
+ type: String,
17
+ },
18
+ });
19
+ const emits = defineEmits(["update:modelValue"]);
20
+ const tabClicked: any = (key: string, event: any) => {
21
+ emits("update:modelValue", key);
22
+ Array.from(event.currentTarget.parentElement.parentElement.children).map(
23
+ (item: any) => item.children[0].classList.remove("active")
24
+ );
25
+ event.currentTarget.classList.add("active");
26
+ };
27
+ </script>
28
+
29
+ <template>
30
+ <div class="glorious-tab">
31
+ <div
32
+ v-for="(item, index) in props.items"
33
+ :key="index"
34
+ class="flex justify-center"
35
+ :style="{ flexBasis: `${100 / props.items.length}%` }"
36
+ >
37
+ <button
38
+ :class="item.active ? `active` : ''"
39
+ @click="tabClicked(item.key, $event)"
40
+ >
41
+ {{ item.text }}
42
+ </button>
43
+ </div>
44
+ </div>
45
+ </template>
46
+
47
+ <style>
48
+ .glorious-tab {
49
+ @apply flex justify-between bg-green-100 px-3 py-2 rounded-lg gap-3 overflow-y-auto w-full shadow-md;
50
+ }
51
+ .glorious-tab > div > button {
52
+ @apply text-gray-700 text-[14px] hover:bg-green-200 hover:text-gray-800 cursor-pointer px-2 py-1 rounded-lg;
53
+ }
54
+ .glorious-tab > div > button.active {
55
+ @apply font-bold text-white bg-green-700;
56
+ }
57
+ </style>
@@ -0,0 +1,123 @@
1
+ <script lang="ts" setup>
2
+ import { watch } from "#imports";
3
+ const props = defineProps({
4
+ items: {
5
+ required: true,
6
+ type: Object,
7
+ },
8
+ step: {
9
+ required: true,
10
+ type: Number,
11
+ default: 1,
12
+ },
13
+ progressColor: {
14
+ required: false,
15
+ default: "#00ff00",
16
+ type: String,
17
+ },
18
+ bgColor: {
19
+ required: false,
20
+ default: "0000ff",
21
+ type: String,
22
+ },
23
+ });
24
+
25
+ const methods = {
26
+ computeWizardMobile: () => {
27
+ const circularProgress = document.querySelectorAll(".circular-progress");
28
+ Array.from(circularProgress).forEach((progressBar: any) => {
29
+ const progressValue: any = progressBar.querySelector(".percentage");
30
+ const innerCircle: any = progressBar.querySelector(".inner-circle");
31
+ console.log(props.step);
32
+ const eachStep = (1 / props.items.length) * 100;
33
+ let startValue =
34
+ Number(progressBar.getAttribute("data-percentage")) - eachStep < 0
35
+ ? 0
36
+ : Number(progressBar.getAttribute("data-percentage"));
37
+
38
+ const endValue: any =
39
+ props.step === 0
40
+ ? 0
41
+ : Number(progressBar.getAttribute("data-percentage")) + eachStep,
42
+ progressColor = progressBar.getAttribute("data-progress-color");
43
+ console.log(startValue, endValue);
44
+ const progress = setInterval(() => {
45
+ progressValue.textContent = props.step + 1;
46
+
47
+ innerCircle.style.backgroundColor = `${progressBar.getAttribute(
48
+ "data-inner-circle-color"
49
+ )}`;
50
+
51
+ progressBar.style.background = `conic-gradient(${progressColor} ${
52
+ startValue * 3.6
53
+ }deg,${progressBar.getAttribute("data-bg-color")} 0deg)`;
54
+ if (startValue === endValue) {
55
+ clearInterval(progress);
56
+ }
57
+ startValue++;
58
+ }, 10);
59
+ });
60
+ },
61
+ };
62
+
63
+ onMounted(() => {
64
+ methods.computeWizardMobile();
65
+ });
66
+
67
+ watch(
68
+ () => props.step,
69
+ () => {
70
+ methods.computeWizardMobile();
71
+ }
72
+ );
73
+ </script>
74
+
75
+ <template>
76
+ <div class="glorious-wizard">
77
+ <div class="glorious-wizard-desktop">
78
+ <div v-for="(item, index) in props.items" :key="index">
79
+ <div class="circle" :class="index < props.step ? 'checked' : ''">
80
+ <GIcon
81
+ v-if="index < props.step"
82
+ name="glorious-check-fill"
83
+ color="#ffffff"
84
+ />
85
+
86
+ <span v-else>{{ index }}</span>
87
+ </div>
88
+ <span class="text-[14px] font-medium">{{ item }}</span>
89
+ </div>
90
+ </div>
91
+ <div class="glorious-wizard-mobile">
92
+ <div
93
+ class="circular-progress"
94
+ :style="{ width: '48px', height: '48px' }"
95
+ :data-percentage="(props.step / props.items.length) * 100"
96
+ :data-progress-color="props.progressColor"
97
+ :data-bg-color="props.bgColor"
98
+ >
99
+ <div
100
+ class="inner-circle"
101
+ :class="[props.step === props.items.length ? 'checked' : '']"
102
+ :style="{ width: '44px', height: '44px' }"
103
+ />
104
+ <p
105
+ v-show="props.step !== props.items.length"
106
+ class="percentage text-blue-500"
107
+ >
108
+ {{ props.step + 1 }}
109
+ </p>
110
+ <GIcon
111
+ v-show="props.step === props.items.length"
112
+ name="glorious-check-fill"
113
+ color="#ffffff"
114
+ />
115
+ </div>
116
+ <span>{{ props.items[props.step] }}</span>
117
+ </div>
118
+ </div>
119
+ </template>
120
+
121
+ <style scoped>
122
+ .glorious-wizard{@apply md:w-full w-max}.glorious-wizard-desktop{@apply md:flex hidden flex-wrap gap-[3%] w-full justify-center}.glorious-wizard-desktop div{@apply flex flex-col items-center}.glorious-wizard-desktop>div>div.circle{@apply rounded-full border border-blue-200 w-12 h-12 flex justify-center items-center}.glorious-wizard-desktop>div>div.circle.checked{@apply border-green-500 bg-green-500}.glorious-wizard-mobile{@apply w-max flex flex-col items-center}.glorious-wizard-mobile>span{@apply text-gray-500 text-[12px]}.circular-progress{align-items:center;border-radius:50%;display:flex;justify-content:center}.circular-progress p,.circular-progress>div{@apply z-[25] text-gray-500}.inner-circle{background-color:#fff;border-radius:50%;position:absolute}.inner-circle.checked{@apply bg-green-500}.percentage{font-size:1rem;position:relative}
123
+ </style>
@@ -0,0 +1,141 @@
1
+ <script setup lang="ts">
2
+ import { GloriousStore, ref, watch } from "#imports";
3
+ const props = defineProps({
4
+ modelValue: {
5
+ required: false,
6
+ default: "",
7
+ type: String,
8
+ },
9
+ color: {
10
+ required: false,
11
+ default: "primary",
12
+ type: String,
13
+ },
14
+ placeholder: {
15
+ required: false,
16
+ default: "",
17
+ type: String,
18
+ },
19
+ title: {
20
+ required: false,
21
+ default: "",
22
+ type: String,
23
+ },
24
+ size: {
25
+ required: false,
26
+ default: "md",
27
+ type: String,
28
+ },
29
+ error: {
30
+ required: false,
31
+ default: "|",
32
+ type: String,
33
+ },
34
+ disabled: {
35
+ required: false,
36
+ default: false,
37
+ type: Boolean,
38
+ },
39
+ autocomplete: {
40
+ required: false,
41
+ default: "off",
42
+ type: String,
43
+ },
44
+ });
45
+
46
+ const inputValue: any = ref(null);
47
+ if (props.modelValue !== "") inputValue.value = props.modelValue;
48
+ const emits = defineEmits(["update:modelValue"]);
49
+ watch(
50
+ () => inputValue.value,
51
+ () => emits("update:modelValue", inputValue.value)
52
+ );
53
+
54
+ const gs: any = GloriousStore();
55
+ const error: any = props.error.split("|");
56
+ </script>
57
+
58
+ <template>
59
+ <div class="flex flex-col">
60
+ <span class="text-[14px] font-medium text-gray-500">{{ props.title }}</span>
61
+ <div class="glorious-textarea">
62
+ <textarea
63
+ v-model="inputValue"
64
+ :autocomplete="props.autocomplete"
65
+ :class="[props.size, `glorious-textarea-${props.color}`]"
66
+ :placeholder="props.placeholder"
67
+ :disabled="props.disabled"
68
+ />
69
+ </div>
70
+ <span v-if="gs.forms[error[0]]?.errors[error[1]]" class="text-red-500">
71
+ {{ gs.forms[error[0]].errors[error[1]][0] }}
72
+ </span>
73
+ </div>
74
+ </template>
75
+
76
+ <style>
77
+ .xl.glorious-textarea-orange, .xl.glorious-textarea-blue, .xl.glorious-textarea-gray, .xl.glorious-textarea-red, .xl.glorious-textarea-primary {
78
+ @apply py-2.5;
79
+ }
80
+ .lg.glorious-textarea-orange, .lg.glorious-textarea-blue, .lg.glorious-textarea-gray, .lg.glorious-textarea-red, .lg.glorious-textarea-primary {
81
+ @apply py-2;
82
+ }
83
+ .md.glorious-textarea-orange, .md.glorious-textarea-blue, .md.glorious-textarea-gray, .md.glorious-textarea-red, .md.glorious-textarea-primary {
84
+ @apply py-1.5;
85
+ }
86
+ .sm.glorious-textarea-orange, .sm.glorious-textarea-blue, .sm.glorious-textarea-gray, .sm.glorious-textarea-red, .sm.glorious-textarea-primary {
87
+ @apply py-1;
88
+ }
89
+ .xsm.glorious-textarea-orange, .xsm.glorious-textarea-blue, .xsm.glorious-textarea-gray, .xsm.glorious-textarea-red, .xsm.glorious-textarea-primary {
90
+ @apply py-0.5;
91
+ }
92
+
93
+ .glorious-textarea-orange:focus-visible, .glorious-textarea-blue:focus-visible, .glorious-textarea-gray:focus-visible, .glorious-textarea-red:focus-visible, .glorious-textarea-primary:focus-visible {
94
+ @apply outline-none ring-2;
95
+ }
96
+
97
+ .glorious-textarea-primary {
98
+ @apply rounded-md ring-1 ring-green-500 px-3;
99
+ }
100
+ .glorious-textarea-primary:disabled {
101
+ @apply bg-green-300 cursor-not-allowed;
102
+ }
103
+
104
+ .glorious-textarea-red {
105
+ @apply rounded-md ring-1 ring-red-500 px-3;
106
+ }
107
+ .glorious-textarea-red:disabled {
108
+ @apply cursor-not-allowed;
109
+ }
110
+
111
+ .glorious-textarea-gray {
112
+ @apply rounded-md ring-1 ring-gray-500 px-3;
113
+ }
114
+ .glorious-textarea-gray:disabled {
115
+ @apply cursor-not-allowed;
116
+ }
117
+
118
+ .glorious-textarea-blue {
119
+ @apply rounded-md ring-1 ring-blue-500 px-3;
120
+ }
121
+ .glorious-textarea-blue:disabled {
122
+ @apply cursor-not-allowed;
123
+ }
124
+
125
+ .glorious-textarea-orange {
126
+ @apply rounded-md ring-1 ring-orange-500 px-3;
127
+ }
128
+ .glorious-textarea-orange:disabled {
129
+ @apply cursor-not-allowed;
130
+ }
131
+
132
+ .glorious-textarea {
133
+ @apply relative w-full;
134
+ }
135
+ .glorious-textarea > textarea {
136
+ @apply w-full;
137
+ }
138
+ .glorious-textarea > textarea::placeholder {
139
+ @apply text-[14px];
140
+ }
141
+ </style>
@@ -0,0 +1,11 @@
1
+ interface appSettingInterface {
2
+ dir?: String;
3
+ darkMode?: Boolean;
4
+ }
5
+ export declare const useGloriousAppSetting: {
6
+ getSetting: () => appSettingInterface;
7
+ setSetting: (key: any, value: any) => void;
8
+ setDarkMode: () => void;
9
+ setDir: (type: "rtl" | "ltr") => void;
10
+ };
11
+ export {};
@@ -0,0 +1,37 @@
1
+ import { useCookie } from "#imports";
2
+ import defu from "defu";
3
+ const defaultSetting = {
4
+ dir: "rtl",
5
+ darkMode: false
6
+ };
7
+ export const useGloriousAppSetting = {
8
+ getSetting: () => {
9
+ const appSetting = useCookie("glorious-app-setting");
10
+ let result = {};
11
+ if (typeof appSetting.value === "undefined") {
12
+ appSetting.value = defaultSetting;
13
+ result = defaultSetting;
14
+ } else
15
+ result = defu(appSetting.value, defaultSetting);
16
+ return result;
17
+ },
18
+ setSetting: (key, value) => {
19
+ const setting = useGloriousAppSetting.getSetting();
20
+ setting[key] = value;
21
+ const appSetting = useCookie("glorious-app-setting");
22
+ appSetting.value[key] = value;
23
+ },
24
+ setDarkMode: () => {
25
+ const html = document.getElementsByTagName("html")[0];
26
+ useGloriousAppSetting.setSetting(
27
+ "darkMode",
28
+ !html.classList.contains("dark")
29
+ );
30
+ html.classList.toggle("dark");
31
+ },
32
+ setDir: (type) => {
33
+ const html = document.getElementsByTagName("html")[0];
34
+ html.dir = type;
35
+ useGloriousAppSetting.setSetting("dir", type);
36
+ }
37
+ };
@@ -0,0 +1,13 @@
1
+ interface gloriousFetchOptions {
2
+ gKey?: String;
3
+ params?: Object;
4
+ server?: Boolean;
5
+ is$?: Boolean;
6
+ lazy?: Boolean;
7
+ headers?: Object;
8
+ body?: Object;
9
+ method?: "POST" | "GET" | "PATCH" | "PUT" | "DELETE" | "HEAD";
10
+ credentials?: "same-origin" | "include";
11
+ }
12
+ export default function (url: string, options: gloriousFetchOptions): Promise<unknown>;
13
+ export {};
@@ -0,0 +1,107 @@
1
+ import { useCookie, useFetch, useRuntimeConfig } from "nuxt/app";
2
+ import { GloriousStore } from "../stores/GloriousStore.mjs";
3
+ import defu from "defu";
4
+ const defaultOptions = {
5
+ server: false,
6
+ method: "GET",
7
+ lazy: true,
8
+ is$: true,
9
+ params: {},
10
+ headers: {
11
+ Accept: "application/json"
12
+ },
13
+ body: {},
14
+ credentials: "same-origin"
15
+ };
16
+ export default function(url, options) {
17
+ const moduleConfig = useRuntimeConfig();
18
+ options = defu(moduleConfig.public.glorious.fetch, options, defaultOptions);
19
+ const gs = GloriousStore();
20
+ const gKey = computeGKey(options.gKey, url);
21
+ options.params = computeParams(options.params);
22
+ options.headers = { ...options.headers, ...computeAuth() };
23
+ if (Object.entries(options.body).length === 0)
24
+ delete options.body;
25
+ if (Object.prototype.hasOwnProperty.call(options, "bodyType") && options.bodyType === "formData") {
26
+ const form = new FormData();
27
+ Object.entries(options.body).forEach((item) => {
28
+ if (item[1] === null)
29
+ return;
30
+ if (Object.prototype.hasOwnProperty.call(options, "fileKey") && options.fileKey.includes(item[0]))
31
+ form.append(item[0], item[1]);
32
+ else {
33
+ if (typeof item[1] === "object")
34
+ Object.entries(item[1]).forEach((nestedItem, index) => {
35
+ form.append(`${item[0]}[${index}]`, nestedItem[1]);
36
+ });
37
+ else
38
+ form.append(`${item[0]}`, item[1]);
39
+ }
40
+ });
41
+ options.body = form;
42
+ }
43
+ const opt = {
44
+ ...options,
45
+ onRequest() {
46
+ try {
47
+ gs.loading[gKey] = true;
48
+ } catch (e) {
49
+ }
50
+ },
51
+ onResponse({ response: res }) {
52
+ try {
53
+ gs.loading[gKey] = false;
54
+ gs.forms[gKey].errors = [];
55
+ if (res.status >= 200 && res.status <= 299 && Object.prototype.hasOwnProperty.call(options, "saveBody") && !options.saveBody)
56
+ gs.forms[gKey].form = {};
57
+ } catch (e) {
58
+ }
59
+ },
60
+ async onResponseError({ response: res }) {
61
+ const fetch = import.meta.glob("/glorious/fetch.ts");
62
+ if (typeof fetch["/glorious/fetch.ts"] !== "undefined")
63
+ fetch["/glorious/fetch.ts"]().then((data) => {
64
+ data.fetchHandler.onResponseError(res, gKey);
65
+ });
66
+ else {
67
+ if (res.status === 422) {
68
+ try {
69
+ gs.forms[gKey].errors = res._data.errors;
70
+ } catch (e) {
71
+ }
72
+ }
73
+ if (res.status === 401 && process.client) {
74
+ const cookieToken = useCookie(moduleConfig.auth.cookie.name);
75
+ if (typeof cookieToken.value !== "undefined")
76
+ gs.authLogout();
77
+ }
78
+ }
79
+ }
80
+ };
81
+ if (opt.method === "GET" && typeof opt.body !== "undefined") {
82
+ opt.method = "POST";
83
+ return $fetch(url, opt);
84
+ } else if (opt.method === "GET" && typeof opt.body === "undefined" && !opt.is$)
85
+ return useFetch(url, opt);
86
+ else
87
+ return $fetch(url, opt);
88
+ }
89
+ function computeParams(params) {
90
+ const computeParams2 = {};
91
+ Object.entries(params).map((item) => {
92
+ if (item[1] !== null && item[1] !== "")
93
+ computeParams2[item[0]] = item[1];
94
+ });
95
+ return computeParams2;
96
+ }
97
+ function computeGKey(gKey, url) {
98
+ return typeof gKey !== "undefined" ? gKey : url.split("/")[url.split("/").length - 1];
99
+ }
100
+ function computeAuth() {
101
+ const moduleConfig = useRuntimeConfig();
102
+ const header = {};
103
+ const token = useCookie(moduleConfig.public.glorious.auth.cookie.name);
104
+ if (typeof token.value !== "undefined")
105
+ header.Authorization = "Bearer " + token.value;
106
+ return header;
107
+ }
@@ -0,0 +1,8 @@
1
+ interface headInterface {
2
+ title?: string;
3
+ description?: string;
4
+ image?: string;
5
+ type?: string;
6
+ }
7
+ export default function (object?: headInterface): void;
8
+ export {};