@countriesdb/widget 0.1.27 → 0.1.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -940,6 +940,27 @@
940
940
  select.innerHTML += `<option value="${defaultValue}" disabled>Error: No country select present</option>`;
941
941
  }
942
942
  }
943
+ /**
944
+ * Get current subdivision config from window.CountriesDBConfig
945
+ * This ensures we always use the latest config values, even after widget reload
946
+ */
947
+ function getCurrentSubdivisionConfig(apiKey, backendUrl) {
948
+ const globalConfig = typeof window !== 'undefined' && window.CountriesDBConfig
949
+ ? window.CountriesDBConfig
950
+ : null;
951
+ return {
952
+ followRelated: globalConfig?.followRelated || false,
953
+ followUpward: globalConfig?.followUpward || false,
954
+ showSubdivisionType: globalConfig?.showSubdivisionType !== false,
955
+ allowParentSelection: globalConfig?.allowParentSelection || false,
956
+ preferOfficialSubdivisions: globalConfig?.preferOfficialSubdivisions || false,
957
+ subdivisionRomanizationPreference: globalConfig?.subdivisionRomanizationPreference,
958
+ preferLocalVariant: globalConfig?.preferLocalVariant || false,
959
+ forcedLanguage: globalConfig?.forcedLanguage,
960
+ defaultLanguage: globalConfig?.defaultLanguage,
961
+ subdivisionNameFilter: globalConfig?.subdivisionNameFilter,
962
+ };
963
+ }
943
964
  /**
944
965
  * Update subdivisions for all linked subdivision selects when country changes
945
966
  */
@@ -1040,8 +1061,13 @@
1040
1061
  }
1041
1062
  // Dispatch update event for user-initiated country change
1042
1063
  dispatchUpdateEvent(select, { type: 'country', reason: 'regular' });
1043
- // Update subdivisions
1044
- await updateSubdivisions(select, apiKey, backendUrl, state, subdivisionConfig);
1064
+ // Get current config dynamically to ensure we use the latest values
1065
+ const currentSubdivisionConfig = getCurrentSubdivisionConfig(apiKey, backendUrl);
1066
+ const currentConfig = typeof window !== 'undefined' && window.CountriesDBConfig
1067
+ ? window.CountriesDBConfig
1068
+ : config;
1069
+ // Update subdivisions with current config
1070
+ await updateSubdivisions(select, apiKey, backendUrl, state, currentSubdivisionConfig);
1045
1071
  const chosen = select.value;
1046
1072
  if (!chosen) {
1047
1073
  return;
@@ -1053,8 +1079,9 @@
1053
1079
  }
1054
1080
  // followUpward from country perspective
1055
1081
  // Only works when country is single-select (never for multi-select)
1056
- if (config.followUpward && !select.multiple && picked.is_subdivision_of) {
1057
- await handleFollowUpwardFromCountry(select, apiKey, backendUrl, state, config.followUpward, (s, key, code) => updateSubdivisionSelect(s, key, backendUrl, state, subdivisionConfig, code));
1082
+ const currentFollowUpward = currentConfig?.followUpward || false;
1083
+ if (currentFollowUpward && !select.multiple && picked.is_subdivision_of) {
1084
+ await handleFollowUpwardFromCountry(select, apiKey, backendUrl, state, currentFollowUpward, (s, key, code) => updateSubdivisionSelect(s, key, backendUrl, state, currentSubdivisionConfig, code));
1058
1085
  }
1059
1086
  };
1060
1087
  // Store and attach the handler
@@ -1171,7 +1198,7 @@
1171
1198
  followRelated: config.followRelated || false,
1172
1199
  followUpward: config.followUpward || false,
1173
1200
  countryNameFilter: config.countryNameFilter,
1174
- }, subdivisionConfig);
1201
+ });
1175
1202
  // After countries are set up, update subdivisions for any preselected countries
1176
1203
  const countrySelects = Array.from(document.querySelectorAll('.country-selection'));
1177
1204
  for (const select of countrySelects) {