mirror of
https://gitverse.ru/anarchic/claude-code
synced 2026-05-05 16:02:38 +00:00
new initial commit (history rewritten)
This commit is contained in:
commit
c1996f2e3b
1907 changed files with 514172 additions and 0 deletions
50
components/CustomSelect/option-map.ts
Normal file
50
components/CustomSelect/option-map.ts
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
import type { ReactNode } from 'react'
|
||||
import type { OptionWithDescription } from './select.js'
|
||||
|
||||
type OptionMapItem<T> = {
|
||||
label: ReactNode
|
||||
value: T
|
||||
description?: string
|
||||
previous: OptionMapItem<T> | undefined
|
||||
next: OptionMapItem<T> | undefined
|
||||
index: number
|
||||
}
|
||||
|
||||
export default class OptionMap<T> extends Map<T, OptionMapItem<T>> {
|
||||
readonly first: OptionMapItem<T> | undefined
|
||||
readonly last: OptionMapItem<T> | undefined
|
||||
|
||||
constructor(options: OptionWithDescription<T>[]) {
|
||||
const items: Array<[T, OptionMapItem<T>]> = []
|
||||
let firstItem: OptionMapItem<T> | undefined
|
||||
let lastItem: OptionMapItem<T> | undefined
|
||||
let previous: OptionMapItem<T> | undefined
|
||||
let index = 0
|
||||
|
||||
for (const option of options) {
|
||||
const item = {
|
||||
label: option.label,
|
||||
value: option.value,
|
||||
description: option.description,
|
||||
previous,
|
||||
next: undefined,
|
||||
index,
|
||||
}
|
||||
|
||||
if (previous) {
|
||||
previous.next = item
|
||||
}
|
||||
|
||||
firstItem ||= item
|
||||
lastItem = item
|
||||
|
||||
items.push([option.value, item])
|
||||
index++
|
||||
previous = item
|
||||
}
|
||||
|
||||
super(items)
|
||||
this.first = firstItem
|
||||
this.last = lastItem
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue