@dbcdk/react-components 0.0.195 → 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 (107) 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 -253
  20. package/dist/components/json-viewer/JsonViewer.js +37 -250
  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/menu/Menu.cjs +3 -23
  38. package/dist/components/menu/Menu.js +3 -23
  39. package/dist/components/menu/Menu.module.css +4 -3
  40. package/dist/components/metric-tile/MetricTile.cjs +3 -2
  41. package/dist/components/metric-tile/MetricTile.js +2 -1
  42. package/dist/components/overlay/tooltip/Tooltip.cjs +7 -2
  43. package/dist/components/overlay/tooltip/Tooltip.d.ts +7 -1
  44. package/dist/components/overlay/tooltip/Tooltip.js +7 -2
  45. package/dist/components/overlay/tooltip/useTooltipTrigger.cjs +7 -1
  46. package/dist/components/overlay/tooltip/useTooltipTrigger.js +7 -1
  47. package/dist/components/page-layout/PageLayout.module.css +1 -1
  48. package/dist/components/table/Table.cjs +45 -16
  49. package/dist/components/table/Table.d.ts +1 -1
  50. package/dist/components/table/Table.js +47 -18
  51. package/dist/components/table/Table.module.css +135 -7
  52. package/dist/components/table/Table.types.d.ts +47 -1
  53. package/dist/components/table/TanstackTable.cjs +30 -2
  54. package/dist/components/table/TanstackTable.js +31 -3
  55. package/dist/components/table/components/TableBody.d.ts +1 -2
  56. package/dist/components/table/components/TableHeader.cjs +6 -4
  57. package/dist/components/table/components/TableHeader.d.ts +2 -1
  58. package/dist/components/table/components/TableHeader.js +6 -4
  59. package/dist/components/table/components/TableHeaderCell.cjs +5 -4
  60. package/dist/components/table/components/TableHeaderCell.d.ts +3 -1
  61. package/dist/components/table/components/TableHeaderCell.js +5 -4
  62. package/dist/components/table/components/TableRow.cjs +1 -1
  63. package/dist/components/table/components/TableRow.d.ts +1 -2
  64. package/dist/components/table/components/TableRow.js +1 -1
  65. package/dist/components/table/components/TableSkeletonBody.cjs +30 -0
  66. package/dist/components/table/components/TableSkeletonBody.d.ts +13 -0
  67. package/dist/components/table/components/TableSkeletonBody.js +24 -0
  68. package/dist/components/table/components/table-settings/TableHeaderSettings.cjs +28 -0
  69. package/dist/components/table/components/table-settings/TableHeaderSettings.d.ts +11 -0
  70. package/dist/components/table/components/table-settings/TableHeaderSettings.js +26 -0
  71. package/dist/components/table/components/table-settings/TableSettings.cjs +82 -32
  72. package/dist/components/table/components/table-settings/TableSettings.d.ts +14 -6
  73. package/dist/components/table/components/table-settings/TableSettings.js +84 -34
  74. package/dist/components/table/table.utils.cjs +2 -0
  75. package/dist/components/table/table.utils.d.ts +6 -0
  76. package/dist/components/table/table.utils.js +2 -1
  77. package/dist/components/table/tableSettings.utils.cjs +29 -0
  78. package/dist/components/table/tableSettings.utils.d.ts +9 -0
  79. package/dist/components/table/tableSettings.utils.js +24 -0
  80. package/dist/components/table/tanstackTable.utils.cjs +18 -0
  81. package/dist/components/table/tanstackTable.utils.js +19 -1
  82. package/dist/components/theme-button/ThemeButton.cjs +9 -4
  83. package/dist/components/theme-button/ThemeButton.d.ts +4 -2
  84. package/dist/components/theme-button/ThemeButton.js +9 -4
  85. package/dist/components/theme-script/ThemeScript.cjs +10 -4
  86. package/dist/components/theme-script/ThemeScript.d.ts +9 -1
  87. package/dist/components/theme-script/ThemeScript.js +10 -4
  88. package/dist/hooks/useColorScheme.cjs +18 -14
  89. package/dist/hooks/useColorScheme.d.ts +11 -1
  90. package/dist/hooks/useColorScheme.js +19 -15
  91. package/dist/hooks/useGetActiveTheme.cjs +4 -3
  92. package/dist/hooks/useGetActiveTheme.d.ts +7 -1
  93. package/dist/hooks/useGetActiveTheme.js +4 -3
  94. package/dist/hooks/useTableData.cjs +11 -7
  95. package/dist/hooks/useTableData.d.ts +8 -2
  96. package/dist/hooks/useTableData.js +11 -7
  97. package/dist/hooks/useTableSettings.cjs +25 -9
  98. package/dist/hooks/useTableSettings.d.ts +9 -6
  99. package/dist/hooks/useTableSettings.js +25 -9
  100. package/dist/hooks/useTheme.d.ts +6 -0
  101. package/dist/styles/styles.css +7 -3
  102. package/dist/styles/themes/dbc/colors.css +1 -1
  103. package/dist/styles.css +1 -476
  104. package/dist/tanstack-virtual.cjs +12 -0
  105. package/dist/tanstack-virtual.d.ts +1 -0
  106. package/dist/tanstack-virtual.js +1 -0
  107. package/package.json +13 -1
@@ -118,6 +118,7 @@ function buildDistributedColumnWidths(args) {
118
118
  id: c.id,
119
119
  width: resizedPx,
120
120
  weight: 0,
121
+ min,
121
122
  max: resizedPx,
122
123
  fixed: true
123
124
  };
@@ -128,10 +129,17 @@ function buildDistributedColumnWidths(args) {
128
129
  id: c.id,
129
130
  width: min,
130
131
  weight,
132
+ min,
131
133
  max,
132
134
  fixed: false
133
135
  };
134
136
  });
137
+ const lastTrack = tracks[tracks.length - 1];
138
+ if (hasContextMenu && lastTrack && !lastTrack.fixed) {
139
+ lastTrack.min += table_utils.ROW_ACTIONS_RESERVE_PX;
140
+ lastTrack.width += table_utils.ROW_ACTIONS_RESERVE_PX;
141
+ if (lastTrack.max != null) lastTrack.max += table_utils.ROW_ACTIONS_RESERVE_PX;
142
+ }
135
143
  const fixedWidth = selectionWidth + contextMenuWidth + tracks.reduce((sum, track) => sum + track.width, 0);
136
144
  let remaining = Math.max(0, availableWidth - fixedWidth);
137
145
  let active = tracks.filter(
@@ -156,6 +164,16 @@ function buildDistributedColumnWidths(args) {
156
164
  remaining -= consumed;
157
165
  active = nextActive;
158
166
  }
167
+ const flexible = tracks.filter((track) => !track.fixed);
168
+ if (remaining > 0.5 && flexible.length > 0 && flexible.every((track) => track.max != null)) {
169
+ const stretchable = flexible.filter((track) => track.max > track.min);
170
+ const totalWeight = stretchable.reduce((sum, track) => sum + track.weight, 0);
171
+ if (totalWeight > 0) {
172
+ for (const track of stretchable) {
173
+ track.width += remaining * track.weight / totalWeight;
174
+ }
175
+ }
176
+ }
159
177
  const floatTrackTotal = tracks.reduce((sum, track) => sum + track.width, 0);
160
178
  const maxTrackWidth = availableWidth - selectionWidth - contextMenuWidth;
161
179
  const targetTrackWidth = Math.min(
@@ -1,4 +1,4 @@
1
- import { DEFAULT_COLUMN_PX, SELECTION_COLUMN_PX } from './table.utils';
1
+ import { DEFAULT_COLUMN_PX, ROW_ACTIONS_RESERVE_PX, SELECTION_COLUMN_PX } from './table.utils';
2
2
 
3
3
  function getColumnId(def, index) {
4
4
  const d = def;
@@ -116,6 +116,7 @@ function buildDistributedColumnWidths(args) {
116
116
  id: c.id,
117
117
  width: resizedPx,
118
118
  weight: 0,
119
+ min,
119
120
  max: resizedPx,
120
121
  fixed: true
121
122
  };
@@ -126,10 +127,17 @@ function buildDistributedColumnWidths(args) {
126
127
  id: c.id,
127
128
  width: min,
128
129
  weight,
130
+ min,
129
131
  max,
130
132
  fixed: false
131
133
  };
132
134
  });
135
+ const lastTrack = tracks[tracks.length - 1];
136
+ if (hasContextMenu && lastTrack && !lastTrack.fixed) {
137
+ lastTrack.min += ROW_ACTIONS_RESERVE_PX;
138
+ lastTrack.width += ROW_ACTIONS_RESERVE_PX;
139
+ if (lastTrack.max != null) lastTrack.max += ROW_ACTIONS_RESERVE_PX;
140
+ }
133
141
  const fixedWidth = selectionWidth + contextMenuWidth + tracks.reduce((sum, track) => sum + track.width, 0);
134
142
  let remaining = Math.max(0, availableWidth - fixedWidth);
135
143
  let active = tracks.filter(
@@ -154,6 +162,16 @@ function buildDistributedColumnWidths(args) {
154
162
  remaining -= consumed;
155
163
  active = nextActive;
156
164
  }
165
+ const flexible = tracks.filter((track) => !track.fixed);
166
+ if (remaining > 0.5 && flexible.length > 0 && flexible.every((track) => track.max != null)) {
167
+ const stretchable = flexible.filter((track) => track.max > track.min);
168
+ const totalWeight = stretchable.reduce((sum, track) => sum + track.weight, 0);
169
+ if (totalWeight > 0) {
170
+ for (const track of stretchable) {
171
+ track.width += remaining * track.weight / totalWeight;
172
+ }
173
+ }
174
+ }
157
175
  const floatTrackTotal = tracks.reduce((sum, track) => sum + track.width, 0);
158
176
  const maxTrackWidth = availableWidth - selectionWidth - contextMenuWidth;
159
177
  const targetTrackWidth = Math.min(
@@ -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
  );
@@ -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