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>
|
</main>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
const WINDOW_SESSION_STORAGE_KEY = "zotero-kb.import-window";
|
||||||
const IMPORT_SESSION_STORAGE_KEY = "zotero-kb.import-modal";
|
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() {
|
function readImportSessionState() {
|
||||||
try {
|
try {
|
||||||
const raw = window.sessionStorage.getItem(IMPORT_SESSION_STORAGE_KEY);
|
const raw = window.sessionStorage.getItem(IMPORT_SESSION_STORAGE_KEY);
|
||||||
@ -446,7 +460,19 @@
|
|||||||
currentProjectId: null,
|
currentProjectId: null,
|
||||||
currentCards: [],
|
currentCards: [],
|
||||||
collectionTree: [],
|
collectionTree: [],
|
||||||
|
isImportWindowOpen: false,
|
||||||
isImportModalOpen: 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"
|
selectedCollectionKey: typeof importSessionState.selectedCollectionKey === "string"
|
||||||
? importSessionState.selectedCollectionKey
|
? importSessionState.selectedCollectionKey
|
||||||
: null,
|
: null,
|
||||||
@ -471,18 +497,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"),
|
||||||
openImportModalButton: document.getElementById("open-import-modal-button"),
|
openImportModalButton: document.getElementById("open-import-modal-button"),
|
||||||
closeImportModalButton: document.getElementById("close-import-modal-button"),
|
windowMinimizeButton: document.getElementById("window-minimize-button"),
|
||||||
importModalProjectLabel: document.getElementById("import-modal-project-label"),
|
windowMaximizeButton: document.getElementById("window-maximize-button"),
|
||||||
collectionStatus: document.getElementById("collection-status"),
|
windowCloseButton: document.getElementById("window-close-button"),
|
||||||
collectionTree: document.getElementById("modal-collection-tree"),
|
windowRestoreButton: document.getElementById("window-restore-button"),
|
||||||
collectionItems: document.getElementById("modal-collection-items"),
|
importWindowMinimizedBar: document.getElementById("import-window-minimized-bar"),
|
||||||
selectedCount: document.getElementById("modal-selected-count"),
|
windowProjectLabel: document.getElementById("import-window-project-label"),
|
||||||
selectDescendantsButton: document.getElementById("modal-select-descendants-button"),
|
windowSelectedCount: document.getElementById("window-selected-count"),
|
||||||
clearSelectionButton: document.getElementById("modal-clear-selection-button"),
|
windowClearSelectionButton: document.getElementById("window-clear-selection-button"),
|
||||||
importSelectedItemsButton: document.getElementById("modal-import-selected-items-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"),
|
currentProjectLabel: document.getElementById("current-project-label"),
|
||||||
cardList: document.getElementById("card-list"),
|
cardList: document.getElementById("card-list"),
|
||||||
cardDetail: document.getElementById("card-detail"),
|
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) {
|
function setStatus(target, message, isError = false) {
|
||||||
target.textContent = message || "";
|
target.textContent = message || "";
|
||||||
target.classList.toggle("error", Boolean(isError));
|
target.classList.toggle("error", Boolean(isError));
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user