@@ -32,11 +32,12 @@ import {
3232import { getActiveFunboxNames } from "../test/funbox/list" ;
3333import { SnapshotPreset } from "../constants/default-snapshot" ;
3434import { LayoutsList } from "../constants/layouts" ;
35- import { DataArrayPartial } from "slim-select/store" ;
35+ import { DataArrayPartial , Optgroup } from "slim-select/store" ;
3636
3737type SettingsGroups < T extends ConfigValue > = Record < string , SettingsGroup < T > > ;
3838
3939let customLayoutFluidSelect : SlimSelect | undefined ;
40+ let customPolyglotSelect : SlimSelect | undefined ;
4041
4142export const groups : SettingsGroups < ConfigValue > = { } ;
4243
@@ -476,21 +477,12 @@ async function fillSettingsPage(): Promise<void> {
476477 ".pageSettings .section[data-config-name='language'] select"
477478 ) as Element ;
478479
479- let html = "" ;
480- if ( languageGroups ) {
481- for ( const group of languageGroups ) {
482- html += `<optgroup label="${ group . name } ">` ;
483- for ( const language of group . languages ) {
484- const selected = language === Config . language ? "selected" : "" ;
485- const text = Strings . getLanguageDisplayString ( language ) ;
486- html += `<option value="${ language } " ${ selected } >${ text } </option>` ;
487- }
488- html += `</optgroup>` ;
489- }
490- }
491- element . innerHTML = html ;
492480 new SlimSelect ( {
493481 select : element ,
482+ data : getLanguageDropdownData (
483+ languageGroups ?? [ ] ,
484+ ( language ) => language === Config . language
485+ ) ,
494486 settings : {
495487 searchPlaceholder : "search" ,
496488 } ,
@@ -687,11 +679,11 @@ async function fillSettingsPage(): Promise<void> {
687679 Config . keymapSize
688680 ) ;
689681
690- const customLayoutfluidElement = document . querySelector (
691- ".pageSettings .section[data-config-name='customLayoutfluid'] select"
692- ) as Element ;
693-
694682 if ( customLayoutFluidSelect === undefined ) {
683+ const customLayoutfluidElement = document . querySelector (
684+ ".pageSettings .section[data-config-name='customLayoutfluid'] select"
685+ ) as Element ;
686+
695687 customLayoutFluidSelect = new SlimSelect ( {
696688 select : customLayoutfluidElement ,
697689 settings : { keepOrder : true } ,
@@ -706,6 +698,27 @@ async function fillSettingsPage(): Promise<void> {
706698 } ) ;
707699 }
708700
701+ if ( customPolyglotSelect === undefined ) {
702+ const customPolyglotElement = document . querySelector (
703+ ".pageSettings .section[data-config-name='customPolyglot'] select"
704+ ) as Element ;
705+
706+ customPolyglotSelect = new SlimSelect ( {
707+ select : customPolyglotElement ,
708+ data : getLanguageDropdownData ( languageGroups ?? [ ] , ( language ) =>
709+ Config . customPolyglot . includes ( language )
710+ ) ,
711+ events : {
712+ afterChange : ( newVal ) : void => {
713+ const customPolyglot = newVal . map ( ( it ) => it . value ) ;
714+ if ( customPolyglot . toSorted ( ) !== Config . customPolyglot . toSorted ( ) ) {
715+ void UpdateConfig . setCustomPolyglot ( customPolyglot ) ;
716+ }
717+ } ,
718+ } ,
719+ } ) ;
720+ }
721+
709722 $ ( ".pageSettings .section[data-config-name='tapeMargin'] input" ) . val (
710723 Config . tapeMargin
711724 ) ;
@@ -911,6 +924,13 @@ export async function update(groupUpdate = true): Promise<void> {
911924 ) {
912925 customLayoutFluidSelect . setData ( getLayoutfluidDropdownData ( ) ) ;
913926 }
927+
928+ if (
929+ customPolyglotSelect !== undefined &&
930+ customPolyglotSelect . getSelected ( ) !== Config . customPolyglot
931+ ) {
932+ customPolyglotSelect . setSelected ( Config . customPolyglot ) ;
933+ }
914934}
915935function toggleSettingsGroup ( groupName : string ) : void {
916936 const groupEl = $ ( `.pageSettings .settingsGroup.${ groupName } ` ) ;
@@ -1359,6 +1379,23 @@ export function setEventDisabled(value: boolean): void {
13591379 configEventDisabled = value ;
13601380}
13611381
1382+ function getLanguageDropdownData (
1383+ languageGroups : JSONData . LanguageGroup [ ] ,
1384+ isActive : ( val : string ) => boolean
1385+ ) : DataArrayPartial {
1386+ return languageGroups . map (
1387+ ( group ) =>
1388+ ( {
1389+ label : group . name ,
1390+ options : group . languages . map ( ( language ) => ( {
1391+ text : Strings . getLanguageDisplayString ( language ) ,
1392+ value : language ,
1393+ selected : isActive ( language ) ,
1394+ } ) ) ,
1395+ } as Optgroup )
1396+ ) ;
1397+ }
1398+
13621399function getLayoutfluidDropdownData ( ) : DataArrayPartial {
13631400 const customLayoutfluidActive = Config . customLayoutfluid . split ( "#" ) ;
13641401 return [
0 commit comments