@extend-ai/react-xlsx 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -16009,6 +16009,7 @@ function darkenColor3(color, ratio) {
16009
16009
  return mixRgbColor3(color, "#000000", ratio);
16010
16010
  }
16011
16011
  var ViewerContext = React4.createContext(null);
16012
+ var ViewerAppearanceContext = React4.createContext({ isDark: false });
16012
16013
  function classNames(...values) {
16013
16014
  return values.filter(Boolean).join(" ");
16014
16015
  }
@@ -17270,40 +17271,8 @@ function resolveImageHandleStyle(position, stroke, surface) {
17270
17271
  }
17271
17272
  return style;
17272
17273
  }
17273
- function resolveIsDarkMode() {
17274
- if (typeof document === "undefined") {
17275
- return false;
17276
- }
17277
- const classList = document.documentElement.classList;
17278
- if (classList.contains("dark")) {
17279
- return true;
17280
- }
17281
- if (classList.contains("light")) {
17282
- return false;
17283
- }
17284
- return typeof window !== "undefined" && window.matchMedia("(prefers-color-scheme: dark)").matches;
17285
- }
17286
- function useViewerPalette() {
17287
- const [isDarkMode, setIsDarkMode] = React4.useState(resolveIsDarkMode);
17288
- React4.useEffect(() => {
17289
- if (typeof window === "undefined") {
17290
- return;
17291
- }
17292
- const update = () => setIsDarkMode(resolveIsDarkMode());
17293
- const mediaQuery = window.matchMedia("(prefers-color-scheme: dark)");
17294
- const observer = new MutationObserver(update);
17295
- observer.observe(document.documentElement, {
17296
- attributeFilter: ["class", "data-theme"],
17297
- attributes: true
17298
- });
17299
- mediaQuery.addEventListener?.("change", update);
17300
- update();
17301
- return () => {
17302
- observer.disconnect();
17303
- mediaQuery.removeEventListener?.("change", update);
17304
- };
17305
- }, []);
17306
- return isDarkMode ? DARK_PALETTE : LIGHT_PALETTE;
17274
+ function useViewerPalette(isDark = false) {
17275
+ return isDark ? DARK_PALETTE : LIGHT_PALETTE;
17307
17276
  }
17308
17277
  function columnLabel2(col) {
17309
17278
  let label = "";
@@ -18148,6 +18117,57 @@ function DefaultTableHeaderMenu({
18148
18117
  }
18149
18118
  );
18150
18119
  }
18120
+ function SegmentedControl({
18121
+ items,
18122
+ onValueChange,
18123
+ palette,
18124
+ value
18125
+ }) {
18126
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
18127
+ "div",
18128
+ {
18129
+ "aria-label": "Workbook sheets",
18130
+ role: "tablist",
18131
+ style: {
18132
+ alignItems: "center",
18133
+ backgroundColor: palette.sheetInactiveSurface,
18134
+ border: `1px solid ${palette.strongBorder}`,
18135
+ borderRadius: 10,
18136
+ display: "inline-flex",
18137
+ gap: 2,
18138
+ minHeight: 36,
18139
+ padding: 2
18140
+ },
18141
+ children: items.map((item) => {
18142
+ const selected = item.id === value;
18143
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
18144
+ "button",
18145
+ {
18146
+ "aria-selected": selected,
18147
+ onClick: () => onValueChange(item.id),
18148
+ role: "tab",
18149
+ style: {
18150
+ backgroundColor: selected ? palette.sheetActiveSurface : "transparent",
18151
+ border: "none",
18152
+ borderRadius: 8,
18153
+ boxShadow: selected ? palette.shadow : "none",
18154
+ color: selected ? palette.sheetActiveText : palette.sheetInactiveText,
18155
+ cursor: "pointer",
18156
+ fontSize: 12,
18157
+ fontWeight: selected ? 600 : 500,
18158
+ padding: "7px 12px",
18159
+ transition: "background-color 120ms ease, color 120ms ease, box-shadow 120ms ease",
18160
+ whiteSpace: "nowrap"
18161
+ },
18162
+ type: "button",
18163
+ children: item.label
18164
+ },
18165
+ item.id
18166
+ );
18167
+ })
18168
+ }
18169
+ );
18170
+ }
18151
18171
  function DefaultToolbar({ controller, palette }) {
18152
18172
  const {
18153
18173
  activeTabIndex,
@@ -18269,19 +18289,26 @@ function DefaultToolbar({ controller, palette }) {
18269
18289
  canDownload ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
18270
18290
  "button",
18271
18291
  {
18292
+ "aria-label": "Download workbook",
18272
18293
  onClick: download,
18273
18294
  style: {
18295
+ alignItems: "center",
18274
18296
  background: palette.buttonSurface,
18275
18297
  border: `1px solid ${palette.strongBorder}`,
18276
18298
  borderRadius: 8,
18277
18299
  color: palette.buttonText,
18278
18300
  cursor: "pointer",
18279
- fontSize: 12,
18301
+ display: "inline-flex",
18302
+ fontSize: 16,
18280
18303
  fontWeight: 500,
18281
- padding: "6px 10px"
18304
+ height: 32,
18305
+ justifyContent: "center",
18306
+ padding: 0,
18307
+ width: 32
18282
18308
  },
18309
+ title: "Download workbook",
18283
18310
  type: "button",
18284
- children: "Download"
18311
+ children: "\u2193"
18285
18312
  }
18286
18313
  ) : null
18287
18314
  ] })
@@ -18294,32 +18321,18 @@ function DefaultToolbar({ controller, palette }) {
18294
18321
  style: {
18295
18322
  backgroundColor: palette.subtleSurface,
18296
18323
  borderBottom: `1px solid ${palette.border}`,
18297
- display: "flex",
18298
- gap: 6,
18299
18324
  overflowX: "auto",
18300
18325
  padding: "8px 12px"
18301
18326
  },
18302
- children: tabs.map((tab, index) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
18303
- "button",
18327
+ children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
18328
+ SegmentedControl,
18304
18329
  {
18305
- onClick: () => setActiveTabIndex(index),
18306
- style: {
18307
- backgroundColor: index === activeTabIndex ? palette.sheetActiveSurface : palette.sheetInactiveSurface,
18308
- border: `1px solid ${index === activeTabIndex ? palette.strongBorder : "transparent"}`,
18309
- borderRadius: 8,
18310
- boxShadow: index === activeTabIndex ? palette.shadow : "none",
18311
- color: index === activeTabIndex ? palette.sheetActiveText : palette.sheetInactiveText,
18312
- cursor: "pointer",
18313
- fontSize: 12,
18314
- fontWeight: 500,
18315
- padding: "6px 12px",
18316
- whiteSpace: "nowrap"
18317
- },
18318
- type: "button",
18319
- children: tab.name
18320
- },
18321
- tab.id
18322
- ))
18330
+ items: tabs.map((tab, index) => ({ id: String(index), label: tab.name })),
18331
+ onValueChange: (value) => setActiveTabIndex(Number(value)),
18332
+ palette,
18333
+ value: String(activeTabIndex)
18334
+ }
18335
+ )
18323
18336
  }
18324
18337
  ) : null
18325
18338
  ] });
@@ -21584,7 +21597,7 @@ function XlsxGrid({
21584
21597
  selectionFillColor,
21585
21598
  selectionHeaderColor
21586
21599
  });
21587
- const selectionBorderWidth = 1.5;
21600
+ const selectionBorderWidth = 1;
21588
21601
  const rowColSpan = renderedCols.length + 1 + (leadingColumnSpacerWidth > 0 ? 1 : 0) + (trailingColumnSpacerWidth > 0 ? 1 : 0);
21589
21602
  const gutterSeparatorShadow = `inset -1px 0 0 ${palette.border}, inset 0 -1px 0 ${palette.border}`;
21590
21603
  const headerCellStyle = {
@@ -21807,7 +21820,7 @@ function XlsxGrid({
21807
21820
  "div",
21808
21821
  {
21809
21822
  style: {
21810
- border: `1.5px solid ${selectionStroke}`,
21823
+ border: `1px solid ${selectionStroke}`,
21811
21824
  boxShadow: `0 0 0 1px ${palette.surface}`,
21812
21825
  boxSizing: "border-box",
21813
21826
  inset: 0,
@@ -21838,7 +21851,7 @@ function XlsxGrid({
21838
21851
  "div",
21839
21852
  {
21840
21853
  style: {
21841
- border: `1.5px solid ${selectionStroke}`,
21854
+ border: `1px solid ${selectionStroke}`,
21842
21855
  boxShadow: `0 0 0 1px ${palette.surface}`,
21843
21856
  boxSizing: "border-box",
21844
21857
  inset: 0,
@@ -21911,7 +21924,7 @@ function XlsxGrid({
21911
21924
  "div",
21912
21925
  {
21913
21926
  style: {
21914
- border: `1.5px solid ${selectionStroke}`,
21927
+ border: `1px solid ${selectionStroke}`,
21915
21928
  boxShadow: `0 0 0 1px ${palette.surface}`,
21916
21929
  boxSizing: "border-box",
21917
21930
  inset: 0,
@@ -22729,7 +22742,8 @@ function XlsxViewerInner({
22729
22742
  emptyState,
22730
22743
  errorState,
22731
22744
  fileTooLargeState,
22732
- height = "100%",
22745
+ height,
22746
+ isDark = false,
22733
22747
  loadingComponent,
22734
22748
  loadingState,
22735
22749
  renderChartLoading,
@@ -22744,15 +22758,14 @@ function XlsxViewerInner({
22744
22758
  showDefaultToolbar = true,
22745
22759
  toolbar
22746
22760
  }) {
22747
- const palette = useViewerPalette();
22748
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ViewerContext.Provider, { value: controller, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
22761
+ const palette = useViewerPalette(isDark);
22762
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ViewerAppearanceContext.Provider, { value: { isDark }, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ViewerContext.Provider, { value: controller, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
22749
22763
  "div",
22750
22764
  {
22751
22765
  className: classNames("react-xlsx-viewer", className),
22752
22766
  style: {
22753
22767
  blockSize: height,
22754
22768
  backgroundColor: palette.surface,
22755
- border: `1px solid ${palette.border}`,
22756
22769
  borderRadius: rounded ? 12 : 0,
22757
22770
  color: palette.text,
22758
22771
  display: "flex",
@@ -22790,7 +22803,7 @@ function XlsxViewerInner({
22790
22803
  ) })
22791
22804
  ]
22792
22805
  }
22793
- ) });
22806
+ ) }) });
22794
22807
  }
22795
22808
  function XlsxViewerWithInlineController(props) {
22796
22809
  const controller = useXlsxViewerController(props);
@@ -22798,16 +22811,17 @@ function XlsxViewerWithInlineController(props) {
22798
22811
  }
22799
22812
  function XlsxViewerProviderWithInlineController({
22800
22813
  children,
22814
+ isDark = false,
22801
22815
  ...options
22802
22816
  }) {
22803
22817
  const controller = useXlsxViewerController(options);
22804
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ViewerContext.Provider, { value: controller, children });
22818
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ViewerAppearanceContext.Provider, { value: { isDark }, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ViewerContext.Provider, { value: controller, children }) });
22805
22819
  }
22806
- function XlsxViewerProvider({ children, controller, ...options }) {
22820
+ function XlsxViewerProvider({ children, controller, isDark = false, ...options }) {
22807
22821
  if (controller) {
22808
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ViewerContext.Provider, { value: controller, children });
22822
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ViewerAppearanceContext.Provider, { value: { isDark }, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ViewerContext.Provider, { value: controller, children }) });
22809
22823
  }
22810
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(XlsxViewerProviderWithInlineController, { ...options, children });
22824
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(XlsxViewerProviderWithInlineController, { ...options, isDark, children });
22811
22825
  }
22812
22826
  function useXlsxViewer() {
22813
22827
  const context = React4.useContext(ViewerContext);
@@ -23133,7 +23147,8 @@ function XlsxViewer(props) {
23133
23147
  }
23134
23148
  function DefaultXlsxToolbar() {
23135
23149
  const controller = useXlsxViewer();
23136
- const palette = useViewerPalette();
23150
+ const { isDark } = React4.useContext(ViewerAppearanceContext);
23151
+ const palette = useViewerPalette(isDark);
23137
23152
  return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(DefaultToolbar, { controller, palette });
23138
23153
  }
23139
23154
  // Annotate the CommonJS export names for ESM import in node: