Skip to content

Commit ed9a093

Browse files
committed
refactor(desk)!: remake i-value components
1 parent 168d703 commit ed9a093

File tree

28 files changed

+916
-461
lines changed

28 files changed

+916
-461
lines changed

packages/core/entities/view-common.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,15 @@ export interface ViewOrder {
2121

2222
export default class ViewCommon extends View {
2323
public search = ''
24+
public limit?: number
2425
public filters: ViewFilter[] = []
2526
public columns: ViewColumn[] = []
2627
public orderBy: ViewOrder[] = []
2728

2829
constructor(props?: Partial<ViewCommon>, id?: string) {
2930
super(props, id)
3031

32+
this.limit = props?.limit
3133
this.search = props?.search || ''
3234
this.filters = props?.filters || []
3335
this.columns = props?.columns || []

packages/core/repositories/item/implementations/entry-item-repository.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@ export default class EntryItemRepository implements IItemRepository {
4040
.map((id) => {
4141
const meta = metas.find((i) => i.id === id)
4242

43-
return new Item(meta, id)
43+
const item = new Item(meta, id)
44+
45+
item._path = DirectoryEntry.normalize(this.collection.path, id)
46+
47+
return item
4448
})
4549
}
4650

packages/desktop/components/v-btn.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ const variations = {
5656
'danger': 'bg-danger hover:bg-danger/75 text-t-primary',
5757
'info': 'bg-info hover:bg-info/75 text-t-primary',
5858
'warn': 'bg-warn hover:bg-warn/75 text-t-primary',
59-
'b-secondary': 'bg-b-secondary hover:bg-b-secondary/75 text-t-primary',
59+
'b-secondary': 'bg-b-secondary text-t-secondary hover:text-t-primary',
6060
},
6161
text: {
6262
'accent':

packages/desktop/components/v-select.vue

Lines changed: 29 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,16 @@ export default { inheritAttrs: false }
33
</script>
44
<script setup lang="ts">
55
import { createBindings } from '@/composables/binding'
6-
import { computed, ref, useAttrs } from 'vue'
6+
import { computed, ref, useAttrs, PropType } from 'vue'
77
import { useVModel } from 'vue-wind/composables/v-model'
88
99
// Props & Emits
1010
1111
const props = defineProps({
1212
modelValue: {
13-
type: [String, Number, Object, Boolean],
13+
type: [String, Number, Object, Boolean] as PropType<any>,
1414
default: '',
1515
},
16-
label: {
17-
type: String,
18-
default: '',
19-
},
20-
size: {
21-
type: String,
22-
default: 'md',
23-
},
24-
color: {
25-
type: String,
26-
default: 'accent',
27-
},
28-
flat: {
29-
type: Boolean,
30-
default: false,
31-
},
3216
readonly: {
3317
type: Boolean,
3418
default: false,
@@ -53,6 +37,10 @@ const props = defineProps({
5337
type: Boolean,
5438
default: false,
5539
},
40+
clearValue: {
41+
type: [Function] as PropType<() => any>,
42+
default: () => () => undefined,
43+
},
5644
})
5745
5846
const emit = defineEmits(['update:modelValue'])
@@ -96,7 +84,7 @@ function getLabel(option: any) {
9684
9785
// display label
9886
99-
const displayLabel = computed(() => {
87+
const displayValue = computed(() => {
10088
let label: any = model.value
10189
10290
if (!label) {
@@ -131,26 +119,32 @@ function onShowMenu(value: boolean) {
131119
@update:model-value="onShowMenu"
132120
>
133121
<template #activator="{ attrs, toggle }">
134-
<v-input
135-
v-bind="{ ...attrs, ...bindings.root }"
136-
:model-value="displayLabel"
137-
:label="label"
138-
:color="color"
139-
:flat="flat"
140-
:size="size"
141-
class="cursor-pointer"
142-
input:class="cursor-pointer"
143-
readonly
144-
@keydown.enter="toggle"
145-
@keydown.esc="menu = false"
122+
<slot
123+
name="selection"
124+
:attrs="{ ...attrs, ...bindings.root }"
125+
:display-value="displayValue"
146126
>
147-
<template v-if="!noChevron" #append>
148-
<v-icon name="chevron-down" class="ml-auto text-t-secondary" />
149-
</template>
150-
</v-input>
127+
<v-input
128+
v-bind="{ ...attrs, ...bindings.root }"
129+
:model-value="displayValue"
130+
class="cursor-pointer"
131+
input:class="cursor-pointer"
132+
readonly
133+
@keydown.enter="toggle"
134+
@keydown.esc="menu = false"
135+
>
136+
<template v-if="!noChevron" #append>
137+
<v-icon name="chevron-down" class="ml-auto text-t-secondary" />
138+
</template>
139+
</v-input>
140+
</slot>
151141
</template>
152142

153143
<v-card color="b-secondary" v-bind="bindings.card">
144+
<v-list-item class="border-b border-lines" @click="model = clearValue()">
145+
{{ $t('clear') }}
146+
</v-list-item>
147+
154148
<template v-for="option in options" :key="option">
155149
<slot name="option" :option="option">
156150
<v-list-item dark @click="onSelect(option)">

packages/desktop/components/v-tr.vue

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,28 @@
1+
<script setup lang="ts">
2+
import { toCssMeasurement } from '@/composables/utils'
3+
import { computed } from 'vue'
4+
5+
const props = defineProps({
6+
height: {
7+
type: [String, Number],
8+
default: null,
9+
},
10+
})
11+
12+
// style
13+
14+
const style = computed(() => {
15+
const result: any = {}
16+
17+
if (props.height) {
18+
result.height = toCssMeasurement(props.height)
19+
}
20+
21+
return result
22+
})
23+
</script>
124
<template>
2-
<tr>
25+
<tr :style="style">
326
<slot></slot>
427
</tr>
528
</template>
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { open } from '@tauri-apps/api/shell'
2+
13
export function openURL(url: string) {
2-
return (window as any).openURL(url)
4+
return open(url)
35
}

packages/desktop/i18n/en-US.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ export default {
8686
date: 'Date',
8787
displayFormat: 'Display format',
8888
saveFormat: 'Save format',
89+
limit: 'Limit',
8990
errors: {
9091
unknown: 'Unknown error',
9192
workspaceNotFound: '@:workspace not found: {0}',

packages/desktop/modules/collection-column/composables/with-view.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,22 @@ import Column from '@core/entities/column'
66
export function withView<T = ViewColumn>(columns: Column[], viewColumns: ViewColumn[] = []) {
77
const result: any[] = useNonReactive(columns)
88

9-
result.forEach((c) => {
9+
for (const c of result) {
1010
const vColumn = viewColumns.find((vc) => vc.id === c.id)
1111

1212
if (vColumn) {
1313
Object.assign(c, useNonReactive(vColumn))
1414
}
15-
})
15+
}
1616

17-
result.sort((a, b) => {
18-
const aIndex = viewColumns.findIndex((s) => s.id === a.id)
19-
const bIndex = viewColumns.findIndex((s) => s.id === b.id)
17+
// result.sort((a, b) => {
18+
// const aIndex = viewColumns.findIndex((s) => s.id === a.id)
19+
// const bIndex = viewColumns.findIndex((s) => s.id === b.id)
2020

21-
if (aIndex === -1 || bIndex === -1) return 0
21+
// if (aIndex === -1 || bIndex === -1) return 0
2222

23-
return aIndex - bIndex
24-
})
23+
// return aIndex - bIndex
24+
// })
2525

2626
return result as (Column & T)[]
2727
}

packages/desktop/modules/collection-column/store.ts

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,8 @@ interface StoreItem {
1818
export const useStore = defineStore('column', () => {
1919
const items = ref<StoreItem[]>([])
2020

21-
const stores = {
22-
workspace: useWorkspace(),
23-
collection: useCollection(),
24-
}
21+
const workspace = useWorkspace()
22+
const collection = useCollection()
2523

2624
async function set(collectionId: string, forceUpdate = false) {
2725
let item = items.value.find((i) => i.collectionId === collectionId)
@@ -44,13 +42,13 @@ export const useStore = defineStore('column', () => {
4442

4543
item.loading = true
4644

47-
await stores.collection.setCollections()
45+
await collection.setCollections()
4846

49-
const collection = stores.collection.collections.find((c) => c.id === collectionId)
47+
const data = collection.collections.find((c) => c.id === collectionId)
5048

51-
if (!collection) return
49+
if (!data) return
5250

53-
item.columns = useNonReactive(collection.columns)
51+
item.columns = useNonReactive(data.columns)
5452

5553
setTimeout(() => {
5654
const index = items.value.findIndex((i) => i.collectionId === collectionId)
@@ -87,6 +85,20 @@ export const useStore = defineStore('column', () => {
8785
return null
8886
}
8987

88+
async function show(collectionId: string, columnId: string): Promise<Column | null> {
89+
if (!collection.collections.length) {
90+
await collection.setCollections()
91+
}
92+
93+
const search = collection.collections.find((c) => c.id === collectionId)
94+
95+
if (!search) return null
96+
97+
const column = search.columns.find((c) => c.id === columnId)
98+
99+
return column ? useNonReactive(column) : null
100+
}
101+
90102
function isLoading(collectionId: string) {
91103
const item = items.value.find((i) => i.collectionId === collectionId)
92104

@@ -98,7 +110,7 @@ export const useStore = defineStore('column', () => {
98110
async function create(collectionId: string) {
99111
const item = items.value.find((i) => i.collectionId === collectionId)
100112

101-
await stores.collection.setCollections()
113+
await collection.setCollections()
102114

103115
if (!item) return
104116

@@ -108,14 +120,14 @@ export const useStore = defineStore('column', () => {
108120
async function save(collectionId: string) {
109121
const item = items.value.find((i) => i.collectionId === collectionId)
110122

111-
await stores.collection.setCollections()
123+
await collection.setCollections()
112124

113-
const collection = stores.collection.collections.find((c) => c.id === collectionId)
125+
const data = collection.collections.find((c) => c.id === collectionId)
114126

115-
if (!item || !collection) return
127+
if (!item || !data) return
116128

117-
await stores.collection.update({
118-
workspaceId: stores.workspace.currentId!,
129+
await collection.update({
130+
workspaceId: workspace.currentId!,
119131
collectionId,
120132
data: {
121133
columns: item.columns,
@@ -138,6 +150,7 @@ export const useStore = defineStore('column', () => {
138150
return {
139151
all,
140152
get,
153+
show,
141154
set,
142155
isLoading,
143156
create,

packages/desktop/modules/collection/components/CActions.vue

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { useStore } from '@/store/global'
99
import CDrawerFilter from './CDrawerFilter.vue'
1010
import CDrawerHideColumns from './CDrawerHideColumns.vue'
1111
import CActionsOrder from './CActionsOrder.vue'
12+
import View from '@/../core/entities/view'
1213
1314
// Props & emit
1415
const props = defineProps({
@@ -58,6 +59,14 @@ async function refresh() {
5859
5960
await store.column.set(props.collectionId, true)
6061
}
62+
63+
function isCommon(v: View): v is ViewCommon {
64+
return ['table', 'gallery'].includes(v.component)
65+
}
66+
67+
function isGallery(v: View): v is ViewGallery {
68+
return v.component === 'gallery'
69+
}
6170
</script>
6271
<template>
6372
<v-card-head :class="register?.loading ? 'border-b-accent' : ''">
@@ -66,7 +75,7 @@ async function refresh() {
6675
<div class="grow"></div>
6776

6877
<template v-if="view">
69-
<template v-if="view instanceof ViewCommon">
78+
<template v-if="isCommon(view)">
7079
<div class="flex items-center transition-all">
7180
<transition name="slide-left">
7281
<v-input
@@ -118,8 +127,9 @@ async function refresh() {
118127
<v-card color="b-secondary" width="300">
119128
<v-card-content class="flex flex-wrap gap-y-4">
120129
<v-input v-model="view.label" :label="$t('label')" />
130+
<v-input v-model="view.limit" type="number" :label="$t('limit')" />
121131

122-
<template v-if="view instanceof ViewGallery">
132+
<template v-if="isGallery(view)">
123133
<v-select
124134
v-model="view.thumbnail.key"
125135
:options="columns"

0 commit comments

Comments
 (0)