1- import { deepEqual } from "@/lib/deep-equal.js" ;
2- import { isObject } from '@/lib/object.js' ;
1+ import { isObject } from "@/lib/object.js" ;
32
4- import type { EnumOption , SchemaArrayValue , SchemaValue } from '@/core/index.js' ;
3+ import {
4+ isSchemaValueDeepEqual ,
5+ type EnumOption ,
6+ type SchemaArrayValue ,
7+ type SchemaValue ,
8+ } from "@/core/index.js" ;
59
610export interface OptionsMapper < V > {
711 fromValue : ( value : SchemaValue | undefined ) => V ;
812 toValue : ( value : V ) => SchemaValue | undefined ;
913}
1014
11- export function indexMapper ( options : EnumOption < SchemaValue > [ ] ) : OptionsMapper < number > {
15+ export function indexMapper (
16+ options : EnumOption < SchemaValue > [ ]
17+ ) : OptionsMapper < number > {
1218 const map = new Map ( options . map ( ( option , index ) => [ option . value , index ] ) ) ;
1319 return {
1420 fromValue ( value : SchemaValue | undefined ) {
@@ -22,15 +28,19 @@ export function indexMapper(options: EnumOption<SchemaValue>[]): OptionsMapper<n
2228 if ( ! isObject ( value ) ) {
2329 return options . findIndex ( ( option ) => option . value === value ) ;
2430 }
25- return options . findIndex ( ( option ) => deepEqual ( option . value , value ) ) ;
31+ return options . findIndex ( ( option ) =>
32+ isSchemaValueDeepEqual ( option . value , value )
33+ ) ;
2634 } ,
2735 toValue ( index : number ) {
2836 return options [ index ] ?. value ;
2937 } ,
3038 } ;
3139}
3240
33- export function stringIndexMapper ( options : EnumOption < SchemaValue > [ ] ) : OptionsMapper < string > {
41+ export function stringIndexMapper (
42+ options : EnumOption < SchemaValue > [ ]
43+ ) : OptionsMapper < string > {
3444 const { fromValue, toValue } = indexMapper ( options ) ;
3545 return {
3646 fromValue ( value ) {
@@ -47,9 +57,9 @@ export function singleOption<V>({
4757 value,
4858 update,
4959} : {
50- mapper : ( ) => OptionsMapper < V > ,
51- value : ( ) => SchemaValue | undefined ,
52- update : ( value : SchemaValue | undefined ) => void ,
60+ mapper : ( ) => OptionsMapper < V > ;
61+ value : ( ) => SchemaValue | undefined ;
62+ update : ( value : SchemaValue | undefined ) => void ;
5363} ) {
5464 const { fromValue, toValue } = $derived ( mapper ( ) ) ;
5565 return {
@@ -58,18 +68,18 @@ export function singleOption<V>({
5868 } ,
5969 set value ( v ) {
6070 update ( toValue ( v ) ) ;
61- }
62- }
71+ } ,
72+ } ;
6373}
6474
6575export function multipleOptions < V > ( {
6676 mapper,
6777 value,
6878 update,
6979} : {
70- mapper : ( ) => OptionsMapper < V > ,
71- value : ( ) => SchemaArrayValue | undefined ,
72- update : ( value : SchemaArrayValue ) => void ,
80+ mapper : ( ) => OptionsMapper < V > ;
81+ value : ( ) => SchemaArrayValue | undefined ;
82+ update : ( value : SchemaArrayValue ) => void ;
7383} ) {
7484 const { fromValue, toValue } = $derived ( mapper ( ) ) ;
7585 return {
@@ -78,6 +88,6 @@ export function multipleOptions<V>({
7888 } ,
7989 set value ( v ) {
8090 update ( v . map ( toValue ) ) ;
81- }
82- }
91+ } ,
92+ } ;
8393}
0 commit comments