@malloydata/render 0.0.101-dev231114015212 → 0.0.101
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/.storybook/main.ts +4 -0
- package/dist/component/render.d.ts +13 -0
- package/dist/component/render.js +39 -0
- package/dist/component/table.d.ts +12 -0
- package/dist/component/table.js +70 -0
- package/dist/html/html_view.d.ts +1 -0
- package/dist/html/html_view.js +7 -0
- package/dist/stories/basic.stories.js +3 -3
- package/dist/stories/image.stories.js +3 -3
- package/dist/stories/render-malloy-legacy.d.ts +6 -0
- package/dist/stories/render-malloy-legacy.js +23 -0
- package/dist/stories/tables.stories.d.ts +24 -0
- package/dist/stories/tables.stories.js +43 -0
- package/dist/stories/util.d.ts +11 -0
- package/dist/stories/util.js +25 -0
- package/package.json +4 -2
- package/dist/stories/render-malloy.d.ts +0 -9
- package/dist/stories/render-malloy.js +0 -21
package/.storybook/main.ts
CHANGED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Result } from '@malloydata/malloy';
|
|
2
|
+
import { LitElement } from 'lit';
|
|
3
|
+
import './table';
|
|
4
|
+
export declare class MalloyRender extends LitElement {
|
|
5
|
+
static styles: import("lit").CSSResult;
|
|
6
|
+
result: Result;
|
|
7
|
+
render(): import("lit-html").TemplateResult<1>;
|
|
8
|
+
}
|
|
9
|
+
declare global {
|
|
10
|
+
interface HTMLElementTagNameMap {
|
|
11
|
+
'malloy-render': MalloyRender;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.MalloyRender = void 0;
|
|
10
|
+
const lit_1 = require("lit");
|
|
11
|
+
const decorators_js_1 = require("lit/decorators.js");
|
|
12
|
+
require("./table");
|
|
13
|
+
let MalloyRender = exports.MalloyRender = class MalloyRender extends lit_1.LitElement {
|
|
14
|
+
render() {
|
|
15
|
+
return (0, lit_1.html) `<malloy-table .data=${this.result.data}></malloy-table>`;
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
MalloyRender.styles = (0, lit_1.css) `
|
|
19
|
+
:host {
|
|
20
|
+
--table-font-size: 12px;
|
|
21
|
+
--table-row-height: 36px;
|
|
22
|
+
--table-header-color: #5d626b;
|
|
23
|
+
--table-header-weight: bold;
|
|
24
|
+
--table-body-color: #727883;
|
|
25
|
+
--table-body-weight: 400;
|
|
26
|
+
--table-border: 1px solid #e5e7eb;
|
|
27
|
+
--table-background: white;
|
|
28
|
+
|
|
29
|
+
font-family: Inter, system-ui, sans-serif;
|
|
30
|
+
font-size: var(--table-font-size);
|
|
31
|
+
}
|
|
32
|
+
`;
|
|
33
|
+
__decorate([
|
|
34
|
+
(0, decorators_js_1.property)({ attribute: false })
|
|
35
|
+
], MalloyRender.prototype, "result", void 0);
|
|
36
|
+
exports.MalloyRender = MalloyRender = __decorate([
|
|
37
|
+
(0, decorators_js_1.customElement)('malloy-render')
|
|
38
|
+
], MalloyRender);
|
|
39
|
+
//# sourceMappingURL=render.js.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { DataArray } from '@malloydata/malloy';
|
|
2
|
+
import { LitElement } from 'lit';
|
|
3
|
+
export declare class Table extends LitElement {
|
|
4
|
+
static styles: import("lit").CSSResult;
|
|
5
|
+
data: DataArray;
|
|
6
|
+
render(): import("lit-html").TemplateResult<1>;
|
|
7
|
+
}
|
|
8
|
+
declare global {
|
|
9
|
+
interface HTMLElementTagNameMap {
|
|
10
|
+
'malloy-table': Table;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.Table = void 0;
|
|
10
|
+
const lit_1 = require("lit");
|
|
11
|
+
const decorators_js_1 = require("lit/decorators.js");
|
|
12
|
+
let Table = exports.Table = class Table extends lit_1.LitElement {
|
|
13
|
+
render() {
|
|
14
|
+
const fields = this.data.field.allFields;
|
|
15
|
+
const headers = fields.map(f => (0, lit_1.html) `<th class="column-cell">${f.name}</th>`);
|
|
16
|
+
const rows = Array.from(this.data, row => (0, lit_1.html) `<tr>
|
|
17
|
+
${fields.map(f => (0, lit_1.html) `<td class="column-cell">${row.cell(f).value}</td>`)}
|
|
18
|
+
</tr>`);
|
|
19
|
+
return (0, lit_1.html) `<table>
|
|
20
|
+
<thead>
|
|
21
|
+
${headers}
|
|
22
|
+
</thead>
|
|
23
|
+
<tbody>
|
|
24
|
+
${rows}
|
|
25
|
+
</tbody>
|
|
26
|
+
</table>`;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
Table.styles = (0, lit_1.css) `
|
|
30
|
+
table {
|
|
31
|
+
border-collapse: collapse;
|
|
32
|
+
background: var(--table-background);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.column-cell {
|
|
36
|
+
height: var(--table-row-height);
|
|
37
|
+
border-block: var(--table-border);
|
|
38
|
+
overflow: hidden;
|
|
39
|
+
white-space: nowrap;
|
|
40
|
+
text-align: left;
|
|
41
|
+
padding: 0px 15px;
|
|
42
|
+
font-variant-numeric: tabular-nums;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
th.column-cell {
|
|
46
|
+
font-weight: var(--table-header-weight);
|
|
47
|
+
color: var(--table-header-color);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
td.column-cell {
|
|
51
|
+
font-weight: var(--table-body-weight);
|
|
52
|
+
color: var(--table-body-color);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
th.column-cell:first-child,
|
|
56
|
+
td.column-cell:first-child {
|
|
57
|
+
padding-left: 0px;
|
|
58
|
+
}
|
|
59
|
+
th.column-cell:last-child,
|
|
60
|
+
td.column-cell:last-child {
|
|
61
|
+
padding-right: 0px;
|
|
62
|
+
}
|
|
63
|
+
`;
|
|
64
|
+
__decorate([
|
|
65
|
+
(0, decorators_js_1.property)({ attribute: false })
|
|
66
|
+
], Table.prototype, "data", void 0);
|
|
67
|
+
exports.Table = Table = __decorate([
|
|
68
|
+
(0, decorators_js_1.customElement)('malloy-table')
|
|
69
|
+
], Table);
|
|
70
|
+
//# sourceMappingURL=table.js.map
|
package/dist/html/html_view.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { DataArray, Explore, Field, Result, Tag } from '@malloydata/malloy';
|
|
|
2
2
|
import { StyleDefaults } from '../data_styles';
|
|
3
3
|
import { Renderer } from '../renderer';
|
|
4
4
|
import { RendererOptions } from '../renderer_types';
|
|
5
|
+
import '../component/render';
|
|
5
6
|
export declare class HTMLView {
|
|
6
7
|
private document;
|
|
7
8
|
constructor(document: Document);
|
package/dist/html/html_view.js
CHANGED
|
@@ -31,11 +31,18 @@ const container_1 = require("./container");
|
|
|
31
31
|
const utils_1 = require("./utils");
|
|
32
32
|
const main_renderer_factory_1 = require("../main_renderer_factory");
|
|
33
33
|
const list_1 = require("./list");
|
|
34
|
+
require("../component/render");
|
|
34
35
|
class HTMLView {
|
|
35
36
|
constructor(document) {
|
|
36
37
|
this.document = document;
|
|
37
38
|
}
|
|
38
39
|
async render(result, options) {
|
|
40
|
+
const isNextRenderer = result.resultExplore.modelTag.has('renderer_next');
|
|
41
|
+
if (isNextRenderer) {
|
|
42
|
+
const el = this.document.createElement('malloy-render');
|
|
43
|
+
el.result = result;
|
|
44
|
+
return el;
|
|
45
|
+
}
|
|
39
46
|
const table = result.data;
|
|
40
47
|
const renderer = makeRenderer(table.field, this.document, options, {
|
|
41
48
|
size: 'large',
|
|
@@ -5,11 +5,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.FlattenNestedMeasures = exports.ProductsBar = exports.ProductsTable = void 0;
|
|
7
7
|
const basic_malloy_raw_1 = __importDefault(require("./static/basic.malloy?raw"));
|
|
8
|
-
const
|
|
8
|
+
const render_malloy_legacy_1 = require("./render-malloy-legacy");
|
|
9
9
|
exports.default = {
|
|
10
|
-
title: 'Malloy/Basic',
|
|
10
|
+
title: 'Malloy Legacy/Basic',
|
|
11
11
|
render: ({ source, view }, { globals: { connection } }) => {
|
|
12
|
-
return (0,
|
|
12
|
+
return (0, render_malloy_legacy_1.renderMalloy)({ script: basic_malloy_raw_1.default, source, view, connection });
|
|
13
13
|
},
|
|
14
14
|
argTypes: {},
|
|
15
15
|
};
|
|
@@ -5,11 +5,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.ImageAltFromGrandparent = exports.ImageAltFromParent = exports.ImageAltFromRecord = void 0;
|
|
7
7
|
const image_malloy_raw_1 = __importDefault(require("./static/image.malloy?raw"));
|
|
8
|
-
const
|
|
8
|
+
const render_malloy_legacy_1 = require("./render-malloy-legacy");
|
|
9
9
|
exports.default = {
|
|
10
|
-
title: 'Malloy/Image',
|
|
10
|
+
title: 'Malloy Legacy/Image',
|
|
11
11
|
render: ({ source, view }, { globals: { connection } }) => {
|
|
12
|
-
return (0,
|
|
12
|
+
return (0, render_malloy_legacy_1.renderMalloy)({ script: image_malloy_raw_1.default, source, view, connection });
|
|
13
13
|
},
|
|
14
14
|
argTypes: {},
|
|
15
15
|
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.renderMalloy = void 0;
|
|
4
|
+
const html_1 = require("../html");
|
|
5
|
+
const util_1 = require("./util");
|
|
6
|
+
async function runAndRender({ script, source, view, connection }, options = { dataStyles: {} }) {
|
|
7
|
+
const viewer = new html_1.HTMLView(document);
|
|
8
|
+
const result = await (0, util_1.runQuery)({ script, source, view, connection });
|
|
9
|
+
return await viewer.render(result, options);
|
|
10
|
+
}
|
|
11
|
+
function renderMalloy(options) {
|
|
12
|
+
const div = document.createElement('div');
|
|
13
|
+
runAndRender(options, {
|
|
14
|
+
dataStyles: {},
|
|
15
|
+
}).then(el => {
|
|
16
|
+
if (options.classes)
|
|
17
|
+
el.classList.add(options.classes);
|
|
18
|
+
div.replaceChildren(el);
|
|
19
|
+
});
|
|
20
|
+
return div;
|
|
21
|
+
}
|
|
22
|
+
exports.renderMalloy = renderMalloy;
|
|
23
|
+
//# sourceMappingURL=render-malloy-legacy.js.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Meta } from '@storybook/html';
|
|
2
|
+
import './themes.css';
|
|
3
|
+
import '../component/render';
|
|
4
|
+
declare const meta: Meta;
|
|
5
|
+
export default meta;
|
|
6
|
+
export declare const ProductsTable: {
|
|
7
|
+
args: {
|
|
8
|
+
source: string;
|
|
9
|
+
view: string;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
export declare const ProductsTableCustomTheme: {
|
|
13
|
+
args: {
|
|
14
|
+
source: string;
|
|
15
|
+
view: string;
|
|
16
|
+
classes: string;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
export declare const Products2Column: {
|
|
20
|
+
args: {
|
|
21
|
+
source: string;
|
|
22
|
+
view: string;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Products2Column = exports.ProductsTableCustomTheme = exports.ProductsTable = void 0;
|
|
7
|
+
const tables_malloy_raw_1 = __importDefault(require("./static/tables.malloy?raw"));
|
|
8
|
+
const util_1 = require("./util");
|
|
9
|
+
require("./themes.css");
|
|
10
|
+
require("../component/render");
|
|
11
|
+
const meta = {
|
|
12
|
+
title: 'Malloy Next/Tables',
|
|
13
|
+
render: ({ classes }, context) => {
|
|
14
|
+
const el = document.createElement('malloy-render');
|
|
15
|
+
if (classes)
|
|
16
|
+
el.classList.add(classes);
|
|
17
|
+
el.result = context.loaded['result'];
|
|
18
|
+
return el;
|
|
19
|
+
},
|
|
20
|
+
loaders: [(0, util_1.createLoader)(tables_malloy_raw_1.default)],
|
|
21
|
+
argTypes: {},
|
|
22
|
+
};
|
|
23
|
+
exports.default = meta;
|
|
24
|
+
exports.ProductsTable = {
|
|
25
|
+
args: {
|
|
26
|
+
source: 'products',
|
|
27
|
+
view: `records`,
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
exports.ProductsTableCustomTheme = {
|
|
31
|
+
args: {
|
|
32
|
+
source: 'products',
|
|
33
|
+
view: 'records',
|
|
34
|
+
classes: 'night',
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
exports.Products2Column = {
|
|
38
|
+
args: {
|
|
39
|
+
source: 'products',
|
|
40
|
+
view: 'category_bar',
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
//# sourceMappingURL=tables.stories.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { LoaderFunction, Args } from '@storybook/types';
|
|
2
|
+
import { HtmlRenderer } from '@storybook/html';
|
|
3
|
+
import { DuckDBWASMConnection } from '@malloydata/db-duckdb/wasm';
|
|
4
|
+
export type QueryOptions = {
|
|
5
|
+
script: string;
|
|
6
|
+
source: string;
|
|
7
|
+
view: string;
|
|
8
|
+
connection: Promise<DuckDBWASMConnection>;
|
|
9
|
+
};
|
|
10
|
+
export declare function createLoader(script: string): LoaderFunction<HtmlRenderer, Args>;
|
|
11
|
+
export declare function runQuery({ script, source, view, connection, }: QueryOptions): Promise<import("@malloydata/malloy").Result>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runQuery = exports.createLoader = void 0;
|
|
4
|
+
const malloy_1 = require("@malloydata/malloy");
|
|
5
|
+
function createLoader(script) {
|
|
6
|
+
return async (context) => ({
|
|
7
|
+
result: await runQuery({
|
|
8
|
+
script,
|
|
9
|
+
source: context.args['source'],
|
|
10
|
+
view: context.args['view'],
|
|
11
|
+
connection: context.globals['connection'],
|
|
12
|
+
}),
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
exports.createLoader = createLoader;
|
|
16
|
+
async function runQuery({ script, source, view, connection, }) {
|
|
17
|
+
const conn = await connection;
|
|
18
|
+
const runtime = new malloy_1.SingleConnectionRuntime(conn);
|
|
19
|
+
const model = runtime.loadModel(script);
|
|
20
|
+
const runner = model.loadQuery(`run: ${source} -> ${view}`);
|
|
21
|
+
const result = await runner.run();
|
|
22
|
+
return result;
|
|
23
|
+
}
|
|
24
|
+
exports.runQuery = runQuery;
|
|
25
|
+
//# sourceMappingURL=util.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@malloydata/render",
|
|
3
|
-
"version": "0.0.101
|
|
3
|
+
"version": "0.0.101",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -23,8 +23,9 @@
|
|
|
23
23
|
"build-storybook": "storybook build"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@malloydata/malloy": "^0.0.101
|
|
26
|
+
"@malloydata/malloy": "^0.0.101",
|
|
27
27
|
"@types/luxon": "^2.4.0",
|
|
28
|
+
"lit": "^3.0.2",
|
|
28
29
|
"lodash": "^4.17.20",
|
|
29
30
|
"luxon": "^2.4.0",
|
|
30
31
|
"ssf": "^0.11.2",
|
|
@@ -40,6 +41,7 @@
|
|
|
40
41
|
"@storybook/html": "^7.5.0",
|
|
41
42
|
"@storybook/html-vite": "^7.5.0",
|
|
42
43
|
"@storybook/testing-library": "^0.2.2",
|
|
44
|
+
"@storybook/types": "^7.5.3",
|
|
43
45
|
"storybook": "^7.5.0"
|
|
44
46
|
}
|
|
45
47
|
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { DuckDBWASMConnection } from '@malloydata/db-duckdb/wasm';
|
|
2
|
-
type RenderOptions = {
|
|
3
|
-
script: string;
|
|
4
|
-
source: string;
|
|
5
|
-
view: string;
|
|
6
|
-
connection: Promise<DuckDBWASMConnection>;
|
|
7
|
-
};
|
|
8
|
-
export declare function renderMalloy(options: RenderOptions): HTMLDivElement;
|
|
9
|
-
export {};
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.renderMalloy = void 0;
|
|
4
|
-
const malloy_1 = require("@malloydata/malloy");
|
|
5
|
-
const html_1 = require("../html");
|
|
6
|
-
async function runAndRender({ script, source, view, connection }) {
|
|
7
|
-
const conn = await connection;
|
|
8
|
-
const runtime = new malloy_1.SingleConnectionRuntime(conn);
|
|
9
|
-
const model = runtime.loadModel(script);
|
|
10
|
-
const runner = model.loadQuery(`run: ${source} -> ${view}`);
|
|
11
|
-
const viewer = new html_1.HTMLView(document);
|
|
12
|
-
const result = await runner.run();
|
|
13
|
-
return await viewer.render(result, { dataStyles: {} });
|
|
14
|
-
}
|
|
15
|
-
function renderMalloy(options) {
|
|
16
|
-
const div = document.createElement('div');
|
|
17
|
-
runAndRender(options).then(el => div.replaceChildren(el));
|
|
18
|
-
return div;
|
|
19
|
-
}
|
|
20
|
-
exports.renderMalloy = renderMalloy;
|
|
21
|
-
//# sourceMappingURL=render-malloy.js.map
|