mirror of
https://github.com/johndoe6345789/metabuilder.git
synced 2026-04-25 14:25:02 +00:00
Directory Restructuring: - qml/qml-components/qml-components/* → qml/components/ (flattens nesting) - All 104 QML files moved with git history preserved - Eliminates redundant qml-components nesting Documentation Updates: - ARCHITECTURE.md: Updated qml/components references (2 locations) - GETTING_STARTED.md: Updated qml/components path (1 location, end of file) - README.md: Updated qml/components references (3 locations) - CODE_REVIEW.md: Updated qml/components file paths (4 locations) - docs/ARCHITECTURE.md: Complete refactor with qml/components paths Verification: - ✅ No remaining qml-components/ references in documentation - ✅ All 104 QML files present in flattened structure - ✅ Directory structure verified (12 component categories) - ✅ First-class directory naming convention Structure Post-Refactor: qml/ ├── components/ │ ├── atoms/ (16 files) │ ├── core/ (11 files) │ ├── data-display/ (10 files) │ ├── feedback/ (11 files) │ ├── form/ (19 files) │ ├── lab/ (11 files) │ ├── layout/ (12 files) │ ├── navigation/ (12 files) │ ├── surfaces/ (7 files) │ ├── theming/ (4 files) │ └── utils/ (13 files) ├── hybrid/ └── widgets/ Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
60 lines
1.5 KiB
TypeScript
60 lines
1.5 KiB
TypeScript
/**
|
|
* useStack hook - Stack/LIFO (Last In First Out) operations
|
|
* Provides React state management for stack data structures
|
|
*/
|
|
|
|
import { useCallback, useRef, useState } from 'react'
|
|
|
|
export interface UseStackReturn<T> {
|
|
items: T[]
|
|
push: (item: T) => void
|
|
pop: () => T | undefined
|
|
peek: () => T | undefined
|
|
clear: () => void
|
|
isEmpty: boolean
|
|
size: number
|
|
}
|
|
|
|
/**
|
|
* Hook for managing stack state with LIFO (Last In First Out) operations
|
|
* @template T - The type of items in the stack
|
|
* @param initialItems - Optional initial items for the stack (bottom to top)
|
|
* @returns Object containing the stack items and operation methods
|
|
*/
|
|
export function useStack<T>(initialItems?: T[]): UseStackReturn<T> {
|
|
const [items, setItems] = useState<T[]>(initialItems ?? [])
|
|
const lastPoppedRef = useRef<T | undefined>(undefined)
|
|
|
|
const push = useCallback((item: T) => {
|
|
setItems((prevItems) => [...prevItems, item])
|
|
}, [])
|
|
|
|
const pop = useCallback(() => {
|
|
if (items.length === 0) {
|
|
return undefined
|
|
}
|
|
const popped = items[items.length - 1]
|
|
lastPoppedRef.current = popped
|
|
setItems((prevItems) => prevItems.slice(0, -1))
|
|
return popped
|
|
}, [items])
|
|
|
|
const peek = useCallback(() => {
|
|
return items.length > 0 ? items[items.length - 1] : undefined
|
|
}, [items])
|
|
|
|
const clear = useCallback(() => {
|
|
setItems([])
|
|
}, [])
|
|
|
|
return {
|
|
items,
|
|
push,
|
|
pop,
|
|
peek,
|
|
clear,
|
|
isEmpty: items.length === 0,
|
|
size: items.length,
|
|
}
|
|
}
|