-
-
Notifications
You must be signed in to change notification settings - Fork 622
Expand file tree
/
Copy pathGrid.vue
More file actions
261 lines (249 loc) · 11.2 KB
/
Grid.vue
File metadata and controls
261 lines (249 loc) · 11.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
<template>
<ui-card class="asset-browser-grid" :class="{
'space-y-8': folders.length || assets.length || creatingFolder,
'!p-0': folders.length === 0 && assets.length === 0 && !creatingFolder
}">
<!-- Folders -->
<section class="folder-grid-listing" v-if="folders.length || creatingFolder">
<div
v-if="!restrictFolderNavigation"
v-for="folder in folders"
:key="folder.path"
class="group/folder relative p-1"
:class="{ 'rounded-xl ring-2 ring-blue-400': dragOverFolder === folder.path }"
:draggable="true"
@dragover.prevent="dragOverFolder = folder.path"
@dragleave.prevent="dragOverFolder = null"
@drop="
handleFolderDrop(folder);
dragOverFolder = null;
"
@dragstart="draggingFolder = folder.path"
@dragend="
draggingFolder = null;
dragOverFolder = null;
"
>
<ItemActions
:url="folderActionUrl"
:actions="folderActions(folder)"
:item="folder.path"
@started="actionStarted"
@completed="actionCompleted"
v-slot="{ actions }"
>
<Context>
<template #trigger>
<button @click="selectFolder(folder.path)" class="group h-[66px] w-[80px]">
<FolderSvg class="size-full text-blue-400/90 hover:text-blue-400" />
<div
class="overflow-hidden mt-2 text-center text-xs text-ellipsis whitespace-nowrap text-gray-500 dark:text-gray-300"
v-text="folder.basename"
:title="folder.basename"
/>
</button>
</template>
<ContextMenu>
<ContextItem
v-for="action in actions"
:key="action.handle"
:text="__(action.title)"
:icon="action.icon"
:variant="action.dangerous ? 'destructive' : 'default'"
@click="action.run"
/>
</ContextMenu>
</Context>
</ItemActions>
</div>
<div v-if="creatingFolder" class="group/folder relative p-1">
<div class="group h-[66px] w-[80px]">
<FolderSvg class="size-full text-blue-400/90 hover:text-blue-400" />
<Editable
ref="newFolderInput"
v-model:modelValue="newFolderName"
:start-with-edit-mode="true"
submit-mode="enter"
:placeholder="__('Name')"
:class="[
'flex w-[80px] items-center placeholder:lowercase justify-center overflow-hidden mt-2 text-center text-xs text-ellipsis whitespace-nowrap placeholder:text-gray-400 dark:placeholder:text-gray-500 text-gray-500',
{ 'st-has-error': creatingFolderError }
]"
@submit="$emit('create-folder', newFolderName)"
@cancel="
() => {
newFolderName = null;
$emit('cancel-creating-folder');
}
"
/>
</div>
</div>
</section>
<!-- Assets -->
<section class="asset-grid-listing" v-if="assets.length" :style="{ gridTemplateColumns: gridSize }">
<div
v-for="(asset, index) in assets"
:key="asset.id"
class="group relative"
:class="{ selected: isSelected(asset.id) }"
>
<ItemActions
:url="actionUrl"
:actions="asset.actions"
:item="asset.id"
@started="actionStarted"
@completed="actionCompleted"
v-slot="{ actions }"
>
<Context>
<template #trigger>
<div
class="asset-tile group relative bg-white dark:bg-gray-900"
:class="[
{ 'opacity-50!': draggingAsset === asset.id },
asset.can_be_transparent && showCheckerboard ? `bg-checkerboard bg-checkerboard-${checkerboardMode}` : '',
asset.can_be_transparent && !showCheckerboard ? 'bg-checkerboard before:opacity-0 hover:before:opacity-100' : '',
]"
>
<button
class="size-full"
:draggable="true"
@dragover.prevent
@dragstart="draggingAsset = asset.id"
@dragend="draggingAsset = null"
@click.stop="selectionClicked(index, $event)"
@dblclick.stop="$emit('edit-asset', asset)"
>
<div class="relative flex aspect-square size-full items-center justify-center" :class="{ 'cursor-pointer': maxFiles === 1 }">
<div class="asset-thumb">
<img
v-if="asset.thumbnail"
:src="asset.thumbnail"
loading="lazy"
:draggable="false"
:class="{
'w-full p-4': asset.extension === 'svg',
'rounded-lg p-1': asset.orientation === 'square',
}"
/>
<file-icon v-else :extension="asset.extension" class="size-1/2" />
</div>
</div>
</button>
<div class="absolute end-1 top-1 opacity-0 group-hover:opacity-100 group-focus-within:opacity-100 transition-opacity [&_button]:bg-white [&_button]:hover:bg-white [&_button]:dark:bg-gray-900 [&_button]:dark:hover:bg-gray-900">
<Dropdown placement="left-start">
<DropdownMenu>
<DropdownItem
:text="__(asset.editable ? 'Edit' : 'View')"
@click="edit(asset.id)"
icon="edit"
/>
<DropdownSeparator v-if="asset.actions.length" />
<DropdownItem
v-for="action in actions"
:key="action.handle"
:text="__(action.title)"
:icon="action.icon"
:variant="action.dangerous ? 'destructive' : 'default'"
@click="action.run"
/>
</DropdownMenu>
</Dropdown>
</div>
</div>
</template>
<ContextMenu>
<ContextItem icon="edit" :text="__(asset.editable ? 'Edit' : 'View')" @click="edit(asset.id)" />
<ContextSeparator />
<ContextItem
v-for="action in actions"
:key="action.handle"
:text="__(action.title)"
:icon="action.icon"
:variant="action.dangerous ? 'destructive' : 'default'"
@click="action.run"
/>
</ContextMenu>
</Context>
</ItemActions>
<div class="asset-filename">
<MiddleEllipsis :text="asset.basename" />
</div>
</div>
</section>
<!-- Empty state -->
<div v-if="folders.length === 0 && assets.length === 0 && !creatingFolder" class="text-center text-gray-500 text-sm py-4">
{{ __('No items found') }}
</div>
</ui-card>
</template>
<script>
import AssetBrowserMixin from './AssetBrowserMixin';
import Breadcrumbs from './Breadcrumbs.vue';
import {
Context,
ContextMenu,
ContextItem,
ContextLabel,
ContextSeparator,
Editable,
Dropdown,
DropdownMenu,
DropdownLabel,
DropdownItem,
DropdownSeparator,
MiddleEllipsis
} from '@ui';
import { injectListingContext } from '@/components/ui/Listing/Listing.vue';
import ItemActions from '@/components/actions/ItemActions.vue';
import FolderSvg from '@/../svg/folder.svg';
export default {
mixins: [AssetBrowserMixin],
components: {
Breadcrumbs,
ContextItem,
ContextLabel,
ContextMenu,
ContextSeparator,
Context,
Editable,
Dropdown,
DropdownMenu,
DropdownLabel,
DropdownItem,
DropdownSeparator,
ItemActions,
FolderSvg,
MiddleEllipsis,
},
props: {
assets: { type: Array },
selectedAssets: { type: Array },
thumbnailSize: { type: Number },
maxFiles: { type: Number },
showCheckerboard: { type: Boolean, default: false },
checkerboardMode: { type: String, default: 'transparent' },
},
data() {
return {
dragOverFolder: null,
shifting: false,
};
},
computed: {
gridSize() {
return `repeat(auto-fill, minmax(${this.thumbnailSize}px, 1fr))`;
},
},
setup() {
const { selectionClicked } = injectListingContext();
return { selectionClicked };
},
methods: {
isSelected(id) {
return this.selectedAssets.includes(id);
},
},
};
</script>