diff --git a/README.md b/README.md index ed5a9c6..fa9f8cb 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,7 @@ JSONPrism is a refracting tool for developers. It takes a single JSON input and - **Smart shape detection** — recognizes flat objects, arrays of objects, scalars; suggests the best target format. - **Per-format options** — pretty-print, indentation, dialect (for SQL), alignment (for Markdown), and more. - **Dark + light themes** — Prism Spectrum palette with violet / cyan / amber / rose accents. +- **Responsive — designed for viewports ≥ 360 × 640.** Smaller screens still work but may feel cramped; on mobile, Input and Output use a Tabs UI to give each panel full height. - **EN + VI** — bilingual interface out of the box. More languages welcome. - **Tauri desktop build** — drag-and-drop file workflow, offline-first (Phase 2 milestone). diff --git a/README.vi.md b/README.vi.md index 862d76f..b18338d 100644 --- a/README.vi.md +++ b/README.vi.md @@ -42,6 +42,7 @@ JSONPrism là công cụ "tán sắc" cho developer. Nhận một JSON đầu v - **Phát hiện shape thông minh** — nhận diện flat object, mảng object, scalar; gợi ý format đích phù hợp. - **Tuỳ chọn theo từng format** — pretty-print, indentation, dialect (SQL), alignment (Markdown), v.v. - **Theme sáng/tối** — bảng màu Prism Spectrum với violet / cyan / amber / rose. +- **Responsive — tối ưu cho viewport ≥ 360 × 640.** Màn hình nhỏ hơn vẫn dùng được nhưng có thể chật; trên mobile, Input và Output dùng Tabs UI để mỗi panel có toàn bộ chiều cao. - **Đa ngôn ngữ EN + VI** — sẵn sàng từ ngày đầu. Hoan nghênh thêm ngôn ngữ khác. - **Bản desktop Tauri** — drag-and-drop file, hoạt động offline (mốc Phase 2). diff --git a/THIRD-PARTY.md b/THIRD-PARTY.md index 9441235..dc4dd08 100644 --- a/THIRD-PARTY.md +++ b/THIRD-PARTY.md @@ -29,6 +29,7 @@ the relevant notices. This file is a starting point. | `@radix-ui/react-dialog` | ^1.1.0 | MIT | [radix-ui.com](https://www.radix-ui.com/) | | `@radix-ui/react-slot` | ^1.1.0 | MIT | [radix-ui.com](https://www.radix-ui.com/) | | `@radix-ui/react-switch` | ^1.1.0 | MIT | [radix-ui.com](https://www.radix-ui.com/) | +| `@radix-ui/react-tabs` | ^1.1.0 | MIT | [radix-ui.com](https://www.radix-ui.com/) | | `lucide-react` | ^0.460.0 | ISC | [lucide.dev](https://lucide.dev/) | | `sonner` | ^1.7.0 | MIT | [sonner.emilkowal.ski](https://sonner.emilkowal.ski/) | | `react-dropzone` | ^14.3.0 | MIT | [react-dropzone.js.org](https://react-dropzone.js.org/) | diff --git a/package-lock.json b/package-lock.json index 861e4c4..42b0c42 100644 --- a/package-lock.json +++ b/package-lock.json @@ -24,6 +24,7 @@ "@radix-ui/react-dialog": "^1.1.0", "@radix-ui/react-slot": "^1.1.0", "@radix-ui/react-switch": "^1.1.0", + "@radix-ui/react-tabs": "^1.1.13", "@tauri-apps/api": "^2.0.0", "@tauri-apps/plugin-dialog": "^2.0.0", "@tauri-apps/plugin-fs": "^2.0.0", @@ -1145,6 +1146,50 @@ "integrity": "sha512-JTF99U/6XIjCBo0wqkU5sK10glYe27MRRsfwoiq5zzOEZLHU3A3KCMa5X/azekYRCJ0HlwI0crAXS/5dEHTzDg==", "license": "MIT" }, + "node_modules/@radix-ui/react-collection": { + "version": "1.1.7", + "resolved": "https://registry.npmjs.org/@radix-ui/react-collection/-/react-collection-1.1.7.tgz", + "integrity": "sha512-Fh9rGN0MoI4ZFUNyfFVNU4y9LUz93u9/0K+yLgA2bwRojxM8JU1DyvvMBabnZPBgMWREAJvU2jjVzq+LrFUglw==", + "license": "MIT", + "dependencies": { + "@radix-ui/react-compose-refs": "1.1.2", + "@radix-ui/react-context": "1.1.2", + "@radix-ui/react-primitive": "2.1.3", + "@radix-ui/react-slot": "1.2.3" + }, + "peerDependencies": { + "@types/react": "*", + "@types/react-dom": "*", + "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc", + "react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + }, + "@types/react-dom": { + "optional": true + } + } + }, + "node_modules/@radix-ui/react-collection/node_modules/@radix-ui/react-slot": { + "version": "1.2.3", + "resolved": "https://registry.npmjs.org/@radix-ui/react-slot/-/react-slot-1.2.3.tgz", + "integrity": "sha512-aeNmHnBxbi2St0au6VBVC7JXFlhLlOnvIIlePNniyUNAClzmtAUEY8/pBiK3iHjufOlwA+c20/8jngo7xcrg8A==", + "license": "MIT", + "dependencies": { + "@radix-ui/react-compose-refs": "1.1.2" + }, + "peerDependencies": { + "@types/react": "*", + "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + } + } + }, "node_modules/@radix-ui/react-compose-refs": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/@radix-ui/react-compose-refs/-/react-compose-refs-1.1.2.tgz", @@ -1229,6 +1274,21 @@ } } }, + "node_modules/@radix-ui/react-direction": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/@radix-ui/react-direction/-/react-direction-1.1.1.tgz", + "integrity": "sha512-1UEWRX6jnOA2y4H5WczZ44gOOjTEmlqv1uNW4GAJEO5+bauCBhv8snY65Iw5/VOS/ghKN9gr2KjnLKxrsvoMVw==", + "license": "MIT", + "peerDependencies": { + "@types/react": "*", + "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + } + } + }, "node_modules/@radix-ui/react-dismissable-layer": { "version": "1.1.11", "resolved": "https://registry.npmjs.org/@radix-ui/react-dismissable-layer/-/react-dismissable-layer-1.1.11.tgz", @@ -1403,6 +1463,37 @@ } } }, + "node_modules/@radix-ui/react-roving-focus": { + "version": "1.1.11", + "resolved": "https://registry.npmjs.org/@radix-ui/react-roving-focus/-/react-roving-focus-1.1.11.tgz", + "integrity": "sha512-7A6S9jSgm/S+7MdtNDSb+IU859vQqJ/QAtcYQcfFC6W8RS4IxIZDldLR0xqCFZ6DCyrQLjLPsxtTNch5jVA4lA==", + "license": "MIT", + "dependencies": { + "@radix-ui/primitive": "1.1.3", + "@radix-ui/react-collection": "1.1.7", + "@radix-ui/react-compose-refs": "1.1.2", + "@radix-ui/react-context": "1.1.2", + "@radix-ui/react-direction": "1.1.1", + "@radix-ui/react-id": "1.1.1", + "@radix-ui/react-primitive": "2.1.3", + "@radix-ui/react-use-callback-ref": "1.1.1", + "@radix-ui/react-use-controllable-state": "1.2.2" + }, + "peerDependencies": { + "@types/react": "*", + "@types/react-dom": "*", + "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc", + "react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + }, + "@types/react-dom": { + "optional": true + } + } + }, "node_modules/@radix-ui/react-slot": { "version": "1.2.4", "resolved": "https://registry.npmjs.org/@radix-ui/react-slot/-/react-slot-1.2.4.tgz", @@ -1450,6 +1541,36 @@ } } }, + "node_modules/@radix-ui/react-tabs": { + "version": "1.1.13", + "resolved": "https://registry.npmjs.org/@radix-ui/react-tabs/-/react-tabs-1.1.13.tgz", + "integrity": "sha512-7xdcatg7/U+7+Udyoj2zodtI9H/IIopqo+YOIcZOq1nJwXWBZ9p8xiu5llXlekDbZkca79a/fozEYQXIA4sW6A==", + "license": "MIT", + "dependencies": { + "@radix-ui/primitive": "1.1.3", + "@radix-ui/react-context": "1.1.2", + "@radix-ui/react-direction": "1.1.1", + "@radix-ui/react-id": "1.1.1", + "@radix-ui/react-presence": "1.1.5", + "@radix-ui/react-primitive": "2.1.3", + "@radix-ui/react-roving-focus": "1.1.11", + "@radix-ui/react-use-controllable-state": "1.2.2" + }, + "peerDependencies": { + "@types/react": "*", + "@types/react-dom": "*", + "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc", + "react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + }, + "@types/react-dom": { + "optional": true + } + } + }, "node_modules/@radix-ui/react-use-callback-ref": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/@radix-ui/react-use-callback-ref/-/react-use-callback-ref-1.1.1.tgz", diff --git a/package.json b/package.json index af05530..1d63022 100644 --- a/package.json +++ b/package.json @@ -48,6 +48,7 @@ "@radix-ui/react-dialog": "^1.1.0", "@radix-ui/react-slot": "^1.1.0", "@radix-ui/react-switch": "^1.1.0", + "@radix-ui/react-tabs": "^1.1.13", "@tauri-apps/api": "^2.0.0", "@tauri-apps/plugin-dialog": "^2.0.0", "@tauri-apps/plugin-fs": "^2.0.0", diff --git a/src/components/converter/ConverterWorkspace.tsx b/src/components/converter/ConverterWorkspace.tsx index 58ee04f..89eecb3 100644 --- a/src/components/converter/ConverterWorkspace.tsx +++ b/src/components/converter/ConverterWorkspace.tsx @@ -1,6 +1,7 @@ -import { useCallback, useMemo, useRef, useState } from 'react'; +import { useCallback, useEffect, useMemo, useRef, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { toast } from '@/components/ui/sonner'; +import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs'; import { getConverter } from '@/converters/registry'; import type { FormatId } from '@/converters/types'; import { parseJsonInput } from '@/lib/detect'; @@ -36,6 +37,11 @@ export function ConverterWorkspace() { const actionsRef = useRef<{ copy: () => void; download: () => void } | null>(null); const [batchOpen, setBatchOpen] = useState(false); const [settingsOpen, setSettingsOpen] = useState(false); + // Mobile tab state — desktop ignores this and renders both panels side-by-side. + const [activeTab, setActiveTab] = useState<'input' | 'output'>('input'); + // Badge dot on Output tab when output changes while user is on Input tab. + const [hasUnreadOutput, setHasUnreadOutput] = useState(false); + const prevOutputRef = useRef(''); const addBatchFiles = useBatchStore((s) => s.addFiles); const handleMultiFileDrop = useCallback( @@ -179,6 +185,21 @@ export function ConverterWorkspace() { { key: ',', mod: true, handler: () => setSettingsOpen((v) => !v) }, ]); + // Flip the badge dot on the Output tab whenever output changes while the + // user is on the Input tab. Clearing happens once the user navigates over. + useEffect(() => { + if (output !== prevOutputRef.current) { + prevOutputRef.current = output; + if (output && activeTab !== 'output') { + setHasUnreadOutput(true); + } + } + }, [output, activeTab]); + + useEffect(() => { + if (activeTab === 'output') setHasUnreadOutput(false); + }, [activeTab]); + const inputBytes = useMemo(() => new TextEncoder().encode(input).length, [input]); const outputBytes = useMemo(() => new TextEncoder().encode(output).length, [output]); @@ -215,8 +236,54 @@ export function ConverterWorkspace() {
-
-
+ {/* Mobile: Tabs UI — each tab gets the full workspace height so panels + never overlap on short viewports. */} + setActiveTab(v as 'input' | 'output')} + className="flex min-h-0 flex-1 flex-col md:hidden" + > + + {t('home.tab_input')} + + {t('home.tab_output')} + {hasUnreadOutput && ( + + )} + + + + + + + { + actionsRef.current = a; + }} + /> + + + + {/* Desktop: side-by-side grid (≥ md). Rendered in parallel with the + Tabs above so neither remounts on viewport resize and CodeMirror + state survives the swap. */} +
+
+
diff --git a/src/components/converter/FormatPicker.tsx b/src/components/converter/FormatPicker.tsx index 57568ad..1551266 100644 --- a/src/components/converter/FormatPicker.tsx +++ b/src/components/converter/FormatPicker.tsx @@ -1,4 +1,7 @@ +import { useState } from 'react'; import { useTranslation } from 'react-i18next'; +import { ChevronDown } from 'lucide-react'; +import { Sheet, SheetContent, SheetHeader, SheetTitle, SheetTrigger } from '@/components/ui/sheet'; import { ALL_FORMATS, getConverter } from '@/converters/registry'; import type { FormatId } from '@/converters/types'; import type { JsonShape } from '@/lib/detect'; @@ -17,51 +20,121 @@ interface FormatPickerProps { export function FormatPicker({ value, onChange, shape, direction = 'forward' }: FormatPickerProps) { const { t } = useTranslation(); + const [sheetOpen, setSheetOpen] = useState(false); + const current = getConverter(value); + + const handlePick = (id: FormatId) => { + onChange(id); + setSheetOpen(false); + }; return ( -
- {ALL_FORMATS.map((id) => { - const c = getConverter(id); - const active = value === id; - const suggested = direction === 'forward' && shape ? isFormatSuggested(id, shape) : false; - const noReverse = direction === 'reverse' && typeof c.reverse !== 'function'; - const enabled = c.meta.ready && !noReverse; - const dimmed = direction === 'forward' && shape && !suggested && c.meta.ready; - - return ( + <> + {/* Mobile: compact Sheet trigger — saves ~50-80px of toolbar height when + the 12 chip grid would otherwise wrap to 2-3 rows on narrow viewports. */} + + - ); - })} -
+ + + + {t('home.format_picker_label')} + +
+ {ALL_FORMATS.map((id) => ( + + ))} +
+
+ + + {/* Desktop: 12 chips inline. */} +
+ {ALL_FORMATS.map((id) => ( + + ))} +
+ + ); +} + +interface FormatChipProps { + id: FormatId; + value: FormatId; + onChange: (id: FormatId) => void; + shape: JsonShape | null | undefined; + direction: Direction; + /** Expanded layout (fills the Sheet grid cell), vs the compact inline chip. */ + expanded?: boolean; +} + +function FormatChip({ id, value, onChange, shape, direction, expanded }: FormatChipProps) { + const { t } = useTranslation(); + const c = getConverter(id); + const active = value === id; + const suggested = direction === 'forward' && shape ? isFormatSuggested(id, shape) : false; + const noReverse = direction === 'reverse' && typeof c.reverse !== 'function'; + const enabled = c.meta.ready && !noReverse; + const dimmed = direction === 'forward' && shape && !suggested && c.meta.ready; + + return ( + ); } diff --git a/src/components/ui/tabs.tsx b/src/components/ui/tabs.tsx new file mode 100644 index 0000000..6ac789b --- /dev/null +++ b/src/components/ui/tabs.tsx @@ -0,0 +1,50 @@ +import * as React from 'react'; +import * as TabsPrimitive from '@radix-ui/react-tabs'; + +import { cn } from '@/lib/utils'; + +const Tabs = TabsPrimitive.Root; + +const TabsList = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => ( + +)); +TabsList.displayName = TabsPrimitive.List.displayName; + +const TabsTrigger = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => ( + +)); +TabsTrigger.displayName = TabsPrimitive.Trigger.displayName; + +const TabsContent = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => ( + +)); +TabsContent.displayName = TabsPrimitive.Content.displayName; + +export { Tabs, TabsList, TabsTrigger, TabsContent }; diff --git a/src/i18n/locales/en.json b/src/i18n/locales/en.json index e2da829..18caa8c 100644 --- a/src/i18n/locales/en.json +++ b/src/i18n/locales/en.json @@ -14,6 +14,8 @@ "input_label_format": "Input {{format}}", "input_placeholder": "Paste your JSON here, drop files, or load a sample…", "input_placeholder_format": "Paste your {{ext}} here, drop files, or load a sample…", + "tab_input": "Input", + "tab_output": "Output", "output_label": "Output", "output_empty": "Output will appear here once you provide valid JSON.", "output_empty_format": "Output will appear here once you provide valid {{ext}}.", diff --git a/src/i18n/locales/ja.json b/src/i18n/locales/ja.json index f29cbd9..46cfe6e 100644 --- a/src/i18n/locales/ja.json +++ b/src/i18n/locales/ja.json @@ -14,6 +14,8 @@ "input_label_format": "{{format}} 入力", "input_placeholder": "ここに JSON を貼り付け、ファイルをドロップ、またはサンプルを読み込み…", "input_placeholder_format": "ここに {{ext}} を貼り付け、ファイルをドロップ、またはサンプルを読み込み…", + "tab_input": "入力", + "tab_output": "出力", "output_label": "出力", "output_empty": "有効な JSON を入力すると、ここに出力が表示されます。", "output_empty_format": "有効な {{ext}} を入力すると、ここに出力が表示されます。", diff --git a/src/i18n/locales/vi.json b/src/i18n/locales/vi.json index 7208e1c..99ed8ec 100644 --- a/src/i18n/locales/vi.json +++ b/src/i18n/locales/vi.json @@ -14,6 +14,8 @@ "input_label_format": "Đầu vào {{format}}", "input_placeholder": "Dán JSON vào đây, thả file, hoặc nạp mẫu…", "input_placeholder_format": "Dán {{ext}} vào đây, thả file, hoặc nạp mẫu…", + "tab_input": "Đầu vào", + "tab_output": "Kết quả", "output_label": "Kết quả", "output_empty": "Kết quả sẽ hiện ở đây khi bạn cung cấp JSON hợp lệ.", "output_empty_format": "Kết quả sẽ hiện ở đây khi bạn cung cấp {{ext}} hợp lệ.", diff --git a/src/i18n/locales/zh-CN.json b/src/i18n/locales/zh-CN.json index ffb2a95..cad2b2b 100644 --- a/src/i18n/locales/zh-CN.json +++ b/src/i18n/locales/zh-CN.json @@ -14,6 +14,8 @@ "input_label_format": "{{format}} 输入", "input_placeholder": "在此处粘贴 JSON、拖入文件或加载示例…", "input_placeholder_format": "在此处粘贴 {{ext}}、拖入文件或加载示例…", + "tab_input": "输入", + "tab_output": "输出", "output_label": "输出", "output_empty": "提供有效的 JSON 后,输出将显示在此处。", "output_empty_format": "提供有效的 {{ext}} 后,输出将显示在此处。",