1- import ko from "knockout" ;
2- import arches from "arches" ;
3- import WidgetViewModel from "viewmodels/widget" ;
4-
5- let LANGUAGE_LOOKUP = { } ;
6- const LanguageSelectViewModel = function ( params ) {
7- params . configKeys = [ "placeholder" , "width" , "uneditable" ] ;
8-
9- WidgetViewModel . apply ( this , [ params ] ) ;
10- const self = this ;
11-
12- self . options = ko . observableArray ( ) ;
13-
14- self . displayValue = ko . computed ( ( ) => {
15- const selectedOption = self . options ( ) . find (
16- ( option ) => option . id === self . value ( )
17- ) ;
18- return selectedOption ? selectedOption . text : "" ;
19- } ) ;
20-
21- async function fetchLanguages ( ) {
22- let languages = [ ] ;
23- try {
24- const response = await fetch ( arches . urls . languages ) ;
25- const data = await response . json ( ) ;
26- languages = data . languages ;
27- } catch ( error ) {
28- console . error ( 'Error fetching languages:' , error ) ;
29- }
30- return languages ;
31- }
32-
33- async function updateLanguageLookups ( ) {
34- const languageCodes = Object . keys ( LANGUAGE_LOOKUP ) ;
35- if ( languageCodes . length === 0 ) {
36- const languages = await fetchLanguages ( ) ;
37- const options = languages . map ( ( lang ) => {
38- LANGUAGE_LOOKUP [ lang . code ] = lang . name ;
39- return { id : lang . code , text : lang . name } ;
40- } ) ;
41- self . options ( options ) ;
42- }
43- else if ( languageCodes . length > 0 && self . options ( ) . length <= 0 ) {
44- self . options (
45- Object . entries ( LANGUAGE_LOOKUP ) . map (
46- ( [ code , name ] ) => (
47- { id : code , text : name }
48- )
49- )
50- ) ;
51- }
52- }
53-
54- const init = async ( ) => {
55- await updateLanguageLookups ( ) ;
56- }
57-
58- init ( ) ;
59- } ;
60-
61- export default LanguageSelectViewModel ;
1+ // Kept as a re-export for backward compatibility with downstream arches applications.
2+ export { default } from "viewmodels/external-domain-select" ;
0 commit comments