@bgottsch/d-naive 1.8.9

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.
@@ -0,0 +1,45 @@
1
+ declare const _default: typeof __VLS_export;
2
+ export default _default;
3
+ declare const __VLS_export: import("vue").DefineComponent<{}, {
4
+ sorterList: import("vue").Ref<never[], never[]>;
5
+ resetFilters: typeof resetFilters;
6
+ scrollTo: typeof scrollTo;
7
+ getData: typeof getData;
8
+ cols: import("vue").Ref<never[], never[]>;
9
+ $emit: typeof emit;
10
+ $props: Partial<typeof props>;
11
+ data: unknown[];
12
+ modelValue: string | number | Record<string, any>;
13
+ columns: unknown[];
14
+ selectable: boolean;
15
+ editable: boolean;
16
+ scrollX: string | number | boolean;
17
+ height: string | number;
18
+ returnObject: boolean;
19
+ selectedClass: string;
20
+ sortable: boolean;
21
+ draggable: boolean;
22
+ resizable: boolean;
23
+ filterable: boolean;
24
+ pagination?: boolean | Record<string, any> | undefined;
25
+ }, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
26
+ declare function resetFilters(): void;
27
+ declare function scrollTo(value: any): void;
28
+ declare function getData(): any;
29
+ declare const emit: (event: "update:modelValue" | "update:expanded" | "put" | "delete" | "dragColumn", ...args: any[]) => void;
30
+ declare const props: {
31
+ readonly data: unknown[];
32
+ readonly modelValue: string | number | Record<string, any>;
33
+ readonly columns: unknown[];
34
+ readonly selectable: boolean;
35
+ readonly editable: boolean;
36
+ readonly scrollX: string | number | boolean;
37
+ readonly height: string | number;
38
+ readonly returnObject: boolean;
39
+ readonly selectedClass: string;
40
+ readonly sortable: boolean;
41
+ readonly draggable: boolean;
42
+ readonly resizable: boolean;
43
+ readonly filterable: boolean;
44
+ readonly pagination?: boolean | Record<string, any> | undefined;
45
+ };
@@ -0,0 +1,19 @@
1
+ declare const _default: typeof __VLS_export;
2
+ export default _default;
3
+ declare const __VLS_export: import("vue").DefineComponent<{}, {
4
+ $emit: typeof emit;
5
+ $props: Partial<typeof props>;
6
+ modelValue: string | number | boolean | Record<string, any> | unknown[] | null;
7
+ style: string | Record<string, any>;
8
+ disableLabel: boolean;
9
+ asyncProps: boolean | Function;
10
+ prefix: string;
11
+ }, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
12
+ declare const emit: (event: "update:modelValue", ...args: any[]) => void;
13
+ declare const props: {
14
+ readonly modelValue: string | number | boolean | Record<string, any> | unknown[] | null;
15
+ readonly style: string | Record<string, any>;
16
+ readonly disableLabel: boolean;
17
+ readonly asyncProps: boolean | Function;
18
+ readonly prefix: string;
19
+ };
@@ -0,0 +1,170 @@
1
+ <template>
2
+ <div :style="style">
3
+ <p v-if="!disableLabel">
4
+ {{ f.label ? f.label : f.title }}
5
+ </p>
6
+ <n-select
7
+ v-if="f.type == 'select'"
8
+ v-model:value="value"
9
+ filterable
10
+ clearable
11
+ :loading="loading"
12
+ v-bind="f"
13
+ />
14
+ <n-select
15
+ v-else-if="f.type == 'list'"
16
+ v-model:value="value"
17
+ filterable
18
+ tag
19
+ multiple
20
+ :show="false"
21
+ clearable
22
+ :loading="loading"
23
+ v-bind="f"
24
+ />
25
+ <n-input-number
26
+ v-else-if="['number'].indexOf(f.type) >= 0"
27
+ v-model:value="value"
28
+ clearable
29
+ v-bind="f"
30
+ >
31
+ <template v-if="f.prefix2" #prefix>
32
+ {{ f.prefix2 }}
33
+ </template>
34
+ <template v-if="f.suffix" #suffix>
35
+ {{ f.suffix }}
36
+ </template>
37
+ </n-input-number>
38
+
39
+ <n-checkbox
40
+ v-else-if="f.type == 'check'"
41
+ v-bind="f"
42
+ v-model:checked="value"
43
+ />
44
+ <n-date-picker
45
+ v-else-if="
46
+ [
47
+ 'date',
48
+ 'month',
49
+ 'daterange',
50
+ 'year',
51
+ 'monthrange',
52
+ 'yearrange',
53
+ 'quarter',
54
+ 'quarterrange',
55
+ 'week',
56
+ ].indexOf(f.type) >= 0
57
+ "
58
+ v-model:formatted-value="value"
59
+ value-format="yyyy-MM-dd"
60
+ :format="'dd/MM/yyyy'"
61
+ v-bind="f"
62
+ />
63
+ <n-date-picker
64
+ v-else-if="['datetime', 'datetimerange'].indexOf(f.type) >= 0"
65
+ v-model:formatted-value="value"
66
+ value-format="yyyy-MM-dd HH:mm:ss"
67
+ :format="'dd/MM/yyyy'"
68
+ v-bind="f"
69
+ />
70
+ <n-spin v-else-if="f.type == 'cascader'" size="small" :show="loading">
71
+ <n-cascader
72
+ v-model:value="value"
73
+ multiple
74
+ clearable
75
+ :options="f.options"
76
+ :max-tag-count="2"
77
+ check-strategy="parent"
78
+ filterable
79
+ :clear-filter-after-select="true"
80
+ v-bind="f"
81
+ />
82
+ </n-spin>
83
+ <n-switch v-else-if="f.type == 'bool'" v-model:value="value" v-bind="f" />
84
+ <n-input v-else v-model:value="value" clearable v-bind="f">
85
+ <template v-if="f.prefix2" #prefix>
86
+ {{ f.prefix2 }}
87
+ </template>
88
+ <template v-if="f.suffix" #suffix>
89
+ {{ f.suffix }}
90
+ </template>
91
+ </n-input>
92
+ </div>
93
+ </template>
94
+
95
+ <script setup>
96
+ import { normalizeDatetime } from "../utils";
97
+ defineOptions({
98
+ name: "DInput"
99
+ });
100
+ const props = defineProps({
101
+ modelValue: {
102
+ type: [String, Number, Boolean, Array, Object, null],
103
+ default: null,
104
+ required: false
105
+ },
106
+ style: { required: false, type: [Object, String], default: "" },
107
+ disableLabel: { required: false, type: Boolean, default: false },
108
+ asyncProps: { required: false, type: [Function, Boolean], default: false },
109
+ prefix: { required: false, type: String, default: "" }
110
+ });
111
+ const attrs = useAttrs();
112
+ const asyncPropsValue = ref({});
113
+ const loadingAsync = ref(false);
114
+ if (props.asyncProps) {
115
+ loadingAsync.value = true;
116
+ props.asyncProps().then((a) => {
117
+ asyncPropsValue.value = a;
118
+ loadingAsync.value = false;
119
+ });
120
+ }
121
+ const loading = computed(() => {
122
+ return loadingAsync.value ?? f.value.loading ?? false;
123
+ });
124
+ const f = computed(() => {
125
+ const field = {
126
+ placeholder: "",
127
+ ...attrs,
128
+ ...asyncPropsValue.value,
129
+ prefix: props.prefix
130
+ };
131
+ if (field.type == "select") {
132
+ if (field.options && field.options.length > 0 && typeof field.options[0] != "object")
133
+ field.options = field.options.map((o) => ({ label: o, value: o }));
134
+ }
135
+ field.prefix2 = field.prefix;
136
+ delete field.prefix;
137
+ return field;
138
+ });
139
+ const initialValue = () => {
140
+ const raw = props.modelValue ?? attrs.default ?? null;
141
+ if (!raw) return null;
142
+ if (["datetime", "datetimerange"].includes(f.value.type)) {
143
+ return normalizeDatetime(raw);
144
+ }
145
+ return raw;
146
+ };
147
+ const value = ref(initialValue());
148
+ const emit = defineEmits(["update:modelValue"]);
149
+ watch(
150
+ () => props.modelValue,
151
+ (newValue) => {
152
+ if (["datetime", "datetimerange"].includes(f.value.type)) {
153
+ value.value = normalizeDatetime(newValue);
154
+ } else {
155
+ value.value = newValue;
156
+ }
157
+ }
158
+ );
159
+ watch(
160
+ () => value,
161
+ (newValue) => {
162
+ emit("update:modelValue", newValue.value);
163
+ },
164
+ { deep: true }
165
+ );
166
+ </script>
167
+
168
+ <style>
169
+ .n-cascader-menu{--n-column-width:350px!important}
170
+ </style>
@@ -0,0 +1,19 @@
1
+ declare const _default: typeof __VLS_export;
2
+ export default _default;
3
+ declare const __VLS_export: import("vue").DefineComponent<{}, {
4
+ $emit: typeof emit;
5
+ $props: Partial<typeof props>;
6
+ modelValue: string | number | boolean | Record<string, any> | unknown[] | null;
7
+ style: string | Record<string, any>;
8
+ disableLabel: boolean;
9
+ asyncProps: boolean | Function;
10
+ prefix: string;
11
+ }, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
12
+ declare const emit: (event: "update:modelValue", ...args: any[]) => void;
13
+ declare const props: {
14
+ readonly modelValue: string | number | boolean | Record<string, any> | unknown[] | null;
15
+ readonly style: string | Record<string, any>;
16
+ readonly disableLabel: boolean;
17
+ readonly asyncProps: boolean | Function;
18
+ readonly prefix: string;
19
+ };
@@ -0,0 +1,2 @@
1
+ declare const _default: any;
2
+ export default _default;
@@ -0,0 +1,3 @@
1
+ export default defineNuxtPlugin((nuxtApp) => {
2
+ nuxtApp.provide('dNaive', {})
3
+ })
@@ -0,0 +1,4 @@
1
+ export function toDate(date: any): Date | null;
2
+ export function formatValue(row: any, field: any): any;
3
+ export function getValue(row: any, field: any): any;
4
+ export function normalizeDatetime(input: any): string | null;
@@ -0,0 +1,109 @@
1
+ import { useNuxtApp } from '#app';
2
+
3
+ function getValidValue(...values) {
4
+ for (let value of values) {
5
+ if (value || value == 0) {
6
+ return value;
7
+ }
8
+ }
9
+ return undefined;
10
+ }
11
+
12
+
13
+ export const toDate = (date) => {
14
+ if (!date) return null
15
+ if (date.length > 10 || !isNaN(date)) return new Date(date)
16
+ return date ? new Date(date + " GMT-0300") : null
17
+ }
18
+
19
+ export const formatValue = (row, field) => {
20
+ const nuxtApp = useNuxtApp();
21
+ const defaultOptions = nuxtApp.$dNaive
22
+ var value = null
23
+ var t = null
24
+ if (typeof row === 'object')
25
+ value = getValue(row, field)
26
+ else value = row
27
+ if (typeof field === 'object')
28
+ t = field.type
29
+ else t = field
30
+ if (!value && value != 0) return ''
31
+ switch (t) {
32
+ case 'number': {
33
+
34
+ if (field.noFormat) return value
35
+ var minPrecision = getValidValue(field.minPrecision, defaultOptions.minPrecision, field.precision, defaultOptions.precision);
36
+ var maxPrecision = getValidValue(field.maxPrecision, defaultOptions.maxPrecision, field.precision, defaultOptions.precision);
37
+ if (field.precision == 0) {
38
+ minPrecision = 0
39
+ maxPrecision = 0
40
+ }
41
+ value = value.toLocaleString("pt-br", {
42
+ minimumFractionDigits: minPrecision,
43
+ maximumFractionDigits: maxPrecision,
44
+ })
45
+ if (field.prefix) value = field.prefix + ' ' + value
46
+ if (field.suffix) value = value + ' ' + field.suffix
47
+ return value
48
+ }
49
+ case "date":
50
+ if (!value) return ""
51
+ return toDate(value).toLocaleDateString("pt-br", { ...field })
52
+ case "datetime":
53
+ if (!value) return ""
54
+ return toDate(value).toLocaleString("pt-br", { ...field })
55
+ case "list":
56
+ return value.join(", ")
57
+ default:
58
+ return value
59
+ }
60
+ }
61
+ export const getValue = (row, field) => {
62
+ var key = null
63
+ if (!row || !field) return undefined
64
+ if (typeof field === 'object')
65
+ key = field.view || field.key
66
+ else key = field
67
+ if (!key) return undefined
68
+ var steps = key.split(".")
69
+ var v = row
70
+ var step = 0
71
+ while (step < steps.length) {
72
+ v = v[steps[step]]
73
+ if (!v) return v
74
+ step++
75
+ }
76
+ return v
77
+ }
78
+
79
+ export const normalizeDatetime = (input) => {
80
+ if (!input) return null;
81
+
82
+ let date;
83
+
84
+ if (input instanceof Date) {
85
+ date = input;
86
+ } else if (typeof input === "string") {
87
+ const normalized = input.replace(/\//g, "-").replace("T", " ");
88
+
89
+ date = new Date(normalized);
90
+ } else if (typeof input === "number") {
91
+ date = new Date(input);
92
+ } else {
93
+ return null;
94
+ }
95
+
96
+ if (isNaN(date)) return null;
97
+
98
+ const pad = (n) => (n < 10 ? "0" + n : n);
99
+
100
+ const yyyy = date.getFullYear();
101
+ const mm = pad(date.getMonth() + 1);
102
+ const dd = pad(date.getDate());
103
+
104
+ const hh = pad(date.getHours());
105
+ const mi = pad(date.getMinutes());
106
+ const ss = pad(date.getSeconds());
107
+
108
+ return `${yyyy}-${mm}-${dd} ${hh}:${mi}:${ss}`;
109
+ };
@@ -0,0 +1,3 @@
1
+ export { default } from './module.mjs'
2
+
3
+ export { type ModuleOptions } from './module.mjs'
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "@bgottsch/d-naive",
3
+ "version": "1.8.9",
4
+ "description": "Vue library designed to enhance Naive UI components with additional functionalities for complex data handling and user input management",
5
+ "repository": "mdoreto/d-naive",
6
+ "license": "MIT",
7
+ "type": "module",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/types.d.mts",
11
+ "import": "./dist/module.mjs"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist"
16
+ ],
17
+ "scripts": {
18
+ "prepare": "nuxt-module-build build --failOnWarn=false",
19
+ "prepack": "nuxt-module-build build --failOnWarn=false",
20
+ "dev": "nuxi dev playground",
21
+ "dev:build": "nuxi build playground",
22
+ "dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxi prepare playground",
23
+ "release": "npm run lint && npm run prepack && changelogen --release && npm publish && git push --follow-tags",
24
+ "lint": "eslint . --fix",
25
+ "test": "vitest run",
26
+ "test:watch": "vitest watch"
27
+ },
28
+ "dependencies": {
29
+ "@nuxt/kit": "^4.2.1"
30
+ },
31
+ "devDependencies": {
32
+ "nuxt": "^4.2.1",
33
+ "vue-tsc": "^3.1.5",
34
+ "@nuxt/devtools": "^3.1.0",
35
+ "@nuxt/eslint-config": "^1.10.0",
36
+ "@nuxt/module-builder": "^1.0.2",
37
+ "@nuxt/schema": "^4.2.1",
38
+ "@nuxt/test-utils": "^3.20.1",
39
+ "vitest": "^3.2.0",
40
+ "eslint": "^9.39.1",
41
+ "@types/node": "^24.10.1",
42
+ "changelogen": "^0.6.2"
43
+ }
44
+ }