@deephaven/components 0.49.2-theme-plugins.32 → 0.49.2-theme-plugins.43

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.
@@ -0,0 +1,15 @@
1
+ import { ReactNode } from 'react';
2
+ import { ThemeData } from './ThemeModel';
3
+ export interface ThemeContextValue {
4
+ activeThemes: ThemeData[] | null;
5
+ selectedThemeKey: string;
6
+ setSelectedThemeKey: (themeKey: string) => void;
7
+ }
8
+ export declare const ThemeContext: import("react").Context<ThemeContextValue | null>;
9
+ export interface ThemeProviderProps {
10
+ themes: ThemeData[] | null;
11
+ children: ReactNode;
12
+ }
13
+ export declare function ThemeProvider({ themes, children, }: ThemeProviderProps): JSX.Element;
14
+ export default ThemeProvider;
15
+ //# sourceMappingURL=ThemeProvider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ThemeProvider.d.ts","sourceRoot":"","sources":["../../src/theme/ThemeProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAiB,SAAS,EAAgC,MAAM,OAAO,CAAC;AAE/E,OAAO,EAA0B,SAAS,EAAE,MAAM,cAAc,CAAC;AASjE,MAAM,WAAW,iBAAiB;IAChC,YAAY,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC;IACjC,gBAAgB,EAAE,MAAM,CAAC;IACzB,mBAAmB,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;CACjD;AAID,eAAO,MAAM,YAAY,mDAAgD,CAAC;AAE1E,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC;IAC3B,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED,wBAAgB,aAAa,CAAC,EAC5B,MAAM,EACN,QAAQ,GACT,EAAE,kBAAkB,GAAG,GAAG,CAAC,OAAO,CAoDlC;AAED,eAAe,aAAa,CAAC"}
@@ -0,0 +1,48 @@
1
+ import { createContext, useEffect, useMemo, useState } from 'react';
2
+ import Log from '@deephaven/log';
3
+ import { DEFAULT_DARK_THEME_KEY } from "./ThemeModel.js";
4
+ import { calculatePreloadStyleContent, getActiveThemes, getDefaultBaseThemes, getThemePreloadData, setThemePreloadData } from "./ThemeUtils.js";
5
+ import { jsx as _jsx } from "react/jsx-runtime";
6
+ import { jsxs as _jsxs } from "react/jsx-runtime";
7
+ var log = Log.module('ThemeProvider');
8
+ export var ThemeContext = /*#__PURE__*/createContext(null);
9
+ export function ThemeProvider(_ref) {
10
+ var {
11
+ themes,
12
+ children
13
+ } = _ref;
14
+ var baseThemes = useMemo(() => getDefaultBaseThemes(), []);
15
+ var [selectedThemeKey, setSelectedThemeKey] = useState(() => {
16
+ var _getThemePreloadData$, _getThemePreloadData;
17
+ return (_getThemePreloadData$ = (_getThemePreloadData = getThemePreloadData()) === null || _getThemePreloadData === void 0 ? void 0 : _getThemePreloadData.themeKey) !== null && _getThemePreloadData$ !== void 0 ? _getThemePreloadData$ : DEFAULT_DARK_THEME_KEY;
18
+ });
19
+ var activeThemes = useMemo(() =>
20
+ // Themes remain inactive until a non-null themes value is provided. This
21
+ // avoids the default base theme overriding the preload if we are waiting
22
+ // on additional themes to be available.
23
+ themes == null ? null : getActiveThemes(selectedThemeKey, {
24
+ base: baseThemes,
25
+ custom: themes !== null && themes !== void 0 ? themes : []
26
+ }), [baseThemes, selectedThemeKey, themes]);
27
+ useEffect(function updateThemePreloadData() {
28
+ log.debug('Active themes:', activeThemes === null || activeThemes === void 0 ? void 0 : activeThemes.map(theme => theme.themeKey));
29
+ setThemePreloadData({
30
+ themeKey: selectedThemeKey,
31
+ preloadStyleContent: calculatePreloadStyleContent()
32
+ });
33
+ }, [activeThemes, selectedThemeKey]);
34
+ var value = useMemo(() => ({
35
+ activeThemes,
36
+ selectedThemeKey,
37
+ setSelectedThemeKey
38
+ }), [activeThemes, selectedThemeKey]);
39
+ return /*#__PURE__*/_jsxs(ThemeContext.Provider, {
40
+ value: value,
41
+ children: [activeThemes === null || activeThemes === void 0 ? void 0 : activeThemes.map(theme => /*#__PURE__*/_jsx("style", {
42
+ "data-theme-key": theme.themeKey,
43
+ children: theme.styleContent
44
+ }, theme.themeKey)), children]
45
+ });
46
+ }
47
+ export default ThemeProvider;
48
+ //# sourceMappingURL=ThemeProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ThemeProvider.js","names":["createContext","useEffect","useMemo","useState","Log","DEFAULT_DARK_THEME_KEY","calculatePreloadStyleContent","getActiveThemes","getDefaultBaseThemes","getThemePreloadData","setThemePreloadData","log","module","ThemeContext","ThemeProvider","themes","children","baseThemes","selectedThemeKey","setSelectedThemeKey","themeKey","activeThemes","base","custom","updateThemePreloadData","debug","map","theme","preloadStyleContent","value","styleContent"],"sources":["../../src/theme/ThemeProvider.tsx"],"sourcesContent":["import { createContext, ReactNode, useEffect, useMemo, useState } from 'react';\nimport Log from '@deephaven/log';\nimport { DEFAULT_DARK_THEME_KEY, ThemeData } from './ThemeModel';\nimport {\n calculatePreloadStyleContent,\n getActiveThemes,\n getDefaultBaseThemes,\n getThemePreloadData,\n setThemePreloadData,\n} from './ThemeUtils';\n\nexport interface ThemeContextValue {\n activeThemes: ThemeData[] | null;\n selectedThemeKey: string;\n setSelectedThemeKey: (themeKey: string) => void;\n}\n\nconst log = Log.module('ThemeProvider');\n\nexport const ThemeContext = createContext<ThemeContextValue | null>(null);\n\nexport interface ThemeProviderProps {\n themes: ThemeData[] | null;\n children: ReactNode;\n}\n\nexport function ThemeProvider({\n themes,\n children,\n}: ThemeProviderProps): JSX.Element {\n const baseThemes = useMemo(() => getDefaultBaseThemes(), []);\n\n const [selectedThemeKey, setSelectedThemeKey] = useState<string>(\n () => getThemePreloadData()?.themeKey ?? DEFAULT_DARK_THEME_KEY\n );\n\n const activeThemes = useMemo(\n () =>\n // Themes remain inactive until a non-null themes value is provided. This\n // avoids the default base theme overriding the preload if we are waiting\n // on additional themes to be available.\n themes == null\n ? null\n : getActiveThemes(selectedThemeKey, {\n base: baseThemes,\n custom: themes ?? [],\n }),\n [baseThemes, selectedThemeKey, themes]\n );\n\n useEffect(\n function updateThemePreloadData() {\n log.debug('Active themes:', activeThemes?.map(theme => theme.themeKey));\n\n setThemePreloadData({\n themeKey: selectedThemeKey,\n preloadStyleContent: calculatePreloadStyleContent(),\n });\n },\n [activeThemes, selectedThemeKey]\n );\n\n const value = useMemo(\n () => ({\n activeThemes,\n selectedThemeKey,\n setSelectedThemeKey,\n }),\n [activeThemes, selectedThemeKey]\n );\n\n return (\n <ThemeContext.Provider value={value}>\n {activeThemes?.map(theme => (\n <style data-theme-key={theme.themeKey} key={theme.themeKey}>\n {theme.styleContent}\n </style>\n ))}\n {children}\n </ThemeContext.Provider>\n );\n}\n\nexport default ThemeProvider;\n"],"mappings":"AAAA,SAASA,aAAa,EAAaC,SAAS,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,OAAO;AAC9E,OAAOC,GAAG,MAAM,gBAAgB;AAAC,SACxBC,sBAAsB;AAAA,SAE7BC,4BAA4B,EAC5BC,eAAe,EACfC,oBAAoB,EACpBC,mBAAmB,EACnBC,mBAAmB;AAAA;AAAA;AASrB,IAAMC,GAAG,GAAGP,GAAG,CAACQ,MAAM,CAAC,eAAe,CAAC;AAEvC,OAAO,IAAMC,YAAY,gBAAGb,aAAa,CAA2B,IAAI,CAAC;AAOzE,OAAO,SAASc,aAAa,OAGO;EAAA,IAHN;IAC5BC,MAAM;IACNC;EACkB,CAAC;EACnB,IAAMC,UAAU,GAAGf,OAAO,CAAC,MAAMM,oBAAoB,EAAE,EAAE,EAAE,CAAC;EAE5D,IAAM,CAACU,gBAAgB,EAAEC,mBAAmB,CAAC,GAAGhB,QAAQ,CACtD;IAAA;IAAA,wDAAMM,mBAAmB,EAAE,yDAArB,qBAAuBW,QAAQ,yEAAIf,sBAAsB;EAAA,EAChE;EAED,IAAMgB,YAAY,GAAGnB,OAAO,CAC1B;EACE;EACA;EACA;EACAa,MAAM,IAAI,IAAI,GACV,IAAI,GACJR,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AY,IAAI,IAAI,CAUnC"}
@@ -1,7 +1,19 @@
1
1
  import Log from '@deephaven/log';
2
2
  import { assertNotNull } from '@deephaven/utils';
3
- import darkTheme from "./theme_default_dark.css?inline.js";
4
- import lightTheme from "./theme_default_light.css?inline.js";
3
+ // Note that ?inline imports are natively supported by Vite, but consumers of
4
+ // @deephaven/components using Webpack will need to add a rule to their module
5
+ // config.
6
+ // e.g.
7
+ // module: {
8
+ // rules: [
9
+ // {
10
+ // resourceQuery: /inline/,
11
+ // type: 'asset/source',
12
+ // },
13
+ // ],
14
+ // },
15
+ import darkTheme from "./theme_default_dark.css?inline";
16
+ import lightTheme from "./theme_default_light.css?inline";
5
17
  import { DEFAULT_DARK_THEME_KEY, DEFAULT_LIGHT_THEME_KEY, DEFAULT_PRELOAD_DATA_VARIABLES, THEME_CACHE_LOCAL_STORAGE_KEY } from "./ThemeModel.js";
6
18
  var log = Log.module('ThemeUtils');
7
19
 
@@ -32,7 +44,7 @@ export function getActiveThemes(themeKey, themeRegistration) {
32
44
  var baseThemeKey = (_custom$baseThemeKey = custom === null || custom === void 0 ? void 0 : custom.baseThemeKey) !== null && _custom$baseThemeKey !== void 0 ? _custom$baseThemeKey : themeKey;
33
45
  var base = themeRegistration.base.find(theme => theme.themeKey === baseThemeKey);
34
46
  if (base == null) {
35
- log.error("No registered base theme found for theme key: '".concat(baseThemeKey, "'"));
47
+ log.error("No registered base theme found for theme key: '".concat(baseThemeKey, "'"), 'Registered:', themeRegistration.base.map(theme => theme.themeKey), themeRegistration.custom.map(theme => theme.themeKey));
36
48
  base = themeRegistration.base.find(theme => theme.themeKey === DEFAULT_DARK_THEME_KEY);
37
49
  assertNotNull(base, "Default base theme '".concat(DEFAULT_DARK_THEME_KEY, "' is not registered"));
38
50
  }
@@ -1 +1 @@
1
- {"version":3,"file":"ThemeUtils.js","names":["Log","assertNotNull","darkTheme","lightTheme","DEFAULT_DARK_THEME_KEY","DEFAULT_LIGHT_THEME_KEY","DEFAULT_PRELOAD_DATA_VARIABLES","THEME_CACHE_LOCAL_STORAGE_KEY","log","module","calculatePreloadStyleContent","bodyStyle","getComputedStyle","document","body","pairs","Object","entries","map","key","defaultValue","getPropertyValue","join","getActiveThemes","themeKey","themeRegistration","custom","find","theme","baseThemeKey","base","error","debug","getDefaultBaseThemes","name","styleContent","getThemePreloadData","data","localStorage","getItem","JSON","parse","setThemePreloadData","preloadData","setItem","stringify","getThemeKey","pluginName","themeName","preloadTheme","preloadStyleContent","style","createElement","innerHTML","head","appendChild"],"sources":["../../src/theme/ThemeUtils.ts"],"sourcesContent":["import Log from '@deephaven/log';\nimport { assertNotNull } from '@deephaven/utils';\nimport darkTheme from './theme_default_dark.css?inline';\nimport lightTheme from './theme_default_light.css?inline';\nimport {\n DEFAULT_DARK_THEME_KEY,\n DEFAULT_LIGHT_THEME_KEY,\n DEFAULT_PRELOAD_DATA_VARIABLES,\n ThemeData,\n ThemePreloadData,\n ThemePreloadStyleContent,\n ThemeRegistrationData,\n THEME_CACHE_LOCAL_STORAGE_KEY,\n} from './ThemeModel';\n\nconst log = Log.module('ThemeUtils');\n\n/**\n * Creates a string containing preload style content for the current theme.\n * This resolves the current values of a few CSS variables that can be used\n * to style the page before the theme is loaded on next page load.\n */\nexport function calculatePreloadStyleContent(): ThemePreloadStyleContent {\n const bodyStyle = getComputedStyle(document.body);\n\n // Calculate the current preload variables. If the variable is not set, use\n // the default value.\n const pairs = Object.entries(DEFAULT_PRELOAD_DATA_VARIABLES).map(\n ([key, defaultValue]) =>\n `${key}:${bodyStyle.getPropertyValue(key) || defaultValue}`\n );\n\n return `:root{${pairs.join(';')}}`;\n}\n\n/**\n * Returns an array of the active themes. The first item will always be one\n * of the base themes. Optionally, the second item will be a custom theme.\n */\nexport function getActiveThemes(\n themeKey: string,\n themeRegistration: ThemeRegistrationData\n): [ThemeData] | [ThemeData, ThemeData] {\n const custom = themeRegistration.custom.find(\n theme => theme.themeKey === themeKey\n );\n\n const baseThemeKey = custom?.baseThemeKey ?? themeKey;\n\n let base = themeRegistration.base.find(\n theme => theme.themeKey === baseThemeKey\n );\n\n if (base == null) {\n log.error(\n `No registered base theme found for theme key: '${baseThemeKey}'`\n );\n base = themeRegistration.base.find(\n theme => theme.themeKey === DEFAULT_DARK_THEME_KEY\n );\n\n assertNotNull(\n base,\n `Default base theme '${DEFAULT_DARK_THEME_KEY}' is not registered`\n );\n }\n\n log.debug('Applied themes:', base.themeKey, custom?.themeKey);\n\n return custom == null ? [base] : [base, custom];\n}\n\n/**\n * Get default base theme data.\n */\nexport function getDefaultBaseThemes(): ThemeData[] {\n return [\n {\n name: 'Default Dark',\n themeKey: DEFAULT_DARK_THEME_KEY,\n styleContent: darkTheme,\n },\n {\n name: 'Default Light',\n themeKey: DEFAULT_LIGHT_THEME_KEY,\n styleContent: lightTheme,\n },\n ];\n}\n\n/**\n * Get the preload data from local storage or null if it does not exist or is\n * invalid\n */\nexport function getThemePreloadData(): ThemePreloadData | null {\n const data = localStorage.getItem(THEME_CACHE_LOCAL_STORAGE_KEY);\n\n try {\n return data == null ? null : JSON.parse(data);\n } catch {\n // ignore\n }\n\n return null;\n}\n\n/**\n * Store theme preload data in local storage.\n * @param preloadData The preload data to set\n */\nexport function setThemePreloadData(preloadData: ThemePreloadData): void {\n localStorage.setItem(\n THEME_CACHE_LOCAL_STORAGE_KEY,\n JSON.stringify(preloadData)\n );\n}\n\n/**\n * Derive unique theme key from plugin root path and theme name.\n * @param pluginName The root path of the plugin\n * @param themeName The name of the theme\n */\nexport function getThemeKey(pluginName: string, themeName: string): string {\n return `${pluginName}_${themeName}`;\n}\n\n/**\n * Preload minimal theme variables from the cache.\n */\nexport function preloadTheme(): void {\n const preloadStyleContent =\n getThemePreloadData()?.preloadStyleContent ??\n calculatePreloadStyleContent();\n\n log.debug('Preloading theme content:', `'${preloadStyleContent}'`);\n\n const style = document.createElement('style');\n style.innerHTML = preloadStyleContent;\n document.head.appendChild(style);\n}\n"],"mappings":"AAAA,OAAOA,GAAG,MAAM,g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E,yDAArB,qBAAuBc,mBAAmB,yEAC1CxC,4BAA4B,EAAE;EAEhCF,GAAG,CAACwB,KAAK,CAAC,2BAA2B,aAAMkB,mBAAmB,OAAI;EAElE,IAAMC,KAAK,GAAGtC,QAAQ,CAACuC,aAAa,CAAC,OAAO,CAAC;EAC7CD,KAAK,CAACE,SAAS,GAAGH,mBAAmB;EACrCrC,QAAQ,CAACyC,IAAI,CAACC,WAAW,CAACJ,KAAK,CAAC;AAClC"}
1
+ {"version":3,"file":"ThemeUtils.js","names":["Log","assertNotNull","darkTheme","lightTheme","DEFAULT_DARK_THEME_KEY","DEFAULT_LIGHT_THEME_KEY","DEFAULT_PRELOAD_DATA_VARIABLES","THEME_CACHE_LOCAL_STORAGE_KEY","log","module","calculatePreloadStyleContent","bodyStyle","getComputedStyle","document","body","pairs","Object","entries","map","key","defaultValue","getPropertyValue","join","getActiveThemes","themeKey","themeRegistration","custom","find","theme","baseThemeKey","base","error","debug","getDefaultBaseThemes","name","styleContent","getThemePreloadData","data","localStorage","getItem","JSON","parse","setThemePreloadData","preloadData","setItem","stringify","getThemeKey","pluginName","themeName","preloadTheme","preloadStyleContent","style","createElement","innerHTML","head","appendChild"],"sources":["../../src/theme/ThemeUtils.ts"],"sourcesContent":["import Log from '@deephaven/log';\nimport { assertNotNull } from '@deephaven/utils';\n// Note that ?inline imports are natively supported by Vite, but consumers of\n// @deephaven/components using Webpack will need to add a rule to their module\n// config.\n// e.g.\n// module: {\n// rules: [\n// {\n// resourceQuery: /inline/,\n// type: 'asset/source',\n// },\n// ],\n// },\nimport darkTheme from './theme_default_dark.css?inline';\nimport lightTheme from './theme_default_light.css?inline';\nimport {\n DEFAULT_DARK_THEME_KEY,\n DEFAULT_LIGHT_THEME_KEY,\n DEFAULT_PRELOAD_DATA_VARIABLES,\n ThemeData,\n ThemePreloadData,\n ThemePreloadStyleContent,\n ThemeRegistrationData,\n THEME_CACHE_LOCAL_STORAGE_KEY,\n} from './ThemeModel';\n\nconst log = Log.module('ThemeUtils');\n\n/**\n * Creates a string containing preload style content for the current theme.\n * This resolves the current values of a few CSS variables that can be used\n * to style the page before the theme is loaded on next page load.\n */\nexport function calculatePreloadStyleContent(): ThemePreloadStyleContent {\n const bodyStyle = getComputedStyle(document.body);\n\n // Calculate the current preload variables. If the variable is not set, use\n // the default value.\n const pairs = Object.entries(DEFAULT_PRELOAD_DATA_VARIABLES).map(\n ([key, defaultValue]) =>\n `${key}:${bodyStyle.getPropertyValue(key) || defaultValue}`\n );\n\n return `:root{${pairs.join(';')}}`;\n}\n\n/**\n * Returns an array of the active themes. The first item will always be one\n * of the base themes. Optionally, the second item will be a custom theme.\n */\nexport function getActiveThemes(\n themeKey: string,\n themeRegistration: ThemeRegistrationData\n): [ThemeData] | [ThemeData, ThemeData] {\n const custom = themeRegistration.custom.find(\n theme => theme.themeKey === themeKey\n );\n\n const baseThemeKey = custom?.baseThemeKey ?? themeKey;\n\n let base = themeRegistration.base.find(\n theme => theme.themeKey === baseThemeKey\n );\n\n if (base == null) {\n log.error(\n `No registered base theme found for theme key: '${baseThemeKey}'`,\n 'Registered:',\n themeRegistration.base.map(theme => theme.themeKey),\n themeRegistration.custom.map(theme => theme.themeKey)\n );\n base = themeRegistration.base.find(\n theme => theme.themeKey === DEFAULT_DARK_THEME_KEY\n );\n\n assertNotNull(\n base,\n `Default base theme '${DEFAULT_DARK_THEME_KEY}' is not registered`\n );\n }\n\n log.debug('Applied themes:', base.themeKey, custom?.themeKey);\n\n return custom == null ? [base] : [base, custom];\n}\n\n/**\n * Get default base theme data.\n */\nexport function getDefaultBaseThemes(): ThemeData[] {\n return [\n {\n name: 'Default Dark',\n themeKey: DEFAULT_DARK_THEME_KEY,\n styleContent: darkTheme,\n },\n {\n name: 'Default Light',\n themeKey: DEFAULT_LIGHT_THEME_KEY,\n styleContent: lightTheme,\n },\n ];\n}\n\n/**\n * Get the preload data from local storage or null if it does not exist or is\n * invalid\n */\nexport function getThemePreloadData(): ThemePreloadData | null {\n const data = localStorage.getItem(THEME_CACHE_LOCAL_STORAGE_KEY);\n\n try {\n return data == null ? null : JSON.parse(data);\n } catch {\n // ignore\n }\n\n return null;\n}\n\n/**\n * Store theme preload data in local storage.\n * @param preloadData The preload data to set\n */\nexport function setThemePreloadData(preloadData: ThemePreloadData): void {\n localStorage.setItem(\n THEME_CACHE_LOCAL_STORAGE_KEY,\n JSON.stringify(preloadData)\n );\n}\n\n/**\n * Derive unique theme key from plugin root path and theme name.\n * @param pluginName The root path of the plugin\n * @param themeName The name of the theme\n */\nexport function getThemeKey(pluginName: string, themeName: string): string {\n return `${pluginName}_${themeName}`;\n}\n\n/**\n * Preload minimal theme variables from the cache.\n */\nexport function preloadTheme(): void {\n const preloadStyleContent =\n getThemePreloadData()?.preloadStyleContent ??\n calculatePreloadStyleContent();\n\n log.debug('Preloading theme content:', `'${preloadStyleContent}'`);\n\n const style = document.createElement('style');\n style.innerHTML = preloadStyleContent;\n document.head.appendChild(style);\n}\n"],"mappings":"AAAA,OAAOA,GAAG,MAAM,gBAAgB;AAChC,SAASC,aAAa,QAAQ,kBAAkB;AAChD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAAA,OACOC,SAAS;AAAA,OACTC,UAAU;AAAA,SAEfC,sBAAsB,EACtBC,uBAAuB,EACvBC,8BAA8B,EAK9BC,6BAA6B;AAG/B,IAAMC,GAAG,GAAGR,GAAG,CAACS,MAAM,CAAC,YAAY,CAAC;;AAEpC;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,4BAA4B,GAA6B;EACvE,IAAMC,SAAS,GAAGC,gBAAgB,CAACC,QAAQ,CAACC,IAAI,CAAC;;EAEjD;EACA;EACA,IAAMC,KAAK,GAAGC,MAAM,CAACC,OAAO,CAACX,8BAA8B,CAAC,CAACY,GAAG,CAC9D;IAAA,IAAC,CAACC,GAAG,EAAEC,YAAY,CAAC;IAAA,iBACfD,GAAG,cAAIR,SAAS,CAACU,gBAAgB,CAACF,GAAG,CAA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export * from './ThemeProvider';
3
3
  export * from './ThemeUtils';
4
- export * from './useInitializeThemeContextValue';
5
4
  export * from './useTheme';
6
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/theme/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,kCAAkC,CAAC;AACjD,cAAc,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/theme/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC"}
@@ -1,6 +1,5 @@
1
- export * from "./ThemeContext.js";
2
1
  export * from "./ThemeModel.js";
2
+ export * from "./ThemeProvider.js";
3
3
  export * from "./ThemeUtils.js";
4
- export * from "./useInitializeThemeContextValue.js";
5
4
  export * from "./useTheme.js";
6
5
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../src/theme/index.ts"],"sourcesContent":["export * from './ThemeContext';\nexport * from './ThemeModel';\nexport * from './ThemeUtils';\nexport * from './useInitializeThemeContextValue';\nexport * from './useTheme';\n"],"mappings":""}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../src/theme/index.ts"],"sourcesContent":["export * from './ThemeModel';\nexport * from './ThemeProvider';\nexport * from './ThemeUtils';\nexport * from './useTheme';\n"],"mappings":""}
@@ -1,4 +1,4 @@
1
- import { ThemeContextValue } from './ThemeContext';
1
+ import { ThemeContextValue } from './ThemeProvider';
2
2
  /**
3
3
  * Hook to get the current `ThemeContextValue`.
4
4
  */
@@ -1 +1 @@
1
- {"version":3,"file":"useTheme.d.ts","sourceRoot":"","sources":["../../src/theme/useTheme.ts"],"names":[],"mappings":"AACA,OAAO,EAAgB,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAEjE;;GAEG;AACH,wBAAgB,QAAQ,IAAI,iBAAiB,CAK5C;AAED,eAAe,QAAQ,CAAC"}
1
+ {"version":3,"file":"useTheme.d.ts","sourceRoot":"","sources":["../../src/theme/useTheme.ts"],"names":[],"mappings":"AACA,OAAO,EAAgB,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAElE;;GAEG;AACH,wBAAgB,QAAQ,IAAI,iBAAiB,CAK5C;AAED,eAAe,QAAQ,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import { useContextOrThrow } from '@deephaven/react-hooks';
2
- import { ThemeContext } from "./ThemeContext.js";
2
+ import { ThemeContext } from "./ThemeProvider.js";
3
3
  /**
4
4
  * Hook to get the current `ThemeContextValue`.
5
5
  */
@@ -1 +1 @@
1
- {"version":3,"file":"useTheme.js","names":["useContextOrThrow","ThemeContext","useTheme"],"sources":["../../src/theme/useTheme.ts"],"sourcesContent":["import { useContextOrThrow } from '@deephaven/react-hooks';\nimport { ThemeContext, ThemeContextValue } from './ThemeContext';\n\n/**\n * Hook to get the current `ThemeContextValue`.\n */\nexport function useTheme(): ThemeContextValue {\n return useContextOrThrow(\n ThemeContext,\n 'No ThemeContext value found. Component must be wrapped in a ThemeContext.Provider'\n );\n}\n\nexport default useTheme;\n"],"mappings":"AAAA,SAASA,iBAAiB,QAAQ,wBAAwB;AAAC,SAClDC,YAAY;AAErB;AACA;AACA;AACA,OAAO,SAASC,QAAQ,GAAsB;EAC5C,OAAOF,iBAAiB,CACtBC,YAAY,EACZ,mFAAmF,CACpF;AACH;AAEA,eAAeC,QAAQ"}
1
+ {"version":3,"file":"useTheme.js","names":["useContextOrThrow","ThemeContext","useTheme"],"sources":["../../src/theme/useTheme.ts"],"sourcesContent":["import { useContextOrThrow } from '@deephaven/react-hooks';\nimport { ThemeContext, ThemeContextValue } from './ThemeProvider';\n\n/**\n * Hook to get the current `ThemeContextValue`.\n */\nexport function useTheme(): ThemeContextValue {\n return useContextOrThrow(\n ThemeContext,\n 'No ThemeContext value found. Component must be wrapped in a ThemeContext.Provider'\n );\n}\n\nexport default useTheme;\n"],"mappings":"AAAA,SAASA,iBAAiB,QAAQ,wBAAwB;AAAC,SAClDC,YAAY;AAErB;AACA;AACA;AACA,OAAO,SAASC,QAAQ,GAAsB;EAC5C,OAAOF,iBAAiB,CACtBC,YAAY,EACZ,mFAAmF,CACpF;AACH;AAEA,eAAeC,QAAQ"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deephaven/components",
3
- "version": "0.49.2-theme-plugins.32+0587bde6",
3
+ "version": "0.49.2-theme-plugins.43+029d3494",
4
4
  "description": "Deephaven React component library",
5
5
  "author": "Deephaven Data Labs LLC",
6
6
  "license": "Apache-2.0",
@@ -24,10 +24,10 @@
24
24
  },
25
25
  "dependencies": {
26
26
  "@adobe/react-spectrum": "^3.29.0",
27
- "@deephaven/icons": "^0.49.2-theme-plugins.32+0587bde6",
28
- "@deephaven/log": "^0.49.2-theme-plugins.32+0587bde6",
29
- "@deephaven/react-hooks": "^0.49.2-theme-plugins.32+0587bde6",
30
- "@deephaven/utils": "^0.49.2-theme-plugins.32+0587bde6",
27
+ "@deephaven/icons": "^0.49.2-theme-plugins.43+029d3494",
28
+ "@deephaven/log": "^0.49.2-theme-plugins.43+029d3494",
29
+ "@deephaven/react-hooks": "^0.49.2-theme-plugins.43+029d3494",
30
+ "@deephaven/utils": "^0.49.2-theme-plugins.43+029d3494",
31
31
  "@fortawesome/fontawesome-svg-core": "^6.2.1",
32
32
  "@fortawesome/react-fontawesome": "^0.2.0",
33
33
  "@react-spectrum/theme-default": "^3.5.1",
@@ -51,7 +51,7 @@
51
51
  "react-dom": "^17.x"
52
52
  },
53
53
  "devDependencies": {
54
- "@deephaven/mocks": "^0.49.2-theme-plugins.32+0587bde6"
54
+ "@deephaven/mocks": "^0.49.2-theme-plugins.43+029d3494"
55
55
  },
56
56
  "files": [
57
57
  "dist",
@@ -64,5 +64,5 @@
64
64
  "publishConfig": {
65
65
  "access": "public"
66
66
  },
67
- "gitHead": "0587bde67172eff55952970026115e9b56ecaed0"
67
+ "gitHead": "029d34944b94e28e4b5659182a5608f861fb84cc"
68
68
  }
@@ -1,11 +0,0 @@
1
- /// <reference types="react" />
2
- import { ThemeData, ThemeRegistrationData } from './ThemeModel';
3
- export interface ThemeContextValue {
4
- activeThemes: ThemeData[] | null;
5
- selectedThemeKey: string;
6
- setSelectedThemeKey: (themeKey: string) => void;
7
- registerThemes: (themeRegistrationData: ThemeRegistrationData) => void;
8
- }
9
- export declare const ThemeContext: import("react").Context<ThemeContextValue | null>;
10
- export default ThemeContext;
11
- //# sourceMappingURL=ThemeContext.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ThemeContext.d.ts","sourceRoot":"","sources":["../../src/theme/ThemeContext.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,SAAS,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAEhE,MAAM,WAAW,iBAAiB;IAChC,YAAY,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC;IACjC,gBAAgB,EAAE,MAAM,CAAC;IACzB,mBAAmB,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;IAChD,cAAc,EAAE,CAAC,qBAAqB,EAAE,qBAAqB,KAAK,IAAI,CAAC;CACxE;AAED,eAAO,MAAM,YAAY,mDAAgD,CAAC;AAE1E,eAAe,YAAY,CAAC"}
@@ -1,4 +0,0 @@
1
- import { createContext } from 'react';
2
- export var ThemeContext = /*#__PURE__*/createContext(null);
3
- export default ThemeContext;
4
- //# sourceMappingURL=ThemeContext.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ThemeContext.js","names":["createContext","ThemeContext"],"sources":["../../src/theme/ThemeContext.ts"],"sourcesContent":["import { createContext } from 'react';\nimport { ThemeData, ThemeRegistrationData } from './ThemeModel';\n\nexport interface ThemeContextValue {\n activeThemes: ThemeData[] | null;\n selectedThemeKey: string;\n setSelectedThemeKey: (themeKey: string) => void;\n registerThemes: (themeRegistrationData: ThemeRegistrationData) => void;\n}\n\nexport const ThemeContext = createContext<ThemeContextValue | null>(null);\n\nexport default ThemeContext;\n"],"mappings":"AAAA,SAASA,aAAa,QAAQ,OAAO;AAUrC,OAAO,IAAMC,YAAY,gBAAGD,aAAa,CAA2B,IAAI,CAAC;AAEzE,eAAeC,YAAY"}
@@ -1,7 +0,0 @@
1
- import { ThemeContextValue } from './ThemeContext';
2
- /**
3
- * Initialize a `ThemeContextValue`.
4
- */
5
- export declare function useInitializeThemeContextValue(): ThemeContextValue;
6
- export default useInitializeThemeContextValue;
7
- //# sourceMappingURL=useInitializeThemeContextValue.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useInitializeThemeContextValue.d.ts","sourceRoot":"","sources":["../../src/theme/useInitializeThemeContextValue.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAWnD;;GAEG;AACH,wBAAgB,8BAA8B,IAAI,iBAAiB,CAsDlE;AAED,eAAe,8BAA8B,CAAC"}
@@ -1,46 +0,0 @@
1
- import { useCallback, useEffect, useMemo, useState } from 'react';
2
- import Log from '@deephaven/log';
3
- import { DEFAULT_DARK_THEME_KEY } from "./ThemeModel.js";
4
- import { calculatePreloadStyleContent, getActiveThemes, getThemePreloadData, setThemePreloadData } from "./ThemeUtils.js";
5
- var log = Log.module('useInitializeThemeContextValue');
6
-
7
- /**
8
- * Initialize a `ThemeContextValue`.
9
- */
10
- export function useInitializeThemeContextValue() {
11
- var [selectedThemeKey, setSelectedThemeKey] = useState(() => {
12
- var _getThemePreloadData$, _getThemePreloadData;
13
- return (_getThemePreloadData$ = (_getThemePreloadData = getThemePreloadData()) === null || _getThemePreloadData === void 0 ? void 0 : _getThemePreloadData.themeKey) !== null && _getThemePreloadData$ !== void 0 ? _getThemePreloadData$ : DEFAULT_DARK_THEME_KEY;
14
- });
15
- var [themeRegistration, setThemeRegistration] = useState(null);
16
- var activeThemes = useMemo(() => themeRegistration == null ? null : getActiveThemes(selectedThemeKey, themeRegistration), [selectedThemeKey, themeRegistration]);
17
-
18
- /**
19
- * Register the given custom themes with the cache and activate theming.
20
- */
21
- var registerThemes = useCallback(themeRegistrationData => {
22
- log.debug('Registering themes', themeRegistrationData);
23
- setThemeRegistration(themeRegistrationData);
24
- }, []);
25
-
26
- // Once themes are activated, cache the preload data for next time page is
27
- // refreshed.
28
- useEffect(() => {
29
- if (activeThemes == null) {
30
- return;
31
- }
32
- log.debug('Active themes:', activeThemes.map(theme => theme.themeKey));
33
- setThemePreloadData({
34
- themeKey: selectedThemeKey,
35
- preloadStyleContent: calculatePreloadStyleContent()
36
- });
37
- }, [activeThemes, selectedThemeKey, themeRegistration]);
38
- return useMemo(() => ({
39
- activeThemes,
40
- selectedThemeKey,
41
- registerThemes,
42
- setSelectedThemeKey
43
- }), [activeThemes, registerThemes, selectedThemeKey]);
44
- }
45
- export default useInitializeThemeContextValue;
46
- //# sourceMappingURL=useInitializeThemeContextValue.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useInitializeThemeContextValue.js","names":["useCallback","useEffect","useMemo","useState","Log","DEFAULT_DARK_THEME_KEY","calculatePreloadStyleContent","getActiveThemes","getThemePreloadData","setThemePreloadData","log","module","useInitializeThemeContextValue","selectedThemeKey","setSelectedThemeKey","themeKey","themeRegistration","setThemeRegistration","activeThemes","registerThemes","themeRegistrationData","debug","map","theme","preloadStyleContent"],"sources":["../../src/theme/useInitializeThemeContextValue.ts"],"sourcesContent":["import { useCallback, useEffect, useMemo, useState } from 'react';\nimport Log from '@deephaven/log';\nimport { ThemeContextValue } from './ThemeContext';\nimport { DEFAULT_DARK_THEME_KEY, ThemeRegistrationData } from './ThemeModel';\nimport {\n calculatePreloadStyleContent,\n getActiveThemes,\n getThemePreloadData,\n setThemePreloadData,\n} from './ThemeUtils';\n\nconst log = Log.module('useInitializeThemeContextValue');\n\n/**\n * Initialize a `ThemeContextValue`.\n */\nexport function useInitializeThemeContextValue(): ThemeContextValue {\n const [selectedThemeKey, setSelectedThemeKey] = useState<string>(\n () => getThemePreloadData()?.themeKey ?? DEFAULT_DARK_THEME_KEY\n );\n\n const [themeRegistration, setThemeRegistration] =\n useState<ThemeRegistrationData | null>(null);\n\n const activeThemes = useMemo(\n () =>\n themeRegistration == null\n ? null\n : getActiveThemes(selectedThemeKey, themeRegistration),\n [selectedThemeKey, themeRegistration]\n );\n\n /**\n * Register the given custom themes with the cache and activate theming.\n */\n const registerThemes = useCallback(\n (themeRegistrationData: ThemeRegistrationData) => {\n log.debug('Registering themes', themeRegistrationData);\n setThemeRegistration(themeRegistrationData);\n },\n []\n );\n\n // Once themes are activated, cache the preload data for next time page is\n // refreshed.\n useEffect(() => {\n if (activeThemes == null) {\n return;\n }\n\n log.debug(\n 'Active themes:',\n activeThemes.map(theme => theme.themeKey)\n );\n\n setThemePreloadData({\n themeKey: selectedThemeKey,\n preloadStyleContent: calculatePreloadStyleContent(),\n });\n }, [activeThemes, selectedThemeKey, themeRegistration]);\n\n return useMemo(\n () => ({\n activeThemes,\n selectedThemeKey,\n registerThemes,\n setSelectedThemeKey,\n }),\n [activeThemes, registerThemes, selectedThemeKey]\n );\n}\n\nexport default useInitializeThemeContextValue;\n"],"mappings":"AAAA,SAASA,WAAW,EAAEC,SAAS,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,OAAO;AACjE,OAAOC,GAAG,MAAM,gBAAgB;AAAC,SAExBC,sBAAsB;AAAA,SAE7BC,4BAA4B,EAC5BC,eAAe,EACfC,mBAAmB,EACnBC,mBAAmB;AAGrB,IAAMC,GAAG,GAAGN,GAAG,CAACO,MAAM,CAAC,gCAAgC,CAAC;;AAExD;AACA;AACA;AACA,OAAO,SAASC,8BAA8B,GAAsB;EAClE,IAAM,CAACC,gBAAgB,EAAEC,mBAAmB,CAAC,GAAGX,QAAQ,CACtD;IAAA;IAAA,wDAAMK,m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