移植 Axolotl 的拖拽式实例分组界面到 Starlight,接入阶段1的规范化分组后端: - 新增 helpers/analytics.ts(trackEvent 遥测桩) - 补全 helpers/instance-groups.ts(6 个 invoke 包装) - 新增 composables/useInstanceGroups.ts(分组状态 + 事件监听) - 升级 composables/useGridGrouping.ts(排序方向 isSortAscending/toggleSortDirection) - helpers/events.js 补 instance_groups_listener(对接 instance_groups_changed 事件) - 新增 components/ui/library/DraggableInstanceCard.vue - 新增 components/ui/library/InstanceGroup.vue(并补 group-drag-handle 修复组拖拽重排) - 新增 components/ui/modal/InstanceGroupModal.vue - GridDisplay.vue 替换为 Axolotl 拖拽版(DragDropProvider + vuedraggable) - 补 en-US/zh-CN i18n 键各 39 条
This commit is contained in:
1 parent
253141b6ff
commit
f253d5529b
11 files changed
+2153
-236
No files matched your search
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,92 @@
|
||||
<script setup lang="ts">
|
||||
import { KeyboardSensor, PointerSensor, useDraggable } from '@dnd-kit/vue'
|
||||
import { useEventListener } from '@vueuse/core'
|
||||
import { computed, ref } from 'vue'
|
||||
|
||||
import type { GameInstance } from '@/helpers/types'
|
||||
|
||||
const props = defineProps<{
|
||||
instance: GameInstance
|
||||
instanceGroupId: string
|
||||
disabled: boolean
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'contextmenu' | 'card-click', event: MouseEvent): void
|
||||
(e: 'start-long-press' | 'cancel-long-press'): void
|
||||
}>()
|
||||
|
||||
const cardElement = ref<HTMLElement>()
|
||||
|
||||
const instanceCardSensors = [
|
||||
PointerSensor.configure({
|
||||
preventActivation: () => false,
|
||||
}),
|
||||
KeyboardSensor,
|
||||
]
|
||||
|
||||
const dragDisabled = computed(() => props.disabled)
|
||||
|
||||
const { isDragging } = useDraggable({
|
||||
id: computed(() => `instance:${props.instanceGroupId}:${props.instance.id}`),
|
||||
element: cardElement,
|
||||
disabled: dragDisabled,
|
||||
sensors: instanceCardSensors,
|
||||
data: computed(() => ({
|
||||
instanceId: props.instance.id,
|
||||
fromGroup: props.instanceGroupId,
|
||||
})),
|
||||
})
|
||||
|
||||
let wantsClick = false
|
||||
|
||||
useEventListener(window, 'pointerdown', () => {
|
||||
wantsClick = true
|
||||
})
|
||||
useEventListener(window, 'pointerup', () => {
|
||||
if (isDragging.value) {
|
||||
wantsClick = false
|
||||
}
|
||||
})
|
||||
useEventListener(window, 'blur', () => {
|
||||
wantsClick = false
|
||||
})
|
||||
|
||||
function onCardClick(event: MouseEvent) {
|
||||
if (!wantsClick || isDragging.value) return
|
||||
wantsClick = false
|
||||
emit('card-click', event)
|
||||
}
|
||||
|
||||
function onContextMenu(event: MouseEvent) {
|
||||
emit('contextmenu', event)
|
||||
}
|
||||
|
||||
function onMouseDown() {
|
||||
if (!dragDisabled.value) {
|
||||
emit('start-long-press')
|
||||
}
|
||||
}
|
||||
|
||||
function onMouseUp() {
|
||||
emit('cancel-long-press')
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div
|
||||
ref="cardElement"
|
||||
class="group relative min-w-0 w-full"
|
||||
@click="onCardClick"
|
||||
@mousedown="onMouseDown"
|
||||
@mouseup="onMouseUp"
|
||||
@mouseleave="onMouseUp"
|
||||
@touchstart="!dragDisabled && onMouseDown()"
|
||||
@touchend="onMouseUp"
|
||||
@touchcancel="onMouseUp"
|
||||
@contextmenu.prevent.stop="onContextMenu"
|
||||
>
|
||||
<slot :is-dragging="isDragging" />
|
||||
<slot v-if="!isDragging" name="overlay" />
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,521 @@
|
||||
<script setup lang="ts">
|
||||
import { useDroppable } from '@dnd-kit/vue'
|
||||
import {
|
||||
ArrowDownIcon,
|
||||
ArrowUpIcon,
|
||||
DropdownIcon,
|
||||
EditIcon,
|
||||
PlusIcon,
|
||||
TrashIcon,
|
||||
XIcon,
|
||||
} from '@modrinth/assets'
|
||||
import {
|
||||
Button,
|
||||
Checkbox,
|
||||
commonMessages,
|
||||
defineMessages,
|
||||
IconButton,
|
||||
InlineEditableText,
|
||||
NewModal,
|
||||
TagItem,
|
||||
useVIntl,
|
||||
} from '@modrinth/ui'
|
||||
import { computed, nextTick, ref, watch } from 'vue'
|
||||
|
||||
import ContextMenu from '@/components/ui/ContextMenu.vue'
|
||||
import Instance from '@/components/ui/Instance.vue'
|
||||
import DraggableInstanceCard from '@/components/ui/library/DraggableInstanceCard.vue'
|
||||
import { UNGROUPED_GROUP_KEY } from '@/composables/useGridGrouping'
|
||||
import { FAVORITES_GROUP_ID } from '@/composables/useInstanceGroups'
|
||||
import type { GameInstance } from '@/helpers/types'
|
||||
|
||||
const MAX_GROUP_NAME_LENGTH = 256
|
||||
|
||||
const { formatMessage } = useVIntl()
|
||||
|
||||
const messages = defineMessages({
|
||||
ungrouped: { id: 'app.instances.group.ungrouped', defaultMessage: 'No group' },
|
||||
pinned: { id: 'app.instances.group.pinned', defaultMessage: 'Pinned' },
|
||||
emptyGroup: {
|
||||
id: 'app.instances.group.empty',
|
||||
defaultMessage: 'Drag and drop to add instances.',
|
||||
},
|
||||
editGroupName: {
|
||||
id: 'app.instances.group.edit-name',
|
||||
defaultMessage: 'Edit group name',
|
||||
},
|
||||
deleteGroup: {
|
||||
id: 'app.instances.group.delete-group',
|
||||
defaultMessage: 'Delete group',
|
||||
},
|
||||
deleteGroupDescription: {
|
||||
id: 'app.instances.group.delete-description',
|
||||
defaultMessage: 'Instances in this group will be ungrouped.',
|
||||
},
|
||||
moveGroupUp: {
|
||||
id: 'app.instances.group.move-up',
|
||||
defaultMessage: 'Move group up',
|
||||
},
|
||||
moveGroupDown: {
|
||||
id: 'app.instances.group.move-down',
|
||||
defaultMessage: 'Move group down',
|
||||
},
|
||||
addToGroup: {
|
||||
id: 'app.instances.group.add-to-group',
|
||||
defaultMessage: 'Add to group',
|
||||
},
|
||||
newInstance: {
|
||||
id: 'app.instances.group.new-instance',
|
||||
defaultMessage: 'New instance',
|
||||
},
|
||||
collapseGroup: {
|
||||
id: 'app.instances.group.collapse',
|
||||
defaultMessage: 'Collapse group',
|
||||
},
|
||||
expandGroup: {
|
||||
id: 'app.instances.group.expand',
|
||||
defaultMessage: 'Expand group',
|
||||
},
|
||||
renameGroup: {
|
||||
id: 'app.instances.group.rename-group',
|
||||
defaultMessage: 'Rename group',
|
||||
},
|
||||
groupNameEmpty: {
|
||||
id: 'app.instances.group.name-empty',
|
||||
defaultMessage: 'Group names cannot be empty.',
|
||||
},
|
||||
groupNameTooLong: {
|
||||
id: 'app.instances.group.name-too-long',
|
||||
defaultMessage: 'Group names cannot be longer than {maxLength} characters.',
|
||||
},
|
||||
})
|
||||
|
||||
const props = defineProps<{
|
||||
sectionKey: string
|
||||
groupName?: string
|
||||
instances: GameInstance[]
|
||||
grouping: string
|
||||
isCollapsed: boolean
|
||||
displayMode: string
|
||||
selectMode: boolean
|
||||
selectedInstanceIds: Set<string>
|
||||
isSortAscending?: boolean
|
||||
hideHeader?: boolean
|
||||
canMoveUp?: boolean
|
||||
canMoveDown?: boolean
|
||||
groupPendingNameEdit?: string | null
|
||||
}>()
|
||||
|
||||
// Events are grouped only where the payload shapes genuinely match; the
|
||||
// per-event names are documentation, not part of the type.
|
||||
const emit = defineEmits<{
|
||||
(e: 'toggleCollapse' | 'deleteGroup' | 'addToGroup' | 'startLongPress', id: string): void
|
||||
(e: 'handleCheckboxClick' | 'handleCardClick', instanceId: string, event: MouseEvent): void
|
||||
(e: 'handleContextMenu', event: MouseEvent, instanceId: string, sectionKey: string): void
|
||||
(e: 'renameGroup', oldKey: string, newKey: string): void
|
||||
(e: 'cancelLongPress' | 'newInstance' | 'renameComplete'): void
|
||||
(e: 'moveGroup', groupKey: string, direction: -1 | 1): void
|
||||
}>()
|
||||
|
||||
const groupOptions = ref<InstanceType<typeof ContextMenu>>()
|
||||
const groupContainerRef = ref<HTMLElement>()
|
||||
const groupNameInput = ref<InstanceType<typeof InlineEditableText>>()
|
||||
const deletingGroup = ref(false)
|
||||
const confirmDeleteGroupModal = ref<InstanceType<typeof NewModal>>()
|
||||
const groupName = ref(props.groupName ?? props.sectionKey)
|
||||
|
||||
const isUngrouped = computed(() => props.sectionKey === UNGROUPED_GROUP_KEY)
|
||||
const isFavorites = computed(() => props.sectionKey === FAVORITES_GROUP_ID)
|
||||
const isCustomGroup = computed(
|
||||
() => props.grouping === 'Group' && !isUngrouped.value && !isFavorites.value,
|
||||
)
|
||||
const isGroupDragActive = computed(() => props.grouping === 'Group')
|
||||
const effectiveCollapsed = computed(() => (props.hideHeader ? false : props.isCollapsed))
|
||||
|
||||
const { isDropTarget } = useDroppable({
|
||||
id: computed(() => `instance-group:${props.sectionKey}`),
|
||||
element: groupContainerRef,
|
||||
disabled: computed(() => props.hideHeader || !isGroupDragActive.value),
|
||||
data: computed(() => ({
|
||||
groupId: props.sectionKey,
|
||||
})),
|
||||
})
|
||||
|
||||
watch(
|
||||
() => [props.sectionKey, props.groupName],
|
||||
() => {
|
||||
groupName.value = props.groupName ?? props.sectionKey
|
||||
},
|
||||
)
|
||||
|
||||
watch(
|
||||
() => props.groupPendingNameEdit,
|
||||
async (pendingId) => {
|
||||
if (pendingId !== props.sectionKey) return
|
||||
|
||||
await nextTick()
|
||||
groupContainerRef.value?.scrollIntoView({ block: 'nearest' })
|
||||
await groupNameInput.value?.startEditing()
|
||||
emit('renameComplete')
|
||||
},
|
||||
{ immediate: true, flush: 'post' },
|
||||
)
|
||||
|
||||
function validateGroupName(value: string) {
|
||||
const normalized = value.trim()
|
||||
if (normalized.length === 0) return false
|
||||
if (normalized.length > MAX_GROUP_NAME_LENGTH) return false
|
||||
return true
|
||||
}
|
||||
|
||||
async function updateGroupName(value: string) {
|
||||
const newName = value.trim()
|
||||
if (!newName || newName === groupName.value) return false
|
||||
emit('renameGroup', props.sectionKey, newName)
|
||||
return true
|
||||
}
|
||||
|
||||
function openGroupContextMenu(event: MouseEvent) {
|
||||
groupOptions.value?.showMenu(
|
||||
event,
|
||||
props.sectionKey,
|
||||
isCustomGroup.value
|
||||
? [
|
||||
{ name: 'new_instance' },
|
||||
{ name: 'add_instances' },
|
||||
{ name: 'edit_name' },
|
||||
{ type: 'divider' },
|
||||
{ name: 'delete_group', color: 'danger' },
|
||||
]
|
||||
: [{ name: 'new_instance' }],
|
||||
)
|
||||
}
|
||||
|
||||
async function handleGroupOption({ option }: { option: string }) {
|
||||
if (option === 'new_instance') {
|
||||
emit('newInstance')
|
||||
} else if (option === 'add_instances') {
|
||||
emit('addToGroup', props.sectionKey)
|
||||
} else if (option === 'edit_name') {
|
||||
groupNameInput.value?.startEditing()
|
||||
} else if (option === 'delete_group') {
|
||||
requestGroupDeletion()
|
||||
}
|
||||
}
|
||||
|
||||
function requestGroupDeletion() {
|
||||
if (isUngrouped.value || isFavorites.value) return
|
||||
|
||||
if (props.instances.length > 0) {
|
||||
confirmDeleteGroupModal.value?.show()
|
||||
} else {
|
||||
void removeGroup()
|
||||
}
|
||||
}
|
||||
|
||||
async function removeGroup() {
|
||||
if (deletingGroup.value) return
|
||||
|
||||
deletingGroup.value = true
|
||||
emit('deleteGroup', props.sectionKey)
|
||||
setTimeout(() => {
|
||||
deletingGroup.value = false
|
||||
confirmDeleteGroupModal.value?.hide()
|
||||
}, 300)
|
||||
}
|
||||
|
||||
function onCardClick(instanceId: string, event: MouseEvent) {
|
||||
emit('handleCardClick', instanceId, event)
|
||||
}
|
||||
|
||||
function onStartLongPress(instanceId: string) {
|
||||
emit('startLongPress', instanceId)
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div
|
||||
ref="groupContainerRef"
|
||||
class="instance-group group/instance-container relative select-none pb-3"
|
||||
@contextmenu.prevent.stop="openGroupContextMenu"
|
||||
>
|
||||
<div
|
||||
v-if="!hideHeader && isDropTarget && isGroupDragActive"
|
||||
class="pointer-events-none absolute -inset-2 inset-y-0 z-20 rounded-xl border-2 border-dashed border-contrast opacity-40 bg-transparent transition-opacity duration-150"
|
||||
/>
|
||||
<div
|
||||
v-if="!hideHeader && (grouping === 'Group' || sectionKey !== UNGROUPED_GROUP_KEY)"
|
||||
class="group/header flex h-10 w-full items-center gap-2 border-0 border-b border-solid border-b-surface-5"
|
||||
:class="{ 'group-drag-handle cursor-grab': isCustomGroup }"
|
||||
>
|
||||
<div
|
||||
class="flex min-w-0 cursor-pointer items-center gap-2"
|
||||
@click="emit('toggleCollapse', sectionKey)"
|
||||
>
|
||||
<button
|
||||
class="flex shrink-0 items-center border-0 bg-transparent p-0 cursor-pointer"
|
||||
type="button"
|
||||
:aria-expanded="!effectiveCollapsed"
|
||||
:aria-label="
|
||||
formatMessage(effectiveCollapsed ? messages.expandGroup : messages.collapseGroup)
|
||||
"
|
||||
@click.stop="emit('toggleCollapse', sectionKey)"
|
||||
>
|
||||
<DropdownIcon
|
||||
class="size-5 shrink-0 text-[var(--color-text-tertiary)] transition-transform duration-300"
|
||||
:class="{ 'rotate-180': !effectiveCollapsed }"
|
||||
/>
|
||||
</button>
|
||||
<InlineEditableText
|
||||
v-if="!isUngrouped && !isFavorites"
|
||||
ref="groupNameInput"
|
||||
v-model="groupName"
|
||||
activation-mode="manual"
|
||||
class="text-base font-semibold !h-10 text-[var(--color-text-default)] select-none"
|
||||
max-width="24rem"
|
||||
:max-length="MAX_GROUP_NAME_LENGTH"
|
||||
:on-change="updateGroupName"
|
||||
:validate="validateGroupName"
|
||||
/>
|
||||
<span v-else class="text-base font-semibold text-[var(--color-text-default)] select-none">
|
||||
{{ isFavorites ? formatMessage(messages.pinned) : formatMessage(messages.ungrouped) }}
|
||||
</span>
|
||||
<TagItem v-if="instances.length" class="shrink-0 border-surface-3 bg-surface-2">
|
||||
{{ instances.length }}
|
||||
</TagItem>
|
||||
</div>
|
||||
<div class="min-w-0 flex-1" />
|
||||
<div
|
||||
v-if="isCustomGroup"
|
||||
class="flex shrink-0 items-center opacity-0 transition-opacity duration-250 group-hover/header:opacity-100 focus-within:opacity-100"
|
||||
>
|
||||
<IconButton
|
||||
v-tooltip="formatMessage(messages.moveGroupUp)"
|
||||
:label="formatMessage(messages.moveGroupUp)"
|
||||
type="quiet"
|
||||
size="sm"
|
||||
:disabled="!canMoveUp"
|
||||
@click.stop="emit('moveGroup', sectionKey, -1)"
|
||||
>
|
||||
<ArrowUpIcon />
|
||||
</IconButton>
|
||||
<IconButton
|
||||
v-tooltip="formatMessage(messages.moveGroupDown)"
|
||||
:label="formatMessage(messages.moveGroupDown)"
|
||||
type="quiet"
|
||||
size="sm"
|
||||
:disabled="!canMoveDown"
|
||||
@click.stop="emit('moveGroup', sectionKey, 1)"
|
||||
>
|
||||
<ArrowDownIcon />
|
||||
</IconButton>
|
||||
<IconButton
|
||||
v-tooltip="formatMessage(messages.editGroupName)"
|
||||
:label="formatMessage(messages.editGroupName)"
|
||||
type="quiet"
|
||||
size="sm"
|
||||
@click.stop="groupNameInput?.startEditing()"
|
||||
>
|
||||
<EditIcon />
|
||||
</IconButton>
|
||||
<IconButton
|
||||
v-tooltip="formatMessage(messages.addToGroup)"
|
||||
:label="formatMessage(messages.addToGroup)"
|
||||
type="quiet"
|
||||
size="sm"
|
||||
@click.stop="emit('addToGroup', sectionKey)"
|
||||
>
|
||||
<PlusIcon />
|
||||
</IconButton>
|
||||
<IconButton
|
||||
v-tooltip="formatMessage(messages.deleteGroup)"
|
||||
:label="formatMessage(messages.deleteGroup)"
|
||||
type="quiet"
|
||||
size="sm"
|
||||
:disabled="deletingGroup"
|
||||
@click.stop="handleGroupOption({ option: 'delete_group' })"
|
||||
>
|
||||
<TrashIcon />
|
||||
</IconButton>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="!effectiveCollapsed" class="mt-2.5">
|
||||
<section
|
||||
class="grid grid-cols-[repeat(auto-fill,minmax(16rem,1fr))] w-full gap-3 mr-auto scroll-smooth overflow-y-auto"
|
||||
:class="{
|
||||
'grid-cols-[repeat(auto-fill,minmax(13rem,1fr))] gap-4': displayMode === 'cards',
|
||||
}"
|
||||
>
|
||||
<template v-for="instance in instances" :key="instance.id">
|
||||
<DraggableInstanceCard
|
||||
v-if="isGroupDragActive"
|
||||
:instance="instance"
|
||||
:instance-group-id="sectionKey"
|
||||
:disabled="selectMode"
|
||||
@card-click="(event: MouseEvent) => onCardClick(instance.id, event)"
|
||||
@contextmenu="
|
||||
(event: MouseEvent) => emit('handleContextMenu', event, instance.id, props.sectionKey)
|
||||
"
|
||||
@start-long-press="onStartLongPress(instance.id)"
|
||||
@cancel-long-press="emit('cancelLongPress')"
|
||||
>
|
||||
<template #default="{ isDragging }">
|
||||
<div
|
||||
:class="{
|
||||
'pointer-events-none': selectMode,
|
||||
'relative cursor-pointer select-none rounded-lg transition-all hover:brightness-90 active:scale-[0.98]': true,
|
||||
}"
|
||||
@click.capture="
|
||||
(event: MouseEvent) => {
|
||||
if (event.shiftKey && !selectMode) {
|
||||
event.stopPropagation()
|
||||
emit('handleCardClick', instance.id, event)
|
||||
}
|
||||
}
|
||||
"
|
||||
>
|
||||
<Instance
|
||||
:instance="instance"
|
||||
:disabled="selectMode || isDragging"
|
||||
:variant="displayMode === 'cards' ? 'library' : 'standard'"
|
||||
:class="{
|
||||
'opacity-50': selectMode && !selectedInstanceIds.has(instance.id),
|
||||
}"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
<template #overlay>
|
||||
<div
|
||||
class="absolute right-2 bottom-2 z-10 transition-opacity"
|
||||
:class="
|
||||
selectMode && selectedInstanceIds.has(instance.id)
|
||||
? ''
|
||||
: 'opacity-0 group-hover:opacity-100'
|
||||
"
|
||||
@click.stop="emit('handleCheckboxClick', instance.id, $event)"
|
||||
>
|
||||
<Checkbox :model-value="selectedInstanceIds.has(instance.id)" />
|
||||
</div>
|
||||
<div
|
||||
v-if="!selectMode"
|
||||
class="absolute right-2 top-2 opacity-0 group-hover:opacity-100 transition-opacity"
|
||||
@click.stop="
|
||||
emit('handleContextMenu', $event as MouseEvent, instance.id, props.sectionKey)
|
||||
"
|
||||
>
|
||||
<Button type="quiet" size="2xs" circular icon-only
|
||||
><slot name="moreIcon" />
|
||||
</Button>
|
||||
</div>
|
||||
</template>
|
||||
</DraggableInstanceCard>
|
||||
|
||||
<div v-else class="group relative">
|
||||
<div
|
||||
class="relative cursor-pointer select-none rounded-lg transition-all hover:brightness-90 active:scale-[0.98]"
|
||||
@click.capture="
|
||||
(event: MouseEvent) => {
|
||||
if (event.shiftKey && !selectMode) {
|
||||
event.stopPropagation()
|
||||
emit('handleCardClick', instance.id, event)
|
||||
}
|
||||
}
|
||||
"
|
||||
@click="emit('handleCardClick', instance.id, $event as MouseEvent)"
|
||||
@mousedown="!selectMode && emit('startLongPress', instance.id)"
|
||||
@mouseup="emit('cancelLongPress')"
|
||||
@mouseleave="emit('cancelLongPress')"
|
||||
@touchstart="!selectMode && emit('startLongPress', instance.id)"
|
||||
@touchend="emit('cancelLongPress')"
|
||||
@touchcancel="emit('cancelLongPress')"
|
||||
>
|
||||
<div :class="{ 'pointer-events-none': selectMode }">
|
||||
<Instance
|
||||
:instance="instance"
|
||||
:disabled="selectMode"
|
||||
:variant="displayMode === 'cards' ? 'library' : 'standard'"
|
||||
:class="{
|
||||
'opacity-50': selectMode && !selectedInstanceIds.has(instance.id),
|
||||
}"
|
||||
@contextmenu.prevent.stop="
|
||||
(event: MouseEvent) =>
|
||||
emit('handleContextMenu', event, instance.id, props.sectionKey)
|
||||
"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
class="absolute right-2 bottom-2 z-10 transition-opacity"
|
||||
:class="
|
||||
selectMode && selectedInstanceIds.has(instance.id)
|
||||
? ''
|
||||
: 'opacity-0 group-hover:opacity-100'
|
||||
"
|
||||
@click.stop="emit('handleCheckboxClick', instance.id, $event)"
|
||||
>
|
||||
<Checkbox :model-value="selectedInstanceIds.has(instance.id)" />
|
||||
</div>
|
||||
<div
|
||||
v-if="!selectMode"
|
||||
class="absolute right-2 top-2 opacity-0 group-hover:opacity-100 transition-opacity"
|
||||
@click.stop="
|
||||
emit('handleContextMenu', $event as MouseEvent, instance.id, props.sectionKey)
|
||||
"
|
||||
>
|
||||
<Button type="quiet" size="2xs" circular icon-only><slot name="moreIcon" /> </Button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<p
|
||||
v-if="instances.length === 0"
|
||||
class="col-span-full m-0 pt-1 pl-0.5 text-base font-base text-[var(--color-text-tertiary)] opacity-80"
|
||||
>
|
||||
{{ formatMessage(messages.emptyGroup) }}
|
||||
</p>
|
||||
</section>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<ContextMenu ref="groupOptions" @option-clicked="handleGroupOption">
|
||||
<template #new_instance>
|
||||
<PlusIcon />
|
||||
{{ formatMessage(messages.newInstance) }}
|
||||
</template>
|
||||
<template #add_instances>
|
||||
<PlusIcon />
|
||||
{{ formatMessage(messages.addToGroup) }}
|
||||
</template>
|
||||
<template #edit_name>
|
||||
<EditIcon />
|
||||
{{ formatMessage(messages.editGroupName) }}
|
||||
</template>
|
||||
<template #delete_group>
|
||||
<TrashIcon />
|
||||
{{ formatMessage(messages.deleteGroup) }}
|
||||
</template>
|
||||
</ContextMenu>
|
||||
|
||||
<NewModal
|
||||
ref="confirmDeleteGroupModal"
|
||||
:header="formatMessage(messages.deleteGroup)"
|
||||
fade="danger"
|
||||
width="500px"
|
||||
>
|
||||
<p class="m-0 text-base text-[var(--color-text-default)]">
|
||||
{{ formatMessage(messages.deleteGroupDescription) }}
|
||||
</p>
|
||||
|
||||
<template #actions>
|
||||
<div class="flex justify-end gap-2">
|
||||
<Button type="outlined" @click="confirmDeleteGroupModal?.hide()">
|
||||
<XIcon />
|
||||
{{ formatMessage(commonMessages.cancelButton) }}
|
||||
</Button>
|
||||
<Button type="colored" color="red" :disabled="deletingGroup" @click="removeGroup">
|
||||
<TrashIcon />
|
||||
{{ formatMessage(messages.deleteGroup) }}
|
||||
</Button>
|
||||
</div>
|
||||
</template>
|
||||
</NewModal>
|
||||
</template>
|
||||
@@ -0,0 +1,313 @@
|
||||
<template>
|
||||
<NewModal ref="modal" no-padding scrollable actions-divider max-width="560px" width="560px">
|
||||
<template #title>
|
||||
<span class="text-2xl font-semibold text-[var(--color-text-primary)]">
|
||||
{{
|
||||
existingGroupName
|
||||
? formatMessage(messages.addToGroupTitle, { groupName: existingGroupName })
|
||||
: formatMessage(messages.header)
|
||||
}}
|
||||
</span>
|
||||
</template>
|
||||
|
||||
<template v-if="!existingGroupName">
|
||||
<div class="flex flex-col gap-2.5 p-6">
|
||||
<label for="new-group-name" class="font-semibold text-[var(--color-text-primary)]">
|
||||
{{ formatMessage(messages.groupName) }}
|
||||
</label>
|
||||
<StyledInput
|
||||
id="new-group-name"
|
||||
ref="groupNameInput"
|
||||
v-model="newGroupName"
|
||||
:placeholder="formatMessage(messages.groupNamePlaceholder)"
|
||||
:maxlength="32"
|
||||
@click="groupNameInput?.select()"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="h-px bg-divider" />
|
||||
</template>
|
||||
|
||||
<div class="flex h-[400px] flex-col gap-3 overflow-y-auto bg-surface-2 py-4">
|
||||
<div class="px-6">
|
||||
<StyledInput
|
||||
v-model="newGroupSearch"
|
||||
:icon="SearchIcon"
|
||||
:placeholder="formatMessage(messages.searchInstance)"
|
||||
class="w-full"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-if="newGroupInstances.length === 0"
|
||||
class="flex items-center justify-center py-12 text-[var(--color-text-tertiary)]"
|
||||
>
|
||||
{{ formatMessage(messages.noInstancesFound) }}
|
||||
</div>
|
||||
<div v-else class="flex flex-col gap-1">
|
||||
<div
|
||||
v-for="instance in newGroupInstances"
|
||||
:key="instance.id"
|
||||
class="flex items-center justify-between gap-4 px-6 py-1.5 hover:bg-surface-3"
|
||||
:class="{ 'opacity-60': selectedNewGroupInstanceIds.has(instance.id) }"
|
||||
>
|
||||
<div class="flex min-w-0 items-center gap-2.5">
|
||||
<InstanceIcon
|
||||
:icon-path="instance.icon_path"
|
||||
:instance-id="instance.id"
|
||||
:loader="instance.loader"
|
||||
class="!size-[2rem] !rounded-md"
|
||||
/>
|
||||
<div class="flex min-w-0 items-center gap-2">
|
||||
<span class="truncate font-semibold text-[var(--color-text-primary)]">{{
|
||||
instance.name
|
||||
}}</span>
|
||||
<TagItem v-if="instance.groups && instance.groups.length > 0" class="shrink-0">
|
||||
{{ getGroupName(instance.groups[0]) }}
|
||||
</TagItem>
|
||||
</div>
|
||||
</div>
|
||||
<Button
|
||||
:type="selectedNewGroupInstanceIds.has(instance.id) ? 'outlined' : 'base'"
|
||||
@click="toggleNewGroupInstance(instance.id)"
|
||||
>
|
||||
<CheckIcon v-if="selectedNewGroupInstanceIds.has(instance.id)" />
|
||||
{{
|
||||
formatMessage(
|
||||
selectedNewGroupInstanceIds.has(instance.id) ? messages.added : messages.add,
|
||||
)
|
||||
}}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<template #actions>
|
||||
<div class="flex items-center justify-end gap-2">
|
||||
<Button type="outlined" @click="modal?.hide()">
|
||||
<XIcon />
|
||||
{{ formatMessage(messages.cancel) }}
|
||||
</Button>
|
||||
<Button
|
||||
type="colored"
|
||||
color="brand"
|
||||
:disabled="existingGroupName ? !canSaveGroups : !canCreateGroup"
|
||||
@click="existingGroupName ? handleSaveGroups() : handleCreateGroup()"
|
||||
>
|
||||
<SpinnerIcon v-if="creatingGroup" class="animate-spin" />
|
||||
<CheckIcon v-else-if="existingGroupName" />
|
||||
<PlusIcon v-else />
|
||||
{{ formatMessage(existingGroupName ? messages.saveChanges : messages.createGroup) }}
|
||||
</Button>
|
||||
</div>
|
||||
</template>
|
||||
</NewModal>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { CheckIcon, PlusIcon, SearchIcon, SpinnerIcon, XIcon } from '@modrinth/assets'
|
||||
import { Button, defineMessages, NewModal, StyledInput, TagItem, useVIntl } from '@modrinth/ui'
|
||||
import { computed, ref } from 'vue'
|
||||
|
||||
import InstanceIcon from '@/components/ui/InstanceIcon.vue'
|
||||
import { FAVORITES_GROUP_ID } from '@/composables/useInstanceGroups'
|
||||
import { list } from '@/helpers/instance'
|
||||
import { create_group, list_groups, set_group_memberships } from '@/helpers/instance-groups'
|
||||
import type { GameInstance } from '@/helpers/types'
|
||||
|
||||
const { formatMessage } = useVIntl()
|
||||
|
||||
const props = defineProps<{
|
||||
instanceIds: string[]
|
||||
existingGroupName?: string
|
||||
existingGroupId?: string
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'applied'): void
|
||||
}>()
|
||||
|
||||
const messages = defineMessages({
|
||||
header: {
|
||||
id: 'app.instances.batch-edit-groups.header',
|
||||
defaultMessage: 'Create group',
|
||||
},
|
||||
addToGroupTitle: {
|
||||
id: 'app.instances.batch-edit-groups.add-to-group-title',
|
||||
defaultMessage: 'Add instances to "{groupName}"',
|
||||
},
|
||||
groupName: {
|
||||
id: 'app.instances.batch-edit-groups.group-name',
|
||||
defaultMessage: 'Group name',
|
||||
},
|
||||
groupNamePlaceholder: {
|
||||
id: 'app.instances.batch-edit-groups.group-name-placeholder',
|
||||
defaultMessage: 'Enter group name',
|
||||
},
|
||||
searchInstance: {
|
||||
id: 'app.instances.batch-edit-groups.search-instance',
|
||||
defaultMessage: 'Search instances',
|
||||
},
|
||||
noInstancesFound: {
|
||||
id: 'app.instances.batch-edit-groups.no-instances-found',
|
||||
defaultMessage: 'No instances found',
|
||||
},
|
||||
add: {
|
||||
id: 'app.instances.batch-edit-groups.add',
|
||||
defaultMessage: 'Add',
|
||||
},
|
||||
added: {
|
||||
id: 'app.instances.batch-edit-groups.added',
|
||||
defaultMessage: 'Added',
|
||||
},
|
||||
cancel: {
|
||||
id: 'app.instances.batch-edit-groups.cancel',
|
||||
defaultMessage: 'Cancel',
|
||||
},
|
||||
createGroup: {
|
||||
id: 'app.instances.batch-edit-groups.create',
|
||||
defaultMessage: 'Create group',
|
||||
},
|
||||
pinnedGroupName: {
|
||||
id: 'app.instances.group.pinned',
|
||||
defaultMessage: 'Pinned',
|
||||
},
|
||||
saveChanges: {
|
||||
id: 'app.instances.batch-edit-groups.save-changes',
|
||||
defaultMessage: 'Save',
|
||||
},
|
||||
})
|
||||
|
||||
const modal = ref<InstanceType<typeof NewModal>>()
|
||||
const groupNameInput = ref<InstanceType<typeof StyledInput>>()
|
||||
const newGroupName = ref('')
|
||||
const newGroupSearch = ref('')
|
||||
const creatingGroup = ref(false)
|
||||
const allInstances = ref<GameInstance[]>([])
|
||||
const groupNameMap = ref(new Map<string, string>())
|
||||
const selectedNewGroupInstanceIds = ref(new Set<string>())
|
||||
|
||||
const canCreateGroup = computed(() => newGroupName.value.trim().length > 0)
|
||||
|
||||
const canSaveGroups = computed(() => {
|
||||
if (!props.existingGroupName) return false
|
||||
const groupId = props.existingGroupId
|
||||
if (!groupId) return false
|
||||
return allInstances.value.some((instance) => {
|
||||
const isSelected = selectedNewGroupInstanceIds.value.has(instance.id)
|
||||
const hasGroup = (instance.groups || []).includes(groupId)
|
||||
return isSelected !== hasGroup
|
||||
})
|
||||
})
|
||||
|
||||
const newGroupInstances = computed(() => {
|
||||
const search = newGroupSearch.value.toLowerCase()
|
||||
return allInstances.value.filter((instance) => {
|
||||
if (!search) return true
|
||||
return instance.name.toLowerCase().includes(search)
|
||||
})
|
||||
})
|
||||
|
||||
function getGroupName(groupId: string) {
|
||||
if (groupId === FAVORITES_GROUP_ID) {
|
||||
return formatMessage(messages.pinnedGroupName)
|
||||
}
|
||||
return groupNameMap.value.get(groupId) || groupId
|
||||
}
|
||||
|
||||
function show(ids?: string[]) {
|
||||
newGroupSearch.value = ''
|
||||
creatingGroup.value = false
|
||||
Promise.all([list(), list_groups()]).then(([instances, groups]) => {
|
||||
allInstances.value = instances as GameInstance[]
|
||||
const map = new Map<string, string>()
|
||||
for (const g of groups) {
|
||||
map.set(g.id, g.name)
|
||||
}
|
||||
groupNameMap.value = map
|
||||
|
||||
if (!props.existingGroupName) {
|
||||
const customGroups = groups.filter((g: { id: string }) => g.id !== 'group:favorites')
|
||||
let groupNumber = customGroups.length + 1
|
||||
const existingNames = new Set(groups.map((g: { name: string }) => g.name.toLowerCase()))
|
||||
while (existingNames.has(`group ${groupNumber}`)) {
|
||||
groupNumber++
|
||||
}
|
||||
newGroupName.value = `Group ${groupNumber}`
|
||||
}
|
||||
|
||||
if (props.existingGroupName) {
|
||||
const groupId = props.existingGroupId
|
||||
selectedNewGroupInstanceIds.value = new Set(
|
||||
allInstances.value.filter((i) => (i.groups || []).includes(groupId || '')).map((i) => i.id),
|
||||
)
|
||||
} else {
|
||||
selectedNewGroupInstanceIds.value = new Set(ids ?? props.instanceIds)
|
||||
}
|
||||
})
|
||||
modal.value?.show()
|
||||
}
|
||||
|
||||
function toggleNewGroupInstance(instanceId: string) {
|
||||
const next = new Set(selectedNewGroupInstanceIds.value)
|
||||
if (next.has(instanceId)) {
|
||||
next.delete(instanceId)
|
||||
} else {
|
||||
next.add(instanceId)
|
||||
}
|
||||
selectedNewGroupInstanceIds.value = next
|
||||
}
|
||||
|
||||
async function handleCreateGroup() {
|
||||
const name = newGroupName.value.trim()
|
||||
if (!name || selectedNewGroupInstanceIds.value.size === 0) return
|
||||
|
||||
creatingGroup.value = true
|
||||
|
||||
const group = await create_group(name).catch(() => null)
|
||||
if (!group) {
|
||||
creatingGroup.value = false
|
||||
return
|
||||
}
|
||||
|
||||
if (selectedNewGroupInstanceIds.value.size > 0) {
|
||||
const updates = [...selectedNewGroupInstanceIds.value].map((instanceId) => ({
|
||||
instance_id: instanceId,
|
||||
group_ids: [group.id],
|
||||
}))
|
||||
await set_group_memberships(updates).catch(() => {})
|
||||
}
|
||||
|
||||
creatingGroup.value = false
|
||||
modal.value?.hide()
|
||||
emit('applied')
|
||||
}
|
||||
|
||||
async function handleSaveGroups() {
|
||||
if (!props.existingGroupName) return
|
||||
|
||||
creatingGroup.value = true
|
||||
const groupId = props.existingGroupId
|
||||
|
||||
const changedInstances = allInstances.value.filter((instance) => {
|
||||
const isSelected = selectedNewGroupInstanceIds.value.has(instance.id)
|
||||
const hasGroup = (instance.groups || []).includes(groupId || '')
|
||||
return isSelected !== hasGroup
|
||||
})
|
||||
|
||||
const updates = changedInstances.map((instance) => {
|
||||
const isSelected = selectedNewGroupInstanceIds.value.has(instance.id)
|
||||
return {
|
||||
instance_id: instance.id,
|
||||
group_ids: isSelected ? [groupId!] : [],
|
||||
}
|
||||
})
|
||||
await set_group_memberships(updates).catch(() => {})
|
||||
|
||||
creatingGroup.value = false
|
||||
modal.value?.hide()
|
||||
emit('applied')
|
||||
}
|
||||
|
||||
defineExpose({ show })
|
||||
</script>
|
||||
@@ -7,15 +7,22 @@ export const UNGROUPED_GROUP_KEY = '__ungrouped__'
|
||||
|
||||
export type GridGroupingOption = 'Group' | 'Loader' | 'Game version' | 'None'
|
||||
export type GridSortOption =
|
||||
| 'Name'
|
||||
| 'Last played'
|
||||
| 'Date created'
|
||||
| 'Date modified'
|
||||
| 'Game version'
|
||||
'Name' | 'Last played' | 'Date created' | 'Date modified' | 'Game version'
|
||||
|
||||
export type GridSortDirection = 'asc' | 'desc'
|
||||
|
||||
export const defaultSortDirections: Record<GridSortOption, GridSortDirection> = {
|
||||
Name: 'asc',
|
||||
'Last played': 'desc',
|
||||
'Date created': 'desc',
|
||||
'Date modified': 'desc',
|
||||
'Game version': 'asc',
|
||||
}
|
||||
|
||||
export interface GridDisplayState {
|
||||
group: GridGroupingOption
|
||||
sortBy: GridSortOption
|
||||
sortDirections: Partial<Record<GridSortOption, GridSortDirection>>
|
||||
collapsedGroups: string[]
|
||||
}
|
||||
|
||||
@@ -38,6 +45,7 @@ export function useGridGrouping<T extends Record<string, unknown>>(
|
||||
{
|
||||
group: 'Group',
|
||||
sortBy: 'Name',
|
||||
sortDirections: {},
|
||||
collapsedGroups: [],
|
||||
},
|
||||
localStorage,
|
||||
@@ -66,7 +74,7 @@ export function useGridGrouping<T extends Record<string, unknown>>(
|
||||
state.value.collapsedGroups = [...collapsedSections]
|
||||
}
|
||||
|
||||
function sortInstances(instances: T[], sortBy: GridSortOption): T[] {
|
||||
function sortInstances(instances: T[], sortBy: GridSortOption, ascending: boolean): T[] {
|
||||
const sorted = [...instances]
|
||||
const getGameVersion = options.getGameVersion ?? ((i: T) => i.game_version ?? '')
|
||||
const getLastPlayed = options.getLastPlayed ?? ((i: T) => i.last_played ?? 0)
|
||||
@@ -83,16 +91,19 @@ export function useGridGrouping<T extends Record<string, unknown>>(
|
||||
)
|
||||
break
|
||||
case 'Last played':
|
||||
sorted.sort((a, b) => dayjs(getLastPlayed(b)).diff(dayjs(getLastPlayed(a))))
|
||||
sorted.sort((a, b) => dayjs(getLastPlayed(a)).diff(dayjs(getLastPlayed(b))))
|
||||
break
|
||||
case 'Date created':
|
||||
sorted.sort((a, b) => dayjs(getDateCreated(b)).diff(dayjs(getDateCreated(a))))
|
||||
sorted.sort((a, b) => dayjs(getDateCreated(a)).diff(dayjs(getDateCreated(b))))
|
||||
break
|
||||
case 'Date modified':
|
||||
sorted.sort((a, b) => dayjs(getDateModified(b)).diff(dayjs(getDateModified(a))))
|
||||
sorted.sort((a, b) => dayjs(getDateModified(a)).diff(dayjs(getDateModified(b))))
|
||||
break
|
||||
}
|
||||
|
||||
if (!ascending) {
|
||||
sorted.reverse()
|
||||
}
|
||||
return sorted
|
||||
}
|
||||
|
||||
@@ -148,11 +159,25 @@ export function useGridGrouping<T extends Record<string, unknown>>(
|
||||
function sortSections(
|
||||
instanceMap: Map<string, T[]>,
|
||||
group: GridGroupingOption,
|
||||
sortBy: GridSortOption,
|
||||
): Map<string, T[]> {
|
||||
if (group !== 'Group' && group !== 'Game version') {
|
||||
return instanceMap
|
||||
}
|
||||
|
||||
if (group === 'Group' && sortBy !== 'Name') {
|
||||
if (instanceMap.has(UNGROUPED_GROUP_KEY) && instanceMap.size > 1) {
|
||||
const ungroupedInstances = instanceMap.get(UNGROUPED_GROUP_KEY)!
|
||||
instanceMap.delete(UNGROUPED_GROUP_KEY)
|
||||
const newMap = new Map<string, T[]>([[UNGROUPED_GROUP_KEY, ungroupedInstances]])
|
||||
for (const [key, instances] of instanceMap) {
|
||||
newMap.set(key, instances)
|
||||
}
|
||||
return newMap
|
||||
}
|
||||
return instanceMap
|
||||
}
|
||||
|
||||
const sortedEntries = [...instanceMap.entries()].sort((a, b) => {
|
||||
if (group === 'Group') {
|
||||
if (a[0] === UNGROUPED_GROUP_KEY && b[0] !== UNGROUPED_GROUP_KEY) return -1
|
||||
@@ -166,12 +191,30 @@ export function useGridGrouping<T extends Record<string, unknown>>(
|
||||
return instanceMap
|
||||
}
|
||||
|
||||
const sortDirection = computed<GridSortDirection>(() => {
|
||||
return (
|
||||
state.value.sortDirections[state.value.sortBy] ?? defaultSortDirections[state.value.sortBy]
|
||||
)
|
||||
})
|
||||
|
||||
const isSortAscending = computed(() => sortDirection.value === 'asc')
|
||||
|
||||
const toggleSortDirection = () => {
|
||||
const current = sortDirection.value
|
||||
const next: GridSortDirection = current === 'asc' ? 'desc' : 'asc'
|
||||
state.value.sortDirections = {
|
||||
...state.value.sortDirections,
|
||||
[state.value.sortBy]: next,
|
||||
}
|
||||
}
|
||||
|
||||
const filteredResults = computed(() => {
|
||||
const { group = 'Group', sortBy = 'Name' } = state.value
|
||||
const ascending = isSortAscending.value
|
||||
|
||||
const sorted = sortInstances(instances.value, sortBy)
|
||||
const sorted = sortInstances(instances.value, sortBy, ascending)
|
||||
const grouped = groupInstances(sorted, group)
|
||||
return sortSections(grouped, group)
|
||||
return sortSections(grouped, group, sortBy)
|
||||
})
|
||||
|
||||
return {
|
||||
@@ -180,6 +223,9 @@ export function useGridGrouping<T extends Record<string, unknown>>(
|
||||
filteredResults,
|
||||
isSectionCollapsed,
|
||||
setSectionCollapsed,
|
||||
sortDirection,
|
||||
isSortAscending,
|
||||
toggleSortDirection,
|
||||
UNGROUPED_GROUP_KEY,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,182 @@
|
||||
import { computed, type Ref, ref, watch } from 'vue'
|
||||
|
||||
import { instance_groups_listener } from '@/helpers/events'
|
||||
import {
|
||||
create_group,
|
||||
delete_group,
|
||||
type InstanceGroupDefinition,
|
||||
type InstanceGroupMembershipUpdate,
|
||||
list_groups,
|
||||
MAX_INSTANCE_GROUP_NAME_LENGTH,
|
||||
rename_group,
|
||||
set_group_memberships,
|
||||
set_group_order,
|
||||
} from '@/helpers/instance-groups'
|
||||
|
||||
export const FAVORITES_GROUP_ID = 'group:favorites'
|
||||
|
||||
export const UNGROUPED_GROUP_ID = 'group:none'
|
||||
|
||||
export { MAX_INSTANCE_GROUP_NAME_LENGTH }
|
||||
|
||||
export { type InstanceGroupDefinition, type InstanceGroupMembershipUpdate }
|
||||
|
||||
export interface InstanceGroupWithMembership {
|
||||
key: string
|
||||
name: string
|
||||
instances: string[]
|
||||
}
|
||||
|
||||
export function useInstanceGroups(instances: Ref<{ id: string; groups: string[] }[]>) {
|
||||
const libraryGroups = ref<InstanceGroupDefinition[]>([])
|
||||
const libraryGroupsLoaded = ref(false)
|
||||
|
||||
async function fetchGroups() {
|
||||
libraryGroups.value = await list_groups()
|
||||
libraryGroupsLoaded.value = true
|
||||
}
|
||||
|
||||
fetchGroups()
|
||||
|
||||
instance_groups_listener(() => {
|
||||
fetchGroups()
|
||||
})
|
||||
|
||||
const orderedLibraryGroupIds = ref<string[]>([])
|
||||
|
||||
watch(
|
||||
libraryGroups,
|
||||
(groups) => {
|
||||
orderedLibraryGroupIds.value = groups.map((g) => g.id)
|
||||
},
|
||||
{ immediate: true },
|
||||
)
|
||||
|
||||
const instanceGroups = computed(() => {
|
||||
if (!libraryGroupsLoaded.value) {
|
||||
return []
|
||||
}
|
||||
|
||||
const instanceGroupMap = new Map<string, string[]>()
|
||||
|
||||
for (const instance of instances.value) {
|
||||
const groups = instance.groups ?? []
|
||||
for (const groupId of groups) {
|
||||
if (!instanceGroupMap.has(groupId)) {
|
||||
instanceGroupMap.set(groupId, [])
|
||||
}
|
||||
instanceGroupMap.get(groupId)!.push(instance.id)
|
||||
}
|
||||
}
|
||||
|
||||
const allGroupIds = new Set<string>()
|
||||
const groupMap = new Map<string, string[]>()
|
||||
|
||||
for (const groupId of orderedLibraryGroupIds.value) {
|
||||
allGroupIds.add(groupId)
|
||||
groupMap.set(groupId, instanceGroupMap.get(groupId) ?? [])
|
||||
}
|
||||
|
||||
const ungroupedIds: string[] = []
|
||||
for (const instance of instances.value) {
|
||||
const instanceGroups = instance.groups ?? []
|
||||
const isInAnyGroup = instanceGroups.some((g) => allGroupIds.has(g))
|
||||
if (!isInAnyGroup) {
|
||||
ungroupedIds.push(instance.id)
|
||||
}
|
||||
}
|
||||
|
||||
if (ungroupedIds.length > 0) {
|
||||
groupMap.set(UNGROUPED_GROUP_ID, ungroupedIds)
|
||||
}
|
||||
|
||||
return [...groupMap.entries()].map(([key, instances]) => ({
|
||||
key,
|
||||
name:
|
||||
key === UNGROUPED_GROUP_ID
|
||||
? 'Ungrouped'
|
||||
: (libraryGroups.value.find((g) => g.id === key)?.name ?? key),
|
||||
instances,
|
||||
}))
|
||||
})
|
||||
|
||||
const creatingGroup = ref(false)
|
||||
const reorderingGroups = ref(false)
|
||||
|
||||
async function createNewGroup(name: string): Promise<string | null> {
|
||||
creatingGroup.value = true
|
||||
try {
|
||||
const group = await create_group(name)
|
||||
libraryGroups.value = [...libraryGroups.value, group]
|
||||
orderedLibraryGroupIds.value = [...orderedLibraryGroupIds.value, group.id]
|
||||
return group.id
|
||||
} finally {
|
||||
creatingGroup.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function renameGroupById(id: string, newName: string): Promise<boolean> {
|
||||
if (id === FAVORITES_GROUP_ID) return false
|
||||
const result = await rename_group(id, newName)
|
||||
const idx = libraryGroups.value.findIndex((g) => g.id === id)
|
||||
if (idx !== -1) {
|
||||
libraryGroups.value = [
|
||||
...libraryGroups.value.slice(0, idx),
|
||||
result,
|
||||
...libraryGroups.value.slice(idx + 1),
|
||||
]
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
async function deleteGroupById(id: string): Promise<boolean> {
|
||||
if (id === FAVORITES_GROUP_ID) return false
|
||||
await delete_group(id)
|
||||
libraryGroups.value = libraryGroups.value.filter((g) => g.id !== id)
|
||||
orderedLibraryGroupIds.value = orderedLibraryGroupIds.value.filter((gid) => gid !== id)
|
||||
return true
|
||||
}
|
||||
|
||||
async function reorderGroups(groupIds: string[]): Promise<boolean> {
|
||||
reorderingGroups.value = true
|
||||
try {
|
||||
await set_group_order(groupIds)
|
||||
// Favorites is rendered separately from draggable sections. Keep it in
|
||||
// the local order after a drag even though the backend accepts only the
|
||||
// reorderable group ids; otherwise it appears again as an ordinary
|
||||
// section until the next full group refresh.
|
||||
orderedLibraryGroupIds.value = [
|
||||
FAVORITES_GROUP_ID,
|
||||
...groupIds.filter((id) => id !== FAVORITES_GROUP_ID),
|
||||
]
|
||||
return true
|
||||
} finally {
|
||||
reorderingGroups.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function setMemberships(updates: InstanceGroupMembershipUpdate[]): Promise<boolean> {
|
||||
await set_group_memberships(updates)
|
||||
return true
|
||||
}
|
||||
|
||||
function groupNameById(id: string): string | undefined {
|
||||
if (id === UNGROUPED_GROUP_ID) return 'Ungrouped'
|
||||
return libraryGroups.value.find((g) => g.id === id)?.name
|
||||
}
|
||||
|
||||
return {
|
||||
libraryGroups,
|
||||
libraryGroupsLoaded,
|
||||
orderedLibraryGroupIds,
|
||||
instanceGroups,
|
||||
creatingGroup,
|
||||
reorderingGroups,
|
||||
createGroup: createNewGroup,
|
||||
renameGroupById,
|
||||
deleteGroupById,
|
||||
reorderGroups,
|
||||
setMemberships,
|
||||
groupNameById,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
interface InstanceProperties {
|
||||
loader: string
|
||||
game_version: string
|
||||
}
|
||||
|
||||
interface ProjectProperties extends InstanceProperties {
|
||||
id: string
|
||||
project_type: string
|
||||
}
|
||||
|
||||
type AnalyticsEventMap = {
|
||||
Launched: { version: string; dev: boolean; onboarded: boolean }
|
||||
PageView: { path: string; fromPath: string; failed: unknown }
|
||||
InstanceCreate: { source: string }
|
||||
InstanceCreateStart: { source: string }
|
||||
InstanceStart: InstanceProperties & { source: string }
|
||||
InstanceStop: Partial<InstanceProperties> & { source?: string }
|
||||
InstanceDuplicate: InstanceProperties
|
||||
InstanceRepair: InstanceProperties
|
||||
InstanceSetIcon: Record<string, never>
|
||||
InstanceRemoveIcon: Record<string, never>
|
||||
InstanceUpdateAll: InstanceProperties & { count: number; selected: boolean }
|
||||
InstanceProjectUpdate: InstanceProperties & { id: string; name: string; project_type: string }
|
||||
InstanceProjectDisable: InstanceProperties & {
|
||||
id: string
|
||||
name: string
|
||||
project_type: string
|
||||
disabled: boolean
|
||||
}
|
||||
InstanceProjectRemove: InstanceProperties & { id: string; name: string; project_type: string }
|
||||
ProjectInstall: ProjectProperties & { version_id: string; title: string; source: string }
|
||||
ProjectInstallStart: { source: string }
|
||||
PackInstall: { id: string; version_id: string; title: string; source: string }
|
||||
PackInstallStart: Record<string, never>
|
||||
AccountLogIn: { source?: string }
|
||||
AccountLogOut: Record<string, never>
|
||||
JavaTest: { path: string; success: boolean }
|
||||
JavaManualSelect: { version: string }
|
||||
JavaAutoDetect: { path: string; version: string }
|
||||
GalleryImageNext: { project_id: string; url: string }
|
||||
GalleryImagePrevious: { project_id: string; url: unknown }
|
||||
GalleryImageExpand: { project_id: string; url: string }
|
||||
}
|
||||
|
||||
export type AnalyticsEvent = keyof AnalyticsEventMap
|
||||
|
||||
let optedIn = false
|
||||
let debugEnabled = false
|
||||
|
||||
export const initAnalytics = () => {
|
||||
optedIn = true
|
||||
}
|
||||
|
||||
export const debugAnalytics = () => {
|
||||
debugEnabled = true
|
||||
}
|
||||
|
||||
export const optOutAnalytics = () => {
|
||||
optedIn = false
|
||||
}
|
||||
|
||||
export const optInAnalytics = () => {
|
||||
optedIn = true
|
||||
}
|
||||
|
||||
type OptionalArgs<T> = Record<string, never> extends T ? [properties?: T] : [properties: T]
|
||||
|
||||
export const trackEvent = <E extends AnalyticsEvent>(
|
||||
eventName: E,
|
||||
...args: OptionalArgs<AnalyticsEventMap[E]>
|
||||
) => {
|
||||
if (optedIn && debugEnabled) {
|
||||
console.debug('[Starlight telemetry disabled]', eventName, args[0])
|
||||
}
|
||||
}
|
||||
@@ -82,6 +82,16 @@ export async function instance_bulk_update_progress_listener(callback) {
|
||||
return await listen('instance_bulk_update_progress', (event) => callback(event.payload))
|
||||
}
|
||||
|
||||
/// Payload for the 'instance_groups_changed' event
|
||||
/*
|
||||
InstanceGroupsChangedPayload {
|
||||
instance_ids: string[]
|
||||
}
|
||||
*/
|
||||
export async function instance_groups_listener(callback) {
|
||||
return await listen('instance_groups_changed', (event) => callback(event.payload))
|
||||
}
|
||||
|
||||
export async function install_job_listener(callback) {
|
||||
return await listen('install_job', (event) => callback(event.payload))
|
||||
}
|
||||
|
||||
@@ -1 +1,46 @@
|
||||
import { invoke } from '@tauri-apps/api/core'
|
||||
|
||||
export const MAX_INSTANCE_GROUP_NAME_LENGTH = 256
|
||||
|
||||
export type InstanceGroupDefinition = {
|
||||
id: string
|
||||
name: string
|
||||
}
|
||||
|
||||
export type InstanceGroupMembershipUpdate = {
|
||||
instance_id: string
|
||||
group_ids: string[]
|
||||
}
|
||||
|
||||
export async function list_groups(): Promise<InstanceGroupDefinition[]> {
|
||||
return await invoke('plugin:instance|instance_list_groups')
|
||||
}
|
||||
|
||||
export async function create_group(name: string): Promise<InstanceGroupDefinition> {
|
||||
return await invoke('plugin:instance|instance_create_group', { name })
|
||||
}
|
||||
|
||||
export async function rename_group(id: string, newName: string): Promise<InstanceGroupDefinition> {
|
||||
return await invoke('plugin:instance|instance_rename_group', {
|
||||
id,
|
||||
newName,
|
||||
})
|
||||
}
|
||||
|
||||
export async function delete_group(id: string): Promise<void> {
|
||||
return await invoke('plugin:instance|instance_delete_group', { id })
|
||||
}
|
||||
|
||||
export async function set_group_order(group_ids: string[]): Promise<void> {
|
||||
return await invoke('plugin:instance|instance_set_group_order', {
|
||||
groupIds: group_ids,
|
||||
})
|
||||
}
|
||||
|
||||
export async function set_group_memberships(
|
||||
updates: InstanceGroupMembershipUpdate[],
|
||||
): Promise<void> {
|
||||
return await invoke('plugin:instance|instance_set_group_memberships', {
|
||||
updates,
|
||||
})
|
||||
}
|
||||
@@ -11554,5 +11554,44 @@
|
||||
},
|
||||
"app.settings.logs.export.notification-text": {
|
||||
"message": "The log archive was saved to {path}"
|
||||
}
|
||||
},
|
||||
"app.instances.batch-edit-groups.add": {"message": "Add"},
|
||||
"app.instances.batch-edit-groups.add-to-group-title": {"message": "Add instances to \"{groupName}\""},
|
||||
"app.instances.batch-edit-groups.added": {"message": "Added"},
|
||||
"app.instances.batch-edit-groups.cancel": {"message": "Cancel"},
|
||||
"app.instances.batch-edit-groups.create": {"message": "Create group"},
|
||||
"app.instances.batch-edit-groups.group-name": {"message": "Group name"},
|
||||
"app.instances.batch-edit-groups.group-name-placeholder": {"message": "Enter group name"},
|
||||
"app.instances.batch-edit-groups.no-instances-found": {"message": "No instances found"},
|
||||
"app.instances.batch-edit-groups.save-changes": {"message": "Save"},
|
||||
"app.instances.batch-edit-groups.search-instance": {"message": "Search instances"},
|
||||
"app.instances.group.add-to-group": {"message": "Add to group"},
|
||||
"app.instances.group.collapse": {"message": "Collapse group"},
|
||||
"app.instances.group.delete-description": {"message": "Instances in this group will be ungrouped."},
|
||||
"app.instances.group.delete-group": {"message": "Delete group"},
|
||||
"app.instances.group.edit-name": {"message": "Edit group name"},
|
||||
"app.instances.group.empty": {"message": "Drag and drop to add instances."},
|
||||
"app.instances.group.expand": {"message": "Expand group"},
|
||||
"app.instances.group.move-down": {"message": "Move group down"},
|
||||
"app.instances.group.move-up": {"message": "Move group up"},
|
||||
"app.instances.group.name-empty": {"message": "Group names cannot be empty."},
|
||||
"app.instances.group.name-too-long": {"message": "Group names cannot be longer than {maxLength} characters."},
|
||||
"app.instances.group.new-instance": {"message": "New instance"},
|
||||
"app.instances.group.pinned": {"message": "Pinned"},
|
||||
"app.instances.group.rename-group": {"message": "Rename group"},
|
||||
"app.instances.sort-by": {"message": "Sort by"},
|
||||
"app.instances.sort.direction.asc-alphabetical": {"message": "A–Z"},
|
||||
"app.instances.sort.direction.asc-date": {"message": "Oldest first"},
|
||||
"app.instances.sort.direction.asc-recency": {"message": "Least recent first"},
|
||||
"app.instances.sort.direction.asc-version": {"message": "Oldest version first"},
|
||||
"app.instances.sort.direction.desc-alphabetical": {"message": "Z–A"},
|
||||
"app.instances.sort.direction.desc-date": {"message": "Newest first"},
|
||||
"app.instances.sort.direction.desc-recency": {"message": "Most recent first"},
|
||||
"app.instances.sort.direction.desc-version": {"message": "Newest version first"},
|
||||
"app.library.context-menu.pin-instance": {"message": "Pin instance"},
|
||||
"app.library.context-menu.remove-from-group": {"message": "Remove from group"},
|
||||
"app.library.context-menu.unpin-instance": {"message": "Unpin instance"},
|
||||
"app.library.group.new": {"message": "New group"},
|
||||
"app.library.selection.new-group": {"message": "New group"},
|
||||
"app.library.selection.remove-from-group": {"message": "Remove from group"}
|
||||
}
|
||||
@@ -11385,5 +11385,44 @@
|
||||
"app.settings.logs.export.modal.cancel": { "message": "取消" },
|
||||
"app.settings.logs.export.modal.confirm": { "message": "导出" },
|
||||
"app.settings.logs.export.notification-title": { "message": "日志已导出" },
|
||||
"app.settings.logs.export.notification-text": { "message": "日志压缩包已保存到 {path}" }
|
||||
"app.settings.logs.export.notification-text": { "message": "日志压缩包已保存到 {path}" },
|
||||
"app.instances.batch-edit-groups.add": {"message": "添加"},
|
||||
"app.instances.batch-edit-groups.add-to-group-title": {"message": "添加实例到「{groupName}」"},
|
||||
"app.instances.batch-edit-groups.added": {"message": "已添加"},
|
||||
"app.instances.batch-edit-groups.cancel": {"message": "取消"},
|
||||
"app.instances.batch-edit-groups.create": {"message": "创建分组"},
|
||||
"app.instances.batch-edit-groups.group-name": {"message": "分组名称"},
|
||||
"app.instances.batch-edit-groups.group-name-placeholder": {"message": "输入分组名称"},
|
||||
"app.instances.batch-edit-groups.no-instances-found": {"message": "未找到实例"},
|
||||
"app.instances.batch-edit-groups.save-changes": {"message": "保存"},
|
||||
"app.instances.batch-edit-groups.search-instance": {"message": "搜索实例"},
|
||||
"app.instances.group.add-to-group": {"message": "添加到分组"},
|
||||
"app.instances.group.collapse": {"message": "折叠分组"},
|
||||
"app.instances.group.delete-description": {"message": "此分组中的实例将被取消分组。"},
|
||||
"app.instances.group.delete-group": {"message": "删除分组"},
|
||||
"app.instances.group.edit-name": {"message": "编辑分组名称"},
|
||||
"app.instances.group.empty": {"message": "拖放实例到此处添加。"},
|
||||
"app.instances.group.expand": {"message": "展开分组"},
|
||||
"app.instances.group.move-down": {"message": "下移分组"},
|
||||
"app.instances.group.move-up": {"message": "上移分组"},
|
||||
"app.instances.group.name-empty": {"message": "分组名称不能为空。"},
|
||||
"app.instances.group.name-too-long": {"message": "分组名称不能超过 {maxLength} 个字符。"},
|
||||
"app.instances.group.new-instance": {"message": "新建实例"},
|
||||
"app.instances.group.pinned": {"message": "已置顶"},
|
||||
"app.instances.group.rename-group": {"message": "重命名分组"},
|
||||
"app.instances.sort-by": {"message": "排序方式"},
|
||||
"app.instances.sort.direction.asc-alphabetical": {"message": "A–Z 正序"},
|
||||
"app.instances.sort.direction.asc-date": {"message": "最早的在前"},
|
||||
"app.instances.sort.direction.asc-recency": {"message": "最早游玩在前"},
|
||||
"app.instances.sort.direction.asc-version": {"message": "旧版本在前"},
|
||||
"app.instances.sort.direction.desc-alphabetical": {"message": "Z–A 倒序"},
|
||||
"app.instances.sort.direction.desc-date": {"message": "最新的在前"},
|
||||
"app.instances.sort.direction.desc-recency": {"message": "最近游玩在前"},
|
||||
"app.instances.sort.direction.desc-version": {"message": "新版本在前"},
|
||||
"app.library.context-menu.pin-instance": {"message": "置顶实例"},
|
||||
"app.library.context-menu.remove-from-group": {"message": "移出分组"},
|
||||
"app.library.context-menu.unpin-instance": {"message": "取消置顶"},
|
||||
"app.library.group.new": {"message": "新建分组"},
|
||||
"app.library.selection.new-group": {"message": "新建分组"},
|
||||
"app.library.selection.remove-from-group": {"message": "移出分组"}
|
||||
}
|
||||
Reference in new issue
Block a user