From bc612e5687e8c9268c6dd2f22bafb1ca51a60b35 Mon Sep 17 00:00:00 2001 From: Kirk Swenson Date: Fri, 15 Nov 2024 19:04:17 -0800 Subject: [PATCH] fix: handling of hidden tiles --- v3/src/models/document/free-tile-row.ts | 22 +++++++++++++--------- v3/src/v2/import-v2-document.ts | 10 +++++++--- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/v3/src/models/document/free-tile-row.ts b/v3/src/models/document/free-tile-row.ts index 8dff56c08..fbb12edef 100644 --- a/v3/src/models/document/free-tile-row.ts +++ b/v3/src/models/document/free-tile-row.ts @@ -22,6 +22,14 @@ export const FreeTileLayout = types.model("FreeTileLayout", { isHidden: types.maybe(types.boolean), isMinimized: types.maybe(types.boolean) }) +.preProcessSnapshot(snap => { + if (snap.isHidden && snap.isMinimized) { + // can't be both minimized and hidden + const { isMinimized, ...others } = snap + return { ...others } + } + return snap +}) .views(self => ({ get position() { return { x: self.x, y: self.y } @@ -45,6 +53,8 @@ export const FreeTileLayout = types.model("FreeTileLayout", { setHidden(isHidden: boolean) { // only store it if it's true self.isHidden = isHidden || undefined + // can't be both hidden and minimized + if (isHidden) self.isMinimized = undefined }, setMinimized(isMinimized: boolean) { // only store it if it's true @@ -60,13 +70,7 @@ export function isFreeTileLayout(layout?: any): layout is IFreeTileLayout { Number.isFinite(layout.x) && Number.isFinite(layout.y) } -export interface IFreeTileInRowOptions extends ITileInRowOptions { - x: number - y: number - width?: number - height?: number - zIndex?: number - isMinimized?: boolean +export type IFreeTileInRowOptions = ITileInRowOptions & Omit & { animateCreation?: boolean } export const isFreeTileInRowOptions = (options?: ITileInRowOptions): options is IFreeTileInRowOptions => @@ -143,9 +147,9 @@ export const FreeTileRow = TileRowModel insertTile(tileId: string, options?: ITileInRowOptions) { const { x = 50, y = 50, width = undefined, height = undefined, zIndex = this.nextZIndex(), - isMinimized = undefined, animateCreation = false + isHidden = undefined, isMinimized = undefined, animateCreation = false } = isFreeTileInRowOptions(options) ? options : {} - self.tiles.set(tileId, { tileId, x, y, width, height, zIndex, isMinimized }) + self.tiles.set(tileId, { tileId, x, y, width, height, zIndex, isHidden, isMinimized }) animateCreation && self.animateCreationTiles.add(tileId) }, removeTile(tileId: string) { diff --git a/v3/src/v2/import-v2-document.ts b/v3/src/v2/import-v2-document.ts index 9c18945bf..231b6930b 100644 --- a/v3/src/v2/import-v2-document.ts +++ b/v3/src/v2/import-v2-document.ts @@ -43,14 +43,18 @@ export function importV2Document(v2Document: CodapV2Document) { const { layout: { left = 0, top = 0, width, height: v2Height, isVisible, zIndex }, savedHeight } = v2Component - const isMinimized = (!!savedHeight && savedHeight >= v2Height && !isVisible) || undefined - const height = savedHeight && isMinimized ? savedHeight : v2Height + const isHidden = isVisible === false + const v2Minimized = (!!savedHeight && savedHeight >= v2Height) || undefined + const isMinimized = v2Minimized && !isHidden + const height = savedHeight && v2Minimized ? savedHeight : v2Height // only apply imported width and height to resizable tiles const _width = !info.isFixedWidth ? { width } : {} const _height = !info?.isFixedHeight ? { height } : {} const _zIndex = zIndex != null ? { zIndex } : {} if (zIndex != null && zIndex > maxZIndex) maxZIndex = zIndex - const layout: IFreeTileInRowOptions = { x: left, y: top, ..._width, ..._height, ..._zIndex, isMinimized } + const layout: IFreeTileInRowOptions = { + x: left, y: top, ..._width, ..._height, ..._zIndex, isHidden, isMinimized + } newTile = content?.insertTileSnapshotInRow(tile, row, layout) } }