Spaces:
Running
Running
Download src/utils/layout.ts from zelk12/ShareGPT_Dialogue_Studio: direct link, hf CLI and curl.
- Browser
- Download file 2.46 kB
-
https://huggingface.co/spaces/zelk12/ShareGPT_Dialogue_Studio/resolve/main/src/utils/layout.ts
- Command line
-
hf download hf://spaces/zelk12/ShareGPT_Dialogue_Studio/src/utils/layout.ts
-
curl -L -o layout.ts https://huggingface.co/spaces/zelk12/ShareGPT_Dialogue_Studio/resolve/main/src/utils/layout.ts
2.46 kB
| export interface StudioLayoutSizes { | |
| sidebarWidth: number; | |
| jsonViewerWidth: number; | |
| tagModalSidebarWidth: number; | |
| imagesModalSidebarWidth: number; | |
| templateModalSidebarWidth: number; | |
| imageAttachmentPreviewWidth: number; | |
| systemPromptHeight: number; | |
| } | |
| const LAYOUT_STORAGE_KEY = 'sharegpt_dialogue_studio_layout_v1'; | |
| export const DEFAULT_LAYOUT_SIZES: StudioLayoutSizes = { | |
| sidebarWidth: 296, | |
| jsonViewerWidth: 440, | |
| tagModalSidebarWidth: 320, | |
| imagesModalSidebarWidth: 310, | |
| templateModalSidebarWidth: 340, | |
| imageAttachmentPreviewWidth: 440, | |
| systemPromptHeight: 96, | |
| }; | |
| export function clampNumber(value: number, min: number, max: number): number { | |
| if (!Number.isFinite(value)) return min; | |
| return Math.min(max, Math.max(min, Math.round(value))); | |
| } | |
| export function loadLayoutSizes(): StudioLayoutSizes { | |
| try { | |
| const raw = localStorage.getItem(LAYOUT_STORAGE_KEY); | |
| if (!raw) return { ...DEFAULT_LAYOUT_SIZES }; | |
| const parsed = JSON.parse(raw) as Partial<StudioLayoutSizes>; | |
| return { | |
| sidebarWidth: clampNumber( | |
| parsed.sidebarWidth ?? DEFAULT_LAYOUT_SIZES.sidebarWidth, | |
| 240, | |
| 520 | |
| ), | |
| jsonViewerWidth: clampNumber( | |
| parsed.jsonViewerWidth ?? DEFAULT_LAYOUT_SIZES.jsonViewerWidth, | |
| 320, | |
| 760 | |
| ), | |
| tagModalSidebarWidth: clampNumber( | |
| parsed.tagModalSidebarWidth ?? DEFAULT_LAYOUT_SIZES.tagModalSidebarWidth, | |
| 240, | |
| 520 | |
| ), | |
| imagesModalSidebarWidth: clampNumber( | |
| parsed.imagesModalSidebarWidth ?? | |
| DEFAULT_LAYOUT_SIZES.imagesModalSidebarWidth, | |
| 230, | |
| 500 | |
| ), | |
| templateModalSidebarWidth: clampNumber( | |
| parsed.templateModalSidebarWidth ?? | |
| DEFAULT_LAYOUT_SIZES.templateModalSidebarWidth, | |
| 250, | |
| 520 | |
| ), | |
| imageAttachmentPreviewWidth: clampNumber( | |
| parsed.imageAttachmentPreviewWidth ?? | |
| DEFAULT_LAYOUT_SIZES.imageAttachmentPreviewWidth, | |
| 280, | |
| 680 | |
| ), | |
| systemPromptHeight: clampNumber( | |
| parsed.systemPromptHeight ?? DEFAULT_LAYOUT_SIZES.systemPromptHeight, | |
| 68, | |
| 380 | |
| ), | |
| }; | |
| } catch { | |
| return { ...DEFAULT_LAYOUT_SIZES }; | |
| } | |
| } | |
| export function saveLayoutSizes(sizes: StudioLayoutSizes): void { | |
| try { | |
| localStorage.setItem(LAYOUT_STORAGE_KEY, JSON.stringify(sizes)); | |
| } catch { | |
| // Ignore storage quota or iframe restrictions (e.g. Hugging Face Spaces) | |
| } | |
| } | |