@malloydata/render 0.0.96-dev231024223919 → 0.0.96-dev231025173405

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
  import {join, dirname} from 'path';
2
- import {mergeConfig} from 'vite';
2
+ import {mergeConfig, InlineConfig} from 'vite';
3
3
  import {StorybookConfig} from '@storybook/html-vite';
4
4
 
5
5
  /**
@@ -32,14 +32,22 @@ const config: StorybookConfig = {
32
32
  if (configType === 'PRODUCTION') {
33
33
  // Your production configuration goes here.
34
34
  }
35
- const finalConfig = mergeConfig(config, {
35
+ const configOverride: InlineConfig = {
36
36
  resolve: {
37
37
  preserveSymlinks: true,
38
+ alias: {
39
+ '@malloydata/malloy': join(__dirname, '../../malloy/src'),
40
+ '@malloydata/db-duckdb/wasm': join(
41
+ __dirname,
42
+ '../../malloy-db-duckdb/src/duckdb_wasm_connection_browser'
43
+ ),
44
+ },
38
45
  },
39
46
  define: {
40
47
  'process.env': {},
41
48
  },
42
- });
49
+ };
50
+ const finalConfig = mergeConfig(config, configOverride);
43
51
  return finalConfig;
44
52
  },
45
53
  };
@@ -1 +1 @@
1
- ["products.parquet"]
1
+ ["products.parquet", "logos.csv"]
package/README.md CHANGED
@@ -17,3 +17,7 @@ Stories are written in the `src/stories` directory. To add more data and Malloy
17
17
  - register data files be loaded into the DuckDB WASM connection by adding the file name to `.storybook/registered_data.json`
18
18
 
19
19
  [Take a look at the Basic story as an example.](./src/stories/basic.stories.ts)
20
+
21
+ ### On Reloading Changes
22
+
23
+ When running `npm run storybook`, only changes in the malloy-render package will hot reload properly. Changes to dependencies like the core `malloy` package may require a browser reload to work properly.
@@ -30,27 +30,35 @@ class HTMLImageRenderer {
30
30
  this.document = document;
31
31
  }
32
32
  async render(data) {
33
+ var _a;
33
34
  if (!data.isString()) {
34
35
  return (0, utils_1.createErrorElement)(this.document, 'Invalid field for Image renderer');
35
36
  }
37
+ const { tag } = data.field.tagParse();
38
+ const imgTag = tag.tag('image');
39
+ if (!imgTag) {
40
+ return (0, utils_1.createErrorElement)(this.document, 'Missing tag for Image renderer');
41
+ }
36
42
  const element = data.isNull()
37
43
  ? (0, utils_1.createNullElement)(this.document)
38
44
  : this.document.createElement('img');
39
- const { tag } = data.field.tagParse();
40
- const width = tag.text('image', 'width');
41
- const height = tag.text('image', 'height');
45
+ const width = imgTag.text('width');
46
+ const height = imgTag.text('height');
42
47
  // Both image and null placeholder get matching size
43
48
  if (width)
44
49
  element.style.width = width;
45
50
  if (height)
46
51
  element.style.height = height;
52
+ const img = element;
53
+ const altTag = imgTag.tag('alt');
54
+ if (altTag) {
55
+ const alt = (_a = (0, utils_1.getDynamicValue)({ tag: altTag, data })) !== null && _a !== void 0 ? _a : altTag.text();
56
+ if (alt)
57
+ img.alt = alt;
58
+ }
47
59
  // Image specific props
48
60
  if (!data.isNull()) {
49
- const alt = tag.text('image', 'alt');
50
- const img = element;
51
61
  img.src = data.value;
52
- if (alt)
53
- img.alt = alt;
54
62
  }
55
63
  return element;
56
64
  }
@@ -1,4 +1,4 @@
1
- import { DateTimeframe, Field, TimestampTimeframe } from '@malloydata/malloy';
1
+ import { DataColumn, DateTimeframe, Field, Tag, TimestampTimeframe } from '@malloydata/malloy';
2
2
  import { RenderDef } from '../data_styles';
3
3
  import { RendererOptions } from '../renderer_types';
4
4
  export declare function getColorScale(type: 'temporal' | 'ordinal' | 'quantitative' | 'nominal' | undefined, isRectMark: boolean, hasOverlappingText?: boolean): {
@@ -11,3 +11,8 @@ export declare function createErrorElement(document: Document, error: string | E
11
11
  export declare function createNullElement(document: Document): HTMLElement;
12
12
  export declare function createDrillIcon(document: Document): HTMLElement;
13
13
  export declare function formatTitle(options: RendererOptions, field: Field, renderDef?: RenderDef | undefined, timezone?: string): string;
14
+ export declare function getParentRecord(data: DataColumn, n?: number): DataColumn;
15
+ export declare function getDynamicValue<T = unknown>({ tag, data, }: {
16
+ tag: Tag;
17
+ data: DataColumn;
18
+ }): T | undefined;
@@ -25,7 +25,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
25
25
  return (mod && mod.__esModule) ? mod : { "default": mod };
26
26
  };
27
27
  Object.defineProperty(exports, "__esModule", { value: true });
28
- exports.formatTitle = exports.createDrillIcon = exports.createNullElement = exports.createErrorElement = exports.yieldTask = exports.normalizeToTimezone = exports.timeToString = exports.getColorScale = void 0;
28
+ exports.getDynamicValue = exports.getParentRecord = exports.formatTitle = exports.createDrillIcon = exports.createNullElement = exports.createErrorElement = exports.yieldTask = exports.normalizeToTimezone = exports.timeToString = exports.getColorScale = void 0;
29
29
  const malloy_1 = require("@malloydata/malloy");
30
30
  const startCase_1 = __importDefault(require("lodash/startCase"));
31
31
  const luxon_1 = require("luxon");
@@ -227,4 +227,27 @@ function formatTitle(options, field, renderDef, timezone) {
227
227
  return title;
228
228
  }
229
229
  exports.formatTitle = formatTitle;
230
+ function getParentRecord(data, n = 0) {
231
+ let record = data;
232
+ while (n > 0 && record.parentRecord) {
233
+ n -= 1;
234
+ record = record.parentRecord;
235
+ }
236
+ return record;
237
+ }
238
+ exports.getParentRecord = getParentRecord;
239
+ function getDynamicValue({ tag, data, }) {
240
+ var _a, _b, _c;
241
+ const match = (_b = (_a = tag
242
+ .tag('field')) === null || _a === void 0 ? void 0 : _a.text()) === null || _b === void 0 ? void 0 : _b.match(/^(\^*)(.*)/);
243
+ if (!match)
244
+ return undefined;
245
+ const [, parentScoping, fieldName] = match;
246
+ const ancestorCt = parentScoping.length;
247
+ const scope = getParentRecord(data, ancestorCt);
248
+ if ('cell' in scope)
249
+ return (_c = scope.cell(fieldName)) === null || _c === void 0 ? void 0 : _c.value;
250
+ return undefined;
251
+ }
252
+ exports.getDynamicValue = getDynamicValue;
230
253
  //# sourceMappingURL=utils.js.map
@@ -0,0 +1,31 @@
1
+ declare const _default: {
2
+ title: string;
3
+ render: ({ source, view }: {
4
+ source: any;
5
+ view: any;
6
+ }, { globals: { connection } }: {
7
+ globals: {
8
+ connection: any;
9
+ };
10
+ }) => HTMLDivElement;
11
+ argTypes: {};
12
+ };
13
+ export default _default;
14
+ export declare const ImageAltFromRecord: {
15
+ args: {
16
+ source: string;
17
+ view: string;
18
+ };
19
+ };
20
+ export declare const ImageAltFromParent: {
21
+ args: {
22
+ source: string;
23
+ view: string;
24
+ };
25
+ };
26
+ export declare const ImageAltFromGrandparent: {
27
+ args: {
28
+ source: string;
29
+ view: string;
30
+ };
31
+ };
@@ -0,0 +1,34 @@
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.ImageAltFromGrandparent = exports.ImageAltFromParent = exports.ImageAltFromRecord = void 0;
7
+ const image_malloy_raw_1 = __importDefault(require("./static/image.malloy?raw"));
8
+ const render_malloy_1 = require("./render-malloy");
9
+ exports.default = {
10
+ title: 'Malloy/Image',
11
+ render: ({ source, view }, { globals: { connection } }) => {
12
+ return (0, render_malloy_1.renderMalloy)({ script: image_malloy_raw_1.default, source, view, connection });
13
+ },
14
+ argTypes: {},
15
+ };
16
+ exports.ImageAltFromRecord = {
17
+ args: {
18
+ source: 'logos',
19
+ view: 'img_from_record',
20
+ },
21
+ };
22
+ exports.ImageAltFromParent = {
23
+ args: {
24
+ source: 'logos',
25
+ view: 'img_from_parent',
26
+ },
27
+ };
28
+ exports.ImageAltFromGrandparent = {
29
+ args: {
30
+ source: 'logos',
31
+ view: 'img_from_grandparent',
32
+ },
33
+ };
34
+ //# sourceMappingURL=image.stories.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@malloydata/render",
3
- "version": "0.0.96-dev231024223919",
3
+ "version": "0.0.96-dev231025173405",
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.96-dev231024223919",
26
+ "@malloydata/malloy": "^0.0.96-dev231025173405",
27
27
  "@types/luxon": "^2.4.0",
28
28
  "lodash": "^4.17.20",
29
29
  "luxon": "^2.4.0",