Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions build-cdn-css.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#!/usr/bin/env node

/**
* Simple script to prepare CSS files for CDN
* Creates csvEditorCss folder with combined and minified CSS
*/

const fs = require('fs');
const path = require('path');

const OUTPUT_DIR = path.join(__dirname, 'csvEditorCss');

// CSS files to combine
const CSS_FILES = [
'csvEditorHtml/main.css',
'csvEditorHtml/dark.css',
'csvEditorHtml/light.css',
'csvEditorHtml/high_contrast.css',
'csvEditorHtml/settingsOverwrite.css'
];

// Third-party CSS to copy
const THIRD_PARTY_CSS = [
{ src: 'thirdParty/handsontable/handsontable.min.css', dest: 'handsontable.min.css' },
{ src: 'thirdParty/fortawesome/fontawesome-free/css/all.min.css', dest: 'fontawesome.min.css' }
];

// Simple CSS minification
function minifyCSS(css) {
return css
.replace(/\/\*[\s\S]*?\*\//g, '') // Remove comments
.replace(/\s+/g, ' ') // Replace multiple spaces with single space
.replace(/\s*([{}:;,])\s*/g, '$1') // Remove spaces around {}:;,
.trim();
}

// Create output directory
if (!fs.existsSync(OUTPUT_DIR)) {
fs.mkdirSync(OUTPUT_DIR, { recursive: true });
}

console.log('🔨 Building CDN CSS files...\n');

// Combine and minify CSV editor CSS files
console.log('📦 Combining CSS files...');
let combinedCSS = '';

CSS_FILES.forEach(file => {
const filePath = path.join(__dirname, file);
if (fs.existsSync(filePath)) {
const content = fs.readFileSync(filePath, 'utf-8');
combinedCSS += `\n/* ${path.basename(file)} */\n${content}\n`;
console.log(` ✓ Added ${path.basename(file)}`);
} else {
console.log(` ✗ Not found: ${file}`);
}
});

console.log('\n⚡ Minifying CSS...');
const minifiedCSS = minifyCSS(combinedCSS);
const outputFile = path.join(OUTPUT_DIR, 'index.min.css');
fs.writeFileSync(outputFile, minifiedCSS);
const sizeKB = (minifiedCSS.length / 1024).toFixed(2);
console.log(` ✓ Created main-cdn.min.css (${sizeKB} KB)\n`);

// Copy third-party CSS files
console.log('📋 Copying third-party CSS...');
THIRD_PARTY_CSS.forEach(({ src, dest }) => {
const srcPath = path.join(__dirname, src);
const destPath = path.join(OUTPUT_DIR, dest);

if (fs.existsSync(srcPath)) {
fs.copyFileSync(srcPath, destPath);
const stats = fs.statSync(destPath);
const sizeKB = (stats.size / 1024).toFixed(2);
console.log(` ✓ Copied ${dest} (${sizeKB} KB)`);
} else {
console.log(` ✗ Not found: ${src}`);
}
});

console.log('\n✅ Done! Files created in csvEditorCss/');

5 changes: 5 additions & 0 deletions csvEditorCss/fontawesome.min.css

Large diffs are not rendered by default.

31 changes: 31 additions & 0 deletions csvEditorCss/handsontable.min.css

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions csvEditorCss/index.min.css

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion csvEditorHtml/browser/beforeDomLoadedBrowser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ var initialConfig: EditCsvConfig | undefined = {
initialNumbersStyle: 'en',
insertRowBehavior: 'keepRowKeepColumn',
insertColBehavior: 'keepRowKeepColumn',
initiallyIsInReadonlyMode: false,
hideOpenCsvEditorUiActions: false, //noop, has only effect if set inside the user settings (vs code extension)
openTableAndSelectCellAtCursorPos: "never",
pasteMode: 'normal',
Expand Down
12 changes: 9 additions & 3 deletions csvEditorHtml/io.ts
Original file line number Diff line number Diff line change
Expand Up @@ -540,9 +540,15 @@ function handleVsCodeMessage(event: { data: ReceivedMessageFromVsCode }) {
}

default: {
_error('received unknown message from vs code')
notExhaustiveSwitch(message)
break
try {
const messageStr =
typeof message === "string" ? message : JSON.stringify(message);

if (!/"rpc_[a-zA-Z0-9]+"/.test(messageStr)) {
_error('received unknown message from vs code')
notExhaustiveSwitch(message)
}
} catch {}
}
}

Expand Down
2 changes: 1 addition & 1 deletion csvEditorHtml/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ let shouldApplyHasHeaderAfterRowsAdded = false
* table is editable or not, also disables some related ui, e.g. buttons
* set via {@link EditCsvConfig.initiallyIsInReadonlyMode}
*/
let isReadonlyMode = false
let isReadonlyMode = true

/**
* the original csv file has a layout and sometimes we use the original positions
Expand Down
8 changes: 0 additions & 8 deletions csvEditorHtml/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,14 +309,6 @@ type EditCsvConfig = {
*/
insertColBehavior: 'keepRowFocusNewColumn' | 'keepRowKeepColumn'

/**
* table should start in readonly mode?
* true: table is view only,
* false: edit mode (normal)
* NOTE that initial fixes (e.g. all rows should have the same length) are applied because readonly is only applied after/during the table is created
*/
initiallyIsInReadonlyMode: boolean

/**
* false: hide the edit csv button and the file context menu action to open the editor (useful if you want to call this extension from another extension and show a custom button),
* true: show them
Expand Down
Loading