@hostlink/nuxt-light 1.27.4 → 1.27.6

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.6",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "0.8.4",
7
7
  "unbuild": "2.0.0"
@@ -0,0 +1,42 @@
1
+ <script lang="ts" setup>
2
+ import { useQuasar, QBtn } from "quasar";
3
+ import type { QBtnProps } from "quasar";
4
+
5
+ export interface LBtnProps extends QBtnProps {
6
+ permission?: string;
7
+ confirmMessage?: string;
8
+ confirmTitle?: string;
9
+ }
10
+
11
+ const props = withDefaults(defineProps<LBtnProps>(), {
12
+ permission: "",
13
+ confirmMessage: "",
14
+ confirmTitle: "Confirm",
15
+ });
16
+
17
+ const $q = useQuasar();
18
+
19
+ //filter out the onClick from the props
20
+ const { onClick, ...filteredProps } = props;
21
+
22
+ const handleClick = function () {
23
+ const args = arguments;
24
+ if (props.confirmMessage) {
25
+ $q.dialog({
26
+ title: props.confirmTitle,
27
+ message: props.confirmMessage,
28
+ ok: "Yes",
29
+ cancel: "No",
30
+ }).onOk(() => {
31
+ onClick?.apply(null, args as any);
32
+ });
33
+ } else {
34
+ onClick?.apply(null, args as any);
35
+ }
36
+ };
37
+ </script>
38
+ <template>
39
+ <q-btn v-if="$light.isGranted($props.permission)" @click="handleClick" v-bind="$light.getButtonProps(filteredProps)">
40
+ <slot></slot>
41
+ </q-btn>
42
+ </template>
@@ -0,0 +1,9 @@
1
+ <script setup lang="ts">
2
+ import {type QCheckboxProps } from "quasar"
3
+ defineProps<QCheckboxProps>()
4
+ </script>
5
+ <template>
6
+ <q-checkbox v-bind="$props" :color="color ?? $light.color" :label="label ? $t(label) : undefined">
7
+ <slot></slot>
8
+ </q-checkbox>
9
+ </template>
@@ -0,0 +1,82 @@
1
+ <script setup lang="ts">
2
+ import { ref } from "vue";
3
+ import { QSelect } from "quasar";
4
+ import { type QSelectProps } from "quasar";
5
+
6
+
7
+ const props = withDefaults(defineProps<QSelectProps>(), {
8
+ emitValue: true,
9
+ mapOptions: true,
10
+ hideBottomSpace: true,
11
+ filled: undefined,
12
+ outlined: undefined,
13
+ standout: undefined,
14
+ rounded: undefined,
15
+ dense: undefined,
16
+ square: undefined,
17
+ stackLabel: undefined,
18
+ optionLabel: 'label',
19
+ optionValue: 'value',
20
+ inputDebounce: 0,
21
+ })
22
+
23
+ defineEmits(QSelect.emits);
24
+
25
+
26
+ // 將 normalizeOptions 拆分為更小的函數
27
+ const normalizeOption = (option: any) => {
28
+ if (typeof option === 'string' || typeof option === 'number') {
29
+ return { label: String(option), value: String(option) };
30
+ }
31
+ if (typeof option === 'object') {
32
+ if ('group' in option) {
33
+ option.options = normalizeOptions(option.options || []);
34
+ return option;
35
+ } else if ('value' in option && typeof option.value !== 'string') {
36
+ Object.assign(option, { value: option.value });
37
+ }
38
+ }
39
+ return option;
40
+ };
41
+
42
+ const normalizeOptions = (options: any) => {
43
+ if (Array.isArray(options)) {
44
+ return options.map(option => normalizeOption(option));
45
+ }
46
+ return Object.keys(options).map(value => ({
47
+ label: options[value],
48
+ value,
49
+ }));
50
+ };
51
+
52
+
53
+ const select_options = ref(props.options);
54
+
55
+ const filterFn = (val, update, abort) => {
56
+ if (props.onFilter) {
57
+ props.onFilter(val, update, abort);
58
+ return;
59
+ }
60
+
61
+ const opts = normalizeOptions(props.options);
62
+
63
+ if (val === "") {
64
+ update(() => {
65
+ select_options.value = opts
66
+ });
67
+ return;
68
+ }
69
+
70
+ update(() => {
71
+ const needle = val.toLowerCase();
72
+ select_options.value = opts.filter(option => {
73
+ const label = typeof props.optionLabel === 'function' ? props.optionLabel(option) : option[props.optionLabel];
74
+ return label && label.toLowerCase().includes(needle);
75
+ })
76
+ })
77
+ }
78
+
79
+ </script>
80
+ <template>
81
+ <q-select v-bind="$light.getInputProps($props)" :options="select_options" @filter="filterFn" />
82
+ </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.6",
4
4
  "description": "HostLink Nuxt Light Framework",
5
5
  "repository": {
6
6
  "type": "git",
@@ -1,7 +0,0 @@
1
- declare namespace _default {
2
- let name: string;
3
- let inheritAttrs: boolean;
4
- let props: any;
5
- function render(): any;
6
- }
7
- export default _default;
@@ -1,44 +0,0 @@
1
- import { h } from "vue";
2
- import { useQuasar, QBtn } from "quasar";
3
-
4
- export default {
5
- name: "LBtn",
6
- inheritAttrs:false,
7
- props: {
8
- ...QBtn.props,
9
- permission: { type: String, default: "" },
10
- confirmTitle: { type: String, default: "Confirm" },
11
- confirmMessage: { type: String, default: undefined },
12
- },
13
- render() {
14
- const $q = useQuasar();
15
-
16
- // 從 $attrs 中提取 onClick,並過濾掉它
17
- const { onClick, ...filteredAttrs } = this.$attrs;
18
-
19
- const handleClick = (...args) => {
20
- if (this.$props.confirmMessage) {
21
- $q.dialog({
22
- color: this.$props.color || "primary",
23
- title: this.$props.confirmTitle,
24
- message: this.$props.confirmMessage,
25
- ok: "Yes",
26
- cancel: "No",
27
- }).onOk(() => {
28
- onClick?.(...args); // 執行傳入的 onClick
29
- });
30
- } else {
31
- onClick?.(...args); // 直接執行傳入的 onClick
32
- }
33
- };
34
-
35
- const root = h(QBtn, {
36
- ...this.$props, // 傳遞 props
37
- ...this.$light.getButtonProps(this.$props), // 傳遞按鈕屬性
38
- ...filteredAttrs, // 傳遞過濾後的 attrs
39
- onClick: handleClick, // 明確綁定 handleClick
40
- }, this.$slots);
41
-
42
- return this.$light.isGranted(this.$props.permission) ? root : null;
43
- },
44
- };
@@ -1,46 +0,0 @@
1
- <script lang="ts" setup>
2
- import { h, useSlots } from "vue";
3
- import { useQuasar, QBtn } from "quasar";
4
- import { useLight } from "#imports";
5
- import type { QBtnProps } from "quasar";
6
-
7
- export interface LBtnProps extends QBtnProps {
8
- permission?: string;
9
- confirmMessage?: string;
10
- confirmTitle?: string;
11
- }
12
-
13
- const props = withDefaults(defineProps<LBtnProps>(), {
14
- permission: "",
15
- confirmMessage: "",
16
- confirmTitle: "Confirm",
17
- });
18
-
19
- const $light = useLight();
20
- const $q = useQuasar();
21
- const slots = useSlots() as ReturnType<typeof useSlots>;
22
-
23
- const root = h(QBtn, {
24
- ...props,
25
- ...$light.getButtonProps(props),
26
- onClick: function () {
27
- const args = arguments;
28
- if (props.confirmMessage) {
29
- $q.dialog({
30
- title: props.confirmTitle,
31
- message: props.confirmMessage,
32
- ok: "Yes",
33
- cancel: "No",
34
- }).onOk(() => {
35
- props.onClick?.apply(null, args as any);
36
- });
37
- } else {
38
- props.onClick?.apply(null, args as any);
39
- }
40
- },
41
- }, slots);
42
-
43
- </script>
44
- <template>
45
- <component :is="root" v-if="$light.isGranted($props.permission)"/>
46
- </template>
@@ -1,12 +0,0 @@
1
- declare namespace _default {
2
- let name: string;
3
- let props: any;
4
- let emits: any;
5
- function setup(props: any, { slots, emit }: {
6
- slots: any;
7
- emit: any;
8
- }): () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
9
- [key: string]: any;
10
- }>;
11
- }
12
- export default _default;
@@ -1,23 +0,0 @@
1
- import { QCheckbox } from "quasar";
2
- import { h } from "vue";
3
- import { useLight } from "#imports";
4
- import { useI18n } from "vue-i18n";
5
-
6
-
7
- export default {
8
- name: "LCheckbox",
9
- props: QCheckbox.props,
10
- emits: QCheckbox.emits,
11
- setup(props, { slots, emit }) {
12
- return () => {
13
- const $light = useLight();
14
- const $t = useI18n().t;
15
- return h(QCheckbox, {
16
- ...props,
17
- color: props.color || $light.color,
18
- label: props.label ? $t(props.label) : null,
19
- 'onUpdate:modelValue': emit.bind(this, 'update:modelValue'),
20
- }, slots);
21
- }
22
- }
23
- }
@@ -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
- };