@malloydata/render 0.0.103 → 0.0.104-dev231116200719

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.
@@ -3,7 +3,9 @@ import {Preview} from '@storybook/html';
3
3
  import registeredData from './registered_data.json';
4
4
 
5
5
  async function createConnection() {
6
- const connection = new DuckDBWASMConnection('duckdb');
6
+ const connection = new DuckDBWASMConnection('duckdb', null, undefined, {
7
+ rowLimit: 1000,
8
+ });
7
9
  await connection.connecting;
8
10
  for (let tableName of registeredData) {
9
11
  const fullTableName = `data/${tableName}`;
@@ -47,6 +47,7 @@ MalloyRender.styles = (0, lit_1.css) `
47
47
  --table-body-weight: 400;
48
48
  --table-border: 1px solid #e5e7eb;
49
49
  --table-background: white;
50
+ --table-gutter-size: 15px;
50
51
 
51
52
  font-family: Inter, system-ui, sans-serif;
52
53
  font-size: var(--table-font-size);
@@ -31,16 +31,75 @@ Object.defineProperty(exports, "__esModule", { value: true });
31
31
  exports.Table = void 0;
32
32
  const lit_1 = require("lit");
33
33
  const decorators_js_1 = require("lit/decorators.js");
34
+ const class_map_js_1 = require("lit/directives/class-map.js");
35
+ const util_1 = require("./util");
36
+ // TODO: replace with an estimator per column
37
+ function getColumnWidth() {
38
+ return 130;
39
+ }
40
+ const getContentStyle = (f) => {
41
+ if (f.isAtomicField()) {
42
+ const width = getColumnWidth();
43
+ return `width: ${width}px; min-width: ${width}px; max-width: ${width}px;`;
44
+ }
45
+ return '';
46
+ };
47
+ const renderCell = (f, value) => {
48
+ return (0, lit_1.html) `<div class="cell-wrapper">
49
+ <div class="cell-gutter-start"></div>
50
+ <div class="cell-content" style="${getContentStyle(f)}">${value}</div>
51
+ <div class="cell-gutter-end"></div>
52
+ </div>`;
53
+ };
54
+ const renderFieldContent = (row, f) => {
55
+ if (f.isExploreField()) {
56
+ return (0, lit_1.html) `<malloy-table
57
+ .data=${row.cell(f)}
58
+ ></malloy-table>`;
59
+ }
60
+ return renderCell(f, row.cell(f).value);
61
+ };
62
+ const renderField = (row, f) => {
63
+ return (0, lit_1.html) `<td
64
+ class=${(0, class_map_js_1.classMap)({
65
+ 'column-cell': true,
66
+ 'hide-end-gutter': (0, util_1.isLastChild)(f),
67
+ 'hide-start-gutter': (0, util_1.isFirstChild)(f),
68
+ })}
69
+ >
70
+ ${renderFieldContent(row, f)}
71
+ </td>`;
72
+ };
73
+ const renderHeader = (f) => {
74
+ const isFirst = (0, util_1.isFirstChild)(f);
75
+ const isParentFirst = (0, util_1.isFirstChild)(f.parentExplore);
76
+ const isParentNotAField = !f.parentExplore.isExploreField();
77
+ const hideStartGutter = isFirst && (isParentFirst || isParentNotAField);
78
+ const isLast = (0, util_1.isLastChild)(f);
79
+ const isParentLast = (0, util_1.isLastChild)(f.parentExplore);
80
+ const hideEndGutter = isLast && (isParentLast || isParentNotAField);
81
+ return (0, lit_1.html) `<th
82
+ class=${(0, class_map_js_1.classMap)({
83
+ 'column-cell': true,
84
+ 'hide-end-gutter': hideEndGutter,
85
+ 'hide-start-gutter': hideStartGutter,
86
+ })}
87
+ >
88
+ ${renderCell(f, f.name)}
89
+ </th>`;
90
+ };
34
91
  let Table = exports.Table = class Table extends lit_1.LitElement {
35
92
  render() {
36
93
  const fields = this.data.field.allFields;
37
- const headers = fields.map(f => (0, lit_1.html) `<th class="column-cell">${f.name}</th>`);
94
+ const headers = fields.map(f => renderHeader(f));
38
95
  const rows = Array.from(this.data, row => (0, lit_1.html) `<tr>
39
- ${fields.map(f => (0, lit_1.html) `<td class="column-cell">${row.cell(f).value}</td>`)}
96
+ ${fields.map(f => renderField(row, f))}
40
97
  </tr>`);
41
98
  return (0, lit_1.html) `<table>
42
99
  <thead>
43
- ${headers}
100
+ <tr>
101
+ ${headers}
102
+ </tr>
44
103
  </thead>
45
104
  <tbody>
46
105
  ${rows}
@@ -52,16 +111,26 @@ Table.styles = (0, lit_1.css) `
52
111
  table {
53
112
  border-collapse: collapse;
54
113
  background: var(--table-background);
114
+ font-variant-numeric: tabular-nums;
115
+ }
116
+
117
+ table * {
118
+ box-sizing: border-box;
55
119
  }
56
120
 
57
121
  .column-cell {
58
122
  height: var(--table-row-height);
59
- border-block: var(--table-border);
60
123
  overflow: hidden;
61
124
  white-space: nowrap;
62
125
  text-align: left;
63
- padding: 0px 15px;
64
- font-variant-numeric: tabular-nums;
126
+ padding: 0px;
127
+ vertical-align: top;
128
+ position: relative;
129
+ }
130
+
131
+ td.column-cell {
132
+ font-weight: var(--table-body-weight);
133
+ color: var(--table-body-color);
65
134
  }
66
135
 
67
136
  th.column-cell {
@@ -69,18 +138,40 @@ Table.styles = (0, lit_1.css) `
69
138
  color: var(--table-header-color);
70
139
  }
71
140
 
72
- td.column-cell {
73
- font-weight: var(--table-body-weight);
74
- color: var(--table-body-color);
141
+ .cell-wrapper {
142
+ height: var(--table-row-height);
143
+ display: flex;
144
+ align-items: center;
145
+ overflow: hidden;
146
+ }
147
+
148
+ .cell-content {
149
+ border-top: var(--table-border);
150
+ height: var(--table-row-height);
151
+ line-height: var(--table-row-height);
152
+ flex: 1;
153
+ overflow: hidden;
154
+ text-overflow: ellipsis;
155
+ }
156
+
157
+ .cell-gutter-start {
158
+ border-top: var(--table-border);
159
+ height: var(--table-row-height);
160
+ width: var(--table-gutter-size);
75
161
  }
76
162
 
77
- th.column-cell:first-child,
78
- td.column-cell:first-child {
79
- padding-left: 0px;
163
+ .cell-gutter-end {
164
+ border-top: var(--table-border);
165
+ height: var(--table-row-height);
166
+ width: var(--table-gutter-size);
167
+ }
168
+
169
+ .hide-end-gutter .cell-gutter-end {
170
+ border-top: none;
80
171
  }
81
- th.column-cell:last-child,
82
- td.column-cell:last-child {
83
- padding-right: 0px;
172
+
173
+ .hide-start-gutter .cell-gutter-start {
174
+ border-top: none;
84
175
  }
85
176
  `;
86
177
  __decorate([
@@ -0,0 +1,3 @@
1
+ import { Explore, Field } from '@malloydata/malloy';
2
+ export declare function isLastChild(f: Field | Explore): boolean;
3
+ export declare function isFirstChild(f: Field | Explore): boolean;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isFirstChild = exports.isLastChild = void 0;
4
+ function getLocationInParent(f) {
5
+ var _a;
6
+ const parent = f.parentExplore;
7
+ return (_a = parent === null || parent === void 0 ? void 0 : parent.allFields.findIndex(pf => pf.name === f.name)) !== null && _a !== void 0 ? _a : -1;
8
+ }
9
+ function isLastChild(f) {
10
+ if (f.parentExplore)
11
+ return getLocationInParent(f) === f.parentExplore.allFields.length - 1;
12
+ return true;
13
+ }
14
+ exports.isLastChild = isLastChild;
15
+ function isFirstChild(f) {
16
+ return getLocationInParent(f) === 0;
17
+ }
18
+ exports.isFirstChild = isFirstChild;
19
+ //# sourceMappingURL=util.js.map
@@ -16,7 +16,7 @@ exports.default = {
16
16
  exports.ProductsTable = {
17
17
  args: {
18
18
  source: 'products',
19
- view: '{ select: * }',
19
+ view: 'records',
20
20
  },
21
21
  };
22
22
  exports.ProductsBar = {
@@ -22,3 +22,9 @@ export declare const Products2Column: {
22
22
  view: string;
23
23
  };
24
24
  };
25
+ export declare const Nested: {
26
+ args: {
27
+ source: string;
28
+ view: string;
29
+ };
30
+ };
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.Products2Column = exports.ProductsTableCustomTheme = exports.ProductsTable = void 0;
6
+ exports.Nested = exports.Products2Column = exports.ProductsTableCustomTheme = exports.ProductsTable = void 0;
7
7
  const tables_malloy_raw_1 = __importDefault(require("./static/tables.malloy?raw"));
8
8
  const util_1 = require("./util");
9
9
  require("./themes.css");
@@ -40,4 +40,10 @@ exports.Products2Column = {
40
40
  view: 'category_bar',
41
41
  },
42
42
  };
43
+ exports.Nested = {
44
+ args: {
45
+ source: 'products',
46
+ view: 'nested',
47
+ },
48
+ };
43
49
  //# sourceMappingURL=tables.stories.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@malloydata/render",
3
- "version": "0.0.103",
3
+ "version": "0.0.104-dev231116200719",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -23,7 +23,7 @@
23
23
  "build-storybook": "storybook build"
24
24
  },
25
25
  "dependencies": {
26
- "@malloydata/malloy": "^0.0.103",
26
+ "@malloydata/malloy": "^0.0.104-dev231116200719",
27
27
  "@types/luxon": "^2.4.0",
28
28
  "lit": "^3.0.2",
29
29
  "lodash": "^4.17.20",