zlocalz
Version:
ZLocalz - TUI Locale Guardian for Flutter ARB l10n/i18n validation and translation with AI-powered fixes
145 lines • 5.13 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.FileTreePane = void 0;
const blessed = __importStar(require("blessed"));
const events_1 = require("events");
class FileTreePane extends events_1.EventEmitter {
element;
container;
constructor(parent, options) {
super();
this.container = blessed.box({
parent,
...options,
border: 'line',
label: ' Locales ',
tags: true,
style: {
border: { fg: '#4a4a4a' },
label: { fg: '#888888' }
}
});
this.element = blessed.list({
parent: this.container,
top: 0,
left: 0,
width: '100%-2',
height: '100%-2',
keys: true,
vi: true,
mouse: true,
scrollbar: {
ch: ' ',
track: {
bg: '#333333'
},
style: {
inverse: true
}
},
style: {
item: {
hover: {
bg: '#2a2a2a',
fg: 'white'
}
},
selected: {
bg: '#0066cc',
fg: 'white',
bold: true
}
}
});
this.element.on('select', (_item, index) => {
const locale = this.getLocaleFromIndex(index);
if (locale) {
this.emit('select-locale', locale);
}
});
}
update(state) {
const items = [];
if (state.sourceFile) {
const sourceIssueCount = state.issues.get(state.sourceFile.locale)?.length || 0;
items.push(`{bold}${state.sourceFile.locale}{/bold} (source) ${sourceIssueCount > 0 ? `{red-fg}⚠ ${sourceIssueCount}{/red-fg}` : '{green-fg}✓{/green-fg}'}`);
}
for (const [locale, _file] of state.targetFiles) {
const issues = state.issues.get(locale) || [];
const errorCount = issues.filter((i) => i.severity === 'error').length;
const warningCount = issues.filter((i) => i.severity === 'warning').length;
let status = '{green-fg}✓{/green-fg}';
if (errorCount > 0) {
status = `{red-fg}✗ ${errorCount}E{/red-fg}`;
}
if (warningCount > 0) {
status += ` {yellow-fg}⚠ ${warningCount}W{/yellow-fg}`;
}
const modified = state.unsavedChanges ? '{cyan-fg}●{/cyan-fg} ' : '';
items.push(`${modified}${locale} ${status}`);
}
this.element.setItems(items);
if (state.currentLocale) {
const index = this.getIndexFromLocale(state.currentLocale, state);
if (index >= 0) {
this.element.select(index);
}
}
}
getLocaleFromIndex(index) {
const item = this.element.getItem(index);
if (!item)
return null;
const text = item.getText();
const match = text.match(/^[●\s]*(\w+)/);
return match ? match[1] : null;
}
getIndexFromLocale(locale, state) {
let index = 0;
if (state.sourceFile?.locale === locale)
return 0;
if (state.sourceFile)
index++;
const locales = Array.from(state.targetFiles.keys());
const targetIndex = locales.indexOf(locale);
return targetIndex >= 0 ? index + targetIndex : -1;
}
focus() {
this.element.focus();
}
}
exports.FileTreePane = FileTreePane;
//# sourceMappingURL=file-tree.js.map