-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathFilePickerBreadcrumbs.vue
More file actions
139 lines (126 loc) · 3.44 KB
/
FilePickerBreadcrumbs.vue
File metadata and controls
139 lines (126 loc) · 3.44 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
<!--
- SPDX-FileCopyrightText: 2023-2024 Nextcloud GmbH and Nextcloud contributors
- SPDX-License-Identifier: AGPL-3.0-or-later
-->
<template>
<NcBreadcrumbs class="file-picker__breadcrumbs">
<template #default>
<NcBreadcrumb :name="t('All files')"
:title="t('Home')"
@click="emit('update:path', '/')">
<template #icon>
<IconHome :size="20" />
</template>
</NcBreadcrumb>
<NcBreadcrumb v-for="dir in pathElements"
:key="dir.path"
:name="dir.name"
:title="dir.path"
@click="emit('update:path', dir.path)" />
</template>
<template v-if="showMenu" #actions>
<NcActions v-model:open="actionsOpen"
:aria-label="t('Create directory')"
:force-menu="true"
:force-name="true"
:menu-name="t('New')"
type="secondary"
@close="newNodeName = ''">
<template #icon>
<IconPlus :size="20" />
</template>
<NcActionInput ref="nameInput"
v-model:value="newNodeName"
:label="t('New folder')"
:placeholder="t('New folder name')"
@submit="onSubmit"
@input="validateInput">
<template #icon>
<IconFolder :size="20" />
</template>
</NcActionInput>
</NcActions>
</template>
</NcBreadcrumbs>
</template>
<script setup lang="ts">
import type Vue from 'vue'
import IconFolder from 'vue-material-design-icons/Folder.vue'
import IconHome from 'vue-material-design-icons/Home.vue'
import IconPlus from 'vue-material-design-icons/Plus.vue'
import { NcActions, NcActionInput, NcBreadcrumbs, NcBreadcrumb } from '@nextcloud/vue'
import { computed, ref } from 'vue'
import { t } from '../../utils/l10n'
const props = defineProps<{
/** Current path to display */
path: string
/** Whether to show the "new node" menu or not */
showMenu: boolean
}>()
const emit = defineEmits<{
/**
* Triggered when the path was changed by using the breadcrumbs
*/
(e: 'update:path', path: string): void
/**
* Triggered when a new directory on the current path should be created
*/
(e: 'create-node', name: string): void
}>()
const actionsOpen = ref(false)
/**
* Input on the "new node" menu
*/
const newNodeName = ref('')
const nameInput = ref<Vue>()
/**
* Validate user folder name input
*/
function validateInput() {
const name = newNodeName.value.trim()
const input = nameInput.value?.$el?.querySelector('input')
let validity = ''
if (name.length === 0) {
validity = t('Folder name cannot be empty.')
} else if (name.includes('/')) {
validity = t('"/" is not allowed inside a folder name.')
} else if (['..', '.'].includes(name)) {
validity = t('"{name}" is an invalid folder name.', { name })
} else if (window.OC.config?.blacklist_files_regex && name.match(window.OC.config?.blacklist_files_regex)) {
validity = t('"{name}" is not an allowed folder name', { name })
}
if (input) {
input.setCustomValidity(validity)
}
return validity === ''
}
/**
* Handle creating a new node
*/
const onSubmit = function() {
const name = newNodeName.value.trim()
if (validateInput()) {
actionsOpen.value = false
emit('create-node', name)
newNodeName.value = ''
}
}
/**
* Split current path and provide the path and the basename
*/
const pathElements = computed(() => props.path.split('/')
.filter((v) => v !== '')
.map((v, i, elements) => ({
name: v,
path: '/' + elements.slice(0, i + 1).join('/'),
})),
)
</script>
<style scoped lang="scss">
.file-picker {
&__breadcrumbs {
// ensure the breadcrumbs have a static height
flex-grow: 0 !important;
}
}
</style>