vira 26.1.0 → 26.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.
@@ -24,20 +24,49 @@ export type ViraTableHeaders = ReadonlyArray<ViraTableKey>;
24
24
  *
25
25
  * @category Internal
26
26
  */
27
- export type ViraTableEntry<Keys extends ViraTableHeaders | undefined = undefined> = undefined extends Keys ? Record<string | number, HtmlInterpolation> : Record<ArrayElement<Exclude<Keys, undefined>>['key'], HtmlInterpolation>;
27
+ export type ViraTableEntry<Headers extends ViraTableHeaders | undefined = undefined> = Record<HeaderKey<Headers>, HtmlInterpolation>;
28
+ /**
29
+ * An individual cell in {@link ViraTableRow}.
30
+ *
31
+ * @category Internal
32
+ */
33
+ export type ViraTableCell<Headers extends ViraTableHeaders | undefined = undefined, Entry extends ViraTableEntry<Headers> | undefined = ViraTableEntry<Headers>> = {
34
+ content: HtmlInterpolation;
35
+ key: HeaderKey<Headers>;
36
+ /**
37
+ * The original entry that created this row (in default or vertical table orientation) or column
38
+ * (in horizontal table orientation). This is `undefined` in header cells.
39
+ */
40
+ entry: Entry;
41
+ };
42
+ /**
43
+ * An individual row in {@link ViraTable}.
44
+ *
45
+ * @category Internal
46
+ */
47
+ export type ViraTableRow<Headers extends ViraTableHeaders | undefined = undefined, CellEntry extends ViraTableEntry<Headers> | undefined = ViraTableEntry<Headers> | undefined, RowEntry extends ViraTableEntry<Headers> | undefined = CellEntry> = {
48
+ cells: ViraTableCell<Headers, CellEntry>[];
49
+ entry: RowEntry;
50
+ };
51
+ /**
52
+ * All keys for the given headers.
53
+ *
54
+ * @category Internal
55
+ */
56
+ export type HeaderKey<Headers extends ViraTableHeaders | undefined = undefined> = undefined extends Headers ? string | number : ArrayElement<Exclude<Headers, undefined>>['key'];
28
57
  /**
29
58
  * Table information that can easily be mapped into a `<table>` element.
30
59
  *
31
60
  * @category Internal
32
61
  */
33
- export type ViraTable<Orientation extends ViraTableOrientation = ViraTableOrientation.Vertical> = (Orientation extends ViraTableOrientation.Horizontal ? {
62
+ export type ViraTable<Headers extends ViraTableHeaders | undefined = undefined, Orientation extends ViraTableOrientation = ViraTableOrientation.Vertical, Entry extends ViraTableEntry<Headers> = ViraTableEntry<Headers>> = Orientation extends ViraTableOrientation.Horizontal ? {
34
63
  headerRow: undefined;
35
64
  orientation: Orientation;
65
+ rows: ViraTableRow<Headers, Entry | undefined, undefined>[];
36
66
  } : {
37
- headerRow: HtmlInterpolation[];
67
+ headerRow: ViraTableCell<Headers, undefined>[];
38
68
  orientation: Orientation;
39
- }) & {
40
- rows: HtmlInterpolation[][];
69
+ rows: ViraTableRow<Headers, Entry>[];
41
70
  };
42
71
  /**
43
72
  * Orientation options for {@link ViraTable}.
@@ -46,12 +75,14 @@ export type ViraTable<Orientation extends ViraTableOrientation = ViraTableOrient
46
75
  */
47
76
  export declare enum ViraTableOrientation {
48
77
  /**
49
- * This is the default table layout. Each entry becomes a new row. Headers are a row at the top
50
- * of the table.
78
+ * This corresponds to a _vertical_ entry sequence (as you move from entry to entry, you move
79
+ * across the table vertically). This is the default table layout. Each entry becomes a new row.
80
+ * Headers are in a separate row.
51
81
  */
52
82
  Vertical = "vertical",
53
83
  /**
54
- * This is a pivoted table layout. Each entry becomes a column. Headers are the left most
84
+ * This corresponds to a _horizontal_ entry sequence (as you move from entry to entry, you move
85
+ * across the table horizontally). Each entry becomes a column. Headers are the left most
55
86
  * column.
56
87
  */
57
88
  Horizontal = "horizontal"
@@ -72,6 +103,6 @@ export type ViraTableOptions<Orientation extends ViraTableOrientation = ViraTabl
72
103
  *
73
104
  * @category Table
74
105
  */
75
- export declare function defineTable<const Headers extends ViraTableHeaders, const Orientation extends ViraTableOrientation = ViraTableOrientation.Vertical>(
106
+ export declare function defineTable<const Headers extends ViraTableHeaders, Entry extends ViraTableEntry<Headers>, const Orientation extends ViraTableOrientation = ViraTableOrientation.Vertical>(
76
107
  /** The order of these keys determines the order that they render in. */
77
- headers: Readonly<Headers>, entries: ReadonlyArray<Readonly<ViraTableEntry<Headers>>>, options?: ViraTableOptions<Orientation>): ViraTable<Orientation>;
108
+ headers: Readonly<Headers>, entries: Entry[], options?: ViraTableOptions<Orientation>): ViraTable<Headers, Orientation>;
@@ -6,12 +6,14 @@
6
6
  export var ViraTableOrientation;
7
7
  (function (ViraTableOrientation) {
8
8
  /**
9
- * This is the default table layout. Each entry becomes a new row. Headers are a row at the top
10
- * of the table.
9
+ * This corresponds to a _vertical_ entry sequence (as you move from entry to entry, you move
10
+ * across the table vertically). This is the default table layout. Each entry becomes a new row.
11
+ * Headers are in a separate row.
11
12
  */
12
13
  ViraTableOrientation["Vertical"] = "vertical";
13
14
  /**
14
- * This is a pivoted table layout. Each entry becomes a column. Headers are the left most
15
+ * This corresponds to a _horizontal_ entry sequence (as you move from entry to entry, you move
16
+ * across the table horizontally). Each entry becomes a column. Headers are the left most
15
17
  * column.
16
18
  */
17
19
  ViraTableOrientation["Horizontal"] = "horizontal";
@@ -30,14 +32,28 @@ headers, entries, options = {}) {
30
32
  const rows = headers.map((header) => {
31
33
  const headerCellArray = options.hideHeaders
32
34
  ? []
33
- : [header.content ?? header.key];
35
+ : [
36
+ {
37
+ content: header.content ?? header.key,
38
+ key: header.key,
39
+ entry: undefined,
40
+ },
41
+ ];
34
42
  const cells = entries.map((entry) => {
35
- return entry[header.key];
43
+ return {
44
+ content: entry[header.key],
45
+ key: header.key,
46
+ entry,
47
+ };
36
48
  });
37
- return [
49
+ const allCells = [
38
50
  ...headerCellArray,
39
51
  ...cells,
40
52
  ];
53
+ return {
54
+ cells: allCells,
55
+ entry: undefined,
56
+ };
41
57
  });
42
58
  return {
43
59
  headerRow: undefined,
@@ -48,11 +64,24 @@ headers, entries, options = {}) {
48
64
  else {
49
65
  const headerRow = options.hideHeaders
50
66
  ? []
51
- : headers.map((header) => header.content ?? header.key);
52
- const rows = entries.map((entry) => {
53
- return headers.map((header) => {
54
- return entry[header.key];
67
+ : headers.map((header) => {
68
+ return {
69
+ content: header.content ?? header.key,
70
+ key: header.key,
71
+ entry: undefined,
72
+ };
55
73
  });
74
+ const rows = entries.map((entry) => {
75
+ return {
76
+ cells: headers.map((header) => {
77
+ return {
78
+ content: entry[header.key],
79
+ key: header.key,
80
+ entry,
81
+ };
82
+ }),
83
+ entry,
84
+ };
56
85
  });
57
86
  return {
58
87
  headerRow,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vira",
3
- "version": "26.1.0",
3
+ "version": "26.2.0",
4
4
  "description": "A simple and highly versatile design system using element-vir.",
5
5
  "keywords": [
6
6
  "design",
@@ -47,7 +47,7 @@
47
47
  "lit-css-vars": "^3.0.11",
48
48
  "observavir": "^2.0.5",
49
49
  "page-active": "^1.0.1",
50
- "spa-router-vir": "^6.0.0",
50
+ "spa-router-vir": "^6.1.1",
51
51
  "type-fest": "^4.41.0",
52
52
  "typed-event-target": "^4.1.0"
53
53
  },
@@ -56,7 +56,7 @@
56
56
  "@web/dev-server-esbuild": "^1.0.4",
57
57
  "@web/test-runner": "^0.20.2",
58
58
  "@web/test-runner-commands": "^0.9.0",
59
- "@web/test-runner-playwright": "^0.11.0",
59
+ "@web/test-runner-playwright": "^0.11.1",
60
60
  "@web/test-runner-visual-regression": "^0.10.0",
61
61
  "esbuild": "^0.25.5",
62
62
  "istanbul-smart-text-reporter": "^1.1.5",
@@ -67,7 +67,7 @@
67
67
  "vite-tsconfig-paths": "^5.1.4"
68
68
  },
69
69
  "peerDependencies": {
70
- "element-vir": "^26.1.0"
70
+ "element-vir": "^26.2.0"
71
71
  },
72
72
  "engines": {
73
73
  "node": ">=22"