@m3ui-vue/m3ui-vue 0.8.4 → 0.8.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.
Files changed (54) hide show
  1. package/README.md +1 -1
  2. package/dist/{MMenuItem-DiilFeDO.js → MMenuItem-BmPLAyv5.js} +64 -62
  3. package/dist/{MMenuItem-DiilFeDO.js.map → MMenuItem-BmPLAyv5.js.map} +1 -1
  4. package/dist/code-editor.js +1 -1
  5. package/dist/components/MChatBubble.vue.d.ts +4 -2
  6. package/dist/components/MCheckbox.vue.d.ts +2 -0
  7. package/dist/components/MDragDropList.vue.d.ts +19 -6
  8. package/dist/components/MFileUpload.vue.d.ts +16 -4
  9. package/dist/components/MKanban.vue.d.ts +15 -6
  10. package/dist/components/MTable.vue.d.ts +8 -0
  11. package/dist/components/MTransferList.vue.d.ts +9 -3
  12. package/dist/components/_MTransferPane.vue.d.ts +39 -0
  13. package/dist/composables/useLocale.d.ts +24 -0
  14. package/dist/locales/index.js +175 -7
  15. package/dist/locales/index.js.map +1 -1
  16. package/dist/m3ui-vue.css +1 -1
  17. package/dist/m3ui.js +3600 -2696
  18. package/dist/m3ui.js.map +1 -1
  19. package/dist/rich-text-editor.js +2 -2
  20. package/dist/styles.css +1 -1
  21. package/dist/{useLocale-DbREg9Zn.js → useLocale-4afAzuuP.js} +26 -2
  22. package/dist/useLocale-4afAzuuP.js.map +1 -0
  23. package/package.json +1 -1
  24. package/src/__tests__/MChatBubble.test.ts +33 -0
  25. package/src/__tests__/MDragDropList.test.ts +194 -0
  26. package/src/__tests__/MFileUpload.test.ts +78 -0
  27. package/src/__tests__/MKanban.test.ts +150 -0
  28. package/src/__tests__/MMenu.test.ts +84 -0
  29. package/src/__tests__/MPullToRefresh.test.ts +67 -0
  30. package/src/__tests__/MRating.test.ts +72 -0
  31. package/src/__tests__/MTransferList.test.ts +76 -0
  32. package/src/components/MChatBubble.vue +107 -20
  33. package/src/components/MCheckbox.vue +3 -0
  34. package/src/components/MContextMenu.vue +10 -1
  35. package/src/components/MDragDropList.vue +485 -56
  36. package/src/components/MFileUpload.vue +56 -20
  37. package/src/components/MKanban.vue +720 -78
  38. package/src/components/MMenu.vue +10 -1
  39. package/src/components/MNavigationRail.vue +35 -23
  40. package/src/components/MPullToRefresh.vue +101 -35
  41. package/src/components/MRating.vue +163 -67
  42. package/src/components/MResult.vue +19 -9
  43. package/src/components/MTable.vue +10 -3
  44. package/src/components/MTransferList.vue +133 -130
  45. package/src/components/_MTransferPane.vue +182 -0
  46. package/src/composables/useLocale.ts +68 -0
  47. package/src/locales/de.ts +34 -0
  48. package/src/locales/es.ts +34 -0
  49. package/src/locales/fr.ts +34 -0
  50. package/src/locales/ja.ts +34 -0
  51. package/src/locales/ko.ts +34 -0
  52. package/src/locales/pt.ts +34 -0
  53. package/src/locales/zh.ts +34 -0
  54. 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
- const files = ref<UploadFile[]>([])
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
- const entries: UploadFile[] = valid.map((f) => {
72
- const entry: UploadFile = {
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
- if (f.type.startsWith('image/')) {
79
- entry.preview = URL.createObjectURL(f)
80
- }
81
- return entry
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
- if (entry.preview) URL.revokeObjectURL(entry.preview)
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