Skip to content

Commit

Permalink
Hide Toolbox in Minecraft Python Hour of Code (#10234)
Browse files Browse the repository at this point in the history
This adds a hideToolbox metadata field for tutorials (only supported for monaco at the moment, not sure it makes much sense in a blocks scenario). When present, the toolbox is not shown and the user actually has to type things out.

It also fixes a separate issue (that I initially thought was related to these changes but actually wasn't) with the workspace header, where it was always assuming we were in blocks mode. Now it accepts a property for the workspace id, which allows it to size everything correctly (thus, fixing the border).
  • Loading branch information
thsparks authored Oct 15, 2024
1 parent 9d326fc commit 9e6dd9e
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 8 deletions.
8 changes: 8 additions & 0 deletions docs/writing-docs/tutorials/control-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ You can highlight the differences in code between the current step hint and the
### @diffs true
```

### Hide Toolbox

For text-based tutorials, you can choose to hide the toolbox altogether. This is done by specifying **@hideToolbox** in the metadata. The default is ``false``.

```
### @hideToolbox true
```

## Special blocks

### Templates
Expand Down
3 changes: 2 additions & 1 deletion localtypings/pxtarget.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1197,6 +1197,7 @@ declare namespace pxt.tutorial {
activities?: boolean; // tutorial consists of activities, then steps. uses `###` for steps
explicitHints?: boolean; // tutorial expects explicit hints in `#### ~ tutorialhint` format
flyoutOnly?: boolean; // no categories, display all blocks in flyout
hideToolbox?: boolean; // hide the toolbox in the tutorial
hideIteration?: boolean; // hide step control in tutorial
diffs?: boolean; // automatically diff snippets
noDiffs?: boolean; // don't automatically generated diffs
Expand Down Expand Up @@ -1347,4 +1348,4 @@ declare namespace pxt.auth {
type: "skillmap-completion";
sourceURL: string;
}
}
}
1 change: 1 addition & 0 deletions pxtlib/docsrender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ namespace pxt.docs {
"activities": "<!-- activities -->",
"explicitHints": "<!-- hints -->",
"flyoutOnly": "<!-- flyout -->",
"hideToolbox": "<!-- hideToolbox -->",
"hideIteration": "<!-- iter -->",
"codeStart": "<!-- start -->",
"codeStop": "<!-- stop -->",
Expand Down
8 changes: 7 additions & 1 deletion pxtlib/tutorial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ namespace pxt.tutorial {
simThemeJson
} = computeBodyMetadata(body);

// For python HOC, hide the toolbox (we don't support flyoutOnly mode).
if (pxt.BrowserUtils.useOldTutorialLayout() && language === "python" && metadata.flyoutOnly) {
metadata.flyoutOnly = false;
metadata.hideToolbox = true;
}

// noDiffs legacy
if (metadata.diffs === true // enabled in tutorial
|| (metadata.diffs !== false && metadata.noDiffs !== true // not disabled
Expand Down Expand Up @@ -406,7 +412,7 @@ ${code}
if (metadata.explicitHints !== undefined
&& pxt.appTarget.appTheme
&& pxt.appTarget.appTheme.tutorialExplicitHints)
metadata.explicitHints = true;
metadata.explicitHints = true;

return { metadata, body };
}
Expand Down
6 changes: 5 additions & 1 deletion theme/tutorial.less
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,10 @@ code.lang-filterblocks {
}
}

.hideToolbox #headers #flyoutHeader {
display: none;
}

/*******************************
Sidebar Tutorial
*******************************/
Expand Down Expand Up @@ -913,4 +917,4 @@ code.lang-filterblocks {
100% {
transform: rotate(0deg);
}
}
}
13 changes: 10 additions & 3 deletions webapp/src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5034,7 +5034,11 @@ export class ProjectView
} else {
const tc = document.getElementById("tutorialcard");
if (tc) {
const flyoutOnly = this.state.editorState?.hasCategories === false || this.state.tutorialOptions?.metadata?.flyoutOnly;
const flyoutOnly =
this.state.editorState?.hasCategories === false
|| this.state.tutorialOptions?.metadata?.flyoutOnly
|| this.state.tutorialOptions?.metadata?.hideToolbox;

let headerHeight = 0;
if (flyoutOnly) {
const headers = document.getElementById("headers");
Expand Down Expand Up @@ -5257,7 +5261,9 @@ export class ProjectView
const inEditor = !!this.state.header && !inHome;
const { lightbox, greenScreen, accessibleBlocks } = this.state;
const hideTutorialIteration = inTutorial && tutorialOptions.metadata?.hideIteration;
const flyoutOnly = this.state.editorState?.hasCategories === false || (inTutorial && tutorialOptions.metadata?.flyoutOnly);
const hideToolbox = inTutorial && tutorialOptions.metadata?.hideToolbox;
// flyoutOnly has become a de facto css class for styling tutorials (especially minecraft HOC), so keep it if hideToolbox is true, even if flyoutOnly is false.
const flyoutOnly = this.state.editorState?.hasCategories === false || (inTutorial && (tutorialOptions.metadata?.flyoutOnly || hideToolbox));
const { hideEditorToolbar, transparentEditorToolbar } = targetTheme;
const hideMenuBar = targetTheme.hideMenuBar || hideTutorialIteration || (isTabTutorial && pxt.appTarget.appTheme.embeddedTutorial) || pxt.shell.isTimeMachineEmbed();
const isHeadless = simOpts && simOpts.headless;
Expand Down Expand Up @@ -5308,6 +5314,7 @@ export class ProjectView
logoWide ? "logo-wide" : "",
isHeadless ? "headless" : "",
flyoutOnly ? "flyoutOnly" : "",
hideToolbox ? "hideToolbox" : "",
hideTutorialIteration ? "hideIteration" : "",
this.editor != this.blocksEditor ? "editorlang-text" : "",
this.editor == this.textEditor && this.state.errorListState,
Expand Down Expand Up @@ -5356,7 +5363,7 @@ export class ProjectView
{isSidebarTutorial && flyoutOnly && inTutorial && <sidebarTutorial.SidebarTutorialCard ref={ProjectView.tutorialCardId} parent={this} pokeUser={this.state.pokeUserComponent == ProjectView.tutorialCardId} />}
{inTutorial && !isTabTutorial && <div id="maineditor" className={sandbox ? "sandbox" : ""} role="main">
{!(isSidebarTutorial && flyoutOnly) && inTutorial && <tutorial.TutorialCard ref={ProjectView.tutorialCardId} parent={this} pokeUser={this.state.pokeUserComponent == ProjectView.tutorialCardId} />}
{flyoutOnly && <tutorial.WorkspaceHeader parent={this} />}
{flyoutOnly && <tutorial.WorkspaceHeader parent={this} workspaceId={this.editor.getId()} />}
</div>}
<sidepanel.Sidepanel parent={this} inHome={inHome}
showKeymap={this.state.keymap && simOpts.keymap}
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/marked.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ export class MarkedContent extends data.Component<MarkedContentProps, MarkedCont
// Renders inline blocks, such as "||controller: Controller||".
private renderInlineBlocks(content: HTMLElement) {
const { parent } = this.props;
const hasCategories = !parent.state.tutorialOptions?.metadata?.flyoutOnly;
const hasCategories = !parent.state.tutorialOptions?.metadata?.flyoutOnly && !parent.state.tutorialOptions?.metadata?.hideToolbox;
const inlineBlocks = pxt.Util.toArray(content.querySelectorAll(`:not(pre) > code`))
.map((inlineBlock: HTMLElement) => {
const text = inlineBlock.innerText;
Expand Down
6 changes: 6 additions & 0 deletions webapp/src/monaco.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1326,8 +1326,14 @@ export class Editor extends toolboxeditor.ToolboxEditor {
|| this.currFile.isReadonly()
|| pxt.shell.isReadOnly()
|| this.isDebugging();

const hideForTutorial =
this.parent.isTutorial()
&& this.parent.state.header.tutorial?.metadata?.hideToolbox;

return pxt.appTarget.appTheme.monacoToolbox
&& !readOnly
&& !hideForTutorial
&& (this.fileType == "typescript" || this.fileType == "python");
}

Expand Down
2 changes: 1 addition & 1 deletion webapp/src/tutorial.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@ export class WorkspaceHeader extends data.Component<any, WorkspaceHeaderState> {
this.flyoutWidth = flyout.getBoundingClientRect().width;
}

const workspace = document.querySelector('#blocksArea');
const workspace = document.querySelector(`#${this.props.workspaceId || "blocksArea"}`);
if (workspace) {
this.workspaceWidth = workspace.clientWidth - this.flyoutWidth - 4;
}
Expand Down

0 comments on commit 9e6dd9e

Please sign in to comment.