mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-04-15 17:24:10 +00:00
Now that the legacy v1 frontend (commit 064bdf53) is gone, the v2 directory is the only frontend and the v2 suffix is just noise. Renames resources/scripts-v2 to resources/scripts via git mv (so git records the move as renames, preserving blame and log --follow), then bulk-rewrites the 152 files that imported via @v2/... to use @/scripts/... instead. The existing @ alias (resources/) covers the new path with no extra config needed.
Drops the now-unused @v2 alias from vite.config.js and points the laravel-vite-plugin entry at resources/scripts/main.ts. Updates the only blade reference (resources/views/app.blade.php) to match. The package.json test script (eslint ./resources/scripts) automatically targets the right place after the rename without any edit.
Verified: npm run build exits clean and the Vite warning lines now reference resources/scripts/plugins/i18n.ts, confirming every import resolved through the new path. git log --follow on any moved file walks back through its scripts-v2 history.
102 lines
2.2 KiB
TypeScript
102 lines
2.2 KiB
TypeScript
import { ref, computed, readonly } from 'vue'
|
|
import type { DeepReadonly, Ref, ComputedRef } from 'vue'
|
|
import type { ModalSize } from '@/scripts/config/constants'
|
|
|
|
export interface ModalState {
|
|
active: boolean
|
|
componentName: string
|
|
title: string
|
|
content: string
|
|
id: string
|
|
size: ModalSize
|
|
data: unknown
|
|
refreshData: (() => void) | null
|
|
variant: string
|
|
}
|
|
|
|
export interface OpenModalOptions {
|
|
componentName: string
|
|
title?: string
|
|
content?: string
|
|
id?: string
|
|
size?: ModalSize
|
|
data?: unknown
|
|
refreshData?: () => void
|
|
variant?: string
|
|
}
|
|
|
|
export interface UseModalReturn {
|
|
modalState: DeepReadonly<Ref<ModalState>>
|
|
isEdit: ComputedRef<boolean>
|
|
openModal: (options: OpenModalOptions) => void
|
|
closeModal: () => void
|
|
resetModalData: () => void
|
|
}
|
|
|
|
const DEFAULT_STATE: ModalState = {
|
|
active: false,
|
|
componentName: '',
|
|
title: '',
|
|
content: '',
|
|
id: '',
|
|
size: 'md',
|
|
data: null,
|
|
refreshData: null,
|
|
variant: '',
|
|
}
|
|
|
|
const modalState = ref<ModalState>({ ...DEFAULT_STATE })
|
|
|
|
/**
|
|
* Composable for managing a global modal.
|
|
* Supports opening modals by component name with props, and tracks edit vs create mode.
|
|
*/
|
|
export function useModal(): UseModalReturn {
|
|
const isEdit = computed<boolean>(() => modalState.value.id !== '')
|
|
|
|
/**
|
|
* Open a modal with the specified options.
|
|
*
|
|
* @param options - Modal configuration including component name and optional props
|
|
*/
|
|
function openModal(options: OpenModalOptions): void {
|
|
modalState.value = {
|
|
active: true,
|
|
componentName: options.componentName,
|
|
title: options.title ?? '',
|
|
content: options.content ?? '',
|
|
id: options.id ?? '',
|
|
size: options.size ?? 'md',
|
|
data: options.data ?? null,
|
|
refreshData: options.refreshData ?? null,
|
|
variant: options.variant ?? '',
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Close the modal with a brief delay for animation.
|
|
*/
|
|
function closeModal(): void {
|
|
modalState.value.active = false
|
|
|
|
setTimeout(() => {
|
|
resetModalData()
|
|
}, 300)
|
|
}
|
|
|
|
/**
|
|
* Reset modal data back to defaults.
|
|
*/
|
|
function resetModalData(): void {
|
|
modalState.value = { ...DEFAULT_STATE }
|
|
}
|
|
|
|
return {
|
|
modalState: readonly(modalState),
|
|
isEdit,
|
|
openModal,
|
|
closeModal,
|
|
resetModalData,
|
|
}
|
|
}
|