zlocalz
Version:
ZLocalz - TUI Locale Guardian for Flutter ARB l10n/i18n validation and translation with AI-powered fixes
190 lines • 6.59 kB
JavaScript
"use strict";
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.KeyListPane = void 0;
const blessed = __importStar(require("blessed"));
const events_1 = require("events");
class KeyListPane extends events_1.EventEmitter {
element;
container;
items = [];
filtered = [];
constructor(parent, options) {
super();
this.container = blessed.box({
parent,
...options,
border: 'line',
label: ' Keys ',
tags: true,
style: {
border: { fg: '#4a4a4a' },
label: { fg: '#888888' }
}
});
this.element = blessed.listtable({
parent: this.container,
top: 0,
left: 0,
width: '100%-2',
height: '100%-2',
align: 'left',
tags: true,
keys: true,
vi: true,
mouse: true,
scrollbar: {
ch: ' ',
track: {
bg: '#333333'
},
style: {
inverse: true
}
},
style: {
header: {
fg: 'blue',
bold: true
},
cell: {
hover: {
bg: '#2a2a2a',
fg: 'white'
}
},
selected: {
bg: '#0066cc',
fg: 'white',
bold: true
}
}
});
this.element.on('select', (_item, index) => {
if (index > 0 && this.filtered[index - 1]) {
this.emit('select-key', this.filtered[index - 1].key);
}
});
this.element.key(['space'], () => {
const index = this.element.selected;
if (index > 0 && this.filtered[index - 1]) {
this.emit('toggle-selection', this.filtered[index - 1].key);
}
});
}
update(state) {
if (!state.currentLocale) {
this.element.setData([['No locale selected']]);
return;
}
const targetFile = state.currentLocale === state.sourceFile?.locale
? state.sourceFile
: state.targetFiles.get(state.currentLocale);
if (!targetFile) {
this.element.setData([['No file loaded']]);
return;
}
const issues = state.issues.get(state.currentLocale) || [];
const issueMap = new Map();
for (const issue of issues) {
if (!issueMap.has(issue.key)) {
issueMap.set(issue.key, []);
}
issueMap.get(issue.key).push(issue);
}
this.items = Object.entries(targetFile.entries).map(([key, entry]) => ({
key,
value: entry.value,
issues: (issueMap.get(key) || []).map(i => ({ type: i.type, severity: i.severity })),
selected: state.selectedKeys.has(key)
}));
if (state.sourceFile && state.currentLocale !== state.sourceFile.locale) {
const missingKeys = Object.keys(state.sourceFile.entries)
.filter(key => !targetFile.entries[key]);
for (const key of missingKeys) {
this.items.push({
key,
value: '(missing)',
issues: [{ type: 'missing', severity: 'error' }],
selected: state.selectedKeys.has(key)
});
}
}
this.applyFilter(state.filter);
this.render();
}
applyFilter(filter) {
if (!filter) {
this.filtered = [...this.items];
}
else {
this.filtered = this.items.filter(item => item.issues.some((issue) => issue.type === filter));
}
}
render() {
const data = [
['{bold}Key{/bold}', '{bold}Value{/bold}', '{bold}Issues{/bold}']
];
for (const item of this.filtered) {
const checkbox = item.selected ? '{cyan-fg}☑{/cyan-fg}' : '☐';
const key = `${checkbox} ${item.key}`;
const value = item.value.length > 40
? item.value.substring(0, 37) + '...'
: item.value;
const issueIndicators = item.issues.map(issue => {
const color = issue.severity === 'error' ? 'red' : 'yellow';
const icon = issue.severity === 'error' ? '✗' : '⚠';
return `{${color}-fg}${icon}{/${color}-fg}`;
}).join(' ');
data.push([key, value, issueIndicators]);
}
this.element.setData(data);
}
updateSelection(selectedKeys) {
for (const item of this.items) {
item.selected = selectedKeys.has(item.key);
}
this.render();
}
selectAll() {
const allKeys = this.filtered.map(item => item.key);
this.emit('select-all', allKeys);
}
focus() {
this.element.focus();
}
}
exports.KeyListPane = KeyListPane;
//# sourceMappingURL=key-list.js.map