mirror of
https://github.com/johndoe6345789/metabuilder.git
synced 2026-04-25 06:14:59 +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>
84 lines
1.8 KiB
TypeScript
84 lines
1.8 KiB
TypeScript
/**
|
|
* useMap hook - Typed Map state management
|
|
* Provides React state management for Map data structures with full operation support
|
|
*/
|
|
|
|
import { useState, useCallback } from 'react'
|
|
|
|
export interface UseMapReturn<K, V> {
|
|
data: Map<K, V>
|
|
set: (key: K, value: V) => void
|
|
get: (key: K) => V | undefined
|
|
delete: (key: K) => void
|
|
clear: () => void
|
|
has: (key: K) => boolean
|
|
entries: () => IterableIterator<[K, V]>
|
|
keys: () => IterableIterator<K>
|
|
values: () => IterableIterator<V>
|
|
}
|
|
|
|
/**
|
|
* Hook for managing Map state
|
|
* @template K - The type of keys in the map
|
|
* @template V - The type of values in the map
|
|
* @param initialEntries - Optional initial key-value pairs
|
|
* @returns Object containing the map and operation methods
|
|
*/
|
|
export function useMap<K, V>(initialEntries?: Array<[K, V]>): UseMapReturn<K, V> {
|
|
const [data, setData] = useState<Map<K, V>>(
|
|
() => new Map(initialEntries)
|
|
)
|
|
|
|
const set = useCallback((key: K, value: V) => {
|
|
setData((prevMap) => {
|
|
const newMap = new Map(prevMap)
|
|
newMap.set(key, value)
|
|
return newMap
|
|
})
|
|
}, [])
|
|
|
|
const get = useCallback((key: K) => {
|
|
return data.get(key)
|
|
}, [data])
|
|
|
|
const deleteKey = useCallback((key: K) => {
|
|
setData((prevMap) => {
|
|
const newMap = new Map(prevMap)
|
|
newMap.delete(key)
|
|
return newMap
|
|
})
|
|
}, [])
|
|
|
|
const clear = useCallback(() => {
|
|
setData(new Map())
|
|
}, [])
|
|
|
|
const has = useCallback((key: K) => {
|
|
return data.has(key)
|
|
}, [data])
|
|
|
|
const entries = useCallback(() => {
|
|
return data.entries()
|
|
}, [data])
|
|
|
|
const keys = useCallback(() => {
|
|
return data.keys()
|
|
}, [data])
|
|
|
|
const values = useCallback(() => {
|
|
return data.values()
|
|
}, [data])
|
|
|
|
return {
|
|
data,
|
|
set,
|
|
get,
|
|
delete: deleteKey,
|
|
clear,
|
|
has,
|
|
entries,
|
|
keys,
|
|
values,
|
|
}
|
|
}
|