feat(import-window): add window state management to JS

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Saberlve 2026-04-15 15:49:31 +08:00
parent 05a5e99ee0
commit fa0b4933c3

View File

@ -490,12 +490,39 @@
const importSessionState = readImportSessionState(); const importSessionState = readImportSessionState();
const WINDOW_SESSION_STORAGE_KEY = "zotero-kb.import-window";
function readWindowSessionState() {
try {
const raw = window.sessionStorage.getItem(WINDOW_SESSION_STORAGE_KEY);
if (!raw) return {};
const payload = JSON.parse(raw);
return typeof payload === "object" && payload ? payload : {};
} catch (_error) {
return {};
}
}
const windowSessionState = readWindowSessionState();
const state = { const state = {
projects: [], projects: [],
currentProjectId: null, currentProjectId: null,
currentCards: [], currentCards: [],
collectionTree: [], collectionTree: [],
isImportModalOpen: false, isImportModalOpen: false,
isImportWindowOpen: false,
windowX: typeof windowSessionState.x === "number" ? windowSessionState.x : null,
windowY: typeof windowSessionState.y === "number" ? windowSessionState.y : null,
windowWidth: typeof windowSessionState.width === "number" ? windowSessionState.width : null,
windowHeight: typeof windowSessionState.height === "number" ? windowSessionState.height : null,
isWindowMinimized: Boolean(windowSessionState.isMinimized),
isWindowMaximized: Boolean(windowSessionState.isMaximized),
isWindowDragging: false,
windowDragStartX: 0,
windowDragStartY: 0,
windowDragStartLeft: 0,
windowDragStartTop: 0,
selectedCollectionKey: typeof importSessionState.selectedCollectionKey === "string" selectedCollectionKey: typeof importSessionState.selectedCollectionKey === "string"
? importSessionState.selectedCollectionKey ? importSessionState.selectedCollectionKey
: null, : null,
@ -523,17 +550,22 @@
projectForm: document.getElementById("create-project-form"), projectForm: document.getElementById("create-project-form"),
projectStatus: document.getElementById("project-status"), projectStatus: document.getElementById("project-status"),
projectList: document.getElementById("project-list"), projectList: document.getElementById("project-list"),
importModal: document.getElementById("import-modal"), importWindowShell: document.getElementById("import-window-shell"),
importModalOverlay: document.getElementById("import-modal-overlay"), importWindow: document.getElementById("import-window"),
windowToolbar: document.getElementById("import-window-toolbar"),
windowMinimizeButton: document.getElementById("window-minimize-button"),
windowMaximizeButton: document.getElementById("window-maximize-button"),
windowCloseButton: document.getElementById("window-close-button"),
windowRestoreButton: document.getElementById("window-restore-button"),
importWindowMinimizedBar: document.getElementById("import-window-minimized-bar"),
openImportModalButton: document.getElementById("open-import-modal-button"), openImportModalButton: document.getElementById("open-import-modal-button"),
closeImportModalButton: document.getElementById("close-import-modal-button"), windowProjectLabel: document.getElementById("import-window-project-label"),
importModalProjectLabel: document.getElementById("import-modal-project-label"), windowSelectedCount: document.getElementById("window-selected-count"),
collectionStatus: document.getElementById("collection-status"), windowClearSelectionButton: document.getElementById("window-clear-selection-button"),
collectionTree: document.getElementById("modal-collection-tree"), windowImportSelectedItemsButton: document.getElementById("window-import-selected-items-button"),
collectionItems: document.getElementById("modal-collection-items"), windowCollectionStatus: document.getElementById("window-collection-status"),
selectedCount: document.getElementById("modal-selected-count"), windowCollectionTree: document.getElementById("window-collection-tree"),
clearSelectionButton: document.getElementById("modal-clear-selection-button"), windowCollectionItems: document.getElementById("window-collection-items"),
importSelectedItemsButton: document.getElementById("modal-import-selected-items-button"),
previewPopover: document.getElementById("item-preview-popover"), previewPopover: document.getElementById("item-preview-popover"),
currentProjectLabel: document.getElementById("current-project-label"), currentProjectLabel: document.getElementById("current-project-label"),
cardList: document.getElementById("card-list"), cardList: document.getElementById("card-list"),
@ -563,6 +595,27 @@
); );
} }
function persistWindowSessionState() {
const fw = elements.importWindow;
if (!fw) return;
const style = window.getComputedStyle(fw);
const width = parseFloat(style.width);
const height = parseFloat(style.height);
const left = parseFloat(style.left);
const top = parseFloat(style.top);
window.sessionStorage.setItem(
WINDOW_SESSION_STORAGE_KEY,
JSON.stringify({
x: left,
y: top,
width: width,
height: height,
isMinimized: state.isWindowMinimized,
isMaximized: state.isWindowMaximized,
})
);
}
function setStatus(target, message, isError = false) { function setStatus(target, message, isError = false) {
target.textContent = message || ""; target.textContent = message || "";
target.classList.toggle("error", Boolean(isError)); target.classList.toggle("error", Boolean(isError));