Skip to content
Merged
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
69 changes: 55 additions & 14 deletions src/components/Output/ZplImportModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { useRef, useState } from 'react';
import { XMarkIcon, ClipboardDocumentIcon, CheckIcon, FolderOpenIcon } from '@heroicons/react/16/solid';
import { importZplText } from '../../lib/zplImportService';
import { readFileAsText } from '../../lib/readFile';
import { useLabelStore } from '../../store/labelStore';
import { useLabelStore, type Page } from '../../store/labelStore';
import type { LabelConfig } from '../../types/ObjectType';
import { formatReportAsText, type ImportResult } from '../../lib/importReport';
import { ImportSummaryBody } from './ImportReportModal';
import { useT } from '../../lib/useT';
Expand All @@ -18,9 +19,30 @@ export function ZplImportModal({ onClose }: Props) {
const [error, setError] = useState<string | null>(null);
const [result, setResult] = useState<ImportResult | null>(null);
const [copied, setCopied] = useState(false);
const [appendMode, setAppendMode] = useState(false);
const fileInputRef = useRef<HTMLInputElement>(null);
const loadDesign = useLabelStore((s) => s.loadDesign);
const appendPages = useLabelStore((s) => s.appendPages);
const label = useLabelStore((s) => s.label);
const pages = useLabelStore((s) => s.pages);

// Append-mode only makes sense when there is something to append *to*.
// On a fresh designer (one empty page) we hide the toggle entirely
// because the resulting [empty, imported] state would just be clutter
// the user has to clean up manually.
const hasExistingContent =
pages.length > 1 || (pages[0]?.objects.length ?? 0) > 0;

const applyImport = (labelConfig: Partial<LabelConfig>, importedPages: Page[]) => {
if (appendMode && hasExistingContent) {
// Keep the current label config — the user opted to keep the
// existing design's dimensions, so any imported ^PW/^LL is
// intentionally discarded.
appendPages(importedPages);
} else {
loadDesign({ ...label, ...labelConfig }, importedPages);
}
};

const handleImport = () => {
setError(null);
Expand All @@ -29,15 +51,15 @@ export function ZplImportModal({ onClose }: Props) {
return;
}

const { labelConfig, pages, report } = importZplText(zpl, label.dpmm);
const totalObjects = pages.reduce((s, p) => s + p.objects.length, 0);
const { labelConfig, pages: importedPages, report } = importZplText(zpl, label.dpmm);
const totalObjects = importedPages.reduce((s, p) => s + p.objects.length, 0);

if (totalObjects === 0 && Object.keys(labelConfig).length === 0) {
setError('No supported objects found in the ZPL code.');
return;
}

loadDesign({ ...label, ...labelConfig }, pages);
applyImport(labelConfig, importedPages);
setResult({ objectCount: totalObjects, report });
};

Expand All @@ -60,9 +82,15 @@ export function ZplImportModal({ onClose }: Props) {
return;
}

const { labelConfig, pages, report } = importZplText(text, label.dpmm);
const totalObjects = pages.reduce((s, p) => s + p.objects.length, 0);
loadDesign({ ...label, ...labelConfig }, pages);
const { labelConfig, pages: importedPages, report } = importZplText(text, label.dpmm);
const totalObjects = importedPages.reduce((s, p) => s + p.objects.length, 0);

if (totalObjects === 0 && Object.keys(labelConfig).length === 0) {
setError('No supported objects found in the ZPL code.');
return;
}

applyImport(labelConfig, importedPages);
Comment thread
u8array marked this conversation as resolved.
setResult({ objectCount: totalObjects, report });
};

Expand Down Expand Up @@ -142,13 +170,26 @@ export function ZplImportModal({ onClose }: Props) {
</div>

<div className="flex items-center justify-between px-4 py-3 border-t border-border shrink-0">
<button
onClick={() => fileInputRef.current?.click()}
className="flex items-center gap-1.5 font-mono text-[10px] text-muted hover:text-text transition-colors"
>
<FolderOpenIcon className="w-3.5 h-3.5" />
Choose file
</button>
<div className="flex items-center gap-4">
<button
onClick={() => fileInputRef.current?.click()}
className="flex items-center gap-1.5 font-mono text-[10px] text-muted hover:text-text transition-colors"
>
<FolderOpenIcon className="w-3.5 h-3.5" />
{t.app.chooseFile}
</button>
{hasExistingContent && (
<label className="flex items-center gap-1.5 cursor-pointer font-mono text-[10px] text-muted hover:text-text transition-colors">
<input
type="checkbox"
className="accent-accent"
checked={appendMode}
onChange={(e) => setAppendMode(e.target.checked)}
/>
{t.app.keepExistingPages}
</label>
)}
</div>
<div className="flex gap-2">
<button
onClick={onClose}
Expand Down
2 changes: 2 additions & 0 deletions src/locales/ar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ const ar = {
app: {
file: 'ملف',
importZpl: 'استيراد ZPL',
keepExistingPages: 'الاحتفاظ بالصفحات الحالية',
chooseFile: 'اختيار ملف',
exportZpl: 'تصدير ZPL',
newDesign: 'تصميم جديد',
addPage: 'إضافة صفحة',
Expand Down
2 changes: 2 additions & 0 deletions src/locales/bg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ const bg = {
app: {
file: 'Файл',
importZpl: 'Import ZPL',
keepExistingPages: 'Запазване на съществуващите страници',
chooseFile: 'Избор на файл',
exportZpl: 'Export ZPL',
newDesign: 'Нов дизайн',
addPage: 'Добавяне на страница',
Expand Down
2 changes: 2 additions & 0 deletions src/locales/cs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ const cs = {
app: {
file: 'Soubor',
importZpl: 'Import ZPL',
keepExistingPages: 'Zachovat stávající stránky',
chooseFile: 'Vybrat soubor',
exportZpl: 'Export ZPL',
newDesign: 'Nový návrh',
addPage: 'Přidat stránku',
Expand Down
2 changes: 2 additions & 0 deletions src/locales/da.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ const da = {
app: {
file: 'Fil',
importZpl: 'Import ZPL',
keepExistingPages: 'Behold eksisterende sider',
chooseFile: 'Vælg fil',
exportZpl: 'Export ZPL',
newDesign: 'Nyt design',
addPage: 'Tilføj side',
Expand Down
2 changes: 2 additions & 0 deletions src/locales/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ const de = {
app: {
file: 'Datei',
importZpl: 'Import ZPL',
keepExistingPages: 'Bestehende Seiten behalten',
chooseFile: 'Datei wählen',
exportZpl: 'Export ZPL',
newDesign: 'Neues Design',
addPage: 'Seite hinzufügen',
Expand Down
2 changes: 2 additions & 0 deletions src/locales/el.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ const el = {
app: {
file: 'Αρχείο',
importZpl: 'Import ZPL',
keepExistingPages: 'Διατήρηση υπαρχουσών σελίδων',
chooseFile: 'Επιλογή αρχείου',
exportZpl: 'Export ZPL',
newDesign: 'Νέο σχέδιο',
addPage: 'Προσθήκη σελίδας',
Expand Down
2 changes: 2 additions & 0 deletions src/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ const en = {
app: {
file: 'File',
importZpl: 'Import ZPL',
keepExistingPages: 'Keep existing pages',
chooseFile: 'Choose file',
exportZpl: 'Export ZPL',
newDesign: 'New design',
addPage: 'Add page',
Expand Down
2 changes: 2 additions & 0 deletions src/locales/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ const es = {
app: {
file: 'Archivo',
importZpl: 'Import ZPL',
keepExistingPages: 'Conservar páginas existentes',
chooseFile: 'Elegir archivo',
exportZpl: 'Export ZPL',
newDesign: 'Nuevo diseño',
addPage: 'Añadir página',
Expand Down
2 changes: 2 additions & 0 deletions src/locales/et.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ const et = {
app: {
file: 'Fail',
importZpl: 'Import ZPL',
keepExistingPages: 'Säilita olemasolevad lehed',
chooseFile: 'Vali fail',
exportZpl: 'Export ZPL',
newDesign: 'Uus kujundus',
addPage: 'Lisa leht',
Expand Down
2 changes: 2 additions & 0 deletions src/locales/fa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ const fa = {
app: {
file: 'فایل',
importZpl: 'وارد کردن ZPL',
keepExistingPages: 'حفظ صفحات موجود',
chooseFile: 'انتخاب فایل',
exportZpl: 'خروجی ZPL',
newDesign: 'طرح جدید',
addPage: 'افزودن صفحه',
Expand Down
2 changes: 2 additions & 0 deletions src/locales/fi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ const fi = {
app: {
file: 'Tiedosto',
importZpl: 'Import ZPL',
keepExistingPages: 'Säilytä olemassa olevat sivut',
chooseFile: 'Valitse tiedosto',
exportZpl: 'Export ZPL',
newDesign: 'Uusi rakenne',
addPage: 'Lisää sivu',
Expand Down
2 changes: 2 additions & 0 deletions src/locales/fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ const fr = {
app: {
file: 'Fichier',
importZpl: 'Import ZPL',
keepExistingPages: 'Conserver les pages existantes',
chooseFile: 'Choisir un fichier',
exportZpl: 'Export ZPL',
newDesign: 'Nouveau design',
addPage: 'Ajouter une page',
Expand Down
2 changes: 2 additions & 0 deletions src/locales/he.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ const he = {
app: {
file: 'קובץ',
importZpl: 'ייבוא ZPL',
keepExistingPages: 'שמור על דפים קיימים',
chooseFile: 'בחר קובץ',
exportZpl: 'ייצוא ZPL',
newDesign: 'עיצוב חדש',
addPage: 'הוסף דף',
Expand Down
2 changes: 2 additions & 0 deletions src/locales/hr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ const hr = {
app: {
file: 'Datoteka',
importZpl: 'Import ZPL',
keepExistingPages: 'Zadrži postojeće stranice',
chooseFile: 'Odaberi datoteku',
exportZpl: 'Export ZPL',
newDesign: 'Novi dizajn',
addPage: 'Dodaj stranicu',
Expand Down
2 changes: 2 additions & 0 deletions src/locales/hu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ const hu = {
app: {
file: 'Fájl',
importZpl: 'Import ZPL',
keepExistingPages: 'Meglévő oldalak megtartása',
chooseFile: 'Fájl kiválasztása',
exportZpl: 'Export ZPL',
newDesign: 'Új terv',
addPage: 'Oldal hozzáadása',
Expand Down
2 changes: 2 additions & 0 deletions src/locales/it.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ const it = {
app: {
file: 'File',
importZpl: 'Import ZPL',
keepExistingPages: 'Mantieni pagine esistenti',
chooseFile: 'Scegli file',
exportZpl: 'Export ZPL',
newDesign: 'Nuovo design',
addPage: 'Aggiungi pagina',
Expand Down
2 changes: 2 additions & 0 deletions src/locales/ja.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ const ja = {
app: {
file: 'ファイル',
importZpl: 'ZPL インポート',
keepExistingPages: '既存のページを保持',
chooseFile: 'ファイルを選択',
exportZpl: 'ZPL エクスポート',
newDesign: '新しいデザイン',
addPage: 'ページを追加',
Expand Down
2 changes: 2 additions & 0 deletions src/locales/ko.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ const ko = {
app: {
file: '파일',
importZpl: 'ZPL 가져오기',
keepExistingPages: '기존 페이지 유지',
chooseFile: '파일 선택',
exportZpl: 'ZPL 내보내기',
newDesign: '새 디자인',
addPage: '페이지 추가',
Expand Down
2 changes: 2 additions & 0 deletions src/locales/lt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ const lt = {
app: {
file: 'Failas',
importZpl: 'Import ZPL',
keepExistingPages: 'Išsaugoti esamus puslapius',
chooseFile: 'Pasirinkti failą',
exportZpl: 'Export ZPL',
newDesign: 'Naujas dizainas',
addPage: 'Pridėti puslapį',
Expand Down
2 changes: 2 additions & 0 deletions src/locales/lv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ const lv = {
app: {
file: 'Fails',
importZpl: 'Import ZPL',
keepExistingPages: 'Saglabāt esošās lapas',
chooseFile: 'Izvēlēties failu',
exportZpl: 'Export ZPL',
newDesign: 'Jauns dizains',
addPage: 'Pievienot lapu',
Expand Down
2 changes: 2 additions & 0 deletions src/locales/nl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ const nl = {
app: {
file: 'Bestand',
importZpl: 'Import ZPL',
keepExistingPages: 'Bestaande pagina\'s behouden',
chooseFile: 'Bestand kiezen',
exportZpl: 'Export ZPL',
newDesign: 'Nieuw ontwerp',
addPage: 'Pagina toevoegen',
Expand Down
2 changes: 2 additions & 0 deletions src/locales/no.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ const no = {
app: {
file: 'Fil',
importZpl: 'Import ZPL',
keepExistingPages: 'Behold eksisterende sider',
chooseFile: 'Velg fil',
exportZpl: 'Export ZPL',
newDesign: 'Nytt design',
addPage: 'Legg til side',
Expand Down
2 changes: 2 additions & 0 deletions src/locales/pl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ const pl = {
app: {
file: 'Plik',
importZpl: 'Import ZPL',
keepExistingPages: 'Zachowaj istniejące strony',
chooseFile: 'Wybierz plik',
exportZpl: 'Export ZPL',
newDesign: 'Nowy projekt',
addPage: 'Dodaj stronę',
Expand Down
2 changes: 2 additions & 0 deletions src/locales/pt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ const pt = {
app: {
file: 'Arquivo',
importZpl: 'Import ZPL',
keepExistingPages: 'Manter páginas existentes',
chooseFile: 'Escolher ficheiro',
exportZpl: 'Export ZPL',
newDesign: 'Novo design',
addPage: 'Adicionar página',
Expand Down
2 changes: 2 additions & 0 deletions src/locales/ro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ const ro = {
app: {
file: 'Fișier',
importZpl: 'Import ZPL',
keepExistingPages: 'Păstrează paginile existente',
chooseFile: 'Alege fișier',
exportZpl: 'Export ZPL',
newDesign: 'Design nou',
addPage: 'Adaugă pagină',
Expand Down
2 changes: 2 additions & 0 deletions src/locales/sk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ const sk = {
app: {
file: 'Súbor',
importZpl: 'Import ZPL',
keepExistingPages: 'Zachovať existujúce stránky',
chooseFile: 'Vybrať súbor',
exportZpl: 'Export ZPL',
newDesign: 'Nový návrh',
addPage: 'Pridať stránku',
Expand Down
2 changes: 2 additions & 0 deletions src/locales/sl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ const sl = {
app: {
file: 'Datoteka',
importZpl: 'Import ZPL',
keepExistingPages: 'Ohrani obstoječe strani',
chooseFile: 'Izberi datoteko',
exportZpl: 'Export ZPL',
newDesign: 'Nov dizajn',
addPage: 'Dodaj stran',
Expand Down
2 changes: 2 additions & 0 deletions src/locales/sr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ const sr = {
app: {
file: 'Датотека',
importZpl: 'Import ZPL',
keepExistingPages: 'Задржи постојеће странице',
chooseFile: 'Изабери датотеку',
exportZpl: 'Export ZPL',
newDesign: 'Нови дизајн',
addPage: 'Додај страницу',
Expand Down
2 changes: 2 additions & 0 deletions src/locales/sv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ const sv = {
app: {
file: 'Fil',
importZpl: 'Import ZPL',
keepExistingPages: 'Behåll befintliga sidor',
chooseFile: 'Välj fil',
exportZpl: 'Export ZPL',
newDesign: 'Nytt design',
addPage: 'Lägg till sida',
Expand Down
2 changes: 2 additions & 0 deletions src/locales/tr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ const tr = {
app: {
file: 'Dosya',
importZpl: 'ZPL İçe Aktar',
keepExistingPages: 'Mevcut sayfaları koru',
chooseFile: 'Dosya seç',
exportZpl: 'ZPL Dışa Aktar',
newDesign: 'Yeni Tasarım',
addPage: 'Sayfa ekle',
Expand Down
2 changes: 2 additions & 0 deletions src/locales/zh-hans.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ const zhHans = {
app: {
file: '文件',
importZpl: '导入 ZPL',
keepExistingPages: '保留现有页面',
chooseFile: '选择文件',
exportZpl: '导出 ZPL',
newDesign: '新建设计',
addPage: '添加页面',
Expand Down
Loading