nuxt-glorious 1.2.2-8 → 1.2.3-0

Sign up to get free protection for your applications and to get access to all the features.
package/dist/module.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "glorious",
3
3
  "configKey": "glorious",
4
- "version": "1.2.2-8"
4
+ "version": "1.2.3-0"
5
5
  }
package/dist/module.mjs CHANGED
@@ -70,7 +70,7 @@ const module = defineNuxtModule({
70
70
  });
71
71
  });
72
72
  addPlugin(resolver.resolve("./runtime/plugins/glorious-app-setting"));
73
- addPlugin(resolver.resolve("./runtime/plugins/Drawer"));
73
+ addPlugin(resolver.resolve("./runtime/plugins/InputComponent"));
74
74
  addRouteMiddleware({
75
75
  name: "g-auth-strategy",
76
76
  path: resolver.resolve("./runtime/middlewares/AuthStrategy"),
@@ -88,4 +88,14 @@
88
88
  }
89
89
  .glorious-input-tag > div {
90
90
  @apply bg-green-500 px-1 rounded text-white flex items-center gap-2 cursor-pointer;
91
+ }
92
+
93
+ .glorious-input-options {
94
+ @apply p-1 shadow-lg absolute w-full bg-white rounded border-gray-200 border max-h-[200px] overflow-y-auto;
95
+ }
96
+ .glorious-input-options > div {
97
+ @apply py-2 hover:bg-gray-100 cursor-pointer rounded px-2;
98
+ }
99
+ .glorious-input-options.size-md {
100
+ @apply top-11;
91
101
  }
@@ -1,40 +1,40 @@
1
1
  <script setup lang="ts">
2
- import { computed, ref, watch } from "#imports";
3
- import { useGloriousCore } from "../../composables/useGloriousCore";
2
+ import { computed, ref, watch } from '#imports'
3
+ import { useGloriousCore } from '../../composables/useGloriousCore'
4
4
  const props = defineProps({
5
5
  modelValue: {
6
6
  required: false,
7
- default: "",
7
+ default: '',
8
8
  type: [String, Array<String>, Number],
9
9
  },
10
10
  color: {
11
11
  required: false,
12
- default: "primary",
13
- type: String as () => "orange" | "blue" | "gray" | "red" | "primary",
12
+ default: 'primary',
13
+ type: String as () => 'orange' | 'blue' | 'gray' | 'red' | 'primary',
14
14
  },
15
15
  placeholder: {
16
16
  required: false,
17
- default: "",
17
+ default: '',
18
18
  type: String,
19
19
  },
20
20
  title: {
21
21
  required: false,
22
- default: "",
22
+ default: '',
23
23
  type: String,
24
24
  },
25
25
  size: {
26
26
  required: false,
27
- default: "md",
28
- type: String as () => "xl" | "lg" | "md" | "sm" | "xsm",
27
+ default: 'md',
28
+ type: String as () => 'xl' | 'lg' | 'md' | 'sm' | 'xsm',
29
29
  },
30
30
  error: {
31
31
  required: false,
32
- default: "|",
32
+ default: '|',
33
33
  type: String,
34
34
  },
35
35
  icon: {
36
36
  required: false,
37
- default: "",
37
+ default: '',
38
38
  type: String,
39
39
  },
40
40
  disabled: {
@@ -44,139 +44,177 @@ const props = defineProps({
44
44
  },
45
45
  type: {
46
46
  required: false,
47
- default: "text",
47
+ default: 'text',
48
48
  type: String as () =>
49
- | "button"
50
- | "checkbox"
51
- | "color"
52
- | "date"
53
- | "email"
54
- | "file"
55
- | "hidden"
56
- | "password"
57
- | "radio"
58
- | "range"
59
- | "tel"
60
- | "text"
61
- | "url"
62
- | "number",
49
+ | 'button'
50
+ | 'checkbox'
51
+ | 'color'
52
+ | 'date'
53
+ | 'email'
54
+ | 'file'
55
+ | 'hidden'
56
+ | 'password'
57
+ | 'radio'
58
+ | 'range'
59
+ | 'tel'
60
+ | 'text'
61
+ | 'url'
62
+ | 'number',
63
63
  },
64
64
  autocomplete: {
65
65
  required: false,
66
- default: "off",
67
- type: String as () => "off" | "on" | "new-password",
68
- },
69
- mode: {
70
- required: false,
71
- default: "normal",
72
- type: String as () => "normal" | "tag",
66
+ default: 'off',
67
+ type: String as () => 'off' | 'on' | 'new-password',
73
68
  },
74
69
  display: {
75
70
  required: false,
76
- default: "",
77
- type: String as () => "price",
71
+ default: '',
72
+ type: String as () => 'price',
78
73
  },
79
74
  inputMode: {
80
75
  required: false,
81
- default: "text",
76
+ default: 'text',
82
77
  type: String as () =>
83
- | "text"
84
- | "none"
85
- | "decimal"
86
- | "numeric"
87
- | "tel"
88
- | "search"
89
- | "email"
90
- | "url",
78
+ | 'text'
79
+ | 'none'
80
+ | 'decimal'
81
+ | 'numeric'
82
+ | 'tel'
83
+ | 'search'
84
+ | 'email'
85
+ | 'url',
86
+ },
87
+ mode: {
88
+ required: false,
89
+ default: 'normal',
90
+ type: String as () => 'normal' | 'tag',
91
91
  },
92
- });
92
+ tagLockOption: {
93
+ required: false,
94
+ default: false,
95
+ type: Boolean,
96
+ },
97
+ options: {
98
+ required: false,
99
+ default: [],
100
+ type: Array<object>,
101
+ },
102
+ loadingOptions: {
103
+ required: false,
104
+ default: false,
105
+ type: Boolean,
106
+ },
107
+ })
93
108
 
94
- const inputValue: any = ref(null);
109
+ const inputValue: any = ref(null)
95
110
 
96
- const emits = defineEmits(["update:modelValue"]);
111
+ const emits = defineEmits(['update:modelValue'])
97
112
 
98
113
  watch(
99
114
  () => inputValue.value,
100
115
  () => {
101
- if (props.mode === "tag") return;
116
+ if (props.mode === 'tag') return
102
117
 
103
118
  switch (props.display) {
104
- case "price":
119
+ case 'price':
105
120
  inputValue.value = useGloriousCore.numbersWithSeperateSamePrice(
106
121
  inputValue.value
107
- );
122
+ )
108
123
  emits(
109
- "update:modelValue",
110
- inputValue.value.toString().replaceAll(",", "")
111
- );
112
- break;
124
+ 'update:modelValue',
125
+ inputValue.value.toString().replaceAll(',', '')
126
+ )
127
+ break
113
128
  default:
114
- emits("update:modelValue", inputValue.value);
115
- break;
129
+ emits('update:modelValue', inputValue.value)
130
+ break
116
131
  }
117
132
  }
118
- );
133
+ )
119
134
 
120
135
  const computeIconSize = computed(() => {
121
- let iconSize = 0;
136
+ let iconSize = 0
122
137
 
123
138
  switch (props.size) {
124
- case "xl":
125
- iconSize = 30;
126
- break;
127
- case "lg":
128
- iconSize = 27;
129
- break;
130
- case "md":
131
- iconSize = 25;
132
- break;
133
- case "sm":
134
- iconSize = 23;
135
- break;
136
- case "xsm":
137
- iconSize = 20;
138
- break;
139
+ case 'xl':
140
+ iconSize = 30
141
+ break
142
+ case 'lg':
143
+ iconSize = 27
144
+ break
145
+ case 'md':
146
+ iconSize = 25
147
+ break
148
+ case 'sm':
149
+ iconSize = 23
150
+ break
151
+ case 'xsm':
152
+ iconSize = 20
153
+ break
139
154
  default:
140
- iconSize = 30;
141
- break;
155
+ iconSize = 30
156
+ break
142
157
  }
143
158
 
144
- return iconSize;
145
- });
159
+ return iconSize
160
+ })
146
161
 
147
162
  // ------------------------------------------------------------------------------------------------ TAG
148
- const tags: any = ref([]);
163
+ const tags: any = ref([])
149
164
 
150
165
  const addTag = (event: any) => {
151
- if (tags.value.length === 0) tags.value = [];
166
+ if (props.tagLockOption) return
167
+
168
+ if (tags.value.length === 0) tags.value = []
169
+
170
+ if (props.mode !== 'tag') return
171
+ const value: any = event.target.value
172
+ tags.value.push(value)
173
+ emits('update:modelValue', tags.value)
174
+ inputValue.value = ''
175
+ }
176
+
177
+ const addTagViaOption = (option: any, event: any) => {
178
+ // event.stopPropagation() if want not close with window
179
+ if (tags.value.length === 0) tags.value = []
180
+
181
+ const value: any = option
182
+ tags.value.push(value)
183
+ emits('update:modelValue', tags.value)
184
+ inputValue.value = ''
185
+ }
152
186
 
153
- if (props.mode !== "tag") return;
154
- const value: any = event.target.value;
155
- tags.value.push(value);
156
- emits("update:modelValue", tags.value);
157
- inputValue.value = "";
158
- };
159
187
  const removeTag = (tag: string) => {
160
- tags.value = tags.value.filter((item: any) => item !== tag);
161
- emits("update:modelValue", tags.value);
162
- };
188
+ tags.value = tags.value.filter((item: any) => item !== tag)
189
+ emits('update:modelValue', tags.value)
190
+ }
163
191
 
164
192
  // -------------------------------------- init value
165
193
  const initValue = () => {
166
- if (props.mode === "tag") {
167
- tags.value = props.modelValue;
168
- return;
194
+ if (props.mode === 'tag') {
195
+ tags.value = props.modelValue
196
+ return
169
197
  }
170
198
 
171
- inputValue.value = props.modelValue;
172
- };
173
- initValue();
199
+ inputValue.value = props.modelValue
200
+ }
201
+ initValue()
174
202
  watch(
175
203
  () => props.modelValue,
176
204
  () => initValue()
177
- );
205
+ )
206
+
207
+ const typeInput = ref(props.type)
208
+
209
+ const inputClicked = (event: any) => {
210
+ if (props.mode === 'tag' && props.options) {
211
+ console.log(event.currentTarget.parentElement.children)
178
212
 
179
- const typeInput = ref(props.type);
213
+ const optionsElement = event.currentTarget.parentElement.children[1]
214
+ if (optionsElement.classList.contains('hidden'))
215
+ optionsElement.classList.remove('hidden')
216
+ }
217
+ }
180
218
  </script>
181
219
 
182
220
  <template>
@@ -191,7 +229,7 @@ const typeInput = ref(props.type);
191
229
  v-model="inputValue"
192
230
  :inputmode="props.inputMode"
193
231
  :autocomplete="props.autocomplete"
194
- class="w-full"
232
+ class="w-full glorious-input-field"
195
233
  :class="[
196
234
  props.size,
197
235
  `glorious-input-${props.color}`,
@@ -201,6 +239,7 @@ const typeInput = ref(props.type);
201
239
  :disabled="props.disabled"
202
240
  :type="typeInput"
203
241
  @keyup.enter="addTag($event)"
242
+ @click="inputClicked($event)"
204
243
  />
205
244
  <GIcon
206
245
  v-if="props.type === 'password' && typeInput === 'password'"
@@ -216,10 +255,29 @@ const typeInput = ref(props.type);
216
255
  name="glorious-eye-off-fill"
217
256
  @click="typeInput = 'password'"
218
257
  ></GIcon>
258
+
259
+ <div
260
+ v-if="props.options.length > 0"
261
+ class="glorious-input-options"
262
+ :class="[`size-${props.size}`]"
263
+ >
264
+ <div v-if="props.loadingOptions" class="flex justify-center">
265
+ <GLoading color="green" />
266
+ </div>
267
+ <template v-else>
268
+ <div
269
+ v-for="(option, index) in props.options"
270
+ :key="index"
271
+ @click="addTagViaOption(option, $event)"
272
+ >
273
+ {{ option.text }}
274
+ </div>
275
+ </template>
276
+ </div>
219
277
  </div>
220
278
  <div v-if="tags.length !== 0" class="glorious-input-tag">
221
279
  <div v-for="(item, index) in tags" :key="index">
222
- {{ item }}
280
+ {{ typeof item === 'object' ? item.text : item }}
223
281
  <GIcon
224
282
  name="glorious-x"
225
283
  :size="10"
@@ -331,4 +389,14 @@ const typeInput = ref(props.type);
331
389
  .glorious-input-tag > div {
332
390
  @apply bg-green-500 px-1 rounded text-white flex items-center gap-2 cursor-pointer;
333
391
  }
392
+
393
+ .glorious-input-options {
394
+ @apply p-1 shadow-lg absolute w-full bg-white rounded border-gray-200 border max-h-[200px] overflow-y-auto;
395
+ }
396
+ .glorious-input-options > div {
397
+ @apply py-2 hover:bg-gray-100 cursor-pointer rounded px-2;
398
+ }
399
+ .glorious-input-options.size-md {
400
+ @apply top-11;
401
+ }
334
402
  </style>
@@ -0,0 +1,13 @@
1
+ import { defineNuxtPlugin } from "#imports";
2
+ export default defineNuxtPlugin((nuxtApp) => {
3
+ nuxtApp.hook("app:beforeMount", () => {
4
+ window.addEventListener("click", (event) => {
5
+ if (!event.target.matches(".glorious-input-field")) {
6
+ const options = document.querySelectorAll(".glorious-input-options");
7
+ options.forEach((el) => {
8
+ el.classList.add("hidden");
9
+ });
10
+ }
11
+ });
12
+ });
13
+ });
@@ -0,0 +1,4 @@
1
+ export interface ModuleOptions {
2
+ }
3
+ declare const _default: import("@nuxt/schema").NuxtModule<ModuleOptions, ModuleOptions, false>;
4
+ export default _default;
@@ -0,0 +1,94 @@
1
+ import {
2
+ defineNuxtModule,
3
+ addPlugin,
4
+ addComponentsDir,
5
+ createResolver,
6
+ addImportsDir,
7
+ installModule,
8
+ addRouteMiddleware
9
+ } from "@nuxt/kit";
10
+ import defu from "defu";
11
+ export default defineNuxtModule({
12
+ meta: {
13
+ name: "glorious",
14
+ configKey: "glorious"
15
+ },
16
+ // Default configuration options of the Nuxt module
17
+ defaults: {},
18
+ async setup(options, nuxt) {
19
+ const resolver = createResolver(import.meta.url);
20
+ nuxt.options.runtimeConfig.public.glorious = defu(nuxt.options.glorious, {
21
+ fetch: {
22
+ baseURL: "/",
23
+ credentials: "same-origin"
24
+ },
25
+ seo: {
26
+ suffix: "",
27
+ title: "",
28
+ description: ""
29
+ },
30
+ auth: {
31
+ cookie: {
32
+ name: "ga-token",
33
+ httpOnly: false
34
+ },
35
+ redirect: {
36
+ logout: "/login",
37
+ login: "/login"
38
+ },
39
+ strategy: {
40
+ provider: "",
41
+ //[laravel-passport]
42
+ endpoints: {
43
+ userInfo: {
44
+ url: "/",
45
+ method: "GET",
46
+ pick: ""
47
+ }
48
+ }
49
+ }
50
+ }
51
+ });
52
+ await installModule("@nuxtjs/tailwindcss", {
53
+ // module configuration
54
+ exposeConfig: true,
55
+ config: {
56
+ darkMode: "class",
57
+ content: {
58
+ files: [
59
+ resolver.resolve("./runtime/components/G/**/*.{vue,mjs,ts}"),
60
+ resolver.resolve("./runtime/*.{mjs,js,ts}")
61
+ ]
62
+ }
63
+ }
64
+ });
65
+ await installModule("@pinia/nuxt");
66
+ addImportsDir(resolver.resolve("runtime/composables"));
67
+ addImportsDir(resolver.resolve("runtime/stores"));
68
+ addImportsDir(resolver.resolve("runtime/middlewares"));
69
+ addComponentsDir({
70
+ path: resolver.resolve("runtime/components"),
71
+ global: true,
72
+ watch: false
73
+ });
74
+ nuxt.hook("nitro:config", async (nitro) => {
75
+ nitro.publicAssets.push({
76
+ dir: resolver.resolve("./runtime/assets")
77
+ });
78
+ });
79
+ addPlugin(resolver.resolve("./runtime/plugins/glorious-app-setting"));
80
+ addPlugin({
81
+ src: resolver.resolve("./runtime/plugins/InputComponent"),
82
+ mode: "client"
83
+ });
84
+ addRouteMiddleware({
85
+ name: "g-auth-strategy",
86
+ path: resolver.resolve("./runtime/middlewares/AuthStrategy"),
87
+ global: true
88
+ });
89
+ addRouteMiddleware({
90
+ name: "g-auth",
91
+ path: resolver.resolve("./runtime/middlewares/Auth")
92
+ });
93
+ }
94
+ });
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.2.2-8",
2
+ "version": "1.2.3-0",
3
3
  "name": "nuxt-glorious",
4
4
  "description": "This package provides many things needed by a project, including server requests and authentication, SEO and other requirements of a project.",
5
5
  "repository": "sajadhzj/nuxt-glorious",
@@ -1,35 +0,0 @@
1
- import { defineNuxtPlugin } from "#app";
2
- export default defineNuxtPlugin(() => {
3
- const methods = {
4
- addBlurBackground: (key) => {
5
- const backgroundBlur = document.createElement("div");
6
- backgroundBlur.classList.add("bg-blur-drawer");
7
- const nuxt = document.getElementById("__nuxt");
8
- nuxt.appendChild(backgroundBlur);
9
- backgroundBlur.addEventListener("click", () => {
10
- const componentId = document.getElementById(key);
11
- componentId.classList.replace("open", "close");
12
- backgroundBlur.remove();
13
- });
14
- },
15
- drawer: {
16
- provide: (key) => {
17
- let drawer = document.getElementById(key);
18
- if (drawer.classList.contains("close")) {
19
- drawer.classList.remove("hidden");
20
- drawer.classList.replace("close", "open");
21
- methods.addBlurBackground(key);
22
- } else {
23
- drawer.classList.replace("open", "close");
24
- const bgBlur = document.querySelector(".bg-blur-drawer");
25
- bgBlur?.remove();
26
- }
27
- }
28
- }
29
- };
30
- return {
31
- provide: {
32
- drawer: (key = "drawer") => methods.drawer.provide(key)
33
- }
34
- };
35
- });