Spaces:
Running
Running
File size: 3,855 Bytes
c65c22e 6680666 21a73d8 6680666 c65c22e b8f62c1 6680666 21a73d8 6680666 c65c22e b8f62c1 6680666 c65c22e 6680666 21a73d8 6680666 c65c22e b8f62c1 6680666 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | export type FullscreenTurnViewMode = 'edit' | 'split' | 'preview';
export interface StudioLayoutSizes {
sidebarWidth: number;
jsonViewerWidth: number;
tagModalSidebarWidth: number;
imagesModalSidebarWidth: number;
templateModalSidebarWidth: number;
exportModalSidebarWidth: number;
imageAttachmentPreviewWidth: number;
systemPromptHeight: number;
fullscreenEditorWidth: number;
showInvisibleChars: boolean;
fullscreenViewMode: FullscreenTurnViewMode;
syncSplitLocation: boolean;
}
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,
exportModalSidebarWidth: 360,
imageAttachmentPreviewWidth: 440,
systemPromptHeight: 96,
fullscreenEditorWidth: 620,
showInvisibleChars: false,
fullscreenViewMode: 'split',
syncSplitLocation: true,
};
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>;
const validViewMode: FullscreenTurnViewMode =
parsed.fullscreenViewMode === 'edit' ||
parsed.fullscreenViewMode === 'split' ||
parsed.fullscreenViewMode === 'preview'
? parsed.fullscreenViewMode
: DEFAULT_LAYOUT_SIZES.fullscreenViewMode;
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
),
exportModalSidebarWidth: clampNumber(
parsed.exportModalSidebarWidth ??
DEFAULT_LAYOUT_SIZES.exportModalSidebarWidth,
260,
560
),
imageAttachmentPreviewWidth: clampNumber(
parsed.imageAttachmentPreviewWidth ??
DEFAULT_LAYOUT_SIZES.imageAttachmentPreviewWidth,
280,
680
),
systemPromptHeight: clampNumber(
parsed.systemPromptHeight ?? DEFAULT_LAYOUT_SIZES.systemPromptHeight,
68,
380
),
fullscreenEditorWidth: clampNumber(
parsed.fullscreenEditorWidth ??
DEFAULT_LAYOUT_SIZES.fullscreenEditorWidth,
320,
980
),
showInvisibleChars:
typeof parsed.showInvisibleChars === 'boolean'
? parsed.showInvisibleChars
: DEFAULT_LAYOUT_SIZES.showInvisibleChars,
fullscreenViewMode: validViewMode,
syncSplitLocation:
typeof parsed.syncSplitLocation === 'boolean'
? parsed.syncSplitLocation
: DEFAULT_LAYOUT_SIZES.syncSplitLocation,
};
} 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)
}
}
|