@hostlink/nuxt-light 1.27.4 → 1.27.5

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/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "light",
3
3
  "configKey": "light",
4
- "version": "1.27.4",
4
+ "version": "1.27.5",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "0.8.4",
7
7
  "unbuild": "2.0.0"
@@ -0,0 +1,84 @@
1
+ <script setup>
2
+ import { computed, ref } from "vue";
3
+ import { QSelect } from "quasar";
4
+ console.log(QSelect);
5
+
6
+ const emits = defineEmits(["update:modelValue"]);
7
+
8
+ const props = defineProps({
9
+ ...QSelect.props,
10
+ emitValue: { type: Boolean, default: true },
11
+ mapOptions: { type: Boolean, default: true },
12
+ hideBottomSpace: { type: Boolean, default: true },
13
+ required: Boolean,
14
+ filled: { type: Boolean, default: undefined },
15
+ outlined: { type: Boolean, default: undefined },
16
+ standout: { type: Boolean, default: undefined },
17
+ rounded: { type: Boolean, default: undefined },
18
+ dense: { type: Boolean, default: undefined },
19
+ square: { type: Boolean, default: undefined },
20
+ stackLabel: { type: Boolean, default: undefined },
21
+ optionLabel: { type: [String, Function], default: 'label' },
22
+ optionValue: { type: String, default: 'value' },
23
+ inputDebounce: { type: [Number, String], default: 0 },
24
+ })
25
+
26
+
27
+ // 將 normalizeOptions 拆分為更小的函數
28
+ const normalizeOption = (option, i) => {
29
+ if (typeof option === 'string' || typeof option === 'number') {
30
+ return { label: String(option), value: String(option) };
31
+ }
32
+ if (typeof option === 'object') {
33
+ if ('group' in option) {
34
+ option.options = normalizeOptions(option.options || [], i);
35
+ return option;
36
+ } else if ('value' in option && typeof option.value !== 'string') {
37
+ Object.assign(option, { value: option.value });
38
+ }
39
+ }
40
+ return option;
41
+ };
42
+
43
+ const normalizeOptions = (options, i = { count: 1 }) => {
44
+ if (Array.isArray(options)) {
45
+ return options.map(option => normalizeOption(option, i));
46
+ }
47
+ return Object.keys(options).map(value => ({
48
+ label: options[value],
49
+ value,
50
+ }));
51
+ };
52
+
53
+
54
+ const select_options = ref(props.options);
55
+
56
+ const filterFn = (val, update, abort) => {
57
+ if (props.onFilter) {
58
+ props.onFilter(val, update, abort);
59
+ return;
60
+ }
61
+
62
+ const opts = normalizeOptions(props.options);
63
+
64
+ if (val === "") {
65
+ update(() => {
66
+ select_options.value = opts
67
+ });
68
+ return;
69
+ }
70
+
71
+ update(() => {
72
+ const needle = val.toLowerCase();
73
+ select_options.value = opts.filter(option => {
74
+ const label = typeof props.optionLabel === 'function' ? props.optionLabel(option) : option[props.optionLabel];
75
+ return label && label.toLowerCase().includes(needle);
76
+ })
77
+ })
78
+ }
79
+
80
+ </script>
81
+ <template>
82
+ <q-select v-bind="$light.getInputProps($props)" :options="select_options" @filter="filterFn"
83
+ :model-value="modelValue" @update:model-value="$emit('update:modelValue', $event)" />
84
+ </template>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hostlink/nuxt-light",
3
- "version": "1.27.4",
3
+ "version": "1.27.5",
4
4
  "description": "HostLink Nuxt Light Framework",
5
5
  "repository": {
6
6
  "type": "git",
@@ -1,13 +0,0 @@
1
- declare namespace _default {
2
- let name: string;
3
- let props: any;
4
- function setup(props: any): {
5
- filteredOptions: import("vue").Ref<any, any>;
6
- normalizedOptions: import("vue").ComputedRef<any[]>;
7
- };
8
- namespace methods {
9
- function filterOptions(inputValue: any, update: any, abort: any): void;
10
- }
11
- function render(): any;
12
- }
13
- export default _default;
@@ -1,90 +0,0 @@
1
- import { computed, h, ref } from 'vue';
2
- import { QSelect } from 'quasar';
3
-
4
- // 將 normalizeOptions 拆分為更小的函數
5
- const normalizeOption = (option, i) => {
6
- if (typeof option === 'string' || typeof option === 'number') {
7
- return { label: String(option), value: String(option) };
8
- }
9
- if (typeof option === 'object') {
10
- if ('group' in option) {
11
- option.options = normalizeOptions(option.options || [], i);
12
- return option;
13
- } else if ('value' in option && typeof option.value !== 'string') {
14
- Object.assign(option, { value: option.value });
15
- }
16
- }
17
- return option;
18
- };
19
-
20
- const normalizeOptions = (options, i = { count: 1 }) => {
21
- if (Array.isArray(options)) {
22
- return options.map(option => normalizeOption(option, i));
23
- }
24
- return Object.keys(options).map(value => ({
25
- label: options[value],
26
- value,
27
- }));
28
- };
29
-
30
- export default {
31
- name: 'LSelect',
32
- props: {
33
- ...QSelect.props,
34
- emitValue: { type: Boolean, default: true },
35
- mapOptions: { type: Boolean, default: true },
36
- hideBottomSpace: { type: Boolean, default: true },
37
- required: Boolean,
38
- filled: { type: Boolean, default: undefined },
39
- outlined: { type: Boolean, default: undefined },
40
- standout: { type: Boolean, default: undefined },
41
- rounded: { type: Boolean, default: undefined },
42
- dense: { type: Boolean, default: undefined },
43
- square: { type: Boolean, default: undefined },
44
- stackLabel: { type: Boolean, default: undefined },
45
- optionLabel: { type: [String, Function], default: 'label' },
46
- optionValue: { type: String, default: 'value' },
47
- inputDebounce: { type: [Number, String], default: 0 },
48
- },
49
- setup(props) {
50
- // 使用 computed 來緩存 normalizedOptions
51
- const normalizedOptions = computed(() => normalizeOptions(props.options));
52
- const filteredOptions = ref(props.options);
53
-
54
- return {
55
- filteredOptions,
56
- normalizedOptions,
57
- };
58
- },
59
- methods: {
60
- filterOptions(inputValue, update, abort) {
61
- if (this.onFilter) {
62
- this.onFilter(inputValue, update, abort);
63
- return;
64
- }
65
-
66
- update(() => {
67
- this.filteredOptions.value = this.normalizedOptions.filter(option => {
68
- const label =
69
- typeof this.optionLabel === 'function'
70
- ? this.optionLabel(option)
71
- : option[this.optionLabel];
72
- return label && label.toLowerCase().includes(inputValue.toLowerCase());
73
- });
74
- });
75
- },
76
- },
77
- render() {
78
- return h(
79
- QSelect,
80
- {
81
- ...this.$props,
82
- ...this.$light.getInputProps(this.$props), // 使用主題樣式的輸入屬性
83
- 'onUpdate:modelValue': this.$emit.bind(this, 'update:modelValue'),
84
- onFilter: this.$props.useInput ? this.filterOptions : undefined, // 僅在 filterable 為 true 時使用 filterOptions
85
- options: this.$props.useInput ? this.filteredOptions.value : this.$props.options,
86
- },
87
- this.$slots
88
- );
89
- },
90
- };