@mekari/pixel3-upload 0.0.1

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,97 @@
1
+ import * as vue from 'vue';
2
+ import { UploadProps, UploadEmits, UploadListProps, UploadListEmits } from './upload.props.js';
3
+
4
+ declare function useUpload(props: UploadProps, emit: UploadEmits): {
5
+ rootAttrs: vue.ComputedRef<{
6
+ 'data-pixel-component': string;
7
+ 'data-invalid': true | undefined;
8
+ 'data-disabled': true | undefined;
9
+ id: string | undefined;
10
+ tabindex: number;
11
+ class: string;
12
+ style: {
13
+ maxWidth: string;
14
+ };
15
+ onClick: (e: Event) => void;
16
+ }>;
17
+ buttonAttrs: vue.ComputedRef<{
18
+ variant: "secondary";
19
+ size: "sm";
20
+ isDisabled: boolean;
21
+ }>;
22
+ textAttrs: vue.ComputedRef<{
23
+ color: string;
24
+ isTruncated: boolean;
25
+ }>;
26
+ resetButtonAttrs: vue.ComputedRef<{
27
+ class: string;
28
+ 'aria-label': string;
29
+ name: string;
30
+ size: "sm";
31
+ color: string;
32
+ onClick: (e: Event) => void;
33
+ }>;
34
+ inputAttrs: vue.ComputedRef<{
35
+ ref: vue.Ref<any>;
36
+ id: string;
37
+ class: string;
38
+ type: string;
39
+ name: string | undefined;
40
+ accept: string | undefined;
41
+ multiple: boolean;
42
+ disabled: boolean;
43
+ required: boolean;
44
+ onChange: (e: Event) => void;
45
+ }>;
46
+ fileName: vue.ComputedRef<unknown>;
47
+ totalFiles: vue.ComputedRef<number>;
48
+ isShowTooltip: vue.ComputedRef<boolean>;
49
+ };
50
+ declare function useUploadList(props: UploadListProps, emit: UploadListEmits): {
51
+ color: vue.ComputedRef<{
52
+ title: string;
53
+ subtitle: string;
54
+ }>;
55
+ rootAttrs: vue.ComputedRef<{
56
+ 'data-pixel-component': string;
57
+ id: string | undefined;
58
+ tabindex: number;
59
+ class: string;
60
+ }>;
61
+ iconAttrs: vue.ComputedRef<{
62
+ size: "md";
63
+ name: string;
64
+ color: string;
65
+ variant: "outline" | "duotone" | "fill";
66
+ }>;
67
+ titleWrapperAttrs: vue.ComputedRef<{
68
+ class: string;
69
+ style: {
70
+ cursor: string;
71
+ };
72
+ onClick: (e: Event) => void;
73
+ }>;
74
+ buttonCancelAttrs: vue.ComputedRef<{
75
+ variant: "ghost";
76
+ size: "sm";
77
+ leftIcon: string;
78
+ onClick: (e: Event) => void;
79
+ }>;
80
+ buttonDownloadAttrs: vue.ComputedRef<{
81
+ variant: "ghost";
82
+ size: "sm";
83
+ leftIcon: string;
84
+ onClick: (e: Event) => void;
85
+ }>;
86
+ buttonRemoveAttrs: vue.ComputedRef<{
87
+ variant: "ghost";
88
+ size: "sm";
89
+ leftIcon: string;
90
+ onClick: (e: Event) => void;
91
+ }>;
92
+ hasCancelButton: vue.ComputedRef<boolean>;
93
+ hasDownloadButton: vue.ComputedRef<boolean>;
94
+ hasRemoveButton: vue.ComputedRef<boolean>;
95
+ };
96
+
97
+ export { useUpload, useUploadList };
@@ -0,0 +1,279 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // src/modules/upload.hooks.ts
22
+ var upload_hooks_exports = {};
23
+ __export(upload_hooks_exports, {
24
+ useUpload: () => useUpload,
25
+ useUploadList: () => useUploadList
26
+ });
27
+ module.exports = __toCommonJS(upload_hooks_exports);
28
+ var import_vue = require("vue");
29
+ var import_pixel3_utils = require("@mekari/pixel3-utils");
30
+ var import_recipes = require("@mekari/pixel3-styled-system/recipes");
31
+ function useUpload(props, emit) {
32
+ const {
33
+ id,
34
+ fileList,
35
+ placeholder,
36
+ accept,
37
+ name,
38
+ loadingText,
39
+ isLoading,
40
+ isDisabled,
41
+ isInvalid,
42
+ isRequired,
43
+ isResetOnChange,
44
+ isMultiple,
45
+ isFullWidth
46
+ } = (0, import_vue.toRefs)(props);
47
+ const files = (0, import_vue.ref)(fileList == null ? void 0 : fileList.value);
48
+ const fileInput = (0, import_vue.ref)();
49
+ const getId = id.value || (0, import_pixel3_utils.getUniqueId)("", "upload").value;
50
+ const fileName = (0, import_vue.computed)(() => {
51
+ if (isLoading.value) {
52
+ return loadingText.value;
53
+ } else {
54
+ if (totalFiles.value === 0) {
55
+ return placeholder.value;
56
+ } else if (files.value && totalFiles.value === 1) {
57
+ return files.value[0].name;
58
+ } else {
59
+ return `${totalFiles.value} files`;
60
+ }
61
+ }
62
+ });
63
+ const totalFiles = (0, import_vue.computed)(() => {
64
+ var _a;
65
+ return ((_a = files.value) == null ? void 0 : _a.length) || 0;
66
+ });
67
+ const isShowTooltip = (0, import_vue.computed)(() => {
68
+ var _a;
69
+ return ((_a = files.value) == null ? void 0 : _a.length) === 1;
70
+ });
71
+ const rootAttrs = (0, import_vue.computed)(() => {
72
+ return {
73
+ "data-pixel-component": "MpUpload",
74
+ "data-invalid": isInvalid.value || void 0,
75
+ "data-disabled": isDisabled.value || void 0,
76
+ id: getId,
77
+ tabindex: isDisabled.value ? -1 : 0,
78
+ class: (0, import_recipes.uploadSlotRecipe)().root,
79
+ style: {
80
+ maxWidth: isFullWidth.value ? "100%" : "var(--mp-sizes-65)"
81
+ },
82
+ onClick: handleClick
83
+ };
84
+ });
85
+ const buttonAttrs = (0, import_vue.computed)(() => {
86
+ return {
87
+ variant: "secondary",
88
+ size: "sm",
89
+ isDisabled: isDisabled.value
90
+ };
91
+ });
92
+ const textAttrs = (0, import_vue.computed)(() => {
93
+ return {
94
+ color: !isLoading.value && totalFiles.value >= 1 ? "dark" : "gray.400",
95
+ isTruncated: true
96
+ };
97
+ });
98
+ const resetButtonAttrs = (0, import_vue.computed)(() => {
99
+ return {
100
+ class: (0, import_recipes.uploadSlotRecipe)().resetButton,
101
+ "aria-label": "reset button",
102
+ name: "reset",
103
+ size: "sm",
104
+ color: "gray.400",
105
+ onClick: handleClear
106
+ };
107
+ });
108
+ const inputAttrs = (0, import_vue.computed)(() => {
109
+ return {
110
+ ref: fileInput,
111
+ id: `input-${getId}`,
112
+ class: (0, import_recipes.sharedSlotRecipe)().hidden,
113
+ type: "file",
114
+ name: name == null ? void 0 : name.value,
115
+ accept: accept == null ? void 0 : accept.value,
116
+ multiple: isMultiple.value,
117
+ disabled: isDisabled.value,
118
+ required: isRequired.value,
119
+ onChange: handleChange
120
+ };
121
+ });
122
+ function clear() {
123
+ files.value = void 0;
124
+ fileInput.value.value = "";
125
+ }
126
+ __name(clear, "clear");
127
+ function handleClear(e) {
128
+ e.stopPropagation();
129
+ clear();
130
+ emit("clear", e);
131
+ }
132
+ __name(handleClear, "handleClear");
133
+ function handleChange(e) {
134
+ const target = e.target;
135
+ if (target && target.files) {
136
+ files.value = target.files;
137
+ }
138
+ emit("change", e);
139
+ }
140
+ __name(handleChange, "handleChange");
141
+ function handleClick(e) {
142
+ if (isDisabled.value) {
143
+ return;
144
+ }
145
+ if (isResetOnChange.value) {
146
+ clear();
147
+ }
148
+ fileInput.value.click();
149
+ emit("click", e);
150
+ }
151
+ __name(handleClick, "handleClick");
152
+ (0, import_vue.watch)(() => fileList == null ? void 0 : fileList.value, (newValue) => {
153
+ if (newValue) {
154
+ files.value = newValue;
155
+ }
156
+ });
157
+ return {
158
+ rootAttrs,
159
+ buttonAttrs,
160
+ textAttrs,
161
+ resetButtonAttrs,
162
+ inputAttrs,
163
+ fileName,
164
+ totalFiles,
165
+ isShowTooltip
166
+ };
167
+ }
168
+ __name(useUpload, "useUpload");
169
+ function useUploadList(props, emit) {
170
+ const {
171
+ id,
172
+ status,
173
+ iconName,
174
+ iconColor,
175
+ iconVariant,
176
+ isShowCancelButton,
177
+ isShowDownloadButton,
178
+ isShowRemoveButton
179
+ } = (0, import_vue.toRefs)(props);
180
+ const getId = id.value || (0, import_pixel3_utils.getUniqueId)("", "upload-list").value;
181
+ const color = (0, import_vue.computed)(() => {
182
+ let title = "dark";
183
+ let subtitle = "gray.600";
184
+ if (status.value === "success") {
185
+ title = "blue.700";
186
+ }
187
+ if (status.value === "error") {
188
+ title = "red.400";
189
+ subtitle = "red.400";
190
+ }
191
+ return {
192
+ title,
193
+ subtitle
194
+ };
195
+ });
196
+ const hasCancelButton = (0, import_vue.computed)(() => {
197
+ return isShowCancelButton.value && status.value === "loading";
198
+ });
199
+ const hasDownloadButton = (0, import_vue.computed)(() => {
200
+ return isShowDownloadButton.value && status.value === "success";
201
+ });
202
+ const hasRemoveButton = (0, import_vue.computed)(() => {
203
+ return isShowRemoveButton.value && (status.value === "success" || status.value === "error");
204
+ });
205
+ const rootAttrs = (0, import_vue.computed)(() => {
206
+ return {
207
+ "data-pixel-component": "MpUploadList",
208
+ id: getId,
209
+ tabindex: 0,
210
+ class: (0, import_recipes.uploadListSlotRecipe)().root
211
+ };
212
+ });
213
+ const iconAttrs = (0, import_vue.computed)(() => {
214
+ return {
215
+ size: "md",
216
+ name: status.value === "error" ? "error" : iconName.value,
217
+ color: status.value === "error" ? "red.700" : iconColor.value,
218
+ variant: status.value === "error" ? "duotone" : iconVariant.value
219
+ };
220
+ });
221
+ const titleWrapperAttrs = (0, import_vue.computed)(() => {
222
+ return {
223
+ class: (0, import_recipes.uploadListSlotRecipe)().titleWrapper,
224
+ style: {
225
+ cursor: status.value === "success" ? "pointer" : "default"
226
+ },
227
+ onClick: handleClick
228
+ };
229
+ });
230
+ const buttonCancelAttrs = (0, import_vue.computed)(() => {
231
+ return {
232
+ variant: "ghost",
233
+ size: "sm",
234
+ leftIcon: "close",
235
+ onClick: (e) => emit("cancel", e)
236
+ };
237
+ });
238
+ const buttonDownloadAttrs = (0, import_vue.computed)(() => {
239
+ return {
240
+ variant: "ghost",
241
+ size: "sm",
242
+ leftIcon: "download",
243
+ onClick: (e) => emit("download", e)
244
+ };
245
+ });
246
+ const buttonRemoveAttrs = (0, import_vue.computed)(() => {
247
+ return {
248
+ variant: "ghost",
249
+ size: "sm",
250
+ leftIcon: "minus-circular",
251
+ onClick: (e) => emit("remove", e)
252
+ };
253
+ });
254
+ function handleClick(e) {
255
+ if (status.value !== "success") {
256
+ return;
257
+ }
258
+ emit("click", e);
259
+ }
260
+ __name(handleClick, "handleClick");
261
+ return {
262
+ color,
263
+ rootAttrs,
264
+ iconAttrs,
265
+ titleWrapperAttrs,
266
+ buttonCancelAttrs,
267
+ buttonDownloadAttrs,
268
+ buttonRemoveAttrs,
269
+ hasCancelButton,
270
+ hasDownloadButton,
271
+ hasRemoveButton
272
+ };
273
+ }
274
+ __name(useUploadList, "useUploadList");
275
+ // Annotate the CommonJS export names for ESM import in node:
276
+ 0 && (module.exports = {
277
+ useUpload,
278
+ useUploadList
279
+ });
@@ -0,0 +1,9 @@
1
+ import {
2
+ useUpload,
3
+ useUploadList
4
+ } from "../chunk-IEVDIM2Y.mjs";
5
+ import "../chunk-QZ7VFGWC.mjs";
6
+ export {
7
+ useUpload,
8
+ useUploadList
9
+ };
@@ -0,0 +1,116 @@
1
+ import { PropType, ExtractPropTypes } from 'vue';
2
+
3
+ type File = {
4
+ [key: string]: unknown;
5
+ };
6
+ declare const uploadProps: {
7
+ id: {
8
+ type: PropType<string>;
9
+ default: string;
10
+ };
11
+ fileList: {
12
+ type: PropType<File[]>;
13
+ };
14
+ accept: {
15
+ type: PropType<string>;
16
+ };
17
+ name: {
18
+ type: PropType<string>;
19
+ };
20
+ placeholder: {
21
+ type: PropType<string>;
22
+ default: string;
23
+ };
24
+ loadingText: {
25
+ type: PropType<string>;
26
+ default: string;
27
+ };
28
+ buttonCaption: {
29
+ type: PropType<string>;
30
+ default: string;
31
+ };
32
+ value: {
33
+ type: PropType<string>;
34
+ };
35
+ modelValue: {
36
+ type: PropType<string>;
37
+ };
38
+ isLoading: {
39
+ type: PropType<boolean>;
40
+ default: boolean;
41
+ };
42
+ isDisabled: {
43
+ type: PropType<boolean>;
44
+ default: boolean;
45
+ };
46
+ isInvalid: {
47
+ type: PropType<boolean>;
48
+ default: boolean;
49
+ };
50
+ isRequired: {
51
+ type: PropType<boolean>;
52
+ default: boolean;
53
+ };
54
+ isResetOnChange: {
55
+ type: PropType<boolean>;
56
+ default: boolean;
57
+ };
58
+ isMultiple: {
59
+ type: PropType<boolean>;
60
+ default: boolean;
61
+ };
62
+ isFullWidth: {
63
+ type: PropType<boolean>;
64
+ default: boolean;
65
+ };
66
+ };
67
+ declare const uploadListProps: {
68
+ id: {
69
+ type: PropType<string>;
70
+ default: string;
71
+ };
72
+ status: {
73
+ type: PropType<"error" | "success" | "loading">;
74
+ default: string;
75
+ };
76
+ title: {
77
+ type: PropType<string>;
78
+ default: string;
79
+ };
80
+ subtitle: {
81
+ type: PropType<string>;
82
+ default: string;
83
+ };
84
+ iconName: {
85
+ type: PropType<string>;
86
+ default: string;
87
+ };
88
+ iconColor: {
89
+ type: PropType<string>;
90
+ default: string;
91
+ };
92
+ iconVariant: {
93
+ type: PropType<string>;
94
+ default: string;
95
+ };
96
+ isShowDownloadButton: {
97
+ type: PropType<boolean>;
98
+ default: boolean;
99
+ };
100
+ isShowRemoveButton: {
101
+ type: PropType<boolean>;
102
+ default: boolean;
103
+ };
104
+ isShowCancelButton: {
105
+ type: PropType<boolean>;
106
+ default: boolean;
107
+ };
108
+ };
109
+ declare const uploadEmit: string[];
110
+ declare const uploadListEmit: string[];
111
+ type UploadProps = ExtractPropTypes<typeof uploadProps>;
112
+ type UploadEmits = (event: (typeof uploadEmit)[number], value?: unknown) => void;
113
+ type UploadListProps = ExtractPropTypes<typeof uploadListProps>;
114
+ type UploadListEmits = (event: (typeof uploadListEmit)[number], value?: unknown) => void;
115
+
116
+ export { File, UploadEmits, UploadListEmits, UploadListProps, UploadProps, uploadEmit, uploadListEmit, uploadListProps, uploadProps };
@@ -0,0 +1,116 @@
1
+ import { PropType, ExtractPropTypes } from 'vue';
2
+
3
+ type File = {
4
+ [key: string]: unknown;
5
+ };
6
+ declare const uploadProps: {
7
+ id: {
8
+ type: PropType<string>;
9
+ default: string;
10
+ };
11
+ fileList: {
12
+ type: PropType<File[]>;
13
+ };
14
+ accept: {
15
+ type: PropType<string>;
16
+ };
17
+ name: {
18
+ type: PropType<string>;
19
+ };
20
+ placeholder: {
21
+ type: PropType<string>;
22
+ default: string;
23
+ };
24
+ loadingText: {
25
+ type: PropType<string>;
26
+ default: string;
27
+ };
28
+ buttonCaption: {
29
+ type: PropType<string>;
30
+ default: string;
31
+ };
32
+ value: {
33
+ type: PropType<string>;
34
+ };
35
+ modelValue: {
36
+ type: PropType<string>;
37
+ };
38
+ isLoading: {
39
+ type: PropType<boolean>;
40
+ default: boolean;
41
+ };
42
+ isDisabled: {
43
+ type: PropType<boolean>;
44
+ default: boolean;
45
+ };
46
+ isInvalid: {
47
+ type: PropType<boolean>;
48
+ default: boolean;
49
+ };
50
+ isRequired: {
51
+ type: PropType<boolean>;
52
+ default: boolean;
53
+ };
54
+ isResetOnChange: {
55
+ type: PropType<boolean>;
56
+ default: boolean;
57
+ };
58
+ isMultiple: {
59
+ type: PropType<boolean>;
60
+ default: boolean;
61
+ };
62
+ isFullWidth: {
63
+ type: PropType<boolean>;
64
+ default: boolean;
65
+ };
66
+ };
67
+ declare const uploadListProps: {
68
+ id: {
69
+ type: PropType<string>;
70
+ default: string;
71
+ };
72
+ status: {
73
+ type: PropType<"error" | "success" | "loading">;
74
+ default: string;
75
+ };
76
+ title: {
77
+ type: PropType<string>;
78
+ default: string;
79
+ };
80
+ subtitle: {
81
+ type: PropType<string>;
82
+ default: string;
83
+ };
84
+ iconName: {
85
+ type: PropType<string>;
86
+ default: string;
87
+ };
88
+ iconColor: {
89
+ type: PropType<string>;
90
+ default: string;
91
+ };
92
+ iconVariant: {
93
+ type: PropType<string>;
94
+ default: string;
95
+ };
96
+ isShowDownloadButton: {
97
+ type: PropType<boolean>;
98
+ default: boolean;
99
+ };
100
+ isShowRemoveButton: {
101
+ type: PropType<boolean>;
102
+ default: boolean;
103
+ };
104
+ isShowCancelButton: {
105
+ type: PropType<boolean>;
106
+ default: boolean;
107
+ };
108
+ };
109
+ declare const uploadEmit: string[];
110
+ declare const uploadListEmit: string[];
111
+ type UploadProps = ExtractPropTypes<typeof uploadProps>;
112
+ type UploadEmits = (event: (typeof uploadEmit)[number], value?: unknown) => void;
113
+ type UploadListProps = ExtractPropTypes<typeof uploadListProps>;
114
+ type UploadListEmits = (event: (typeof uploadListEmit)[number], value?: unknown) => void;
115
+
116
+ export { File, UploadEmits, UploadListEmits, UploadListProps, UploadProps, uploadEmit, uploadListEmit, uploadListProps, uploadProps };