@hoci/core 0.7.0 → 0.7.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.
- package/dist/index.cjs +16 -16
- package/dist/index.mjs +17 -17
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -567,15 +567,8 @@ const useFileUpload = shared.defineHookComponent({
|
|
|
567
567
|
setup(props, { emit }) {
|
|
568
568
|
const fileInputRef = shared.elementRef();
|
|
569
569
|
const files = vue.ref([]);
|
|
570
|
-
vue.watch(props.modelValue, (value) => {
|
|
571
|
-
|
|
572
|
-
files.value.push(value);
|
|
573
|
-
} else if (Array.isArray(value)) {
|
|
574
|
-
files.value.push(...value);
|
|
575
|
-
}
|
|
576
|
-
if (props.multiple) {
|
|
577
|
-
files.value.splice(1, files.value.length - 1);
|
|
578
|
-
}
|
|
570
|
+
vue.watch(() => shared.toArray(props.modelValue), (value) => {
|
|
571
|
+
files.value = value;
|
|
579
572
|
}, {
|
|
580
573
|
immediate: true,
|
|
581
574
|
deep: true
|
|
@@ -583,18 +576,25 @@ const useFileUpload = shared.defineHookComponent({
|
|
|
583
576
|
const openFileInput = () => {
|
|
584
577
|
fileInputRef.value?.click();
|
|
585
578
|
};
|
|
579
|
+
const toModelValue = (files2) => {
|
|
580
|
+
if (props.multiple) {
|
|
581
|
+
return files2;
|
|
582
|
+
}
|
|
583
|
+
if (files2.length) {
|
|
584
|
+
return files2[files2.length - 1];
|
|
585
|
+
}
|
|
586
|
+
return null;
|
|
587
|
+
};
|
|
586
588
|
useEventListener(fileInputRef, "change", (event) => {
|
|
587
|
-
const newFiles = event.target.files;
|
|
588
|
-
|
|
589
|
-
if (newFiles) {
|
|
589
|
+
const newFiles = Array.from(event.target.files ?? []);
|
|
590
|
+
if (newFiles?.length) {
|
|
590
591
|
if (props.multiple) {
|
|
591
|
-
value
|
|
592
|
-
files.value.push(...value);
|
|
592
|
+
files.value.push(...newFiles);
|
|
593
593
|
} else {
|
|
594
|
-
value =
|
|
595
|
-
files.value = value ? [value] : [];
|
|
594
|
+
files.value = newFiles.slice(newFiles.length - 1);
|
|
596
595
|
}
|
|
597
596
|
}
|
|
597
|
+
const value = toModelValue(files.value);
|
|
598
598
|
emit("update:modelValue", value);
|
|
599
599
|
emit("change", value);
|
|
600
600
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defineHookProps, defineHookEmits, defineHookComponent, elementRef, toReactive, useElement, throttleByRaf, isWindow, useSharedConfig, valuePropType, labelPropType, classPropType, getFirstChilld } from '@hoci/shared';
|
|
1
|
+
import { defineHookProps, defineHookEmits, defineHookComponent, elementRef, toReactive, useElement, throttleByRaf, isWindow, toArray, useSharedConfig, valuePropType, labelPropType, classPropType, getFirstChilld } from '@hoci/shared';
|
|
2
2
|
export * from '@hoci/shared';
|
|
3
3
|
import { getCurrentInstance, onMounted, nextTick, getCurrentScope, onScopeDispose, unref, watch, ref, computed, inject, watchPostEffect, provide, reactive, renderSlot } from 'vue';
|
|
4
4
|
import { px, createUnitFormat, cls } from 'tslx';
|
|
@@ -566,15 +566,8 @@ const useFileUpload = defineHookComponent({
|
|
|
566
566
|
setup(props, { emit }) {
|
|
567
567
|
const fileInputRef = elementRef();
|
|
568
568
|
const files = ref([]);
|
|
569
|
-
watch(props.modelValue, (value) => {
|
|
570
|
-
|
|
571
|
-
files.value.push(value);
|
|
572
|
-
} else if (Array.isArray(value)) {
|
|
573
|
-
files.value.push(...value);
|
|
574
|
-
}
|
|
575
|
-
if (props.multiple) {
|
|
576
|
-
files.value.splice(1, files.value.length - 1);
|
|
577
|
-
}
|
|
569
|
+
watch(() => toArray(props.modelValue), (value) => {
|
|
570
|
+
files.value = value;
|
|
578
571
|
}, {
|
|
579
572
|
immediate: true,
|
|
580
573
|
deep: true
|
|
@@ -582,18 +575,25 @@ const useFileUpload = defineHookComponent({
|
|
|
582
575
|
const openFileInput = () => {
|
|
583
576
|
fileInputRef.value?.click();
|
|
584
577
|
};
|
|
578
|
+
const toModelValue = (files2) => {
|
|
579
|
+
if (props.multiple) {
|
|
580
|
+
return files2;
|
|
581
|
+
}
|
|
582
|
+
if (files2.length) {
|
|
583
|
+
return files2[files2.length - 1];
|
|
584
|
+
}
|
|
585
|
+
return null;
|
|
586
|
+
};
|
|
585
587
|
useEventListener(fileInputRef, "change", (event) => {
|
|
586
|
-
const newFiles = event.target.files;
|
|
587
|
-
|
|
588
|
-
if (newFiles) {
|
|
588
|
+
const newFiles = Array.from(event.target.files ?? []);
|
|
589
|
+
if (newFiles?.length) {
|
|
589
590
|
if (props.multiple) {
|
|
590
|
-
value
|
|
591
|
-
files.value.push(...value);
|
|
591
|
+
files.value.push(...newFiles);
|
|
592
592
|
} else {
|
|
593
|
-
value =
|
|
594
|
-
files.value = value ? [value] : [];
|
|
593
|
+
files.value = newFiles.slice(newFiles.length - 1);
|
|
595
594
|
}
|
|
596
595
|
}
|
|
596
|
+
const value = toModelValue(files.value);
|
|
597
597
|
emit("update:modelValue", value);
|
|
598
598
|
emit("change", value);
|
|
599
599
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hoci/core",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"author": "Chizuki <chizukicn@outlook.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"maybe-types": "^0.2.0",
|
|
31
31
|
"tslx": "^0.1.1",
|
|
32
|
-
"@hoci/shared": "0.7.
|
|
32
|
+
"@hoci/shared": "0.7.1"
|
|
33
33
|
},
|
|
34
34
|
"scripts": {
|
|
35
35
|
"build": "unbuild",
|