Skip to content

Commit 6015244

Browse files
authored
feat: Set up a custom renderer for data frames. (#60)
1 parent d1ca48b commit 6015244

29 files changed

+3264
-10203
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ jobs:
9696
permissions:
9797
id-token: write
9898
contents: read
99+
packages: read
99100
steps:
100101
- name: Checkout
101102
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5

build/esbuild/build.ts

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ import { lessLoader } from 'esbuild-plugin-less';
99
import fs from 'fs-extra';
1010
import { getZeroMQPreBuildsFoldersToKeep, getBundleConfiguration, bundleConfiguration } from '../webpack/common';
1111
import ImportGlobPlugin from 'esbuild-plugin-import-glob';
12+
import postcss from 'postcss';
13+
import tailwindcss from '@tailwindcss/postcss';
14+
import autoprefixer from 'autoprefixer';
1215
const plugin = require('node-stdlib-browser/helpers/esbuild/plugin');
1316
const stdLibBrowser = require('node-stdlib-browser');
1417

@@ -86,7 +89,11 @@ const loader: { [ext: string]: Loader } = {
8689

8790
// https://github.com/evanw/esbuild/issues/20#issuecomment-802269745
8891
// https://github.com/hyrious/esbuild-plugin-style
89-
function style({ minify = true, charset = 'utf8' }: StylePluginOptions = {}): Plugin {
92+
function style({
93+
minify = true,
94+
charset = 'utf8',
95+
enableTailwind = false
96+
}: StylePluginOptions & { enableTailwind?: boolean } = {}): Plugin {
9097
return {
9198
name: 'style',
9299
setup({ onResolve, onLoad }) {
@@ -132,6 +139,32 @@ function style({ minify = true, charset = 'utf8' }: StylePluginOptions = {}): Pl
132139
}));
133140

134141
onLoad({ filter: /.*/, namespace: 'style-content' }, async (args) => {
142+
// Process with PostCSS/Tailwind if enabled and file exists
143+
if (enableTailwind && args.path.includes('tailwind.css') && fs.existsSync(args.path)) {
144+
try {
145+
const cssContent = await fs.readFile(args.path, 'utf8');
146+
const result = await postcss([tailwindcss, autoprefixer]).process(cssContent, {
147+
from: args.path,
148+
to: args.path
149+
});
150+
151+
const options = { ...opt, stdin: { contents: result.css, loader: 'css' } };
152+
options.loader = options.loader || {};
153+
// Add the same loaders we add for other places
154+
Object.keys(loader).forEach((key) => {
155+
if (options.loader && !options.loader[key]) {
156+
options.loader[key] = loader[key];
157+
}
158+
});
159+
const { errors, warnings, outputFiles } = await esbuild.build(options);
160+
return { errors, warnings, contents: outputFiles![0].text, loader: 'text' };
161+
} catch (error) {
162+
console.error(`PostCSS processing failed for ${args.path}:`, error);
163+
throw error;
164+
}
165+
}
166+
167+
// Default behavior for other CSS files
135168
const options = { entryPoints: [args.path], ...opt };
136169
options.loader = options.loader || {};
137170
// Add the same loaders we add for other places
@@ -140,7 +173,9 @@ function style({ minify = true, charset = 'utf8' }: StylePluginOptions = {}): Pl
140173
options.loader[key] = loader[key];
141174
}
142175
});
176+
143177
const { errors, warnings, outputFiles } = await esbuild.build(options);
178+
144179
return { errors, warnings, contents: outputFiles![0].text, loader: 'text' };
145180
});
146181
}
@@ -158,7 +193,9 @@ function createConfig(
158193
const plugins: Plugin[] = [];
159194
let define: SameShape<BuildOptions, BuildOptions>['define'] = undefined;
160195
if (target === 'web') {
161-
plugins.push(style());
196+
// Enable Tailwind processing for dataframe renderer
197+
const enableTailwind = source.includes(path.join('dataframe-renderer', 'index.ts'));
198+
plugins.push(style({ enableTailwind }));
162199
plugins.push(lessLoader());
163200

164201
define = {
@@ -287,6 +324,11 @@ async function buildAll() {
287324
),
288325
{ target: 'web', watch: watchAll }
289326
),
327+
build(
328+
path.join(extensionFolder, 'src', 'webviews', 'webview-side', 'dataframe-renderer', 'index.ts'),
329+
path.join(extensionFolder, 'dist', 'webviews', 'webview-side', 'dataframeRenderer', 'dataframeRenderer.js'),
330+
{ target: 'web', watch: isWatchMode }
331+
),
290332
build(
291333
path.join(extensionFolder, 'src', 'webviews', 'webview-side', 'variable-view', 'index.tsx'),
292334
path.join(extensionFolder, 'dist', 'webviews', 'webview-side', 'viewers', 'variableView.js'),

0 commit comments

Comments
 (0)