|
11 | 11 | class="preview-controls-previous raw-hover-surface" |
12 | 12 | appearance="raw" |
13 | 13 | :aria-label="previousDescription" |
14 | | - @click="$emit('togglePrevious')" |
| 14 | + @click="emit('togglePrevious')" |
15 | 15 | > |
16 | 16 | <oc-icon size="large" name="arrow-drop-left" /> |
17 | 17 | </oc-button> |
|
24 | 24 | class="preview-controls-next raw-hover-surface" |
25 | 25 | appearance="raw" |
26 | 26 | :aria-label="nextDescription" |
27 | | - @click="$emit('toggleNext')" |
| 27 | + @click="emit('toggleNext')" |
28 | 28 | > |
29 | 29 | <oc-icon size="large" name="arrow-drop-right" /> |
30 | 30 | </oc-button> |
|
34 | 34 | data-testid="toggle-photo-roll" |
35 | 35 | appearance="raw" |
36 | 36 | :aria-label="togglePhotoRollDescription" |
37 | | - @click="$emit('togglePhotoRoll')" |
| 37 | + @click="emit('togglePhotoRoll')" |
38 | 38 | > |
39 | 39 | <oc-icon name="side-bar" :fill-type="photoRollEnabled ? 'fill' : 'line'" /> |
40 | 40 | </oc-button> |
|
48 | 48 | :aria-label=" |
49 | 49 | isFullScreenModeActivated ? exitFullScreenDescription : enterFullScreenDescription |
50 | 50 | " |
51 | | - @click="$emit('toggleFullScreen')" |
| 51 | + @click="emit('toggleFullScreen')" |
52 | 52 | > |
53 | 53 | <oc-icon |
54 | 54 | fill-type="line" |
|
63 | 63 | class="preview-controls-image-shrink raw-hover-surface p-1" |
64 | 64 | appearance="raw" |
65 | 65 | :aria-label="imageShrinkDescription" |
66 | | - @click="$emit('setShrink')" |
| 66 | + @click="emit('setShrink')" |
67 | 67 | > |
68 | 68 | <oc-icon fill-type="line" name="zoom-out" /> |
69 | 69 | </oc-button> |
|
72 | 72 | class="preview-controls-image-zoom raw-hover-surface p-1" |
73 | 73 | appearance="raw" |
74 | 74 | :aria-label="imageZoomDescription" |
75 | | - @click="$emit('setZoom')" |
| 75 | + @click="emit('setZoom')" |
76 | 76 | > |
77 | 77 | <oc-icon fill-type="line" name="zoom-in" /> |
78 | 78 | </oc-button> |
|
83 | 83 | class="preview-controls-rotate-left raw-hover-surface p-1" |
84 | 84 | appearance="raw" |
85 | 85 | :aria-label="imageRotateLeftDescription" |
86 | | - @click="$emit('setRotationLeft')" |
| 86 | + @click="emit('setRotationLeft')" |
87 | 87 | > |
88 | 88 | <oc-icon fill-type="line" name="anticlockwise" /> |
89 | 89 | </oc-button> |
|
92 | 92 | class="preview-controls-rotate-right raw-hover-surface p-1" |
93 | 93 | appearance="raw" |
94 | 94 | :aria-label="imageRotateRightDescription" |
95 | | - @click="$emit('setRotationRight')" |
| 95 | + @click="emit('setRotationRight')" |
96 | 96 | > |
97 | 97 | <oc-icon fill-type="line" name="clockwise" /> |
98 | 98 | </oc-button> |
|
103 | 103 | class="preview-controls-image-reset raw-hover-surface p-1" |
104 | 104 | appearance="raw" |
105 | 105 | :aria-label="imageResetDescription" |
106 | | - @click="$emit('resetImage')" |
| 106 | + @click="emit('resetImage')" |
107 | 107 | > |
108 | 108 | <oc-icon fill-type="line" name="reset-left" /> |
109 | 109 | </oc-button> |
110 | 110 | </div> |
111 | 111 | </div> |
| 112 | + <oc-button |
| 113 | + v-if="showFavoriteButton" |
| 114 | + v-oc-tooltip="resourceFavoriteIconDescription" |
| 115 | + class="preview-controls-favorite raw-hover-surface p-1" |
| 116 | + appearance="raw" |
| 117 | + :aria-label="resourceFavoriteIconDescription" |
| 118 | + @click="favoriteFileActions[0].handler({ space, resources: [files[activeIndex].resource] })" |
| 119 | + > |
| 120 | + <oc-icon fill-type="line" :name="resourceFavoriteIcon" /> |
| 121 | + </oc-button> |
112 | 122 | <oc-button |
113 | 123 | v-if="showDeleteButton" |
114 | 124 | v-oc-tooltip="resourceDeleteDescription" |
115 | 125 | class="preview-controls-delete raw-hover-surface p-1" |
116 | 126 | appearance="raw" |
117 | 127 | :aria-label="resourceDeleteDescription" |
118 | | - @click="$emit('deleteResource')" |
| 128 | + @click="emit('deleteResource')" |
119 | 129 | > |
120 | | - <oc-icon fill-type="line" name="delete-bin" /> |
| 130 | + <oc-icon fill-type="line" :name="resourceDeleteIcon" /> |
121 | 131 | </oc-button> |
122 | 132 | </div> |
123 | 133 | </div> |
124 | 134 | </template> |
125 | | -<script lang="ts"> |
126 | | -import { computed, defineComponent, PropType } from 'vue' |
| 135 | +<script setup lang="ts"> |
| 136 | +import { computed, unref } from 'vue' |
127 | 137 | import { useGettext } from 'vue3-gettext' |
128 | | -import { isMacOs } from '@opencloud-eu/web-pkg' |
| 138 | +import { |
| 139 | + ActionOptions, |
| 140 | + isMacOs, |
| 141 | + useFileActionsDelete, |
| 142 | + useFileActionsFavorite, |
| 143 | + useGetMatchingSpace |
| 144 | +} from '@opencloud-eu/web-pkg' |
129 | 145 | import { MediaFile } from '../helpers/types' |
130 | 146 |
|
131 | | -export default defineComponent({ |
132 | | - name: 'MediaControls', |
133 | | - props: { |
134 | | - files: { |
135 | | - type: Array as PropType<MediaFile[]>, |
136 | | - required: true |
137 | | - }, |
138 | | - activeIndex: { |
139 | | - type: Number, |
140 | | - default: 0 |
141 | | - }, |
142 | | - isFullScreenModeActivated: { |
143 | | - type: Boolean, |
144 | | - default: false |
145 | | - }, |
146 | | - isFolderLoading: { |
147 | | - type: Boolean, |
148 | | - default: false |
149 | | - }, |
150 | | - showImageControls: { |
151 | | - type: Boolean, |
152 | | - default: false |
153 | | - }, |
154 | | - showDeleteButton: { |
155 | | - type: Boolean, |
156 | | - default: true |
157 | | - }, |
158 | | - currentImageRotation: { |
159 | | - type: Number, |
160 | | - default: 0 |
161 | | - }, |
162 | | - photoRollEnabled: { |
163 | | - type: Boolean, |
164 | | - default: true |
165 | | - } |
166 | | - }, |
167 | | - emits: [ |
168 | | - 'setRotationLeft', |
169 | | - 'setRotationRight', |
170 | | - 'setShrink', |
171 | | - 'setZoom', |
172 | | - 'toggleFullScreen', |
173 | | - 'toggleNext', |
174 | | - 'togglePrevious', |
175 | | - 'resetImage', |
176 | | - 'deleteResource', |
177 | | - 'togglePhotoRoll' |
178 | | - ], |
179 | | - setup(props) { |
180 | | - const { $gettext } = useGettext() |
| 147 | +const { |
| 148 | + files, |
| 149 | + activeIndex = 0, |
| 150 | + photoRollEnabled = true, |
| 151 | + isFullScreenModeActivated = false, |
| 152 | + isFolderLoading = false, |
| 153 | + showImageControls = false, |
| 154 | + currentImageRotation = 0 |
| 155 | +} = defineProps<{ |
| 156 | + files: MediaFile[] |
| 157 | + activeIndex?: number |
| 158 | + isFullScreenModeActivated?: boolean |
| 159 | + isFolderLoading?: boolean |
| 160 | + showImageControls?: boolean |
| 161 | + currentImageRotation?: number |
| 162 | + photoRollEnabled?: boolean |
| 163 | +}>() |
| 164 | +
|
| 165 | +void currentImageRotation |
181 | 166 |
|
182 | | - const ariaHiddenFileCount = computed(() => { |
183 | | - return $gettext('%{ displayIndex } of %{ availableMediaFiles }', { |
184 | | - displayIndex: (props.activeIndex + 1).toString(), |
185 | | - availableMediaFiles: props.files.length.toString() |
186 | | - }) |
187 | | - }) |
188 | | - const screenreaderFileCount = computed(() => { |
189 | | - return $gettext('Media file %{ displayIndex } of %{ availableMediaFiles }', { |
190 | | - displayIndex: (props.activeIndex + 1).toString(), |
191 | | - availableMediaFiles: props.files.length.toString() |
192 | | - }) |
193 | | - }) |
| 167 | +const emit = defineEmits<{ |
| 168 | + (e: 'setRotationLeft'): void |
| 169 | + (e: 'setRotationRight'): void |
| 170 | + (e: 'setShrink'): void |
| 171 | + (e: 'setZoom'): void |
| 172 | + (e: 'toggleFullScreen'): void |
| 173 | + (e: 'toggleNext'): void |
| 174 | + (e: 'togglePrevious'): void |
| 175 | + (e: 'resetImage'): void |
| 176 | + (e: 'deleteResource'): void |
| 177 | + (e: 'togglePhotoRoll'): void |
| 178 | +}>() |
194 | 179 |
|
195 | | - const resourceDeleteDescription = computed(() => { |
196 | | - return $gettext('Delete (%{key})', { |
197 | | - key: isMacOs() ? $gettext('⌘ + Backspace') : $gettext('Del') |
198 | | - }) |
199 | | - }) |
| 180 | +const { $gettext } = useGettext() |
| 181 | +const { getMatchingSpace } = useGetMatchingSpace() |
| 182 | +const { actions: favoriteFileActions } = useFileActionsFavorite() |
| 183 | +const { actions: deleteFileActions } = useFileActionsDelete() |
200 | 184 |
|
201 | | - const togglePhotoRollDescription = computed(() => { |
202 | | - if (props.photoRollEnabled) { |
203 | | - return $gettext('Hide photo roll') |
204 | | - } |
205 | | - return $gettext('Show photo roll') |
206 | | - }) |
| 185 | +const space = computed(() => getMatchingSpace(files[activeIndex].resource)) |
207 | 186 |
|
208 | | - return { |
209 | | - screenreaderFileCount, |
210 | | - ariaHiddenFileCount, |
211 | | - resourceDeleteDescription, |
212 | | - togglePhotoRollDescription, |
213 | | - enterFullScreenDescription: $gettext('Enter full screen mode'), |
214 | | - exitFullScreenDescription: $gettext('Exit full screen mode'), |
215 | | - imageShrinkDescription: $gettext('Shrink the image (⇧ + Mouse wheel)'), |
216 | | - imageZoomDescription: $gettext('Enlarge the image (⇧ + Mouse wheel)'), |
217 | | - imageResetDescription: $gettext('Reset'), |
218 | | - imageRotateLeftDescription: $gettext('Rotate the image 90 degrees to the left'), |
219 | | - imageRotateRightDescription: $gettext('Rotate the image 90 degrees to the right'), |
220 | | - previousDescription: $gettext('Show previous media file in folder'), |
221 | | - nextDescription: $gettext('Show next media file in folder') |
222 | | - } |
| 187 | +const ariaHiddenFileCount = computed(() => { |
| 188 | + return $gettext('%{ displayIndex } of %{ availableMediaFiles }', { |
| 189 | + displayIndex: (activeIndex + 1).toString(), |
| 190 | + availableMediaFiles: files.length.toString() |
| 191 | + }) |
| 192 | +}) |
| 193 | +const screenreaderFileCount = computed(() => { |
| 194 | + return $gettext('Media file %{ displayIndex } of %{ availableMediaFiles }', { |
| 195 | + displayIndex: (activeIndex + 1).toString(), |
| 196 | + availableMediaFiles: files.length.toString() |
| 197 | + }) |
| 198 | +}) |
| 199 | +
|
| 200 | +const togglePhotoRollDescription = computed(() => { |
| 201 | + if (photoRollEnabled) { |
| 202 | + return $gettext('Hide photo roll') |
223 | 203 | } |
| 204 | + return $gettext('Show photo roll') |
224 | 205 | }) |
| 206 | +
|
| 207 | +const showDeleteButton = computed(() => { |
| 208 | + return unref(deleteFileActions)[0]?.isVisible({ |
| 209 | + space: unref(space), |
| 210 | + resources: [files[activeIndex].resource] |
| 211 | + }) |
| 212 | +}) |
| 213 | +
|
| 214 | +const showFavoriteButton = computed(() => { |
| 215 | + return unref(favoriteFileActions)[0]?.isVisible({ |
| 216 | + space: unref(space), |
| 217 | + resources: [files[activeIndex].resource] |
| 218 | + }) |
| 219 | +}) |
| 220 | +
|
| 221 | +const resourceDeleteIcon = computed(() => { |
| 222 | + return unref(deleteFileActions)[0].icon as string |
| 223 | +}) |
| 224 | +
|
| 225 | +const resourceDeleteDescription = computed(() => { |
| 226 | + return $gettext('Delete (%{key})', { |
| 227 | + key: isMacOs() ? $gettext('⌘ + Backspace') : $gettext('Del') |
| 228 | + }) |
| 229 | +}) |
| 230 | +
|
| 231 | +const resourceFavoriteIcon = computed(() => { |
| 232 | + return (unref(favoriteFileActions)[0].icon as (options: ActionOptions) => string)({ |
| 233 | + space: unref(space), |
| 234 | + resources: [files[activeIndex].resource] |
| 235 | + }) |
| 236 | +}) |
| 237 | +
|
| 238 | +const resourceFavoriteIconDescription = computed(() => { |
| 239 | + return unref(favoriteFileActions)[0].label({ |
| 240 | + space: unref(space), |
| 241 | + resources: [files[activeIndex].resource] |
| 242 | + }) |
| 243 | +}) |
| 244 | +
|
| 245 | +const enterFullScreenDescription = computed(() => $gettext('Enter full screen mode')) |
| 246 | +const exitFullScreenDescription = computed(() => $gettext('Exit full screen mode')) |
| 247 | +const imageShrinkDescription = computed(() => $gettext('Shrink the image (⇧ + Mouse wheel)')) |
| 248 | +const imageZoomDescription = computed(() => $gettext('Enlarge the image (⇧ + Mouse wheel)')) |
| 249 | +const imageResetDescription = computed(() => $gettext('Reset')) |
| 250 | +const imageRotateLeftDescription = computed(() => |
| 251 | + $gettext('Rotate the image 90 degrees to the left') |
| 252 | +) |
| 253 | +const imageRotateRightDescription = computed(() => |
| 254 | + $gettext('Rotate the image 90 degrees to the right') |
| 255 | +) |
| 256 | +const previousDescription = computed(() => $gettext('Show previous media file in folder')) |
| 257 | +const nextDescription = computed(() => $gettext('Show next media file in folder')) |
225 | 258 | </script> |
0 commit comments