Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions src/BloomBrowserUI/bookEdit/toolbox/canvas/customXmatterPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { CustomPageLayoutMenu } from "./customPageLayoutMenu";
import {
CanvasElementManager,
kBackgroundImageClass,
showCanvasTool,
theOneCanvasElementManager,
} from "../../js/CanvasElementManager";
import { EditableDivUtils } from "../../js/editableDivUtils";
Expand Down Expand Up @@ -60,9 +61,7 @@ import { isLegacyThemeCssLoaded } from "../../bookSettings/appearanceThemeUtils"
visibility of different languages.
*/

export async function convertXmatterPageToCustom(
page: HTMLElement,
): Promise<void> {
async function convertXmatterPageToCustom(page: HTMLElement): Promise<void> {
const marginBox = page.getElementsByClassName(
"marginBox",
)[0] as HTMLElement;
Expand Down Expand Up @@ -257,6 +256,8 @@ function finishReactivatingPage(page: HTMLElement): void {
theOneCanvasElementManager.turnOnCanvasElementEditing();
ensureDerivedFieldsFitOnCustomPage(page);
getToolboxBundleExports()?.applyToolboxStateToPage();
// Enable or show the canvas tool.
showCanvasTool();
}

// This function tries to make sure that all derived-field canvas elements fit on the page.
Expand Down Expand Up @@ -441,6 +442,10 @@ function renderPageLayoutMenu(page: HTMLElement, container: HTMLElement): void {
() => convertXmatterPageToCustom(page),
"customPageLayout-convertStartOver",
);
// This is normally set in editView/toggleCustomPageLayout, but we're not calling that.
// The attribute will be persisted only if some other change is made to the page, but that
// may be good enough since the user is starting over and presumably will make some changes.
page.setAttribute("data-tool-id", "canvas");
renderPageLayoutMenu(page, container);
return;
}
Expand All @@ -461,13 +466,19 @@ function renderPageLayoutMenu(page: HTMLElement, container: HTMLElement): void {
() => convertXmatterPageToCustom(page),
"customPageLayout-convertFirstTime",
);
// Set data-tool-id on the browser DOM so it persists when jumpToPage saves.
// (The C# toggleCustomPageLayout set it on the C# DOM, but returned early
// without SaveThen, so that change would be overwritten by the browser save.)
page.setAttribute("data-tool-id", "canvas");
// Persist the newly created custom layout state so a later toggle back
// to standard has matching server-side state to work from.
await postString(
"editView/jumpToPage",
page.getAttribute("id")!,
);
renderPageLayoutMenu(page, container);
} else if (selection === "custom" && response) {
showCanvasTool(); // otherwise called from convertXmatterPageToCustom()/finishReactivatingPage()
}
}}
/>,
Expand Down
11 changes: 11 additions & 0 deletions src/BloomExe/web/controllers/EditingViewApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,11 @@ private void HandleToggleCustomCover(ApiRequest request)
request.ReplyWithText("false");
return;
}
pageElt.SetAttribute("data-tool-id", "canvas");
}
else
{
pageElt.RemoveAttribute("data-tool-id");
}

request.ReplyWithText("true");
Expand All @@ -200,6 +205,7 @@ private void HandleToggleCustomCover(ApiRequest request)
// page element.
var backgroundAudio = pageElt.GetAttribute(HtmlDom.musicAttrName);
var backgroundAudioVolume = pageElt.GetAttribute(HtmlDom.musicVolumeName);
var dataToolId = pageElt.GetAttribute("data-tool-id");
// Bring everything up to date consistent with the new
// state. Might be enough just do the BookData update.
book.EnsureUpToDateMemory(new NullProgress());
Expand All @@ -223,6 +229,11 @@ private void HandleToggleCustomCover(ApiRequest request)
// Keep the same invariant we enforce elsewhere.
if (string.IsNullOrEmpty(backgroundAudio))
updatedPageElt.RemoveAttribute(HtmlDom.musicVolumeName);

if (string.IsNullOrEmpty(dataToolId))
updatedPageElt.RemoveAttribute("data-tool-id");
else
updatedPageElt.SetAttribute("data-tool-id", dataToolId);
}

return pageId;
Expand Down