UNPKG

zlocalz

Version:

ZLocalz - TUI Locale Guardian for Flutter ARB l10n/i18n validation and translation with AI-powered fixes

230 lines 7.02 kB
"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.MetadataEditor = void 0; const blessed = __importStar(require("blessed")); const events_1 = require("events"); class MetadataEditor extends events_1.EventEmitter { container; form; descriptionInput; placeholdersBox; metadata = {}; constructor(parent) { super(); this.container = blessed.box({ parent, top: 0, left: 0, width: '100%', height: '100%', hidden: true }); this.form = blessed.form({ parent: this.container, top: 0, left: 0, width: '100%', height: '100%', keys: true, vi: true }); blessed.text({ parent: this.form, top: 0, left: 0, content: '{bold}Description:{/bold}', tags: true, height: 1 }); this.descriptionInput = blessed.textarea({ parent: this.form, name: 'description', top: 1, left: 0, width: '100%', height: 5, inputOnFocus: true, border: 'line', style: { fg: 'white', bg: '#2a2a2a', border: { fg: '#444444' }, focus: { bg: '#333333', border: { fg: '#0066cc' } } } }); blessed.text({ parent: this.form, top: 7, left: 0, content: '{bold}Placeholders:{/bold}', tags: true, height: 1 }); this.placeholdersBox = blessed.box({ parent: this.form, top: 8, left: 0, width: '100%', height: '50%', border: 'line', scrollable: true, keys: true, vi: true, mouse: true, style: { border: { fg: '#444444' }, scrollbar: { bg: 'blue' } } }); const buttonBox = blessed.box({ parent: this.form, bottom: 0, left: 0, width: '100%', height: 3 }); const saveButton = blessed.button({ parent: buttonBox, bottom: 0, left: 2, width: 10, height: 3, content: ' Save ', align: 'center', style: { fg: 'white', bg: '#0066cc', hover: { bg: '#0088ff' }, focus: { bg: '#0088ff' } } }); const cancelButton = blessed.button({ parent: buttonBox, bottom: 0, left: 14, width: 10, height: 3, content: ' Cancel ', align: 'center', style: { fg: 'white', bg: '#666666', hover: { bg: '#888888' }, focus: { bg: '#888888' } } }); saveButton.on('press', () => this.save()); cancelButton.on('press', () => this.cancel()); this.form.key(['C-s'], () => this.save()); this.form.key(['escape', 'C-c'], () => this.cancel()); } setMetadata(metadata) { this.metadata = metadata || {}; this.descriptionInput.setValue(this.metadata.description || ''); this.placeholdersBox.children.forEach((child) => child.detach()); if (this.metadata.placeholders) { let y = 0; for (const [name, placeholder] of Object.entries(this.metadata.placeholders)) { const ph = placeholder; blessed.text({ parent: this.placeholdersBox, top: y, left: 1, content: `{bold}{cyan-fg}${name}:{/cyan-fg}{/bold}`, tags: true }); if (ph.type) { blessed.text({ parent: this.placeholdersBox, top: y + 1, left: 3, content: `Type: ${ph.type}`, tags: true }); } if (ph.example) { blessed.text({ parent: this.placeholdersBox, top: y + 2, left: 3, content: `Example: ${ph.example}`, tags: true }); } y += 4; } } this.container.screen.render(); } save() { const description = this.descriptionInput.getValue(); const updatedMetadata = { ...this.metadata }; if (description) { updatedMetadata.description = description; } else { delete updatedMetadata.description; } this.emit('save', updatedMetadata); } cancel() { this.setMetadata(this.metadata); } focus() { this.descriptionInput.focus(); } show() { this.container.show(); } hide() { this.container.hide(); } } exports.MetadataEditor = MetadataEditor; //# sourceMappingURL=metadata-editor.js.map