@vygruppen/spor-react 12.24.0 → 12.24.1

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.
@@ -1,5 +1,5 @@
1
1
 
2
- > @vygruppen/spor-react@12.24.0 build /home/runner/work/spor/spor/packages/spor-react
2
+ > @vygruppen/spor-react@12.24.1 build /home/runner/work/spor/spor/packages/spor-react
3
3
  > tsup
4
4
 
5
5
  CLI Building entry: src/index.tsx, src/icons/index.tsx
@@ -11,18 +11,18 @@ CLI Cleaning output folder
11
11
  ESM Build start
12
12
  CJS Build start
13
13
  DTS Build start
14
- ESM dist/index.mjs 330.53 KB
15
- ESM dist/icons/index.mjs 110.00 B
16
- ESM dist/index.mjs.map 700.07 KB
17
- ESM dist/icons/index.mjs.map 157.00 B
18
- ESM ⚡️ Build success in 2926ms
19
- CJS dist/index.cjs 354.42 KB
14
+ CJS dist/index.cjs 355.66 KB
20
15
  CJS dist/icons/index.cjs 381.00 B
21
- CJS dist/index.cjs.map 700.07 KB
22
16
  CJS dist/icons/index.cjs.map 157.00 B
23
- CJS ⚡️ Build success in 2927ms
24
- DTS ⚡️ Build success in 22676ms
17
+ CJS dist/index.cjs.map 701.23 KB
18
+ CJS ⚡️ Build success in 2706ms
19
+ ESM dist/index.mjs 331.48 KB
20
+ ESM dist/icons/index.mjs 110.00 B
21
+ ESM dist/icons/index.mjs.map 157.00 B
22
+ ESM dist/index.mjs.map 701.23 KB
23
+ ESM ⚡️ Build success in 2715ms
24
+ DTS ⚡️ Build success in 20723ms
25
25
  DTS dist/icons/index.d.ts 44.00 B
26
- DTS dist/index.d.ts 147.69 KB
26
+ DTS dist/index.d.ts 147.51 KB
27
27
  DTS dist/icons/index.d.cts 44.00 B
28
- DTS dist/index.d.cts 147.69 KB
28
+ DTS dist/index.d.cts 147.51 KB
@@ -1,8 +1,8 @@
1
1
 
2
- > @vygruppen/spor-react@12.24.0 postinstall /home/runner/work/spor/spor/packages/spor-react
2
+ > @vygruppen/spor-react@12.24.1 postinstall /home/runner/work/spor/spor/packages/spor-react
3
3
  > chakra typegen src/theme/index.ts
4
4
 
5
- [dotenv@17.2.3] injecting env (0) from .env -- tip: ⚙️ override existing env vars with { override: true }
5
+ [dotenv@17.2.3] injecting env (0) from .env -- tip: 🔄 add secrets lifecycle management: https://dotenvx.com/ops
6
6
  ┌ Chakra CLI ⚡️
7
7
  [?25l│
8
8
  ◒ Generating conditions types...
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @vygruppen/spor-react
2
2
 
3
+ ## 12.24.1
4
+
5
+ ### Patch Changes
6
+
7
+ - c9487f9: Fix issue with dynamic children not working for table sort, and fix column header no longer needing `children: string` to work
8
+
3
9
  ## 12.24.0
4
10
 
5
11
  ### Minor Changes
package/dist/index.cjs CHANGED
@@ -6281,38 +6281,49 @@ var TabsList = react.Tabs.List;
6281
6281
  var TabsTrigger = react.Tabs.Trigger;
6282
6282
  var TabsIndicator = react.Tabs.Indicator;
6283
6283
  var TabsContent = react.Tabs.Content;
6284
- var getNextSortState = (current, key, columnIndex) => {
6285
- if (current.key !== key)
6286
- return { key, columnIndex, direction: "asc" };
6284
+
6285
+ // src/table/sort-utils.ts
6286
+ var getNextSortState = (current, columnIndex) => {
6287
+ if (current.columnIndex !== columnIndex)
6288
+ return { columnIndex, direction: "asc" };
6287
6289
  if (current.direction === "asc")
6288
- return { key, columnIndex, direction: "desc" };
6289
- return { key: null, direction: "asc", columnIndex: null };
6290
+ return { columnIndex, direction: "desc" };
6291
+ return { direction: "asc", columnIndex: null };
6290
6292
  };
6291
- var getSortKey = (children) => typeof children === "string" ? children.trim() : null;
6292
6293
  var getColumnIndex = (element) => {
6293
6294
  var _a5;
6294
6295
  return Array.prototype.indexOf.call((_a5 = element.parentElement) == null ? void 0 : _a5.children, element);
6295
6296
  };
6296
- var getCellText = (row, columnIndex) => {
6297
- const cell = React20.Children.toArray(
6298
- row.props.children
6299
- )[columnIndex];
6300
- if (!React20.isValidElement(cell))
6297
+ var getCellSortText = (row, columnIndex) => {
6298
+ var _a5;
6299
+ const cell = row.cells[columnIndex];
6300
+ if (!cell)
6301
6301
  return "";
6302
- const props = cell.props;
6303
- return typeof props["data-sort"] === "string" && props["data-sort"] || typeof props.children === "string" && props.children.trim() || "";
6302
+ return cell.dataset.sort || ((_a5 = cell.textContent) == null ? void 0 : _a5.trim()) || "";
6304
6303
  };
6305
- var sortRows = (children, columnIndex, direction) => React20.Children.toArray(children).toSorted((a, b) => {
6306
- if (!React20.isValidElement(a) || !React20.isValidElement(b))
6307
- return 0;
6308
- const cmp = getCellText(a, columnIndex).localeCompare(
6309
- getCellText(b, columnIndex)
6310
- );
6311
- return direction === "asc" ? cmp : -cmp;
6312
- });
6304
+ var applyDomSort = (tbody, sortState, originalRows) => {
6305
+ if (sortState.columnIndex == null) {
6306
+ for (const row of originalRows)
6307
+ tbody.append(row);
6308
+ } else {
6309
+ const rows = Array.from(tbody.rows);
6310
+ rows.sort((a, b) => {
6311
+ const cmp = getCellSortText(a, sortState.columnIndex).localeCompare(
6312
+ getCellSortText(b, sortState.columnIndex)
6313
+ );
6314
+ return sortState.direction === "asc" ? cmp : -cmp;
6315
+ });
6316
+ for (const row of rows)
6317
+ tbody.append(row);
6318
+ }
6319
+ };
6320
+ var captureRowOrder = (tbody) => (
6321
+ // eslint-disable-next-line unicorn/prefer-spread -- HTMLCollectionOf is not spreadable
6322
+ Array.from(tbody.rows)
6323
+ );
6313
6324
  var SortContext = React20.createContext({
6314
6325
  enabled: false,
6315
- sortState: { key: null, direction: "asc", columnIndex: null },
6326
+ sortState: { direction: "asc", columnIndex: null },
6316
6327
  onSort: () => {
6317
6328
  }
6318
6329
  });
@@ -6327,14 +6338,13 @@ var Table = React20.forwardRef(
6327
6338
  ...rest
6328
6339
  }, ref) => {
6329
6340
  const [sortState, setSortState] = React20.useState({
6330
- key: null,
6331
6341
  direction: "asc",
6332
6342
  columnIndex: null
6333
6343
  });
6334
- const handleSort = (key, columnIndex) => {
6344
+ const handleSort = (columnIndex) => {
6335
6345
  if (!sortable)
6336
6346
  return;
6337
- setSortState(getNextSortState(sortState, key, columnIndex));
6347
+ setSortState(getNextSortState(sortState, columnIndex));
6338
6348
  };
6339
6349
  const recipe = react.useSlotRecipe({ key: "table" });
6340
6350
  const styles = recipe({ variant, size });
@@ -6361,47 +6371,75 @@ var Table = React20.forwardRef(
6361
6371
  Table.displayName = "Table";
6362
6372
  var TableColumnHeader = React20.forwardRef(({ children, ...rest }, ref) => {
6363
6373
  const { enabled, sortState, onSort } = useTableSort();
6364
- const key = getSortKey(children);
6374
+ const [columnIndex, setColumnIndex] = React20.useState(null);
6365
6375
  const props = rest;
6366
- const columnSortable = enabled && key != null && !("data-nosort" in props);
6367
- const isActive = columnSortable && key === sortState.key;
6368
- return /* @__PURE__ */ jsxRuntime.jsx(react.Table.ColumnHeader, { ref, ...rest, children: /* @__PURE__ */ jsxRuntime.jsxs(react.HStack, { children: [
6369
- children,
6370
- columnSortable && /* @__PURE__ */ jsxRuntime.jsx(
6371
- react.Button,
6372
- {
6373
- variant: "ghost",
6374
- onClick: (event) => {
6375
- const th = event.currentTarget.closest("th");
6376
- if (th)
6377
- onSort(key, getColumnIndex(th));
6378
- },
6379
- p: "0px !important",
6380
- size: "xs",
6381
- children: isActive ? sortState.direction === "asc" ? /* @__PURE__ */ jsxRuntime.jsx(spor_icon_react_star.ArrowUpFill18Icon, { color: "outline.focus" }) : /* @__PURE__ */ jsxRuntime.jsx(spor_icon_react_star.ArrowDownFill18Icon, { color: "outline.focus" }) : /* @__PURE__ */ jsxRuntime.jsx(
6382
- spor_icon_react_star.ChangeDirectionFill18Icon,
6376
+ const columnSortable = enabled && !("data-nosort" in props);
6377
+ const isActive = columnSortable && columnIndex != null && columnIndex === sortState.columnIndex;
6378
+ return /* @__PURE__ */ jsxRuntime.jsx(
6379
+ react.Table.ColumnHeader,
6380
+ {
6381
+ ref: (element) => {
6382
+ if (element)
6383
+ setColumnIndex(getColumnIndex(element));
6384
+ if (typeof ref === "function")
6385
+ ref(element);
6386
+ else if (ref)
6387
+ ref.current = element;
6388
+ },
6389
+ ...rest,
6390
+ children: /* @__PURE__ */ jsxRuntime.jsxs(react.HStack, { children: [
6391
+ children,
6392
+ columnSortable && columnIndex != null && /* @__PURE__ */ jsxRuntime.jsx(
6393
+ react.Button,
6383
6394
  {
6384
- transform: "rotate(90deg)",
6385
- color: "icon.disabled"
6395
+ variant: "ghost",
6396
+ onClick: () => onSort(columnIndex),
6397
+ p: "0px !important",
6398
+ size: "xs",
6399
+ children: isActive ? sortState.direction === "asc" ? /* @__PURE__ */ jsxRuntime.jsx(spor_icon_react_star.ArrowUpFill18Icon, { color: "outline.focus" }) : /* @__PURE__ */ jsxRuntime.jsx(spor_icon_react_star.ArrowDownFill18Icon, { color: "outline.focus" }) : /* @__PURE__ */ jsxRuntime.jsx(
6400
+ spor_icon_react_star.ChangeDirectionFill18Icon,
6401
+ {
6402
+ transform: "rotate(90deg)",
6403
+ color: "icon.disabled"
6404
+ }
6405
+ )
6386
6406
  }
6387
6407
  )
6388
- }
6389
- )
6390
- ] }) });
6408
+ ] })
6409
+ }
6410
+ );
6391
6411
  });
6392
6412
  TableColumnHeader.displayName = "ColumnHeader";
6393
- var TableRow = React20.forwardRef(
6394
- (props, ref) => /* @__PURE__ */ jsxRuntime.jsx(react.Table.Row, { ref, ...props })
6395
- );
6396
- TableRow.displayName = "TableRow";
6397
6413
  var TableBody = React20.forwardRef(
6398
6414
  ({ children, ...rest }, ref) => {
6399
6415
  const { sortState } = useTableSort();
6400
- const sorted = React20.useMemo(
6401
- () => sortState.columnIndex == null ? children : sortRows(children, sortState.columnIndex, sortState.direction),
6402
- [children, sortState]
6416
+ const tbodyRef = React20.useRef(null);
6417
+ const originalOrder = React20.useRef([]);
6418
+ const previousChildren = React20.useRef(children);
6419
+ React20.useLayoutEffect(() => {
6420
+ const tbody = tbodyRef.current;
6421
+ if (!tbody)
6422
+ return;
6423
+ if (previousChildren.current !== children || originalOrder.current.length === 0) {
6424
+ originalOrder.current = captureRowOrder(tbody);
6425
+ previousChildren.current = children;
6426
+ }
6427
+ applyDomSort(tbody, sortState, originalOrder.current);
6428
+ }, [sortState, children]);
6429
+ return /* @__PURE__ */ jsxRuntime.jsx(
6430
+ react.Table.Body,
6431
+ {
6432
+ ref: (element) => {
6433
+ tbodyRef.current = element;
6434
+ if (typeof ref === "function")
6435
+ ref(element);
6436
+ else if (ref)
6437
+ ref.current = element;
6438
+ },
6439
+ ...rest,
6440
+ children
6441
+ }
6403
6442
  );
6404
- return /* @__PURE__ */ jsxRuntime.jsx(react.Table.Body, { ref, ...rest, children: sorted });
6405
6443
  }
6406
6444
  );
6407
6445
  TableBody.displayName = "TableBody";
@@ -9681,7 +9719,12 @@ var nativeSelectSlotRecipe = react.defineSlotRecipe({
9681
9719
  root: {
9682
9720
  width: "100%",
9683
9721
  height: "fit-content",
9684
- position: "relative"
9722
+ position: "relative",
9723
+ backgroundColor: "surface",
9724
+ "& option, & optgroup": {
9725
+ color: "text",
9726
+ backgroundColor: "surface"
9727
+ }
9685
9728
  },
9686
9729
  field: {
9687
9730
  ...inputRecipe.base
@@ -12000,6 +12043,10 @@ Object.defineProperty(exports, "TableRoot", {
12000
12043
  enumerable: true,
12001
12044
  get: function () { return react.TableRoot; }
12002
12045
  });
12046
+ Object.defineProperty(exports, "TableRow", {
12047
+ enumerable: true,
12048
+ get: function () { return react.TableRow; }
12049
+ });
12003
12050
  Object.defineProperty(exports, "VStack", {
12004
12051
  enumerable: true,
12005
12052
  get: function () { return react.VStack; }
@@ -12032,10 +12079,18 @@ Object.defineProperty(exports, "defineRecipe", {
12032
12079
  enumerable: true,
12033
12080
  get: function () { return react.defineRecipe; }
12034
12081
  });
12082
+ Object.defineProperty(exports, "defineSlotRecipe", {
12083
+ enumerable: true,
12084
+ get: function () { return react.defineSlotRecipe; }
12085
+ });
12035
12086
  Object.defineProperty(exports, "defineStyle", {
12036
12087
  enumerable: true,
12037
12088
  get: function () { return react.defineStyle; }
12038
12089
  });
12090
+ Object.defineProperty(exports, "mergeConfigs", {
12091
+ enumerable: true,
12092
+ get: function () { return react.mergeConfigs; }
12093
+ });
12039
12094
  Object.defineProperty(exports, "spor", {
12040
12095
  enumerable: true,
12041
12096
  get: function () { return react.chakra; }
@@ -12253,7 +12308,6 @@ exports.Switch = Switch;
12253
12308
  exports.Table = Table;
12254
12309
  exports.TableBody = TableBody;
12255
12310
  exports.TableColumnHeader = TableColumnHeader;
12256
- exports.TableRow = TableRow;
12257
12311
  exports.Tabs = Tabs;
12258
12312
  exports.TabsContent = TabsContent;
12259
12313
  exports.TabsIndicator = TabsIndicator;