feat(import-window): add window state management to JS
Adds WINDOW_SESSION_STORAGE_KEY, readWindowSessionState(), window state properties to state object, new element references in elements object, and persistWindowSessionState(). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
998551ab19
commit
35d1db4fd7
@ -424,8 +424,22 @@
|
||||
</main>
|
||||
|
||||
<script>
|
||||
const WINDOW_SESSION_STORAGE_KEY = "zotero-kb.import-window";
|
||||
const IMPORT_SESSION_STORAGE_KEY = "zotero-kb.import-modal";
|
||||
|
||||
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();
|
||||
|
||||
function readImportSessionState() {
|
||||
try {
|
||||
const raw = window.sessionStorage.getItem(IMPORT_SESSION_STORAGE_KEY);
|
||||
@ -446,7 +460,19 @@
|
||||
currentProjectId: null,
|
||||
currentCards: [],
|
||||
collectionTree: [],
|
||||
isImportWindowOpen: false,
|
||||
isImportModalOpen: 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"
|
||||
? importSessionState.selectedCollectionKey
|
||||
: null,
|
||||
@ -471,18 +497,22 @@
|
||||
projectForm: document.getElementById("create-project-form"),
|
||||
projectStatus: document.getElementById("project-status"),
|
||||
projectList: document.getElementById("project-list"),
|
||||
importModal: document.getElementById("import-modal"),
|
||||
importModalOverlay: document.getElementById("import-modal-overlay"),
|
||||
importWindowShell: document.getElementById("import-window-shell"),
|
||||
importWindow: document.getElementById("import-window"),
|
||||
windowToolbar: document.getElementById("import-window-toolbar"),
|
||||
openImportModalButton: document.getElementById("open-import-modal-button"),
|
||||
closeImportModalButton: document.getElementById("close-import-modal-button"),
|
||||
importModalProjectLabel: document.getElementById("import-modal-project-label"),
|
||||
collectionStatus: document.getElementById("collection-status"),
|
||||
collectionTree: document.getElementById("modal-collection-tree"),
|
||||
collectionItems: document.getElementById("modal-collection-items"),
|
||||
selectedCount: document.getElementById("modal-selected-count"),
|
||||
selectDescendantsButton: document.getElementById("modal-select-descendants-button"),
|
||||
clearSelectionButton: document.getElementById("modal-clear-selection-button"),
|
||||
importSelectedItemsButton: document.getElementById("modal-import-selected-items-button"),
|
||||
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"),
|
||||
windowProjectLabel: document.getElementById("import-window-project-label"),
|
||||
windowSelectedCount: document.getElementById("window-selected-count"),
|
||||
windowClearSelectionButton: document.getElementById("window-clear-selection-button"),
|
||||
windowImportSelectedItemsButton: document.getElementById("window-import-selected-items-button"),
|
||||
windowCollectionStatus: document.getElementById("window-collection-status"),
|
||||
windowCollectionTree: document.getElementById("window-collection-tree"),
|
||||
windowCollectionItems: document.getElementById("window-collection-items"),
|
||||
currentProjectLabel: document.getElementById("current-project-label"),
|
||||
cardList: document.getElementById("card-list"),
|
||||
cardDetail: document.getElementById("card-detail"),
|
||||
@ -511,6 +541,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) {
|
||||
target.textContent = message || "";
|
||||
target.classList.toggle("error", Boolean(isError));
|
||||
|
||||
Loading…
Reference in New Issue
Block a user