@countriesdb/widget 0.1.31 → 0.1.33
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/dom-manipulation.js +4 -10
- package/dist/index.esm.js +53 -20
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/initialization.js +49 -10
- package/package.json +1 -1
package/dist/dom-manipulation.js
CHANGED
|
@@ -105,9 +105,8 @@ export function applyPreselectedValue(select, apiKey) {
|
|
|
105
105
|
// Read from select element like old widget (line 740)
|
|
106
106
|
const tempOnce = select.dataset._widgetTempPreselect;
|
|
107
107
|
const permanent = select.getAttribute('data-preselected') || select.dataset.preselected;
|
|
108
|
-
const
|
|
109
|
-
|
|
110
|
-
: permanent;
|
|
108
|
+
const hasTemp = tempOnce !== undefined && tempOnce !== null && String(tempOnce).trim() !== '';
|
|
109
|
+
const chosen = hasTemp ? tempOnce : permanent;
|
|
111
110
|
if (!chosen || (typeof chosen === 'string' && chosen.trim() === '')) {
|
|
112
111
|
return;
|
|
113
112
|
}
|
|
@@ -128,16 +127,11 @@ export function applyPreselectedValue(select, apiKey) {
|
|
|
128
127
|
// Single select: set single value
|
|
129
128
|
select.value = value;
|
|
130
129
|
}
|
|
131
|
-
// Consume preselect so it's only applied once (like old widget)
|
|
130
|
+
// Consume temp preselect so it's only applied once (like old widget)
|
|
131
|
+
// Note: We keep data-preselected attribute to support reload: true
|
|
132
132
|
if (select.dataset._widgetTempPreselect !== undefined) {
|
|
133
133
|
delete select.dataset._widgetTempPreselect;
|
|
134
134
|
}
|
|
135
|
-
if (select.dataset.preselected !== undefined) {
|
|
136
|
-
delete select.dataset.preselected;
|
|
137
|
-
}
|
|
138
|
-
if (select.hasAttribute('data-preselected')) {
|
|
139
|
-
select.removeAttribute('data-preselected');
|
|
140
|
-
}
|
|
141
135
|
}
|
|
142
136
|
/**
|
|
143
137
|
* Handle API error by showing error message in select
|
package/dist/index.esm.js
CHANGED
|
@@ -106,9 +106,8 @@ function applyPreselectedValue(select, apiKey) {
|
|
|
106
106
|
// Read from select element like old widget (line 740)
|
|
107
107
|
const tempOnce = select.dataset._widgetTempPreselect;
|
|
108
108
|
const permanent = select.getAttribute('data-preselected') || select.dataset.preselected;
|
|
109
|
-
const
|
|
110
|
-
|
|
111
|
-
: permanent;
|
|
109
|
+
const hasTemp = tempOnce !== undefined && tempOnce !== null && String(tempOnce).trim() !== '';
|
|
110
|
+
const chosen = hasTemp ? tempOnce : permanent;
|
|
112
111
|
if (!chosen || (typeof chosen === 'string' && chosen.trim() === '')) {
|
|
113
112
|
return;
|
|
114
113
|
}
|
|
@@ -129,16 +128,11 @@ function applyPreselectedValue(select, apiKey) {
|
|
|
129
128
|
// Single select: set single value
|
|
130
129
|
select.value = value;
|
|
131
130
|
}
|
|
132
|
-
// Consume preselect so it's only applied once (like old widget)
|
|
131
|
+
// Consume temp preselect so it's only applied once (like old widget)
|
|
132
|
+
// Note: We keep data-preselected attribute to support reload: true
|
|
133
133
|
if (select.dataset._widgetTempPreselect !== undefined) {
|
|
134
134
|
delete select.dataset._widgetTempPreselect;
|
|
135
135
|
}
|
|
136
|
-
if (select.dataset.preselected !== undefined) {
|
|
137
|
-
delete select.dataset.preselected;
|
|
138
|
-
}
|
|
139
|
-
if (select.hasAttribute('data-preselected')) {
|
|
140
|
-
select.removeAttribute('data-preselected');
|
|
141
|
-
}
|
|
142
136
|
}
|
|
143
137
|
/**
|
|
144
138
|
* Handle API error by showing error message in select
|
|
@@ -695,23 +689,62 @@ async function updateSubdivisionSelect(select, apiKey, backendUrl, state, config
|
|
|
695
689
|
}
|
|
696
690
|
}
|
|
697
691
|
/**
|
|
698
|
-
* Get current subdivision config from window.CountriesDBConfig
|
|
692
|
+
* Get current subdivision config from window.CountriesDBConfig and script URL
|
|
699
693
|
* This ensures we always use the latest config values, even after widget reload
|
|
700
694
|
*/
|
|
701
695
|
function getCurrentSubdivisionConfig(apiKey, backendUrl) {
|
|
702
696
|
const globalConfig = typeof window !== 'undefined' && window.CountriesDBConfig
|
|
703
697
|
? window.CountriesDBConfig
|
|
704
698
|
: null;
|
|
699
|
+
// Also check script URL parameters (for backward compatibility and reload scenarios)
|
|
700
|
+
let scriptUrl = null;
|
|
701
|
+
try {
|
|
702
|
+
const scripts = Array.from(document.getElementsByTagName('script'));
|
|
703
|
+
const loaderScript = scripts.find((s) => s.src && (s.src.includes('@countriesdb/widget') ||
|
|
704
|
+
s.src.includes('widget/dist/index.js'))) || null;
|
|
705
|
+
if (loaderScript && loaderScript.src) {
|
|
706
|
+
scriptUrl = new URL(loaderScript.src);
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
catch {
|
|
710
|
+
// Ignore errors
|
|
711
|
+
}
|
|
712
|
+
// Import parseBoolean from dom-manipulation
|
|
713
|
+
const parseBoolean = (value) => {
|
|
714
|
+
if (value === null || value === undefined) {
|
|
715
|
+
return false;
|
|
716
|
+
}
|
|
717
|
+
const lowered = String(value).trim().toLowerCase();
|
|
718
|
+
return !(lowered === '0' || lowered === 'false');
|
|
719
|
+
};
|
|
705
720
|
return {
|
|
706
|
-
followRelated: globalConfig?.followRelated
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
721
|
+
followRelated: globalConfig?.followRelated !== undefined
|
|
722
|
+
? globalConfig.followRelated
|
|
723
|
+
: parseBoolean(scriptUrl?.searchParams.get('follow_related') ?? 'false'),
|
|
724
|
+
followUpward: globalConfig?.followUpward !== undefined
|
|
725
|
+
? globalConfig.followUpward
|
|
726
|
+
: parseBoolean(scriptUrl?.searchParams.get('follow_upward') ?? 'false'),
|
|
727
|
+
showSubdivisionType: globalConfig?.showSubdivisionType !== undefined
|
|
728
|
+
? globalConfig.showSubdivisionType
|
|
729
|
+
: parseBoolean(scriptUrl?.searchParams.get('show_subdivision_type') ?? '1'),
|
|
730
|
+
allowParentSelection: globalConfig?.allowParentSelection !== undefined
|
|
731
|
+
? globalConfig.allowParentSelection
|
|
732
|
+
: parseBoolean(scriptUrl?.searchParams.get('allow_parent_selection') ?? 'false'),
|
|
733
|
+
preferOfficialSubdivisions: globalConfig?.preferOfficialSubdivisions !== undefined
|
|
734
|
+
? globalConfig.preferOfficialSubdivisions
|
|
735
|
+
: parseBoolean(scriptUrl?.searchParams.get('prefer_official') ?? 'false'),
|
|
736
|
+
subdivisionRomanizationPreference: globalConfig?.subdivisionRomanizationPreference ||
|
|
737
|
+
scriptUrl?.searchParams.get('subdivision_romanization_preference') ||
|
|
738
|
+
undefined,
|
|
739
|
+
preferLocalVariant: globalConfig?.preferLocalVariant !== undefined
|
|
740
|
+
? globalConfig.preferLocalVariant
|
|
741
|
+
: parseBoolean(scriptUrl?.searchParams.get('prefer_local_variant') ?? 'false'),
|
|
742
|
+
forcedLanguage: globalConfig?.forcedLanguage ||
|
|
743
|
+
scriptUrl?.searchParams.get('forced_language') ||
|
|
744
|
+
undefined,
|
|
745
|
+
defaultLanguage: globalConfig?.defaultLanguage ||
|
|
746
|
+
scriptUrl?.searchParams.get('default_language') ||
|
|
747
|
+
undefined,
|
|
715
748
|
subdivisionNameFilter: globalConfig?.subdivisionNameFilter,
|
|
716
749
|
};
|
|
717
750
|
}
|