Merge remote-tracking branch 'myori/main' into p284

This commit is contained in:
hjlarry
2025-10-04 15:27:53 +08:00
441 changed files with 8321 additions and 6411 deletions

View File

@ -15,24 +15,17 @@ const strToKeyValueList = (value: string) => {
})
}
const normalizeList = (items: KeyValue[]) => {
return items.map(item => ({
...item,
id: item.id || uniqueId(UNIQUE_ID_PREFIX),
}))
}
const stringifyList = (items: KeyValue[], noFilter?: boolean) => {
const source = noFilter ? items : items.filter(item => item.key && item.value)
return source.map(item => `${item.key}:${item.value}`).join('\n')
}
const useKeyValueList = (value: string, onChange: (value: string) => void, noFilter?: boolean) => {
const [list, doSetList] = useState<KeyValue[]>(value ? normalizeList(strToKeyValueList(value)) : [])
const setList = useCallback((nextList: KeyValue[]) => {
const normalized = normalizeList(nextList)
doSetList(normalized)
const [list, doSetList] = useState<KeyValue[]>(() => value ? strToKeyValueList(value) : [])
const setList = (l: KeyValue[]) => {
doSetList(l.map((item) => {
return {
...item,
id: item.id || uniqueId(UNIQUE_ID_PREFIX),
}
}))
}
useEffect(() => {
if (noFilter)
return