leaflet-theme-control 0.0.2 → 0.0.3
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/package.json +1 -1
- package/src/leaflet-theme-control.js +12 -2
- package/src/leaflet-theme-editor.js +26 -27
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "leaflet-theme-control",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "A Leaflet control for switching between visual themes (light, dark, grayscale, custom, etc.) using CSS filters",
|
|
5
5
|
"main": "src/leaflet-theme-control.js",
|
|
6
6
|
"module": "src/leaflet-theme-control.js",
|
|
@@ -33,8 +33,18 @@ export class ThemeControl extends Control {
|
|
|
33
33
|
initialize(options) {
|
|
34
34
|
Util.setOptions(this, options)
|
|
35
35
|
|
|
36
|
-
// Create
|
|
37
|
-
|
|
36
|
+
// Create deep copies of themes to avoid mutating DEFAULT_THEMES
|
|
37
|
+
// This is necessary because spread operator only does shallow copies
|
|
38
|
+
if (this.options.themes) {
|
|
39
|
+
// User provided custom themes - create deep copies of each theme
|
|
40
|
+
const themesCopy = {}
|
|
41
|
+
Object.keys(this.options.themes).forEach((key) => {
|
|
42
|
+
themesCopy[key] = { ...this.options.themes[key] }
|
|
43
|
+
})
|
|
44
|
+
this.options.themes = themesCopy
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
// No themes provided - use copies of DEFAULT_THEMES
|
|
38
48
|
this.options.themes = {}
|
|
39
49
|
Object.keys(DEFAULT_THEMES).forEach((key) => {
|
|
40
50
|
this.options.themes[key] = { ...DEFAULT_THEMES[key] }
|
|
@@ -402,14 +402,9 @@ export class ThemeEditor {
|
|
|
402
402
|
// Get current filter values or defaults
|
|
403
403
|
const filterValues = this.customFilters[themeKey] || this._parseFilterString(theme.filter)
|
|
404
404
|
|
|
405
|
-
// Get control style preference
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
controlStyle = this.customFilters[themeKey].controlStyle
|
|
409
|
-
}
|
|
410
|
-
else if (theme.controlStyle) {
|
|
411
|
-
controlStyle = theme.controlStyle
|
|
412
|
-
}
|
|
405
|
+
// Get control style preference - always start fresh from theme
|
|
406
|
+
// Don't check customFilters first, as it may have stale data
|
|
407
|
+
const controlStyle = theme.controlStyle || 'light'
|
|
413
408
|
|
|
414
409
|
// Build panel structure
|
|
415
410
|
const header = this._createPanelHeader(`${this._getLabel('customize')}: ${themeLabel}`, true)
|
|
@@ -594,33 +589,37 @@ export class ThemeEditor {
|
|
|
594
589
|
delete this.customFilters[themeKey]
|
|
595
590
|
this._saveCustomFilters()
|
|
596
591
|
|
|
597
|
-
// Restore default
|
|
592
|
+
// Restore default filter and controlStyle from DEFAULT_THEMES
|
|
593
|
+
// but KEEP user-defined properties like applyToSelectors
|
|
598
594
|
const defaultTheme = DEFAULT_THEMES[themeKey]
|
|
595
|
+
const currentTheme = this.themeControl.options.themes[themeKey]
|
|
599
596
|
|
|
600
|
-
if (defaultTheme) {
|
|
601
|
-
//
|
|
602
|
-
|
|
597
|
+
if (defaultTheme && currentTheme) {
|
|
598
|
+
// Only reset the editable properties (filter, controlStyle)
|
|
599
|
+
// Keep other properties like applyToSelectors, icon, label, className
|
|
600
|
+
currentTheme.filter = defaultTheme.filter
|
|
601
|
+
currentTheme.controlStyle = defaultTheme.controlStyle
|
|
602
|
+
}
|
|
603
|
+
else if (!currentTheme) {
|
|
604
|
+
// Theme doesn't exist - this shouldn't happen
|
|
605
|
+
console.warn(`Theme "${themeKey}" not found`)
|
|
606
|
+
return
|
|
603
607
|
}
|
|
604
608
|
else {
|
|
605
|
-
// For custom themes not in DEFAULT_THEMES,
|
|
606
|
-
|
|
607
|
-
const theme = this.themeControl.options.themes[themeKey]
|
|
608
|
-
if (theme) {
|
|
609
|
-
// Keep the theme but clear any custom modifications by re-parsing
|
|
610
|
-
// the original filter (which may still be modified, so this is a no-op for custom themes)
|
|
611
|
-
console.warn(`Theme "${themeKey}" has no default in DEFAULT_THEMES, cannot fully reset`)
|
|
612
|
-
}
|
|
609
|
+
// For custom themes not in DEFAULT_THEMES, we can't reset
|
|
610
|
+
console.warn(`Theme "${themeKey}" has no default in DEFAULT_THEMES, cannot reset filter values`)
|
|
613
611
|
}
|
|
614
612
|
|
|
615
|
-
// Reapply theme
|
|
616
|
-
//
|
|
613
|
+
// Reapply theme if it's currently active
|
|
614
|
+
// Use setTheme to ensure proper application
|
|
617
615
|
if (this.themeControl.getCurrentTheme() === themeKey) {
|
|
618
|
-
this.themeControl.
|
|
616
|
+
this.themeControl.setTheme(themeKey)
|
|
619
617
|
}
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
618
|
+
else {
|
|
619
|
+
// Fire onChange callback even if theme is not currently active
|
|
620
|
+
if (this.themeControl.options.onChange) {
|
|
621
|
+
this.themeControl.options.onChange(themeKey, this.themeControl.options.themes[themeKey])
|
|
622
|
+
}
|
|
624
623
|
}
|
|
625
624
|
|
|
626
625
|
// Re-render editor panel with default values
|