browser-extension-settings 0.6.0 → 0.6.1

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.
@@ -46,10 +46,11 @@ const locales = Object.keys(localeMap)
46
46
  initAvailableLocales(locales)
47
47
 
48
48
  export const prefferedLocale = extractLocaleFromNavigator() || "en"
49
-
49
+ console.log("[settings] prefferedLocale:", prefferedLocale)
50
50
  // eslint-disable-next-line import/no-mutable-exports
51
51
  export let i = initI18n(localeMap, prefferedLocale)
52
52
 
53
53
  export function resetI18n(locale?: string) {
54
+ console.log("[settings] prefferedLocale:", prefferedLocale, "locale:", locale)
54
55
  i = initI18n(localeMap, locale || prefferedLocale)
55
56
  }
package/lib/settings.ts CHANGED
@@ -181,6 +181,23 @@ export function hideSettings() {
181
181
  closeModal()
182
182
  }
183
183
 
184
+ function destroySettings() {
185
+ closeModal()
186
+ const settingsContainer = getSettingsContainer()
187
+ if (settingsContainer) {
188
+ settingsContainer.remove()
189
+ }
190
+ }
191
+
192
+ function isSettingsShown() {
193
+ const settingsContainer = getSettingsContainer()
194
+ if (settingsContainer) {
195
+ return settingsContainer.style.display === "block"
196
+ }
197
+
198
+ return false
199
+ }
200
+
184
201
  const onDocumentClick = (event: Event) => {
185
202
  const target = event.target as HTMLElement
186
203
  if (target?.closest(`.${prefix}container`)) {
@@ -614,10 +631,13 @@ export const initSettings = async (options: SettingsOptions) => {
614
631
  (getSettingsValue("locale") as string | undefined) || prefferedLocale
615
632
  console.log("lastLocale:", lastLocale, "newLocale:", newLocale)
616
633
  if (lastLocale !== newLocale) {
617
- closeModal()
634
+ const isShown = isSettingsShown()
635
+ destroySettings()
618
636
  resetI18n(newLocale)
619
637
  lastLocale = newLocale
620
- setTimeout(showSettings, 100)
638
+ if (isShown) {
639
+ setTimeout(showSettings, 100)
640
+ }
621
641
  }
622
642
 
623
643
  if (typeof options.onValueChange === "function") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "browser-extension-settings",
3
- "version": "0.6.0",
3
+ "version": "0.6.1",
4
4
  "description": "Settings module for developing browser extensions and userscripts",
5
5
  "type": "module",
6
6
  "main": "./lib/index.ts",
@@ -30,7 +30,7 @@
30
30
  },
31
31
  "homepage": "https://github.com/utags/browser-extension-settings#readme",
32
32
  "dependencies": {
33
- "browser-extension-i18n": "^0.1.1",
33
+ "browser-extension-i18n": "^0.1.2",
34
34
  "browser-extension-storage": "^0.1.2",
35
35
  "browser-extension-utils": "^0.2.0"
36
36
  },