@lostgradient/cinder 0.16.0 → 0.16.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @lostgradient/cinder
2
2
 
3
+ ## 0.16.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#766](https://github.com/stevekinney/cinder/pull/766) [`01cfe20`](https://github.com/stevekinney/cinder/commit/01cfe20711569effdd5643c3b985603a1536f7df) Thanks [@stevekinney](https://github.com/stevekinney)! - Add a first-class scrollable wrapper option to the compositional Table API.
8
+
3
9
  ## 0.16.0
4
10
 
5
11
  ### Minor Changes
package/components.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "manifestVersion": 1,
4
4
  "package": {
5
5
  "name": "@lostgradient/cinder",
6
- "version": "0.16.0",
6
+ "version": "0.16.1",
7
7
  "framework": "svelte",
8
8
  "frameworkVersionRange": ">=5.56.0 <6",
9
9
  "classPrefix": "cinder-",
@@ -684,14 +684,70 @@ var rest_excludes5 = new Set([
684
684
  "stickyHeader",
685
685
  "density",
686
686
  "selectable",
687
+ "scrollable",
688
+ "scrollContainerProps",
687
689
  "class",
688
690
  "children"
689
691
  ]);
690
692
  var root6 = $8.from_html(`<caption class="cinder-table__caption"> </caption>`);
691
693
  var root_14 = $8.from_html(`<table><!><!></table>`);
694
+ var root_23 = $8.from_html(`<div><!></div>`);
692
695
  function Table($$anchor, $$props) {
693
696
  $8.push($$props, true);
694
- let sort = $8.prop($$props, "sort", 15), stickyHeader = $8.prop($$props, "stickyHeader", 3, false), density = $8.prop($$props, "density", 3, "comfortable"), selectable = $8.prop($$props, "selectable", 3, false), rest = $8.rest_props($$props, rest_excludes5);
697
+ const table = ($$anchor2) => {
698
+ var table_1 = root_14();
699
+ $8.attribute_effect(table_1, ($0) => ({
700
+ ...rest,
701
+ class: $0,
702
+ "data-cinder-sticky-header": stickyHeader() || undefined,
703
+ "data-cinder-density": density(),
704
+ "data-cinder-selectable": selectable() || undefined,
705
+ [$8.STYLE]: {
706
+ "--cinder-table-caption-height": $8.get(normalizedCaption) ? `${$8.get(captionHeight)}px` : undefined
707
+ }
708
+ }), [() => classNames("cinder-table", $$props.class)]);
709
+ var node = $8.child(table_1);
710
+ {
711
+ var consequent = ($$anchor3) => {
712
+ var caption_1 = root6();
713
+ var text = $8.child(caption_1, true);
714
+ $8.reset(caption_1);
715
+ $8.attach(caption_1, () => measureCaption);
716
+ $8.template_effect(() => $8.set_text(text, $8.get(normalizedCaption)));
717
+ $8.append($$anchor3, caption_1);
718
+ };
719
+ $8.if(node, ($$render) => {
720
+ if ($8.get(normalizedCaption))
721
+ $$render(consequent);
722
+ });
723
+ }
724
+ var node_1 = $8.sibling(node);
725
+ $8.snippet(node_1, () => $$props.children);
726
+ $8.reset(table_1);
727
+ $8.append($$anchor2, table_1);
728
+ };
729
+ let sort = $8.prop($$props, "sort", 15), stickyHeader = $8.prop($$props, "stickyHeader", 3, false), density = $8.prop($$props, "density", 3, "comfortable"), selectable = $8.prop($$props, "selectable", 3, false), scrollable = $8.prop($$props, "scrollable", 3, false), rest = $8.rest_props($$props, rest_excludes5);
730
+ const wrapperClassName = $8.derived(() => $$props.scrollContainerProps?.class);
731
+ const wrapperAriaLabelledBy = $8.derived(() => normalizeOptionalAttribute($$props.scrollContainerProps?.["aria-labelledby"]));
732
+ const explicitWrapperAriaLabel = $8.derived(() => normalizeOptionalAttribute($$props.scrollContainerProps?.["aria-label"]));
733
+ const explicitWrapperRole = $8.derived(() => normalizeOptionalAttribute($$props.scrollContainerProps?.role));
734
+ const normalizedCaption = $8.derived(() => normalizeOptionalAttribute($$props.caption));
735
+ const wrapperAriaLabel = $8.derived(() => $8.get(explicitWrapperAriaLabel) ?? ($8.get(wrapperAriaLabelledBy) ? undefined : $8.get(normalizedCaption) ? `${$8.get(normalizedCaption)} table scroll area` : undefined));
736
+ const wrapperRole = $8.derived(() => $8.get(explicitWrapperRole) ?? ($8.get(wrapperAriaLabel) || $8.get(wrapperAriaLabelledBy) ? "region" : undefined));
737
+ const wrapperTabindex = $8.derived(() => normalizeOptionalTabindex($$props.scrollContainerProps?.tabindex) ?? 0);
738
+ function normalizeOptionalAttribute(value) {
739
+ return typeof value === "string" && value.trim().length > 0 ? value.trim() : undefined;
740
+ }
741
+ function normalizeOptionalTabindex(value) {
742
+ if (typeof value === "number" && Number.isInteger(value))
743
+ return value;
744
+ if (typeof value !== "string")
745
+ return;
746
+ const normalizedValue = value.trim();
747
+ if (!/^-?\d+$/.test(normalizedValue))
748
+ return;
749
+ return Number(normalizedValue);
750
+ }
695
751
  let captionHeight = $8.state(0);
696
752
  const measureCaption = useResizeObserver((entries) => {
697
753
  const entry = entries[0];
@@ -718,36 +774,37 @@ function Table($$anchor, $$props) {
718
774
  },
719
775
  onsortchange
720
776
  });
721
- var table = root_14();
722
- $8.attribute_effect(table, ($0) => ({
723
- ...rest,
724
- class: $0,
725
- "data-cinder-sticky-header": stickyHeader() || undefined,
726
- "data-cinder-density": density(),
727
- "data-cinder-selectable": selectable() || undefined,
728
- [$8.STYLE]: {
729
- "--cinder-table-caption-height": $$props.caption ? `${$8.get(captionHeight)}px` : undefined
730
- }
731
- }), [() => classNames("cinder-table", $$props.class)]);
732
- var node = $8.child(table);
777
+ var fragment = $8.comment();
778
+ var node_2 = $8.first_child(fragment);
733
779
  {
734
- var consequent = ($$anchor2) => {
735
- var caption_1 = root6();
736
- var text = $8.child(caption_1, true);
737
- $8.reset(caption_1);
738
- $8.attach(caption_1, () => measureCaption);
739
- $8.template_effect(() => $8.set_text(text, $$props.caption));
740
- $8.append($$anchor2, caption_1);
780
+ var consequent_1 = ($$anchor2) => {
781
+ var div = root_23();
782
+ $8.attribute_effect(div, ($0) => ({
783
+ ...$$props.scrollContainerProps,
784
+ class: $0,
785
+ role: $8.get(wrapperRole),
786
+ "aria-label": $8.get(wrapperAriaLabel),
787
+ "aria-labelledby": $8.get(wrapperAriaLabelledBy),
788
+ tabindex: $8.get(wrapperTabindex)
789
+ }), [
790
+ () => classNames("cinder-table-scroll", $8.get(wrapperClassName))
791
+ ]);
792
+ var node_3 = $8.child(div);
793
+ table(node_3);
794
+ $8.reset(div);
795
+ $8.append($$anchor2, div);
741
796
  };
742
- $8.if(node, ($$render) => {
743
- if ($$props.caption)
744
- $$render(consequent);
797
+ var alternate = ($$anchor2) => {
798
+ table($$anchor2);
799
+ };
800
+ $8.if(node_2, ($$render) => {
801
+ if (scrollable())
802
+ $$render(consequent_1);
803
+ else
804
+ $$render(alternate, -1);
745
805
  });
746
806
  }
747
- var node_1 = $8.sibling(node);
748
- $8.snippet(node_1, () => $$props.children);
749
- $8.reset(table);
750
- $8.append($$anchor, table);
807
+ $8.append($$anchor, fragment);
751
808
  $8.pop();
752
809
  }
753
810
 
@@ -850,7 +907,7 @@ var rest_excludes6 = new Set([
850
907
  ]);
851
908
  var root7 = $9.from_html(`<th scope="col" class="cinder-table__header-cell cinder-table__header-cell--selection"><!></th>`);
852
909
  var root_15 = $9.from_html(`<!> <!>`, 1);
853
- var root_23 = $9.from_html(`<tr class="cinder-data-table__virtual-spacer" aria-hidden="true"><td class="cinder-data-table__virtual-spacer-cell"></td></tr>`);
910
+ var root_24 = $9.from_html(`<tr class="cinder-data-table__virtual-spacer" aria-hidden="true"><td class="cinder-data-table__virtual-spacer-cell"></td></tr>`);
854
911
  var root_33 = $9.from_html(`<td class="cinder-table__cell cinder-table__cell--selection"><!></td>`);
855
912
  var root_42 = $9.from_html(`<!> <!> <!>`, 1);
856
913
  var root_5 = $9.from_html(`<div><!></div>`);
@@ -955,7 +1012,7 @@ function Data_table($$anchor, $$props) {
955
1012
  var node_5 = $9.first_child(fragment_7);
956
1013
  {
957
1014
  var consequent_2 = ($$anchor5) => {
958
- var tr = root_23();
1015
+ var tr = root_24();
959
1016
  var td = $9.child(tr);
960
1017
  let styles;
961
1018
  $9.reset(tr);
@@ -1048,7 +1105,7 @@ function Data_table($$anchor, $$props) {
1048
1105
  var node_10 = $9.sibling(node_6, 2);
1049
1106
  {
1050
1107
  var consequent_4 = ($$anchor5) => {
1051
- var tr_1 = root_23();
1108
+ var tr_1 = root_24();
1052
1109
  var td_2 = $9.child(tr_1);
1053
1110
  let styles_1;
1054
1111
  $9.reset(tr_1);
@@ -1378,4 +1435,4 @@ export {
1378
1435
  Data_table as DataTable
1379
1436
  };
1380
1437
 
1381
- //# debugId=4476472E5713EABB64756E2164756E21
1438
+ //# debugId=BCCAA92C441D11D164756E2164756E21
@@ -446,14 +446,70 @@ var rest_excludes4 = new Set([
446
446
  "stickyHeader",
447
447
  "density",
448
448
  "selectable",
449
+ "scrollable",
450
+ "scrollContainerProps",
449
451
  "class",
450
452
  "children"
451
453
  ]);
452
454
  var root5 = $7.from_html(`<caption class="cinder-table__caption"> </caption>`);
453
455
  var root_13 = $7.from_html(`<table><!><!></table>`);
456
+ var root_22 = $7.from_html(`<div><!></div>`);
454
457
  function Table($$anchor, $$props) {
455
458
  $7.push($$props, true);
456
- let sort = $7.prop($$props, "sort", 15), stickyHeader = $7.prop($$props, "stickyHeader", 3, false), density = $7.prop($$props, "density", 3, "comfortable"), selectable = $7.prop($$props, "selectable", 3, false), rest = $7.rest_props($$props, rest_excludes4);
459
+ const table = ($$anchor2) => {
460
+ var table_1 = root_13();
461
+ $7.attribute_effect(table_1, ($0) => ({
462
+ ...rest,
463
+ class: $0,
464
+ "data-cinder-sticky-header": stickyHeader() || undefined,
465
+ "data-cinder-density": density(),
466
+ "data-cinder-selectable": selectable() || undefined,
467
+ [$7.STYLE]: {
468
+ "--cinder-table-caption-height": $7.get(normalizedCaption) ? `${$7.get(captionHeight)}px` : undefined
469
+ }
470
+ }), [() => classNames("cinder-table", $$props.class)]);
471
+ var node = $7.child(table_1);
472
+ {
473
+ var consequent = ($$anchor3) => {
474
+ var caption_1 = root5();
475
+ var text = $7.child(caption_1, true);
476
+ $7.reset(caption_1);
477
+ $7.attach(caption_1, () => measureCaption);
478
+ $7.template_effect(() => $7.set_text(text, $7.get(normalizedCaption)));
479
+ $7.append($$anchor3, caption_1);
480
+ };
481
+ $7.if(node, ($$render) => {
482
+ if ($7.get(normalizedCaption))
483
+ $$render(consequent);
484
+ });
485
+ }
486
+ var node_1 = $7.sibling(node);
487
+ $7.snippet(node_1, () => $$props.children);
488
+ $7.reset(table_1);
489
+ $7.append($$anchor2, table_1);
490
+ };
491
+ let sort = $7.prop($$props, "sort", 15), stickyHeader = $7.prop($$props, "stickyHeader", 3, false), density = $7.prop($$props, "density", 3, "comfortable"), selectable = $7.prop($$props, "selectable", 3, false), scrollable = $7.prop($$props, "scrollable", 3, false), rest = $7.rest_props($$props, rest_excludes4);
492
+ const wrapperClassName = $7.derived(() => $$props.scrollContainerProps?.class);
493
+ const wrapperAriaLabelledBy = $7.derived(() => normalizeOptionalAttribute($$props.scrollContainerProps?.["aria-labelledby"]));
494
+ const explicitWrapperAriaLabel = $7.derived(() => normalizeOptionalAttribute($$props.scrollContainerProps?.["aria-label"]));
495
+ const explicitWrapperRole = $7.derived(() => normalizeOptionalAttribute($$props.scrollContainerProps?.role));
496
+ const normalizedCaption = $7.derived(() => normalizeOptionalAttribute($$props.caption));
497
+ const wrapperAriaLabel = $7.derived(() => $7.get(explicitWrapperAriaLabel) ?? ($7.get(wrapperAriaLabelledBy) ? undefined : $7.get(normalizedCaption) ? `${$7.get(normalizedCaption)} table scroll area` : undefined));
498
+ const wrapperRole = $7.derived(() => $7.get(explicitWrapperRole) ?? ($7.get(wrapperAriaLabel) || $7.get(wrapperAriaLabelledBy) ? "region" : undefined));
499
+ const wrapperTabindex = $7.derived(() => normalizeOptionalTabindex($$props.scrollContainerProps?.tabindex) ?? 0);
500
+ function normalizeOptionalAttribute(value) {
501
+ return typeof value === "string" && value.trim().length > 0 ? value.trim() : undefined;
502
+ }
503
+ function normalizeOptionalTabindex(value) {
504
+ if (typeof value === "number" && Number.isInteger(value))
505
+ return value;
506
+ if (typeof value !== "string")
507
+ return;
508
+ const normalizedValue = value.trim();
509
+ if (!/^-?\d+$/.test(normalizedValue))
510
+ return;
511
+ return Number(normalizedValue);
512
+ }
457
513
  let captionHeight = $7.state(0);
458
514
  const measureCaption = useResizeObserver((entries) => {
459
515
  const entry = entries[0];
@@ -480,36 +536,37 @@ function Table($$anchor, $$props) {
480
536
  },
481
537
  onsortchange
482
538
  });
483
- var table = root_13();
484
- $7.attribute_effect(table, ($0) => ({
485
- ...rest,
486
- class: $0,
487
- "data-cinder-sticky-header": stickyHeader() || undefined,
488
- "data-cinder-density": density(),
489
- "data-cinder-selectable": selectable() || undefined,
490
- [$7.STYLE]: {
491
- "--cinder-table-caption-height": $$props.caption ? `${$7.get(captionHeight)}px` : undefined
492
- }
493
- }), [() => classNames("cinder-table", $$props.class)]);
494
- var node = $7.child(table);
539
+ var fragment = $7.comment();
540
+ var node_2 = $7.first_child(fragment);
495
541
  {
496
- var consequent = ($$anchor2) => {
497
- var caption_1 = root5();
498
- var text = $7.child(caption_1, true);
499
- $7.reset(caption_1);
500
- $7.attach(caption_1, () => measureCaption);
501
- $7.template_effect(() => $7.set_text(text, $$props.caption));
502
- $7.append($$anchor2, caption_1);
542
+ var consequent_1 = ($$anchor2) => {
543
+ var div = root_22();
544
+ $7.attribute_effect(div, ($0) => ({
545
+ ...$$props.scrollContainerProps,
546
+ class: $0,
547
+ role: $7.get(wrapperRole),
548
+ "aria-label": $7.get(wrapperAriaLabel),
549
+ "aria-labelledby": $7.get(wrapperAriaLabelledBy),
550
+ tabindex: $7.get(wrapperTabindex)
551
+ }), [
552
+ () => classNames("cinder-table-scroll", $7.get(wrapperClassName))
553
+ ]);
554
+ var node_3 = $7.child(div);
555
+ table(node_3);
556
+ $7.reset(div);
557
+ $7.append($$anchor2, div);
503
558
  };
504
- $7.if(node, ($$render) => {
505
- if ($$props.caption)
506
- $$render(consequent);
559
+ var alternate = ($$anchor2) => {
560
+ table($$anchor2);
561
+ };
562
+ $7.if(node_2, ($$render) => {
563
+ if (scrollable())
564
+ $$render(consequent_1);
565
+ else
566
+ $$render(alternate, -1);
507
567
  });
508
568
  }
509
- var node_1 = $7.sibling(node);
510
- $7.snippet(node_1, () => $$props.children);
511
- $7.reset(table);
512
- $7.append($$anchor, table);
569
+ $7.append($$anchor, fragment);
513
570
  $7.pop();
514
571
  }
515
572
 
@@ -527,4 +584,4 @@ export {
527
584
  Table2 as Table
528
585
  };
529
586
 
530
- //# debugId=2DACDE46B64EA12F64756E2164756E21
587
+ //# debugId=5ED75768E933CF7864756E2164756E21
@@ -36,6 +36,11 @@
36
36
  min-inline-size: max-content;
37
37
  }
38
38
 
39
+ .cinder-table-scroll:focus-visible {
40
+ outline: var(--cinder-ring-width) solid transparent;
41
+ box-shadow: var(--_cinder-focus-ring-shadow);
42
+ }
43
+
39
44
  .cinder-table__caption {
40
45
  caption-side: top;
41
46
  text-align: left;
@@ -163,6 +168,12 @@
163
168
  }
164
169
 
165
170
  @media (forced-colors: active) {
171
+ .cinder-table-scroll:focus-visible {
172
+ outline: var(--cinder-ring-width) solid ButtonText;
173
+ outline-offset: 3px;
174
+ box-shadow: none;
175
+ }
176
+
166
177
  .cinder-table__sort-button:focus-visible {
167
178
  outline: var(--cinder-ring-width) solid ButtonText;
168
179
  /* 2px is correct here: sort-button has border:none so there is no
@@ -72,6 +72,10 @@ var schema = {
72
72
  type: "boolean",
73
73
  description: "Enables the leading selection column on the entire table. When true:\n- The single `TableRow` inside `TableHeader` renders a leading `<th>`\n with a select-all checkbox sourced from the header's props.\n- Every `TableRow` inside `TableBody` renders a leading selection cell.\nSelection is strictly controlled — the consumer owns all selection state."
74
74
  },
75
+ scrollable: {
76
+ type: "boolean",
77
+ description: "When true, wraps the table in a `.cinder-table-scroll` container that\nenables horizontal overflow scrolling for dense or unknown-width tables.\nUse this instead of manually wrapping Table in `.cinder-table-scroll`.\n\nWhen combined with `stickyHeader`, the generated wrapper is the sticky\nheader's scroll container. Set a bounded block size on `scrollContainerProps`\nwhen the table should scroll vertically inside that wrapper."
78
+ },
75
79
  class: {
76
80
  type: "string",
77
81
  description: "Additional class names merged with `.cinder-table`."
@@ -86,6 +90,11 @@ var schema = {
86
90
  required: true,
87
91
  description: "TableHeader, TableBody, etc."
88
92
  },
93
+ {
94
+ name: "scrollContainerProps",
95
+ reason: "unknown-shape",
96
+ description: "Attributes forwarded to the generated `.cinder-table-scroll` wrapper when\n`scrollable` is true. The wrapper is focusable by default so keyboard users\ncan scroll read-only wide tables. When the table has a caption, or when\n`aria-label` or `aria-labelledby` is provided here, the wrapper becomes a\nnamed `region`; pass `role` or `tabindex` here to override those defaults."
97
+ },
89
98
  {
90
99
  name: "sort",
91
100
  reason: "unknown-shape",
@@ -99,4 +108,4 @@ export {
99
108
  table_schema_default as default
100
109
  };
101
110
 
102
- //# debugId=10A0269B30E0BA6764756E2164756E21
111
+ //# debugId=F081B153ACEAE13964756E2164756E21
@@ -1,5 +1,5 @@
1
1
  import type { Snippet } from 'svelte';
2
- import type { HTMLTableAttributes } from 'svelte/elements';
2
+ import type { HTMLAttributes, HTMLTableAttributes } from 'svelte/elements';
3
3
  /** Sort direction. */
4
4
  export type SortDirection = 'ascending' | 'descending';
5
5
  /** Bound sort state shape. */
@@ -40,6 +40,11 @@ export type TableContext = {
40
40
  /** Mirror of Table.selectable. Set synchronously at construction time. */
41
41
  readonly selectionEnabled?: boolean;
42
42
  };
43
+ /** Attributes forwarded to Table's generated scroll wrapper. */
44
+ export type TableScrollContainerProps = Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'class'> & {
45
+ /** Additional class names merged with `.cinder-table-scroll`. */
46
+ class?: string;
47
+ };
43
48
  /**
44
49
  * Props for the Table component.
45
50
  *
@@ -75,6 +80,24 @@ export type TableProps = Omit<HTMLTableAttributes, 'class'> & {
75
80
  * Selection is strictly controlled — the consumer owns all selection state.
76
81
  */
77
82
  selectable?: boolean;
83
+ /**
84
+ * When true, wraps the table in a `.cinder-table-scroll` container that
85
+ * enables horizontal overflow scrolling for dense or unknown-width tables.
86
+ * Use this instead of manually wrapping Table in `.cinder-table-scroll`.
87
+ *
88
+ * When combined with `stickyHeader`, the generated wrapper is the sticky
89
+ * header's scroll container. Set a bounded block size on `scrollContainerProps`
90
+ * when the table should scroll vertically inside that wrapper.
91
+ */
92
+ scrollable?: boolean;
93
+ /**
94
+ * Attributes forwarded to the generated `.cinder-table-scroll` wrapper when
95
+ * `scrollable` is true. The wrapper is focusable by default so keyboard users
96
+ * can scroll read-only wide tables. When the table has a caption, or when
97
+ * `aria-label` or `aria-labelledby` is provided here, the wrapper becomes a
98
+ * named `region`; pass `role` or `tabindex` here to override those defaults.
99
+ */
100
+ scrollContainerProps?: TableScrollContainerProps;
78
101
  /** Additional class names merged with `.cinder-table`. */
79
102
  class?: string;
80
103
  /** TableHeader, TableBody, etc. */