@m3ui-vue/m3ui-vue 0.8.5 → 0.8.7
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/README.md +5 -1
- package/dist/{MMenuItem-BXIxwIdM.js → MMenuItem-DmrsQrK7.js} +2 -2
- package/dist/{MMenuItem-BXIxwIdM.js.map → MMenuItem-DmrsQrK7.js.map} +1 -1
- package/dist/chart.js +5 -1
- package/dist/chart.js.map +1 -1
- package/dist/code-editor.js +1 -1
- package/dist/components/MBottomSheet.vue.d.ts +3 -3
- package/dist/components/MChatBubble.vue.d.ts +4 -2
- package/dist/components/MCheckbox.vue.d.ts +2 -0
- package/dist/components/MDragDropList.vue.d.ts +19 -6
- package/dist/components/MFileUpload.vue.d.ts +16 -4
- package/dist/components/MKanban.vue.d.ts +15 -6
- package/dist/components/MListDetail.vue.d.ts +31 -0
- package/dist/components/MNavigationRail.vue.d.ts +6 -3
- package/dist/components/MNavigationSuite.vue.d.ts +46 -0
- package/dist/components/MShortNavigationBar.vue.d.ts +6 -1
- package/dist/components/MSideSheet.vue.d.ts +4 -4
- package/dist/components/MSupportingPane.vue.d.ts +34 -0
- package/dist/components/MTransferList.vue.d.ts +57 -30
- package/dist/components/MWindow.vue.d.ts +39 -1
- package/dist/components/_MTransferPane.vue.d.ts +46 -0
- package/dist/composables/_useItemLink.d.ts +30 -0
- package/dist/composables/_useSheetMotion.d.ts +7 -0
- package/dist/composables/useLocale.d.ts +27 -0
- package/dist/composables/useWindowSizeClass.d.ts +19 -0
- package/dist/index.d.ts +6 -0
- package/dist/locales/index.js +196 -7
- package/dist/locales/index.js.map +1 -1
- package/dist/m3ui-vue.css +1 -1
- package/dist/m3ui.js +4331 -2945
- package/dist/m3ui.js.map +1 -1
- package/dist/rich-text-editor.js +2 -2
- package/dist/styles.css +1 -1
- package/dist/{useLocale-DbREg9Zn.js → useLocale-Bircp823.js} +29 -2
- package/dist/useLocale-Bircp823.js.map +1 -0
- package/package.json +1 -1
- package/src/__tests__/MChart.test.ts +28 -0
- package/src/__tests__/MChatBubble.test.ts +33 -0
- package/src/__tests__/MDragDropList.test.ts +194 -0
- package/src/__tests__/MFileUpload.test.ts +78 -0
- package/src/__tests__/MKanban.test.ts +150 -0
- package/src/__tests__/MPullToRefresh.test.ts +67 -0
- package/src/__tests__/MRating.test.ts +72 -0
- package/src/__tests__/MShortNavigationBar.test.ts +25 -0
- package/src/__tests__/MTransferList.test.ts +149 -0
- package/src/__tests__/MWindow.test.ts +258 -0
- package/src/__tests__/adaptiveLayouts.test.ts +191 -0
- package/src/__tests__/sheets.test.ts +76 -0
- package/src/components/MBottomSheet.vue +11 -57
- package/src/components/MChart.vue +2 -1
- package/src/components/MChatBubble.vue +107 -20
- package/src/components/MCheckbox.vue +3 -0
- package/src/components/MDragDropList.vue +485 -56
- package/src/components/MFileUpload.vue +56 -20
- package/src/components/MKanban.vue +720 -78
- package/src/components/MListDetail.vue +103 -0
- package/src/components/MNavigationRail.vue +48 -31
- package/src/components/MNavigationSuite.vue +89 -0
- package/src/components/MPullToRefresh.vue +101 -35
- package/src/components/MRating.vue +163 -67
- package/src/components/MResult.vue +19 -9
- package/src/components/MShortNavigationBar.vue +37 -17
- package/src/components/MSideSheet.vue +11 -56
- package/src/components/MSupportingPane.vue +70 -0
- package/src/components/MTransferList.vue +174 -137
- package/src/components/MWindow.vue +507 -108
- package/src/components/_MTransferPane.vue +260 -0
- package/src/composables/_useItemLink.ts +19 -0
- package/src/composables/_useSheetMotion.ts +181 -0
- package/src/composables/useLocale.ts +75 -0
- package/src/composables/useWindowSizeClass.ts +93 -0
- package/src/index.ts +6 -0
- package/src/locales/de.ts +37 -0
- package/src/locales/es.ts +37 -0
- package/src/locales/fr.ts +37 -0
- package/src/locales/ja.ts +37 -0
- package/src/locales/ko.ts +37 -0
- package/src/locales/pt.ts +37 -0
- package/src/locales/zh.ts +37 -0
- package/dist/useLocale-DbREg9Zn.js.map +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
import { ref, computed } from 'vue'
|
|
2
|
+
import { ref, computed, reactive, watch, onBeforeUnmount } from 'vue'
|
|
3
3
|
import MIcon from './MIcon.vue'
|
|
4
4
|
import MIconButton from './MIconButton.vue'
|
|
5
5
|
import MSpinner from './MSpinner.vue'
|
|
@@ -25,6 +25,8 @@ const props = withDefaults(
|
|
|
25
25
|
selectText?: string
|
|
26
26
|
maxSizePrefix?: string
|
|
27
27
|
removeLabel?: string
|
|
28
|
+
/** Optional v-model. Bind it to own the list: clear it, or update each entry's status/progress. Unbound, the component keeps the list itself. */
|
|
29
|
+
modelValue?: UploadFile[]
|
|
28
30
|
}>(),
|
|
29
31
|
{
|
|
30
32
|
multiple: false,
|
|
@@ -35,9 +37,39 @@ const props = withDefaults(
|
|
|
35
37
|
const emit = defineEmits<{
|
|
36
38
|
select: [UploadFile[]]
|
|
37
39
|
remove: [UploadFile]
|
|
40
|
+
'update:modelValue': [UploadFile[]]
|
|
38
41
|
}>()
|
|
39
42
|
|
|
40
|
-
|
|
43
|
+
defineSlots<{
|
|
44
|
+
dropzone?: () => unknown
|
|
45
|
+
/** Shown below the list while it has files, e.g. an "Upload" button. */
|
|
46
|
+
actions?: (props: { files: UploadFile[]; clear: () => void }) => unknown
|
|
47
|
+
}>()
|
|
48
|
+
|
|
49
|
+
// Controlled when v-model is bound, otherwise the component owns the list.
|
|
50
|
+
const internalFiles = ref<UploadFile[]>([])
|
|
51
|
+
const isControlled = computed(() => props.modelValue !== undefined)
|
|
52
|
+
const files = computed(() => (isControlled.value ? props.modelValue! : internalFiles.value))
|
|
53
|
+
|
|
54
|
+
function setFiles(next: UploadFile[]) {
|
|
55
|
+
if (!isControlled.value) internalFiles.value = next
|
|
56
|
+
emit('update:modelValue', next)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Revoke preview URLs of entries that left the list, however they left it (row X,
|
|
60
|
+
// clear(), or the parent replacing/splicing its v-model array).
|
|
61
|
+
watch(
|
|
62
|
+
() => files.value.slice(),
|
|
63
|
+
(next, prev) => {
|
|
64
|
+
const kept = new Set(next.map((f) => f.id))
|
|
65
|
+
for (const f of prev) if (f.preview && !kept.has(f.id)) URL.revokeObjectURL(f.preview)
|
|
66
|
+
},
|
|
67
|
+
)
|
|
68
|
+
onBeforeUnmount(() => {
|
|
69
|
+
// A bound v-model may outlive this component and remount it with the same entries,
|
|
70
|
+
// so only the component's own list is released here.
|
|
71
|
+
if (!isControlled.value) for (const f of internalFiles.value) if (f.preview) URL.revokeObjectURL(f.preview)
|
|
72
|
+
})
|
|
41
73
|
const dragging = ref(false)
|
|
42
74
|
const inputRef = ref<HTMLInputElement | null>(null)
|
|
43
75
|
|
|
@@ -68,26 +100,21 @@ function processFiles(fileList: FileList | File[]) {
|
|
|
68
100
|
return true
|
|
69
101
|
})
|
|
70
102
|
|
|
71
|
-
|
|
72
|
-
|
|
103
|
+
// reactive() up front: the objects emitted in `select` are the exact ones rendered, so
|
|
104
|
+
// setting `entry.status` / `entry.progress` from the parent updates the row. With plain
|
|
105
|
+
// objects the list held Vue's reactive copies and those writes never reached the UI.
|
|
106
|
+
const entries: UploadFile[] = valid.map((f) =>
|
|
107
|
+
reactive<UploadFile>({
|
|
73
108
|
file: f,
|
|
74
109
|
id: crypto.randomUUID(),
|
|
75
110
|
progress: 0,
|
|
76
111
|
status: 'pending',
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
if (props.multiple) {
|
|
85
|
-
files.value.push(...entries)
|
|
86
|
-
} else {
|
|
87
|
-
files.value.forEach((f) => f.preview && URL.revokeObjectURL(f.preview))
|
|
88
|
-
files.value = entries.slice(0, 1)
|
|
89
|
-
}
|
|
90
|
-
|
|
112
|
+
preview: f.type.startsWith('image/') ? URL.createObjectURL(f) : undefined,
|
|
113
|
+
}),
|
|
114
|
+
)
|
|
115
|
+
// A drop/pick where every file was rejected leaves the list alone (it used to wipe the
|
|
116
|
+
// current file in single mode). `select` still fires with exactly what it always did.
|
|
117
|
+
if (entries.length) setFiles(props.multiple ? [...files.value, ...entries] : entries.slice(0, 1))
|
|
91
118
|
emit('select', entries)
|
|
92
119
|
}
|
|
93
120
|
|
|
@@ -104,11 +131,16 @@ function onFileInput(e: Event) {
|
|
|
104
131
|
}
|
|
105
132
|
|
|
106
133
|
function removeFile(entry: UploadFile) {
|
|
107
|
-
|
|
108
|
-
files.value = files.value.filter((f) => f.id !== entry.id)
|
|
134
|
+
setFiles(files.value.filter((f) => f.id !== entry.id))
|
|
109
135
|
emit('remove', entry)
|
|
110
136
|
}
|
|
111
137
|
|
|
138
|
+
function clear() {
|
|
139
|
+
if (files.value.length) setFiles([])
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
defineExpose({ clear, files })
|
|
143
|
+
|
|
112
144
|
function openPicker() {
|
|
113
145
|
if (!props.disabled) inputRef.value?.click()
|
|
114
146
|
}
|
|
@@ -202,6 +234,10 @@ function openPicker() {
|
|
|
202
234
|
<MIconButton icon="close" :label="removeLabel ?? locale.remove" :size="32" @click="removeFile(entry)" />
|
|
203
235
|
</div>
|
|
204
236
|
</TransitionGroup>
|
|
237
|
+
|
|
238
|
+
<div v-if="$slots.actions && files.length" class="flex flex-wrap items-center justify-end gap-2">
|
|
239
|
+
<slot name="actions" :files="files" :clear="clear" />
|
|
240
|
+
</div>
|
|
205
241
|
</div>
|
|
206
242
|
</template>
|
|
207
243
|
|