feat: manage project versions v2 (#5049)

* update add files copy and go to next step on just one file

* rename and reorder stages

* add metadata stage and update details stage

* implement files inside metadata stage

* use regular prettier instead of prettier eslint

* remove changelog stage config

* save button on details stage

* update edit buttons in versions table

* add collapse environment selector

* implement dependencies list in metadata step

* move dependencies into provider

* add suggested dependencies to metadata stage

* pnpm prepr

* fix unused var

* Revert "add collapse environment selector"

This reverts commit f90fabc7a57ff201f26e1b628eeced8e6ef75865.

* hide resource pack loader only when its the only loader

* fix no dependencies for modpack

* add breadcrumbs with hide breadcrumb option

* wider stages

* add proper horizonal scroll breadcrumbs

* fix titles

* handle save version in version page

* remove box shadow

* add notification provider to storybook

* add drop area for versions to drop file right into page

* fix mobile versions table buttons overflowing

* pnpm prepr

* fix drop file opening modal in wrong stage

* implement invalid file for dropping files

* allow horizontal scroll on breadcrumbs

* update infer.js as best as possible

* add create version button uploading version state

* add extractVersionFromFilename for resource pack and datapack

* allow jars for datapack project

* detect multiple loaders when possible

* iris means compatible with optifine too

* infer environment on loader change as well

* add tooltip

* prevent navigate forward when cannot go to next step

* larger breadcrumb click targets

* hide loaders and mc versions stage until files added

* fix max width in header

* fix add files from metadata step jumping steps

* define width in NewModal instead

* disable remove dependency in metadata stage

* switch metadata and details buttons positions

* fix remove button spacing

* do not allow duplicate suggested dependencies

* fix version detection for fabric minecraft version semvar

* better verion number detection based on filename

* show resource pack loader but uneditable

* remove vanilla shader detection

* refactor: break up large infer.js into ts and modules

* remove duplicated types

* add fill missing from file name step

* pnpm prepr

* fix neoforge loader parse failing and not adding neoforge loader

* add missing pack formats

* handle new pack format

* pnpm prepr

* add another regex where it is version in anywhere in filename

* only show resource pack or data pack options for filetype on datapack project

* add redundant zip folder check

* reject RP and DP if has redundant folder

* fix hide stage in breadcrumb

* add snapshot group key in case no release version. brings out 26.1 snapshots

* pnpm prepr

* open in group if has something selected

* fix resource pack loader uneditable if accidentally selected on different project type

* add new environment tags

* add unknown and not applicable environment tags

* pnpm prepr

* use shared constant on labels

* use ref for timeout

* remove console logs

* remove box shadow only for cm-content

* feat: xhr upload + fix wrangler prettierignore

* fix: upload content type fix

* fix dependencies version width

* fix already added dependencies logic

* add changelog minheight

* set progress percentage on button

* add legacy fabric detection logic

* lint

* small update on create version button label

---------

Co-authored-by: Calum H. (IMB11) <contact@cal.engineer>
Co-authored-by: Prospector <6166773+Prospector@users.noreply.github.com>
This commit is contained in:
Truman Gao
2026-01-12 12:41:14 -07:00
committed by GitHub
parent b46f6d0141
commit 61c8cd75cd
64 changed files with 3185 additions and 1709 deletions

View File

@@ -15,6 +15,10 @@
<script setup lang="ts">
import { onMounted, ref } from 'vue'
import { injectNotificationManager } from '../../providers'
const { addNotification } = injectNotificationManager()
const props = withDefaults(
defineProps<{
accept: string
@@ -27,7 +31,6 @@ const props = withDefaults(
const emit = defineEmits(['change'])
const dropAreaRef = ref<HTMLDivElement>()
const fileAllowed = ref(false)
const hideDropArea = () => {
if (dropAreaRef.value) {
@@ -36,29 +39,61 @@ const hideDropArea = () => {
}
const handleDrop = (event: DragEvent) => {
event.preventDefault()
hideDropArea()
if (event.dataTransfer && event.dataTransfer.files && fileAllowed.value) {
emit('change', event.dataTransfer.files)
const files = event.dataTransfer?.files
if (!files || files.length === 0) return
const file = files[0]
if (!matchesAccept({ getAsFile: () => file } as DataTransferItem, props.accept)) {
addNotification({
title: 'Invalid file',
text: `The file "${file.name}" is not a valid file type for this project.`,
type: 'error',
})
return
}
emit('change', files)
}
function matchesAccept(file: DataTransferItem, accept?: string): boolean {
if (!accept || accept.trim() === '') return true
const fileType = file.type // e.g. "image/png"
const fileName = file.getAsFile()?.name.toLowerCase() ?? ''
return accept
.split(',')
.map((t) => t.trim().toLowerCase())
.some((token) => {
// .png, .jpg
if (token.startsWith('.')) {
return fileName.endsWith(token)
}
// image/*
if (token.endsWith('/*')) {
const base = token.slice(0, -1) // "image/"
return fileType.startsWith(base)
}
// image/png
return fileType === token
})
}
const allowDrag = (event: DragEvent) => {
const file = event.dataTransfer?.items[0]
if (
file &&
props.accept
.split(',')
.reduce((acc, t) => acc || file.type.startsWith(t) || file.type === t || t === '*', false)
) {
fileAllowed.value = true
event.dataTransfer.dropEffect = 'copy'
event.preventDefault()
if (dropAreaRef.value) {
dropAreaRef.value.style.visibility = 'visible'
}
} else {
fileAllowed.value = false
hideDropArea()
const item = event.dataTransfer?.items?.[0]
if (!item || item.kind !== 'file') return
event.preventDefault()
event.dataTransfer!.dropEffect = 'copy'
if (dropAreaRef.value) {
dropAreaRef.value.style.visibility = 'visible'
}
}

View File

@@ -50,6 +50,10 @@ import { FolderUpIcon } from '@modrinth/assets'
import { fileIsValid } from '@modrinth/utils'
import { ref } from 'vue'
import { injectNotificationManager } from '../../providers'
const { addNotification } = injectNotificationManager()
const fileInput = ref<HTMLInputElement | null>(null)
const emit = defineEmits<{
@@ -58,7 +62,6 @@ const emit = defineEmits<{
const props = withDefaults(
defineProps<{
prompt?: string
primaryPrompt?: string | null
secondaryPrompt?: string | null
multiple?: boolean
@@ -69,20 +72,58 @@ const props = withDefaults(
size?: 'small' | 'standard'
}>(),
{
prompt: 'Drag and drop files or click to browse',
primaryPrompt: 'Drag and drop files or click to browse',
secondaryPrompt: 'You can try to drag files or folder or click this area to select it',
primaryPrompt: 'Drop files here or click to upload',
secondaryPrompt: 'Only supported file types will be accepted',
size: 'standard',
},
)
const files = ref<File[]>([])
function matchesAccept(file: File, accept?: string): boolean {
if (!accept || accept.trim() === '') return true
const fileType = file.type // e.g. "image/png"
const fileName = file.name.toLowerCase()
return accept
.split(',')
.map((t) => t.trim().toLowerCase())
.some((token) => {
// .png, .jpg
if (token.startsWith('.')) {
return fileName.endsWith(token)
}
// image/*
if (token.endsWith('/*')) {
const base = token.slice(0, -1) // "image/"
return fileType.startsWith(base)
}
// image/png
return fileType === token
})
}
function addFiles(incoming: FileList, shouldNotReset = false) {
if (!shouldNotReset || props.shouldAlwaysReset) {
files.value = Array.from(incoming)
}
// Filter out files that don't match the accept prop
const invalidFiles = files.value.filter((file) => !matchesAccept(file, props.accept))
if (invalidFiles.length > 0) {
for (const file of invalidFiles) {
addNotification({
title: 'Invalid file',
text: `The file "${file.name}" is not a valid file type for this project.`,
type: 'error',
})
}
files.value = files.value.filter((file) => matchesAccept(file, props.accept))
}
const validationOptions = {
maxSize: props.maxSize ?? undefined,
alertOnInvalid: true,

View File

@@ -315,6 +315,7 @@ const props = withDefaults(
placeholder?: string
maxLength?: number
maxHeight?: number
minHeight?: number
}>(),
{
modelValue: '',
@@ -324,6 +325,7 @@ const props = withDefaults(
placeholder: 'Write something...',
maxLength: undefined,
maxHeight: undefined,
minHeight: undefined,
},
)
@@ -360,9 +362,9 @@ onMounted(() => {
border: 'none',
},
'.cm-content': {
minHeight: props.minHeight ? `${props.minHeight}px` : '200px',
marginBlockEnd: '0.5rem',
padding: '0.5rem',
minHeight: '200px',
caretColor: 'var(--color-contrast)',
width: '100%',
},
@@ -609,9 +611,9 @@ watch(
border: 'none',
},
'.cm-content': {
minHeight: props.minHeight ? `${props.minHeight}px` : '200px',
marginBlockEnd: '0.5rem',
padding: '0.5rem',
minHeight: '200px',
caretColor: 'var(--color-contrast)',
width: '100%',
opacity: newValue ? 0.6 : 1,

View File

@@ -6,11 +6,54 @@
:on-hide="onModalHide"
:closable="true"
:close-on-click-outside="false"
:width="resolvedMaxWidth"
>
<template #title>
<div class="flex flex-wrap items-center gap-1 text-secondary">
<span class="text-lg font-bold text-contrast sm:text-xl">{{ resolvedTitle }}</span>
<div
v-if="breadcrumbs && !resolveCtxFn(currentStage.nonProgressStage, context)"
class="relative w-full"
>
<div
class="pointer-events-none absolute left-0 top-0 bottom-0 w-8 bg-gradient-to-r from-bg-raised to-transparent z-10 transition-opacity duration-200"
:class="showLeftShadow ? 'opacity-100' : 'opacity-0'"
/>
<div
ref="breadcrumbScroller"
class="flex w-full overflow-x-auto overflow-y-hidden scrollbar-hide pr-6"
@wheel.prevent="onBreadcrumbWheel"
@scroll="updateScrollShadows"
>
<template v-for="(stage, index) in breadcrumbStages" :key="stage.id">
<div
:ref="(el) => setBreadcrumbRef(stage.id, el as HTMLElement | null)"
class="flex w-max items-center"
>
<button
class="bg-transparent active:scale-95 font-bold text-secondary p-0 w-max py-3 px-1"
:class="{
'!text-contrast font-bold': resolveCtxFn(currentStage.id, context) === stage.id,
'font-bold': resolveCtxFn(currentStage.id, context) !== stage.id,
'opacity-50 cursor-not-allowed': cannotNavigateToStage(index),
}"
:disabled="cannotNavigateToStage(index)"
@click="setStage(stage.id)"
>
{{ resolveCtxFn(stage.title, context) }}
</button>
<ChevronRightIcon
v-if="index < breadcrumbStages.length - 1"
class="h-5 w-5 text-secondary"
stroke-width="3"
/>
</div>
</template>
</div>
<div
class="pointer-events-none absolute right-0 top-0 bottom-0 w-8 bg-gradient-to-l from-bg-raised to-transparent z-10 transition-opacity duration-200"
:class="showRightShadow ? 'opacity-100' : 'opacity-0'"
/>
</div>
<span v-else class="text-lg font-bold text-contrast sm:text-xl">{{ resolvedTitle }}</span>
</template>
<progress
@@ -58,9 +101,10 @@
</template>
<script lang="ts">
import { ChevronRightIcon } from '@modrinth/assets'
import { ButtonStyled, NewModal } from '@modrinth/ui'
import type { Component } from 'vue'
import { computed, ref, useTemplateRef } from 'vue'
import { computed, nextTick, ref, useTemplateRef, watch } from 'vue'
export interface StageButtonConfig {
label?: string
@@ -79,9 +123,13 @@ export interface StageConfigInput<T> {
stageContent: Component
title: MaybeCtxFn<T, string>
skip?: MaybeCtxFn<T, boolean>
hideStageInBreadcrumb?: MaybeCtxFn<T, boolean>
nonProgressStage?: MaybeCtxFn<T, boolean>
cannotNavigateForward?: MaybeCtxFn<T, boolean>
leftButtonConfig: MaybeCtxFn<T, StageButtonConfig | null>
rightButtonConfig: MaybeCtxFn<T, StageButtonConfig | null>
/** Max width for the modal content and header defined in px (e.g., '460px', '600px'). Defaults to '460px'. */
maxWidth?: MaybeCtxFn<T, string>
}
export function resolveCtxFn<T, R>(value: MaybeCtxFn<T, R>, ctx: T): R {
@@ -93,6 +141,8 @@ export function resolveCtxFn<T, R>(value: MaybeCtxFn<T, R>, ctx: T): R {
const props = defineProps<{
stages: StageConfigInput<T>[]
context: T
breadcrumbs?: boolean
fitContent?: boolean
}>()
const modal = useTemplateRef<InstanceType<typeof NewModal>>('modal')
@@ -178,6 +228,12 @@ const nonProgressStage = computed(() => {
return resolveCtxFn(stage.nonProgressStage, props.context)
})
const resolvedMaxWidth = computed(() => {
const stage = currentStage.value
if (!stage?.maxWidth) return '560px'
return resolveCtxFn(stage.maxWidth, props.context)
})
const progressValue = computed(() => {
const isProgressStage = (stage: StageConfigInput<T>) => {
if (resolveCtxFn(stage.nonProgressStage, props.context)) return false
@@ -193,6 +249,99 @@ const progressValue = computed(() => {
return totalCount > 0 ? (completedCount / totalCount) * 100 : 0
})
const breadcrumbScroller = ref<HTMLElement | null>(null)
const breadcrumbRefs = ref<Map<string, HTMLElement>>(new Map())
const showLeftShadow = ref(false)
const showRightShadow = ref(false)
function setBreadcrumbRef(stageId: string, el: HTMLElement | null) {
if (el) breadcrumbRefs.value.set(stageId, el)
else breadcrumbRefs.value.delete(stageId)
}
function scrollToCurrentBreadcrumb() {
const stage = currentStage.value
if (!stage || !breadcrumbScroller.value) return
const el = breadcrumbRefs.value.get(stage.id)
if (!el) return
nextTick(() => {
breadcrumbScroller.value?.scrollTo({
left: el.offsetLeft - 50,
behavior: 'smooth',
})
})
}
function updateScrollShadows() {
const el = breadcrumbScroller.value
if (!el) {
showLeftShadow.value = false
showRightShadow.value = false
return
}
showLeftShadow.value = el.scrollLeft > 0
showRightShadow.value = el.scrollLeft < el.scrollWidth - el.clientWidth - 1
}
function onBreadcrumbWheel(e: WheelEvent) {
if (!breadcrumbScroller.value) return
const el = breadcrumbScroller.value
const canScrollHorizontally = el.scrollWidth > el.clientWidth
if (canScrollHorizontally) {
// Support both horizontal and vertical scroll input
const delta = Math.abs(e.deltaX) > Math.abs(e.deltaY) ? e.deltaX : e.deltaY
el.scrollLeft += delta
}
}
// Stages that are not skipped (visible in breadcrumbs)
const breadcrumbStages = computed(() => {
return props.stages.filter((stage) => {
const visibleStep =
!resolveCtxFn(stage.skip, props.context) &&
!resolveCtxFn(stage.nonProgressStage, props.context) &&
!resolveCtxFn(stage.hideStageInBreadcrumb, props.context)
return visibleStep
})
})
// Check if navigation to a breadcrumb stage is allowed
// Navigation backwards is always allowed, but forward navigation requires all intermediate stages to allow it
function cannotNavigateToStage(breadcrumbIndex: number): boolean {
const targetStage = breadcrumbStages.value[breadcrumbIndex]
if (!targetStage) return false
const targetStageIndex = props.stages.findIndex((s) => s.id === targetStage.id)
if (targetStageIndex === -1) return false
// Always allow navigating to current or previous stages
if (targetStageIndex <= currentStageIndex.value) return false
// For forward navigation, check all stages between current and target
for (let i = currentStageIndex.value; i < targetStageIndex; i++) {
const stage = props.stages[i]
if (stage.skip && resolveCtxFn(stage.skip, props.context)) continue
if (resolveCtxFn(stage.cannotNavigateForward, props.context)) {
return true
}
}
return false
}
watch([breadcrumbStages, currentStageIndex], () => nextTick(() => updateScrollShadows()), {
immediate: true,
})
watch(currentStageIndex, () => {
scrollToCurrentBreadcrumb()
})
const emit = defineEmits<{
(e: 'refresh-data' | 'hide'): void
}>()
@@ -228,4 +377,13 @@ progress::-webkit-progress-value {
progress::-moz-progress-bar {
@apply bg-contrast;
}
.scrollbar-hide {
-ms-overflow-style: none;
scrollbar-width: none;
}
.scrollbar-hide::-webkit-scrollbar {
display: none;
}
</style>