@countriesdb/widget 0.1.36 → 1.0.0

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.
Files changed (2) hide show
  1. package/README.md +47 -18
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -40,20 +40,15 @@ For detailed documentation, visit [countriesdb.com/docs](https://countriesdb.com
40
40
  ### Script Tag (UMD)
41
41
 
42
42
  ```html
43
- <script src="https://unpkg.com/@countriesdb/widget@latest/dist/index.js"></script>
44
- <script>
45
- CountriesWidget.CountriesWidgetLoad({
46
- publicKey: 'YOUR_PUBLIC_KEY',
47
- defaultLanguage: 'en'
48
- });
49
- </script>
43
+ <!-- Widget auto-initializes when script loads -->
44
+ <script src="https://unpkg.com/@countriesdb/widget@latest/dist/index.js?public_key=YOUR_PUBLIC_KEY"></script>
50
45
 
51
46
  <!-- Add CSS classes to your select elements -->
52
- <select class="country-selection" name="country">
47
+ <select class="country-selection" data-name="country1" name="country">
53
48
  <option value="">Select Country</option>
54
49
  </select>
55
50
 
56
- <select class="subdivision-selection" name="state" data-country="country">
51
+ <select class="subdivision-selection" name="state" data-country="country1">
57
52
  <option value="">Select State/Province</option>
58
53
  </select>
59
54
  ```
@@ -62,7 +57,10 @@ For detailed documentation, visit [countriesdb.com/docs](https://countriesdb.com
62
57
 
63
58
  ```html
64
59
  <script type="module">
65
- import { CountriesWidgetLoad } from '@countriesdb/widget';
60
+ import CountriesWidgetLoad from '@countriesdb/widget';
61
+
62
+ // Or use auto-init with window.CountriesDBConfig:
63
+ // import '@countriesdb/widget';
66
64
 
67
65
  CountriesWidgetLoad({
68
66
  publicKey: 'YOUR_PUBLIC_KEY',
@@ -74,12 +72,12 @@ For detailed documentation, visit [countriesdb.com/docs](https://countriesdb.com
74
72
  ### Node.js / Bundler
75
73
 
76
74
  ```javascript
77
- import { CountriesWidgetLoad } from '@countriesdb/widget';
75
+ import CountriesWidgetLoad from '@countriesdb/widget';
78
76
 
79
77
  CountriesWidgetLoad({
80
78
  publicKey: 'YOUR_PUBLIC_KEY',
81
- defaultLanguage: 'en',
82
- enableGeolocation: true
79
+ defaultLanguage: 'en'
80
+ // GeoIP is enabled by default unless disabled via data-preselected=""
83
81
  });
84
82
  ```
85
83
 
@@ -101,6 +99,7 @@ CountriesWidgetLoad({
101
99
  - `countryNameFilter` (optional): Custom function to filter/transform country names
102
100
  - `subdivisionNameFilter` (optional): Custom function to filter/transform subdivision names
103
101
  - `autoInit` (optional): Auto-initialize on load (default: `true`)
102
+ - `reload` (optional): Force re-initialization, clearing cached state and reapplying preselected values (default: `false`)
104
103
 
105
104
  ### Data Attributes
106
105
 
@@ -134,7 +133,7 @@ document.addEventListener('countriesWidget:update', (event) => {
134
133
  // value: 'US',
135
134
  // selectedValues: ['US'],
136
135
  // name: 'country1',
137
- // country: null,
136
+ // country: null, // For subdivision selects: linked country select's data-name
138
137
  // isSubdivision: false,
139
138
  // type: 'country',
140
139
  // reason: 'regular' | 'geoip' | 'preselected' | 'reload' | 'follow'
@@ -153,7 +152,7 @@ document.addEventListener('countriesWidget:ready', (event) => {
153
152
  // value: 'US',
154
153
  // selectedValues: ['US'],
155
154
  // name: 'country1',
156
- // country: null,
155
+ // country: null, // For subdivision selects: linked country select's data-name
157
156
  // isSubdivision: false,
158
157
  // type: 'country' | 'subdivision',
159
158
  // phase: 'initial' | 'reload'
@@ -186,7 +185,19 @@ document.addEventListener('countriesWidget:ready', (event) => {
186
185
  ### Custom Name Filter
187
186
 
188
187
  ```javascript
189
- CountriesWidgetLoad({
188
+ // Using window.CountriesDBConfig (before script loads)
189
+ window.CountriesDBConfig = {
190
+ publicKey: 'YOUR_PUBLIC_KEY',
191
+ countryNameFilter: (code, name, language, item) => {
192
+ if (code === 'US') {
193
+ return 'United States of America';
194
+ }
195
+ return name;
196
+ }
197
+ };
198
+
199
+ // Or using window.CountriesWidgetLoad (after script loads)
200
+ window.CountriesWidgetLoad({
190
201
  publicKey: 'YOUR_PUBLIC_KEY',
191
202
  countryNameFilter: (code, name, language, item) => {
192
203
  if (code === 'US') {
@@ -201,7 +212,25 @@ CountriesWidgetLoad({
201
212
 
202
213
  ### `CountriesWidgetLoad(options)`
203
214
 
204
- Main initialization function. Returns a Promise that resolves when initialization is complete.
215
+ Main initialization function. Returns a Promise that resolves to `true` when initialization is complete, or `false` if initialization failed (e.g., due to conflicting parameters like `followRelated` and `followUpward`).
216
+
217
+ **Parameters:**
218
+ - `options` (object): Configuration options (see [Options](#options) above)
219
+
220
+ **Example:**
221
+ ```javascript
222
+ // Basic initialization
223
+ await CountriesWidgetLoad({
224
+ publicKey: 'YOUR_PUBLIC_KEY',
225
+ defaultLanguage: 'en'
226
+ });
227
+
228
+ // Force reload (clears cached state and reapplies preselected values)
229
+ await CountriesWidgetLoad({
230
+ publicKey: 'YOUR_PUBLIC_KEY',
231
+ reload: true
232
+ });
233
+ ```
205
234
 
206
235
  For complete API documentation, visit [countriesdb.com/docs](https://countriesdb.com/docs).
207
236
 
@@ -214,7 +243,7 @@ For complete API documentation, visit [countriesdb.com/docs](https://countriesdb
214
243
 
215
244
  ## License
216
245
 
217
- PROPRIETARY - Copyright (c) NAYEE LLC. See [LICENSE](https://github.com/countriesdb/countriesdb/blob/main/packages/npm/widget/LICENSE) for details.
246
+ PROPRIETARY - Copyright (c) NAYEE LLC.
218
247
 
219
248
  **Developed by [NAYEE LLC](https://nayee.net)**
220
249
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@countriesdb/widget",
3
- "version": "0.1.36",
3
+ "version": "1.0.0",
4
4
  "description": "Country and state/province select widget with ISO 3166-1 and ISO 3166-2 codes. Auto-populates dropdowns with up-to-date country and subdivision data in multiple languages. Easy integration for forms, location selection, and address validation.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.esm.js",