File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ // SPDX-FileCopyrightText: 2026 LibreCode coop and LibreCode contributors
2+ // SPDX-License-Identifier: AGPL-3.0-or-later
3+
4+ export interface EditableSelectOption {
5+ id : string
6+ value : string
7+ }
8+
9+ export const createEditableSelectOptions = (
10+ values : string [ ] ,
11+ createId : ( ) => string ,
12+ ) : EditableSelectOption [ ] => values . map ( ( value ) => ( {
13+ id : createId ( ) ,
14+ value,
15+ } ) )
16+
17+ export const normalizeEditableSelectOptionValue = ( value : string ) : string => value . trim ( ) . toLowerCase ( )
18+
19+ export const parseEditableSelectOptionValues = ( value : string ) : string [ ] => value
20+ . split ( / \r ? \n / g)
21+ . map ( ( entry ) => entry . trim ( ) )
22+ . filter ( ( entry ) => entry . length > 0 )
23+
24+ export const extractEditableSelectOptionValues = ( options : EditableSelectOption [ ] ) : string [ ] => options . map ( ( { value } ) => value )
25+
26+ export const moveEditableSelectOption = (
27+ options : EditableSelectOption [ ] ,
28+ index : number ,
29+ direction : - 1 | 1 ,
30+ ) : EditableSelectOption [ ] => {
31+ const targetIndex = index + direction
32+ if ( index < 0 || index >= options . length || targetIndex < 0 || targetIndex >= options . length ) {
33+ return options
34+ }
35+
36+ const reordered = [ ...options ]
37+ const [ selected ] = reordered . splice ( index , 1 )
38+ reordered . splice ( targetIndex , 0 , selected )
39+ return reordered
40+ }
You can’t perform that action at this time.
0 commit comments