zlocalz
Version:
ZLocalz - TUI Locale Guardian for Flutter ARB l10n/i18n validation and translation with AI-powered fixes
206 lines • 7.96 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.CommandPalette = void 0;
const blessed = __importStar(require("blessed"));
const events_1 = require("events");
const fuzzy = __importStar(require("fuzzy"));
class CommandPalette extends events_1.EventEmitter {
container;
input;
list;
commands = [
{ name: 'scan', description: 'Scan for ARB files', action: 'scan' },
{ name: 'validate', description: 'Validate all locales', action: 'validate' },
{ name: 'fix', description: 'Auto-fix selected issues', shortcut: 'a', action: 'fix' },
{ name: 'translate', description: 'Translate missing keys', shortcut: 't', action: 'translate' },
{ name: 'save', description: 'Save all changes', shortcut: 'S', action: 'save' },
{ name: 'export', description: 'Export report and patches', action: 'export' },
{ name: 'diff', description: 'Show diff view', shortcut: 'd', action: 'diff' },
{ name: 'filter:missing', description: 'Filter missing keys', action: 'filter:missing' },
{ name: 'filter:extra', description: 'Filter extra keys', action: 'filter:extra' },
{ name: 'filter:duplicates', description: 'Filter duplicate values', action: 'filter:duplicate' },
{ name: 'filter:icu', description: 'Filter ICU errors', action: 'filter:icuError' },
{ name: 'filter:placeholders', description: 'Filter placeholder issues', action: 'filter:placeholderMismatch' },
{ name: 'filter:formatting', description: 'Filter formatting warnings', action: 'filter:formatting' },
{ name: 'filter:clear', description: 'Clear all filters', action: 'filter:clear' },
{ name: 'select:all', description: 'Select all visible keys', shortcut: 'A', action: 'select:all' },
{ name: 'select:none', description: 'Clear selection', action: 'select:none' },
{ name: 'git:stage', description: 'Stage changes in Git', action: 'git:stage' },
{ name: 'git:commit', description: 'Create Git commit', action: 'git:commit' },
{ name: 'update:check', description: 'Check for updates', action: 'update:check' },
{ name: 'update:install', description: 'Update to latest version', action: 'update:install' },
{ name: 'theme:dark', description: 'Switch to dark theme', action: 'theme:dark' },
{ name: 'theme:light', description: 'Switch to light theme', action: 'theme:light' },
{ name: 'help', description: 'Show help', shortcut: '?', action: 'help' }
];
filtered = [];
constructor(parent) {
super();
this.container = blessed.box({
parent,
top: 'center',
left: 'center',
width: '60%',
height: '60%',
border: 'line',
label: ' Command Palette ',
hidden: true,
tags: true,
style: {
border: { fg: '#0066cc' },
label: { fg: 'white', bold: true },
bg: '#1e1e1e'
}
});
this.input = blessed.textbox({
parent: this.container,
top: 0,
left: 0,
width: '100%-2',
height: 3,
inputOnFocus: true,
style: {
fg: 'white',
bg: '#2a2a2a',
focus: {
bg: '#333333'
}
}
});
this.list = blessed.list({
parent: this.container,
top: 3,
left: 0,
width: '100%-2',
height: '100%-5',
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.setupEventHandlers();
this.updateList('');
}
setupEventHandlers() {
this.input.on('submit', () => {
const selected = this.list.selected || 0;
if (this.filtered[selected]) {
this.execute(this.filtered[selected]);
}
});
this.input.on('cancel', () => {
this.hide();
});
this.input.key(['up', 'down', 'C-p', 'C-n'], (_ch, key) => {
if (key.name === 'up' || key.full === 'C-p') {
this.list.up(1);
}
else {
this.list.down(1);
}
this.container.screen.render();
});
let lastValue = '';
this.input.on('keypress', () => {
const value = this.input.getValue();
if (value !== lastValue) {
lastValue = value;
this.updateList(value);
}
});
this.list.on('select', () => {
const selected = this.list.selected || 0;
if (this.filtered[selected]) {
this.execute(this.filtered[selected]);
}
});
this.container.key(['escape', 'C-c'], () => {
this.hide();
});
}
updateList(query) {
if (!query) {
this.filtered = [...this.commands];
}
else {
const results = fuzzy.filter(query, this.commands, {
extract: (cmd) => `${cmd.name} ${cmd.description}`
});
this.filtered = results.map(r => r.original);
}
const items = this.filtered.map(cmd => {
const shortcut = cmd.shortcut ? ` {gray-fg}(${cmd.shortcut}){/gray-fg}` : '';
return `{bold}${cmd.name}{/bold}${shortcut} - {gray-fg}${cmd.description}{/gray-fg}`;
});
this.list.setItems(items);
this.list.select(0);
this.container.screen.render();
}
execute(command) {
this.hide();
this.emit('command', command.action);
}
show() {
this.container.show();
this.input.setValue('');
this.input.focus();
this.updateList('');
this.container.screen.render();
}
hide() {
this.container.hide();
this.container.screen.render();
}
}
exports.CommandPalette = CommandPalette;
//# sourceMappingURL=command-palette.js.map