@dbcdk/react-components 0.0.194 → 0.0.196

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 (114) hide show
  1. package/README.md +78 -10
  2. package/dist/client.cjs +486 -614
  3. package/dist/client.d.ts +176 -102
  4. package/dist/client.js +102 -102
  5. package/dist/components/color-scheme-button/ColorSchemeButton.cjs +7 -4
  6. package/dist/components/color-scheme-button/ColorSchemeButton.d.ts +7 -3
  7. package/dist/components/color-scheme-button/ColorSchemeButton.js +7 -4
  8. package/dist/components/forms/text-area/Textarea.cjs +2 -1
  9. package/dist/components/forms/text-area/Textarea.d.ts +1 -0
  10. package/dist/components/forms/text-area/Textarea.js +2 -1
  11. package/dist/components/highlighted-text/HighlightedText.cjs +6 -3
  12. package/dist/components/highlighted-text/HighlightedText.js +7 -4
  13. package/dist/components/json-viewer/JsonNode.cjs +27 -67
  14. package/dist/components/json-viewer/JsonNode.d.ts +10 -0
  15. package/dist/components/json-viewer/JsonNode.js +28 -68
  16. package/dist/components/json-viewer/JsonRow.cjs +85 -0
  17. package/dist/components/json-viewer/JsonRow.d.ts +5 -0
  18. package/dist/components/json-viewer/JsonRow.js +79 -0
  19. package/dist/components/json-viewer/JsonViewer.cjs +36 -256
  20. package/dist/components/json-viewer/JsonViewer.js +37 -253
  21. package/dist/components/json-viewer/JsonViewerShell.cjs +208 -0
  22. package/dist/components/json-viewer/JsonViewerShell.d.ts +25 -0
  23. package/dist/components/json-viewer/JsonViewerShell.js +202 -0
  24. package/dist/components/json-viewer/TanstackJsonViewer.cjs +127 -0
  25. package/dist/components/json-viewer/TanstackJsonViewer.d.ts +17 -0
  26. package/dist/components/json-viewer/TanstackJsonViewer.js +121 -0
  27. package/dist/components/json-viewer/types.d.ts +27 -0
  28. package/dist/components/json-viewer/useJsonViewerState.cjs +111 -0
  29. package/dist/components/json-viewer/useJsonViewerState.d.ts +42 -0
  30. package/dist/components/json-viewer/useJsonViewerState.js +108 -0
  31. package/dist/components/json-viewer/utils.cjs +36 -0
  32. package/dist/components/json-viewer/utils.d.ts +21 -1
  33. package/dist/components/json-viewer/utils.js +35 -1
  34. package/dist/components/lightbox/Lightbox.cjs +2 -2
  35. package/dist/components/lightbox/Lightbox.d.ts +1 -1
  36. package/dist/components/lightbox/Lightbox.js +1 -1
  37. package/dist/components/line-viewer/LineViewer.cjs +2 -3
  38. package/dist/components/line-viewer/LineViewer.js +2 -3
  39. package/dist/components/line-viewer/tokenizeLineFormat.cjs +37 -17
  40. package/dist/components/line-viewer/tokenizeLineFormat.d.ts +5 -4
  41. package/dist/components/line-viewer/tokenizeLineFormat.js +37 -17
  42. package/dist/components/menu/Menu.cjs +3 -23
  43. package/dist/components/menu/Menu.js +3 -23
  44. package/dist/components/menu/Menu.module.css +4 -3
  45. package/dist/components/metric-tile/MetricTile.cjs +3 -2
  46. package/dist/components/metric-tile/MetricTile.js +2 -1
  47. package/dist/components/overlay/tooltip/Tooltip.cjs +7 -2
  48. package/dist/components/overlay/tooltip/Tooltip.d.ts +7 -1
  49. package/dist/components/overlay/tooltip/Tooltip.js +7 -2
  50. package/dist/components/overlay/tooltip/useTooltipTrigger.cjs +7 -1
  51. package/dist/components/overlay/tooltip/useTooltipTrigger.js +7 -1
  52. package/dist/components/page-layout/PageLayout.module.css +1 -1
  53. package/dist/components/table/Table.cjs +45 -16
  54. package/dist/components/table/Table.d.ts +1 -1
  55. package/dist/components/table/Table.js +47 -18
  56. package/dist/components/table/Table.module.css +135 -7
  57. package/dist/components/table/Table.types.d.ts +47 -1
  58. package/dist/components/table/TanstackTable.cjs +30 -2
  59. package/dist/components/table/TanstackTable.js +31 -3
  60. package/dist/components/table/components/TableBody.d.ts +1 -2
  61. package/dist/components/table/components/TableHeader.cjs +6 -4
  62. package/dist/components/table/components/TableHeader.d.ts +2 -1
  63. package/dist/components/table/components/TableHeader.js +6 -4
  64. package/dist/components/table/components/TableHeaderCell.cjs +5 -4
  65. package/dist/components/table/components/TableHeaderCell.d.ts +3 -1
  66. package/dist/components/table/components/TableHeaderCell.js +5 -4
  67. package/dist/components/table/components/TableRow.cjs +1 -1
  68. package/dist/components/table/components/TableRow.d.ts +1 -2
  69. package/dist/components/table/components/TableRow.js +1 -1
  70. package/dist/components/table/components/TableSkeletonBody.cjs +30 -0
  71. package/dist/components/table/components/TableSkeletonBody.d.ts +13 -0
  72. package/dist/components/table/components/TableSkeletonBody.js +24 -0
  73. package/dist/components/table/components/table-settings/TableHeaderSettings.cjs +28 -0
  74. package/dist/components/table/components/table-settings/TableHeaderSettings.d.ts +11 -0
  75. package/dist/components/table/components/table-settings/TableHeaderSettings.js +26 -0
  76. package/dist/components/table/components/table-settings/TableSettings.cjs +82 -32
  77. package/dist/components/table/components/table-settings/TableSettings.d.ts +14 -6
  78. package/dist/components/table/components/table-settings/TableSettings.js +84 -34
  79. package/dist/components/table/table.utils.cjs +2 -0
  80. package/dist/components/table/table.utils.d.ts +6 -0
  81. package/dist/components/table/table.utils.js +2 -1
  82. package/dist/components/table/tableSettings.utils.cjs +29 -0
  83. package/dist/components/table/tableSettings.utils.d.ts +9 -0
  84. package/dist/components/table/tableSettings.utils.js +24 -0
  85. package/dist/components/table/tanstackTable.utils.cjs +18 -0
  86. package/dist/components/table/tanstackTable.utils.js +19 -1
  87. package/dist/components/theme-button/ThemeButton.cjs +9 -4
  88. package/dist/components/theme-button/ThemeButton.d.ts +4 -2
  89. package/dist/components/theme-button/ThemeButton.js +9 -4
  90. package/dist/components/theme-script/ThemeScript.cjs +10 -4
  91. package/dist/components/theme-script/ThemeScript.d.ts +9 -1
  92. package/dist/components/theme-script/ThemeScript.js +10 -4
  93. package/dist/components/xml-viewer/XmlViewer.cjs +2 -3
  94. package/dist/components/xml-viewer/XmlViewer.js +2 -3
  95. package/dist/hooks/useColorScheme.cjs +18 -14
  96. package/dist/hooks/useColorScheme.d.ts +11 -1
  97. package/dist/hooks/useColorScheme.js +19 -15
  98. package/dist/hooks/useGetActiveTheme.cjs +4 -3
  99. package/dist/hooks/useGetActiveTheme.d.ts +7 -1
  100. package/dist/hooks/useGetActiveTheme.js +4 -3
  101. package/dist/hooks/useTableData.cjs +11 -7
  102. package/dist/hooks/useTableData.d.ts +8 -2
  103. package/dist/hooks/useTableData.js +11 -7
  104. package/dist/hooks/useTableSettings.cjs +25 -9
  105. package/dist/hooks/useTableSettings.d.ts +9 -6
  106. package/dist/hooks/useTableSettings.js +25 -9
  107. package/dist/hooks/useTheme.d.ts +6 -0
  108. package/dist/styles/styles.css +7 -3
  109. package/dist/styles/themes/dbc/colors.css +1 -1
  110. package/dist/styles.css +1 -476
  111. package/dist/tanstack-virtual.cjs +12 -0
  112. package/dist/tanstack-virtual.d.ts +1 -0
  113. package/dist/tanstack-virtual.js +1 -0
  114. package/package.json +13 -1
@@ -9,8 +9,8 @@ var Popover = require('../../components/popover/Popover');
9
9
  var useTheme = require('../../hooks/useTheme');
10
10
  var types = require('../../styles/themes/types');
11
11
 
12
- function ThemeMenuSection({ themes }) {
13
- const { theme, switchTheme } = useTheme.useTheme({ defaultTheme: themes[0] });
12
+ function ThemeMenuSection({ themes, storageKey }) {
13
+ const { theme, switchTheme } = useTheme.useTheme({ defaultTheme: themes[0], storageKey });
14
14
  return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
15
15
  /* @__PURE__ */ jsxRuntime.jsx(Menu.Menu.Header, { children: "Tema" }),
16
16
  themes.map((id) => /* @__PURE__ */ jsxRuntime.jsx(
@@ -26,8 +26,13 @@ function ThemeMenuSection({ themes }) {
26
26
  ))
27
27
  ] });
28
28
  }
29
- function ThemeButton({ themes, size, variant = "outlined" }) {
30
- const { theme, switchTheme } = useTheme.useTheme({ defaultTheme: themes[0] });
29
+ function ThemeButton({
30
+ themes,
31
+ size,
32
+ variant = "outlined",
33
+ storageKey
34
+ }) {
35
+ const { theme, switchTheme } = useTheme.useTheme({ defaultTheme: themes[0], storageKey });
31
36
  return /* @__PURE__ */ jsxRuntime.jsx(
32
37
  Popover.Popover,
33
38
  {
@@ -4,10 +4,12 @@ import type { ThemeId } from '../../hooks/useTheme';
4
4
  export interface ThemeMenuSectionProps {
5
5
  /** Every theme to offer as an option. The first entry is treated as the default. */
6
6
  themes: readonly ThemeId[];
7
+ /** Passed through to `useTheme` — see its docs for when to set this. */
8
+ storageKey?: string;
7
9
  }
8
10
  export interface ThemeButtonProps extends ThemeMenuSectionProps {
9
11
  size?: ButtonSize;
10
12
  variant?: ButtonVariant;
11
13
  }
12
- export declare function ThemeMenuSection({ themes }: ThemeMenuSectionProps): JSX.Element;
13
- export declare function ThemeButton({ themes, size, variant }: ThemeButtonProps): JSX.Element;
14
+ export declare function ThemeMenuSection({ themes, storageKey }: ThemeMenuSectionProps): JSX.Element;
15
+ export declare function ThemeButton({ themes, size, variant, storageKey, }: ThemeButtonProps): JSX.Element;
@@ -7,8 +7,8 @@ import { Popover } from '../../components/popover/Popover';
7
7
  import { useTheme } from '../../hooks/useTheme';
8
8
  import { THEME_LABELS } from '../../styles/themes/types';
9
9
 
10
- function ThemeMenuSection({ themes }) {
11
- const { theme, switchTheme } = useTheme({ defaultTheme: themes[0] });
10
+ function ThemeMenuSection({ themes, storageKey }) {
11
+ const { theme, switchTheme } = useTheme({ defaultTheme: themes[0], storageKey });
12
12
  return /* @__PURE__ */ jsxs(Fragment, { children: [
13
13
  /* @__PURE__ */ jsx(Menu.Header, { children: "Tema" }),
14
14
  themes.map((id) => /* @__PURE__ */ jsx(
@@ -24,8 +24,13 @@ function ThemeMenuSection({ themes }) {
24
24
  ))
25
25
  ] });
26
26
  }
27
- function ThemeButton({ themes, size, variant = "outlined" }) {
28
- const { theme, switchTheme } = useTheme({ defaultTheme: themes[0] });
27
+ function ThemeButton({
28
+ themes,
29
+ size,
30
+ variant = "outlined",
31
+ storageKey
32
+ }) {
33
+ const { theme, switchTheme } = useTheme({ defaultTheme: themes[0], storageKey });
29
34
  return /* @__PURE__ */ jsx(
30
35
  Popover,
31
36
  {
@@ -5,7 +5,7 @@ var productThemes = require('../../styles/themes/product-themes');
5
5
  var colorScheme_constants = require('../../utils/color-scheme.constants');
6
6
  var theme_constants = require('../../utils/theme.constants');
7
7
 
8
- function buildInitScript(defaultColorScheme, defaultTheme, storageKey) {
8
+ function buildInitScript(defaultColorScheme, defaultTheme, storageKey, colorSchemeStorageKey) {
9
9
  const productThemes$1 = JSON.stringify(productThemes.PRODUCT_THEMES);
10
10
  const themeBlock = defaultTheme === void 0 ? "" : `try{
11
11
  var THEME_KEY=${JSON.stringify(storageKey)};
@@ -38,7 +38,7 @@ function buildInitScript(defaultColorScheme, defaultTheme, storageKey) {
38
38
  return `(function(){
39
39
  function getCookie(name){var m=document.cookie.match(new RegExp('(?:^|; )'+name+'=([^;]*)'));return m?decodeURIComponent(m[1]):null}
40
40
  try{
41
- var SCHEME_KEY=${JSON.stringify(colorScheme_constants.COLOR_SCHEME_STORAGE_KEY)};
41
+ var SCHEME_KEY=${JSON.stringify(colorSchemeStorageKey)};
42
42
  var SCHEMES=${JSON.stringify(colorScheme_constants.COLOR_SCHEMES)};
43
43
  function isScheme(x){return !!x && SCHEMES.indexOf(x)!==-1}
44
44
  var resolvedScheme=${JSON.stringify(defaultColorScheme)};
@@ -52,13 +52,19 @@ function buildInitScript(defaultColorScheme, defaultTheme, storageKey) {
52
52
  function ThemeScript({
53
53
  defaultColorScheme = "system",
54
54
  defaultTheme,
55
- storageKey = theme_constants.THEME_STORAGE_KEY
55
+ storageKey = theme_constants.THEME_STORAGE_KEY,
56
+ colorSchemeStorageKey = colorScheme_constants.COLOR_SCHEME_STORAGE_KEY
56
57
  }) {
57
58
  return /* @__PURE__ */ jsxRuntime.jsx(
58
59
  "script",
59
60
  {
60
61
  dangerouslySetInnerHTML: {
61
- __html: buildInitScript(defaultColorScheme, defaultTheme, storageKey)
62
+ __html: buildInitScript(
63
+ defaultColorScheme,
64
+ defaultTheme,
65
+ storageKey,
66
+ colorSchemeStorageKey
67
+ )
62
68
  }
63
69
  }
64
70
  );
@@ -9,7 +9,15 @@ export interface ThemeScriptProps {
9
9
  * `data-product-theme` handling happens at all in that case.
10
10
  */
11
11
  defaultTheme?: ThemeId;
12
+ /**
13
+ * Storage key for the product theme axis. Apps sharing an origin with
14
+ * another app built on this library should each pass their own value here
15
+ * to keep their persisted theme independent — see `colorSchemeStorageKey`
16
+ * for the same concern on the color-scheme axis.
17
+ */
12
18
  storageKey?: string;
19
+ /** Storage key for the color-scheme axis. See `storageKey`. */
20
+ colorSchemeStorageKey?: string;
13
21
  }
14
22
  /**
15
23
  * Renders a blocking inline <script> that restores both the persisted color
@@ -41,4 +49,4 @@ export interface ThemeScriptProps {
41
49
  * </Head>
42
50
  * ```
43
51
  */
44
- export declare function ThemeScript({ defaultColorScheme, defaultTheme, storageKey, }: ThemeScriptProps): import("react/jsx-runtime").JSX.Element;
52
+ export declare function ThemeScript({ defaultColorScheme, defaultTheme, storageKey, colorSchemeStorageKey, }: ThemeScriptProps): import("react/jsx-runtime").JSX.Element;
@@ -3,7 +3,7 @@ import { PRODUCT_THEMES } from '../../styles/themes/product-themes';
3
3
  import { COLOR_SCHEME_STORAGE_KEY, COLOR_SCHEMES } from '../../utils/color-scheme.constants';
4
4
  import { THEME_STORAGE_KEY } from '../../utils/theme.constants';
5
5
 
6
- function buildInitScript(defaultColorScheme, defaultTheme, storageKey) {
6
+ function buildInitScript(defaultColorScheme, defaultTheme, storageKey, colorSchemeStorageKey) {
7
7
  const productThemes = JSON.stringify(PRODUCT_THEMES);
8
8
  const themeBlock = defaultTheme === void 0 ? "" : `try{
9
9
  var THEME_KEY=${JSON.stringify(storageKey)};
@@ -36,7 +36,7 @@ function buildInitScript(defaultColorScheme, defaultTheme, storageKey) {
36
36
  return `(function(){
37
37
  function getCookie(name){var m=document.cookie.match(new RegExp('(?:^|; )'+name+'=([^;]*)'));return m?decodeURIComponent(m[1]):null}
38
38
  try{
39
- var SCHEME_KEY=${JSON.stringify(COLOR_SCHEME_STORAGE_KEY)};
39
+ var SCHEME_KEY=${JSON.stringify(colorSchemeStorageKey)};
40
40
  var SCHEMES=${JSON.stringify(COLOR_SCHEMES)};
41
41
  function isScheme(x){return !!x && SCHEMES.indexOf(x)!==-1}
42
42
  var resolvedScheme=${JSON.stringify(defaultColorScheme)};
@@ -50,13 +50,19 @@ function buildInitScript(defaultColorScheme, defaultTheme, storageKey) {
50
50
  function ThemeScript({
51
51
  defaultColorScheme = "system",
52
52
  defaultTheme,
53
- storageKey = THEME_STORAGE_KEY
53
+ storageKey = THEME_STORAGE_KEY,
54
+ colorSchemeStorageKey = COLOR_SCHEME_STORAGE_KEY
54
55
  }) {
55
56
  return /* @__PURE__ */ jsx(
56
57
  "script",
57
58
  {
58
59
  dangerouslySetInnerHTML: {
59
- __html: buildInitScript(defaultColorScheme, defaultTheme, storageKey)
60
+ __html: buildInitScript(
61
+ defaultColorScheme,
62
+ defaultTheme,
63
+ storageKey,
64
+ colorSchemeStorageKey
65
+ )
60
66
  }
61
67
  }
62
68
  );
@@ -9,6 +9,7 @@ var Popover = require('../../components/popover/Popover');
9
9
  var usePersistentState = require('../../hooks/usePersistentState');
10
10
  var tokenizeXml = require('./tokenizeXml');
11
11
  var styles = require('./XmlViewer.module.css');
12
+ var clipboard_utils = require('../../utils/clipboard.utils');
12
13
  var Button = require('../button/Button');
13
14
  var Icon = require('../icon/Icon');
14
15
 
@@ -54,9 +55,7 @@ function XmlViewer({
54
55
  validate: (stored) => typeof stored === "boolean"
55
56
  });
56
57
  const handleCopy = () => {
57
- var _a;
58
- (_a = navigator.clipboard) == null ? void 0 : _a.writeText(xml).catch(() => {
59
- });
58
+ void clipboard_utils.copyToClipboard(xml);
60
59
  };
61
60
  const handleDoubleClick = () => {
62
61
  const el = codeRef.current;
@@ -7,6 +7,7 @@ import { Popover } from '../../components/popover/Popover';
7
7
  import { usePersistentState } from '../../hooks/usePersistentState';
8
8
  import { tokenizeXml } from './tokenizeXml';
9
9
  import styles from './XmlViewer.module.css';
10
+ import { copyToClipboard } from '../../utils/clipboard.utils';
10
11
  import { Button } from '../button/Button';
11
12
  import { Icon } from '../icon/Icon';
12
13
 
@@ -48,9 +49,7 @@ function XmlViewer({
48
49
  validate: (stored) => typeof stored === "boolean"
49
50
  });
50
51
  const handleCopy = () => {
51
- var _a;
52
- (_a = navigator.clipboard) == null ? void 0 : _a.writeText(xml).catch(() => {
53
- });
52
+ void copyToClipboard(xml);
54
53
  };
55
54
  const handleDoubleClick = () => {
56
55
  const el = codeRef.current;
@@ -6,9 +6,9 @@ var colorScheme_constants = require('../utils/color-scheme.constants');
6
6
  var cookie_utils = require('../utils/cookie.utils');
7
7
  var localStorage_utils = require('../utils/localStorage.utils');
8
8
 
9
- function persistColorScheme(id) {
10
- localStorage_utils.writeLocalStorage(colorScheme_constants.COLOR_SCHEME_STORAGE_KEY, id);
11
- cookie_utils.writeCookie(colorScheme_constants.COLOR_SCHEME_STORAGE_KEY, id);
9
+ function persistColorScheme(storageKey, id) {
10
+ localStorage_utils.writeLocalStorage(storageKey, id);
11
+ cookie_utils.writeCookie(storageKey, id);
12
12
  }
13
13
  function getDomColorScheme() {
14
14
  return document.documentElement.dataset.theme;
@@ -34,40 +34,44 @@ function getSnapshot() {
34
34
  function getServerSnapshot() {
35
35
  return null;
36
36
  }
37
- function resolveInitialColorScheme(initialColorScheme) {
37
+ function resolveInitialColorScheme(storageKey, initialColorScheme) {
38
38
  const fromDomAttribute = getDomColorScheme();
39
39
  let resolvedColorScheme = colorScheme_constants.isColorScheme(fromDomAttribute) ? fromDomAttribute : initialColorScheme;
40
- const fromCookie = cookie_utils.readCookie(colorScheme_constants.COLOR_SCHEME_STORAGE_KEY);
40
+ const fromCookie = cookie_utils.readCookie(storageKey);
41
41
  if (colorScheme_constants.isColorScheme(fromCookie)) {
42
42
  resolvedColorScheme = fromCookie;
43
43
  } else {
44
- const fromStorage = localStorage_utils.readLocalStorage(colorScheme_constants.COLOR_SCHEME_STORAGE_KEY);
44
+ const fromStorage = localStorage_utils.readLocalStorage(storageKey);
45
45
  if (colorScheme_constants.isColorScheme(fromStorage)) resolvedColorScheme = fromStorage;
46
46
  }
47
47
  return resolvedColorScheme;
48
48
  }
49
- function ensureResolved(initialColorScheme) {
49
+ function ensureResolved(initialColorScheme, storageKey) {
50
50
  if (resolved) return;
51
51
  resolved = true;
52
- const value = resolveInitialColorScheme(initialColorScheme);
52
+ const value = resolveInitialColorScheme(storageKey, initialColorScheme);
53
53
  applyColorScheme(value);
54
- persistColorScheme(value);
54
+ persistColorScheme(storageKey, value);
55
55
  currentColorScheme = value;
56
56
  notify();
57
57
  }
58
- function switchColorScheme(id) {
58
+ function switchColorSchemeInternal(storageKey, id) {
59
59
  applyColorScheme(id);
60
- persistColorScheme(id);
60
+ persistColorScheme(storageKey, id);
61
61
  currentColorScheme = id;
62
62
  resolved = true;
63
63
  notify();
64
64
  return id;
65
65
  }
66
- function useColorScheme(initialColorScheme = "system") {
66
+ function useColorScheme(initialColorScheme = "system", options = {}) {
67
+ const { storageKey = colorScheme_constants.COLOR_SCHEME_STORAGE_KEY } = options;
67
68
  react.useEffect(() => {
68
- ensureResolved(initialColorScheme);
69
- }, [initialColorScheme]);
69
+ ensureResolved(initialColorScheme, storageKey);
70
+ }, [initialColorScheme, storageKey]);
70
71
  const colorScheme = react.useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
72
+ function switchColorScheme(id) {
73
+ return switchColorSchemeInternal(storageKey, id);
74
+ }
71
75
  return { colorScheme, switchColorScheme };
72
76
  }
73
77
 
@@ -1,6 +1,16 @@
1
1
  import type { ColorScheme } from '../utils/color-scheme.constants';
2
2
  export type { ColorScheme };
3
- export declare function useColorScheme(initialColorScheme?: ColorScheme): {
3
+ export interface UseColorSchemeOptions {
4
+ /**
5
+ * Storage key used for the cookie + localStorage entry. Defaults to a
6
+ * shared key, so apps that run on the same origin (e.g. multiple products
7
+ * under one domain) should each pass their own value here — otherwise
8
+ * they'll unintentionally read and overwrite each other's persisted color
9
+ * scheme.
10
+ */
11
+ storageKey?: string;
12
+ }
13
+ export declare function useColorScheme(initialColorScheme?: ColorScheme, options?: UseColorSchemeOptions): {
4
14
  colorScheme: ColorScheme | null;
5
15
  switchColorScheme: (id: ColorScheme) => ColorScheme;
6
16
  };
@@ -1,12 +1,12 @@
1
1
  'use client';
2
2
  import { useEffect, useSyncExternalStore } from 'react';
3
- import { isColorScheme, COLOR_SCHEME_STORAGE_KEY } from '../utils/color-scheme.constants';
3
+ import { COLOR_SCHEME_STORAGE_KEY, isColorScheme } from '../utils/color-scheme.constants';
4
4
  import { readCookie, writeCookie } from '../utils/cookie.utils';
5
5
  import { readLocalStorage, writeLocalStorage } from '../utils/localStorage.utils';
6
6
 
7
- function persistColorScheme(id) {
8
- writeLocalStorage(COLOR_SCHEME_STORAGE_KEY, id);
9
- writeCookie(COLOR_SCHEME_STORAGE_KEY, id);
7
+ function persistColorScheme(storageKey, id) {
8
+ writeLocalStorage(storageKey, id);
9
+ writeCookie(storageKey, id);
10
10
  }
11
11
  function getDomColorScheme() {
12
12
  return document.documentElement.dataset.theme;
@@ -32,40 +32,44 @@ function getSnapshot() {
32
32
  function getServerSnapshot() {
33
33
  return null;
34
34
  }
35
- function resolveInitialColorScheme(initialColorScheme) {
35
+ function resolveInitialColorScheme(storageKey, initialColorScheme) {
36
36
  const fromDomAttribute = getDomColorScheme();
37
37
  let resolvedColorScheme = isColorScheme(fromDomAttribute) ? fromDomAttribute : initialColorScheme;
38
- const fromCookie = readCookie(COLOR_SCHEME_STORAGE_KEY);
38
+ const fromCookie = readCookie(storageKey);
39
39
  if (isColorScheme(fromCookie)) {
40
40
  resolvedColorScheme = fromCookie;
41
41
  } else {
42
- const fromStorage = readLocalStorage(COLOR_SCHEME_STORAGE_KEY);
42
+ const fromStorage = readLocalStorage(storageKey);
43
43
  if (isColorScheme(fromStorage)) resolvedColorScheme = fromStorage;
44
44
  }
45
45
  return resolvedColorScheme;
46
46
  }
47
- function ensureResolved(initialColorScheme) {
47
+ function ensureResolved(initialColorScheme, storageKey) {
48
48
  if (resolved) return;
49
49
  resolved = true;
50
- const value = resolveInitialColorScheme(initialColorScheme);
50
+ const value = resolveInitialColorScheme(storageKey, initialColorScheme);
51
51
  applyColorScheme(value);
52
- persistColorScheme(value);
52
+ persistColorScheme(storageKey, value);
53
53
  currentColorScheme = value;
54
54
  notify();
55
55
  }
56
- function switchColorScheme(id) {
56
+ function switchColorSchemeInternal(storageKey, id) {
57
57
  applyColorScheme(id);
58
- persistColorScheme(id);
58
+ persistColorScheme(storageKey, id);
59
59
  currentColorScheme = id;
60
60
  resolved = true;
61
61
  notify();
62
62
  return id;
63
63
  }
64
- function useColorScheme(initialColorScheme = "system") {
64
+ function useColorScheme(initialColorScheme = "system", options = {}) {
65
+ const { storageKey = COLOR_SCHEME_STORAGE_KEY } = options;
65
66
  useEffect(() => {
66
- ensureResolved(initialColorScheme);
67
- }, [initialColorScheme]);
67
+ ensureResolved(initialColorScheme, storageKey);
68
+ }, [initialColorScheme, storageKey]);
68
69
  const colorScheme = useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
70
+ function switchColorScheme(id) {
71
+ return switchColorSchemeInternal(storageKey, id);
72
+ }
69
73
  return { colorScheme, switchColorScheme };
70
74
  }
71
75
 
@@ -4,9 +4,10 @@
4
4
  var useColorScheme = require('../hooks/useColorScheme');
5
5
  var useTheme = require('./useTheme');
6
6
 
7
- function useGetActiveTheme() {
8
- const { theme } = useTheme.useTheme();
9
- const { colorScheme } = useColorScheme.useColorScheme();
7
+ function useGetActiveTheme(options = {}) {
8
+ const { storageKey, colorSchemeStorageKey } = options;
9
+ const { theme } = useTheme.useTheme({ storageKey });
10
+ const { colorScheme } = useColorScheme.useColorScheme("system", { storageKey: colorSchemeStorageKey });
10
11
  const themeKey = theme && colorScheme ? `${theme}-${colorScheme}` : null;
11
12
  return { theme, colorScheme, themeKey };
12
13
  }
@@ -1,9 +1,15 @@
1
1
  import type { ColorScheme } from '../utils/color-scheme.constants';
2
2
  import type { ThemeId } from './useTheme';
3
3
  export type { ColorScheme, ThemeId };
4
+ export interface UseGetActiveThemeOptions {
5
+ /** Passed through to `useTheme` — must match the key used elsewhere in the app. */
6
+ storageKey?: string;
7
+ /** Passed through to `useColorScheme` — must match the key used elsewhere in the app. */
8
+ colorSchemeStorageKey?: string;
9
+ }
4
10
  export interface UseGetActiveThemeResult {
5
11
  theme: ThemeId | null;
6
12
  colorScheme: ColorScheme | null;
7
13
  themeKey: string | null;
8
14
  }
9
- export declare function useGetActiveTheme(): UseGetActiveThemeResult;
15
+ export declare function useGetActiveTheme(options?: UseGetActiveThemeOptions): UseGetActiveThemeResult;
@@ -2,9 +2,10 @@
2
2
  import { useColorScheme } from '../hooks/useColorScheme';
3
3
  import { useTheme } from './useTheme';
4
4
 
5
- function useGetActiveTheme() {
6
- const { theme } = useTheme();
7
- const { colorScheme } = useColorScheme();
5
+ function useGetActiveTheme(options = {}) {
6
+ const { storageKey, colorSchemeStorageKey } = options;
7
+ const { theme } = useTheme({ storageKey });
8
+ const { colorScheme } = useColorScheme("system", { storageKey: colorSchemeStorageKey });
8
9
  const themeKey = theme && colorScheme ? `${theme}-${colorScheme}` : null;
9
10
  return { theme, colorScheme, themeKey };
10
11
  }
@@ -15,17 +15,21 @@ function useTableData({
15
15
  const hasPagination = pagination != null;
16
16
  const nullsMode = (_a = sorting == null ? void 0 : sorting.nulls) != null ? _a : "last";
17
17
  const mergedComparators = react.useMemo(() => {
18
- var _a2, _b2;
18
+ var _a2, _b2, _c2;
19
19
  const derived = {};
20
20
  for (const col of (_a2 = sorting == null ? void 0 : sorting.columns) != null ? _a2 : []) {
21
- const colId = (_b2 = col.id) != null ? _b2 : col.accessorKey;
21
+ const accessorKey = "accessorKey" in col ? col.accessorKey : void 0;
22
+ const colId = (_b2 = col.id) != null ? _b2 : typeof accessorKey === "string" || typeof accessorKey === "number" ? String(accessorKey) : void 0;
22
23
  if (!colId) continue;
23
- const accessorFn = col.accessorFn;
24
- const accessorKey = col.accessorKey;
25
- if (accessorFn) {
24
+ const accessorFn = "accessorFn" in col ? col.accessorFn : void 0;
25
+ const accessor = (_c2 = col.accessor) != null ? _c2 : accessorKey;
26
+ const sortFunction = col.sortFunction;
27
+ if (sortFunction) {
28
+ derived[colId] = (a, b, dir) => dir === "asc" ? sortFunction(a, b) : -sortFunction(a, b);
29
+ } else if (accessorFn) {
26
30
  derived[colId] = (a, b, dir) => useSorting.defaultCompare(accessorFn(a, 0), accessorFn(b, 0), dir, nullsMode);
27
- } else if (accessorKey) {
28
- derived[colId] = (a, b, dir) => useSorting.defaultCompare(a[accessorKey], b[accessorKey], dir, nullsMode);
31
+ } else if (accessor != null) {
32
+ derived[colId] = (a, b, dir) => useSorting.defaultCompare(a[accessor], b[accessor], dir, nullsMode);
29
33
  }
30
34
  }
31
35
  return { ...derived, ...sorting == null ? void 0 : sorting.columnComparators };
@@ -1,7 +1,12 @@
1
- import type { ColumnDef } from '@tanstack/react-table';
2
1
  import type { PageChangeEvent } from '../components/pagination/Pagination';
2
+ import type { ColumnItem } from '../components/table/Table.types';
3
3
  import { type PaginationState } from './usePagination';
4
4
  import { type SortDirection, type SortState, type ColumnComparators } from './useSorting';
5
+ /** Sorting fields from Table, with support for existing accessor-shaped columns. */
6
+ export interface UseTableDataColumn<T> extends Partial<Pick<ColumnItem<T>, 'id' | 'accessor' | 'sortFunction'>> {
7
+ accessorKey?: keyof T | string;
8
+ accessorFn?: (row: T, index: number) => unknown;
9
+ }
5
10
  export interface UseTableDataProps<T> {
6
11
  data?: readonly T[];
7
12
  pagination?: {
@@ -18,7 +23,8 @@ export interface UseTableDataProps<T> {
18
23
  columnComparators?: ColumnComparators<T>;
19
24
  nulls?: 'first' | 'last';
20
25
  allowUnsort?: boolean;
21
- columns?: ReadonlyArray<ColumnDef<T, any>>;
26
+ /** Reuse Table's columns. Explicit columnComparators override derived sorting. */
27
+ columns?: ReadonlyArray<ColumnItem<T> | UseTableDataColumn<T>>;
22
28
  };
23
29
  /**
24
30
  * Resets to page 1 whenever sorting changes (typical UX).
@@ -13,17 +13,21 @@ function useTableData({
13
13
  const hasPagination = pagination != null;
14
14
  const nullsMode = (_a = sorting == null ? void 0 : sorting.nulls) != null ? _a : "last";
15
15
  const mergedComparators = useMemo(() => {
16
- var _a2, _b2;
16
+ var _a2, _b2, _c2;
17
17
  const derived = {};
18
18
  for (const col of (_a2 = sorting == null ? void 0 : sorting.columns) != null ? _a2 : []) {
19
- const colId = (_b2 = col.id) != null ? _b2 : col.accessorKey;
19
+ const accessorKey = "accessorKey" in col ? col.accessorKey : void 0;
20
+ const colId = (_b2 = col.id) != null ? _b2 : typeof accessorKey === "string" || typeof accessorKey === "number" ? String(accessorKey) : void 0;
20
21
  if (!colId) continue;
21
- const accessorFn = col.accessorFn;
22
- const accessorKey = col.accessorKey;
23
- if (accessorFn) {
22
+ const accessorFn = "accessorFn" in col ? col.accessorFn : void 0;
23
+ const accessor = (_c2 = col.accessor) != null ? _c2 : accessorKey;
24
+ const sortFunction = col.sortFunction;
25
+ if (sortFunction) {
26
+ derived[colId] = (a, b, dir) => dir === "asc" ? sortFunction(a, b) : -sortFunction(a, b);
27
+ } else if (accessorFn) {
24
28
  derived[colId] = (a, b, dir) => defaultCompare(accessorFn(a, 0), accessorFn(b, 0), dir, nullsMode);
25
- } else if (accessorKey) {
26
- derived[colId] = (a, b, dir) => defaultCompare(a[accessorKey], b[accessorKey], dir, nullsMode);
29
+ } else if (accessor != null) {
30
+ derived[colId] = (a, b, dir) => defaultCompare(a[accessor], b[accessor], dir, nullsMode);
27
31
  }
28
32
  }
29
33
  return { ...derived, ...sorting == null ? void 0 : sorting.columnComparators };
@@ -2,19 +2,18 @@
2
2
  'use strict';
3
3
 
4
4
  var react = require('react');
5
+ var tableSettings_utils = require('../components/table/tableSettings.utils');
5
6
  var localStorage_utils = require('../utils/localStorage.utils');
6
7
 
7
8
  function getDefaultVisibleIds(tableColumns) {
8
9
  var _a;
9
- return (_a = tableColumns == null ? void 0 : tableColumns.filter((c) => {
10
- var _a2;
11
- return !((_a2 = c.meta) == null ? void 0 : _a2.hidden);
12
- }).map((c) => c.id).filter(Boolean)) != null ? _a : [];
10
+ return (_a = tableColumns == null ? void 0 : tableColumns.filter((c) => !tableSettings_utils.isSettingsColumnHidden(c)).map(tableSettings_utils.getSettingsColumnId).filter((id) => typeof id === "string" && id.length > 0)) != null ? _a : [];
13
11
  }
14
12
  function mergeDefaults(stored, defaults) {
15
13
  const viewMode = (stored == null ? void 0 : stored.viewMode) === "compact" || (stored == null ? void 0 : stored.viewMode) === "wrapped" ? stored.viewMode : defaults.viewMode;
16
14
  const visibleColumnIds = Array.isArray(stored == null ? void 0 : stored.visibleColumnIds) && stored.visibleColumnIds.length > 0 ? stored.visibleColumnIds : defaults.visibleColumnIds;
17
- return { viewMode, visibleColumnIds };
15
+ const striped = typeof (stored == null ? void 0 : stored.striped) === "boolean" ? stored.striped : defaults.striped;
16
+ return { viewMode, visibleColumnIds, striped };
18
17
  }
19
18
  const localStorageTableSettingsStorage = {
20
19
  get: (key) => {
@@ -30,19 +29,23 @@ function useTableSettings({
30
29
  tableColumns,
31
30
  defaultViewMode = "compact",
32
31
  defaultVisibleColumnIds,
32
+ defaultStriped = false,
33
33
  storage = localStorageTableSettingsStorage
34
34
  }) {
35
35
  const defaults = react.useMemo(() => {
36
36
  return {
37
37
  viewMode: defaultViewMode,
38
- visibleColumnIds: defaultVisibleColumnIds != null ? defaultVisibleColumnIds : getDefaultVisibleIds(tableColumns)
38
+ visibleColumnIds: defaultVisibleColumnIds != null ? defaultVisibleColumnIds : getDefaultVisibleIds(tableColumns),
39
+ striped: defaultStriped
39
40
  };
40
- }, [defaultViewMode, defaultVisibleColumnIds, tableColumns]);
41
+ }, [defaultViewMode, defaultVisibleColumnIds, defaultStriped, tableColumns]);
41
42
  const [state, setState] = react.useState(defaults);
42
43
  react.useEffect(() => {
43
44
  const stored = storage.get(storageKey);
44
45
  const next = mergeDefaults(stored, defaults);
45
- setState(next);
46
+ setState(
47
+ (prev) => prev.viewMode === next.viewMode && prev.striped === next.striped && prev.visibleColumnIds.length === next.visibleColumnIds.length && prev.visibleColumnIds.every((id, index) => id === next.visibleColumnIds[index]) ? prev : next
48
+ );
46
49
  }, [storageKey, storage, defaults]);
47
50
  const persist = react.useCallback(
48
51
  (next) => storage.set(storageKey, next),
@@ -77,12 +80,25 @@ function useTableSettings({
77
80
  },
78
81
  [persist]
79
82
  );
83
+ const setStriped = react.useCallback(
84
+ (nextStriped) => {
85
+ setState((prev) => {
86
+ if (prev.striped === nextStriped) return prev;
87
+ const next = { ...prev, striped: nextStriped };
88
+ persist(next);
89
+ return next;
90
+ });
91
+ },
92
+ [persist]
93
+ );
80
94
  return {
81
95
  viewMode: state.viewMode,
82
96
  toggleViewMode,
83
97
  setViewMode,
84
98
  visibleColumnIds: state.visibleColumnIds,
85
- setVisibleColumnIds
99
+ setVisibleColumnIds,
100
+ striped: state.striped,
101
+ setStriped
86
102
  };
87
103
  }
88
104
 
@@ -1,26 +1,29 @@
1
- import { ColumnDef } from '@tanstack/react-table';
2
- export type ViewMode = 'compact' | 'wrapped';
1
+ import type { ColumnItem, TableSettingsColumn, ViewMode } from '../components/table/Table.types';
2
+ export type { ViewMode } from '../components/table/Table.types';
3
3
  export type TableSettingsState = {
4
4
  viewMode: ViewMode;
5
5
  visibleColumnIds: string[];
6
+ striped: boolean;
6
7
  };
7
8
  export type TableSettingsStorage = {
8
9
  get: (key: string) => TableSettingsState | undefined;
9
10
  set: (key: string, next: TableSettingsState) => void;
10
11
  };
11
12
  export declare const localStorageTableSettingsStorage: TableSettingsStorage;
12
- interface UseTableSettingsOptions {
13
+ export interface UseTableSettingsOptions<T = unknown> {
13
14
  storageKey: string;
14
- tableColumns?: ColumnDef<any>[];
15
+ tableColumns?: ReadonlyArray<ColumnItem<T> | TableSettingsColumn>;
15
16
  defaultViewMode?: ViewMode;
16
17
  defaultVisibleColumnIds?: string[];
18
+ defaultStriped?: boolean;
17
19
  storage?: TableSettingsStorage;
18
20
  }
19
- export declare function useTableSettings({ storageKey, tableColumns, defaultViewMode, defaultVisibleColumnIds, storage, }: UseTableSettingsOptions): {
21
+ export declare function useTableSettings<T = unknown>({ storageKey, tableColumns, defaultViewMode, defaultVisibleColumnIds, defaultStriped, storage, }: UseTableSettingsOptions<T>): {
20
22
  viewMode: ViewMode;
21
23
  toggleViewMode: () => void;
22
24
  setViewMode: (mode: ViewMode) => void;
23
25
  visibleColumnIds: string[];
24
26
  setVisibleColumnIds: (ids: string[]) => void;
27
+ striped: boolean;
28
+ setStriped: (nextStriped: boolean) => void;
25
29
  };
26
- export {};