@qld-gov-au/qgds-bootstrap5 2.0.5 → 2.0.6

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.
@@ -6,7 +6,7 @@ let currentTheme = "masterbrand";
6
6
  // Automatically generate theme modules based on available theme files
7
7
  const themeModules = (() => {
8
8
  const modules = {
9
- customized: () => import("../src/css/main.scss"),
9
+ masterbrand: () => import("../src/css/main.scss"),
10
10
  };
11
11
 
12
12
  // Get all theme files in the themes directory
@@ -50,27 +50,23 @@ function mapStyleElementsByTheme(callback) {
50
50
  });
51
51
  }
52
52
 
53
- const unloadTheme = (themeName) => {
54
- // Cache current theme's style elements before removing
55
- // Remove existing style elements for current theme
56
- const currentStyleElements = [];
57
- const themeNotExist = themeName && !themeStyleElements.has(themeName);
58
- mapStyleElementsByTheme((element) => {
59
- if (themeNotExist) {
60
- currentStyleElements.push(element.cloneNode(true));
61
- }
62
- element.remove();
63
- });
64
-
65
- if (currentStyleElements.length > 0) {
66
- themeStyleElements.set(themeName, currentStyleElements);
67
- }
68
- };
69
-
70
53
  const loadTheme = async (themeName) => {
71
- // Unload current theme if it's different
72
- if (currentTheme && currentTheme !== themeName) {
73
- unloadTheme(currentTheme);
54
+ // Store the previous theme name before changing
55
+ const previousTheme = currentTheme;
56
+
57
+ // Cache previous theme's elements BEFORE loading new theme
58
+ const previousThemeElements = [];
59
+ if (previousTheme && previousTheme !== themeName) {
60
+ mapStyleElementsByTheme((element) => {
61
+ previousThemeElements.push(element);
62
+ });
63
+ // Store in cache if not already cached
64
+ if (!themeStyleElements.has(previousTheme)) {
65
+ themeStyleElements.set(
66
+ previousTheme,
67
+ previousThemeElements.map((el) => el.cloneNode(true)),
68
+ );
69
+ }
74
70
  }
75
71
 
76
72
  // If theme style elements are cached, restore them
@@ -79,6 +75,10 @@ const loadTheme = async (themeName) => {
79
75
  cachedElements.forEach((element) => {
80
76
  document.head.appendChild(element.cloneNode(true));
81
77
  });
78
+ // Remove previous theme elements after new theme is fully loaded
79
+ previousThemeElements.forEach((element) => {
80
+ element.remove();
81
+ });
82
82
  currentTheme = themeName;
83
83
  return;
84
84
  }
@@ -108,6 +108,11 @@ const loadTheme = async (themeName) => {
108
108
  // Store references
109
109
  loadedThemes.set(themeName, true);
110
110
  currentTheme = themeName;
111
+
112
+ // Remove previous theme elements after new theme is fully loaded
113
+ previousThemeElements.forEach((element) => {
114
+ element.remove();
115
+ });
111
116
  } catch (error) {
112
117
  console.warn(`Failed to load theme: ${themeName}`, error);
113
118
  }
@@ -132,11 +137,11 @@ export const dynamicThemeGlobalTypes = {
132
137
  icon: "switchalt",
133
138
  items: (() => {
134
139
  // Dynamically generate toolbar items from available themes
135
- const items = [];
140
+ const items = [{ value: "masterbrand", title: "Masterbrand theme" }];
136
141
 
137
142
  // Add items for all discovered themes
138
143
  Object.keys(themeModules).forEach((themeName) => {
139
- if (themeName !== "customized") {
144
+ if (themeName !== "masterbrand") {
140
145
  const capitalizedName =
141
146
  themeName.charAt(0).toUpperCase() + themeName.slice(1);
142
147
  items.push({
@@ -145,7 +150,6 @@ export const dynamicThemeGlobalTypes = {
145
150
  });
146
151
  }
147
152
  });
148
- items.push({ value: "customized", title: "Customized theme" });
149
153
  return items;
150
154
  })(),
151
155
  showName: true,
@@ -46,11 +46,13 @@ const config = {
46
46
 
47
47
  viteFinal: async (config, { configType }) => {
48
48
  config.root = "./dist";
49
-
49
+
50
50
  // Define environment variables for the browser
51
51
  config.define = {
52
52
  ...config.define,
53
- 'import.meta.env.ENABLE_DYNAMIC_THEME': JSON.stringify(process.env.ENABLE_DYNAMIC_THEME === 'true')
53
+ "import.meta.env.ENABLE_DYNAMIC_THEME": JSON.stringify(
54
+ process.env.ENABLE_DYNAMIC_THEME === "true",
55
+ ),
54
56
  };
55
57
  // config.plugins.push({
56
58
  // name: "html-transform",
@@ -1,6 +1,6 @@
1
1
  import "../node_modules/bootstrap/dist/js/bootstrap.bundle.min.js";
2
2
  import "../src/js/qld.bootstrap.js";
3
- import "../src/css/main.masterbrand.scss";
3
+ import "../src/css/main.scss";
4
4
  import { withThemeByClassName } from "@storybook/addon-themes";
5
5
  import {
6
6
  withDynamicTheme,
@@ -1,5 +1,5 @@
1
1
 
2
- <!-- VERSION_DETAILS={"project_id":"@qld-gov-au/qgds-bootstrap5","version":"2.0.5","branch":"HEAD","tag":"v2.0.5","commit":"7972857bf46e8fa3db8ca361447711262fffc21e","majorVersion":"v2"} -->
2
+ <!-- VERSION_DETAILS={"project_id":"@qld-gov-au/qgds-bootstrap5","version":"2.0.6","branch":"HEAD","tag":"v2.0.6","commit":"8e01e15b93ee3bf9a4f97638ef79324fdf6a97a7","majorVersion":"v2"} -->
3
3
 
4
4
  {{! Select environment, used verbatium if not using predefind key
5
5
  cdn := PROD|STAGING|BETA|TEST|DEV|???