Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inline blocks for tutorial content: agent icon now showing up #10271

Merged
merged 2 commits into from
Nov 18, 2024
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
9 changes: 9 additions & 0 deletions theme/tutorial.less
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,15 @@ span.docs.inlineblock {
margin-right: 6px;
}

span.image-icon {
background-image: var(--image-icon-url);
width: 20px;
height: 17px;
background-size: contain !important;
background-repeat: no-repeat !important;
display: inline-block;
}

&.clickable {
cursor: pointer;

Expand Down
61 changes: 38 additions & 23 deletions webapp/src/marked.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,8 @@ export class MarkedContent extends data.Component<MarkedContentProps, MarkedCont
inlineBlock.appendChild(inlineBlockDiv);
inlineBlockDiv.className = lev;
if (hasCategories) {
const inlineBlockIcon = document.createElement('i');
const inlineBlockIcon = document.createElement('span');
inlineBlockIcon.setAttribute("role", "presentation");
inlineBlockDiv.append(inlineBlockIcon);
}
inlineBlockDiv.append(pxt.U.rlf(txt));
Expand Down Expand Up @@ -448,28 +449,42 @@ export class MarkedContent extends data.Component<MarkedContentProps, MarkedCont
}

if (hasCategories) {
const isAdvanced = bi?.attributes?.advanced || ns === "arrays";
inlineBlock.classList.add("clickable");
inlineBlock.tabIndex = 0;
inlineBlock.ariaLabel = lf("Toggle the {0} category", ns);
inlineBlock.title = inlineBlock.ariaLabel;
inlineBlock.children[0].append(bi?.attributes?.icon || pxt.toolbox.getNamespaceIcon(ns) || "");
inlineBlock.addEventListener("click", e => {
// need to filter out editors that are currently hidden as we leave toolboxes in dom
const editorSelector = `#maineditor > div:not([style*="display:none"]):not([style*="display: none"])`;

if (isAdvanced) {
// toggle advanced open first if it is collapsed.
const advancedSelector = `${editorSelector} .blocklyTreeRow[data-ns="advancedcollapsed"]`;
const advancedRow = document.querySelector<HTMLDivElement>(advancedSelector);
advancedRow?.click();
}

const toolboxSelector = `${editorSelector} .blocklyTreeRow[data-ns="${ns}"]`;
const toolboxRow = document.querySelector<HTMLDivElement>(toolboxSelector);
toolboxRow?.click();
});
inlineBlock.addEventListener("keydown", e => fireClickOnEnter(e as any))
const isAdvanced = bi?.attributes?.advanced || ns === "arrays";
inlineBlock.classList.add("clickable");
inlineBlock.tabIndex = 0;
inlineBlock.ariaLabel = lf("Toggle the {0} category", ns);
inlineBlock.title = inlineBlock.ariaLabel;

// handle adding the icon
const iconContainer = inlineBlock.children[0];
const currentIcon = bi?.attributes?.icon || pxt.toolbox.getNamespaceIcon(ns) || "";
const isImageIcon = currentIcon.length > 1; // It's probably an image icon, and not an icon code
if (isImageIcon) {
iconContainer.classList.add('image-icon');
iconContainer.classList.add(ns);
iconContainer.setAttribute("style", `--image-icon-url: url("${pxt.Util.pathJoin(pxt.webConfig.commitCdnUrl, encodeURI(currentIcon))}")`);
} else {
const inlineBlockIcon = document.createElement('i');
inlineBlockIcon.append(currentIcon)
iconContainer.append(inlineBlockIcon);
}

inlineBlock.addEventListener("click", e => {
// need to filter out editors that are currently hidden as we leave toolboxes in dom
const editorSelector = `#maineditor > div:not([style*="display:none"]):not([style*="display: none"])`;

if (isAdvanced) {
// toggle advanced open first if it is collapsed.
const advancedSelector = `${editorSelector} .blocklyTreeRow[data-ns="advancedcollapsed"]`;
const advancedRow = document.querySelector<HTMLDivElement>(advancedSelector);
advancedRow?.click();
}

const toolboxSelector = `${editorSelector} .blocklyTreeRow[data-ns="${ns}"]`;
const toolboxRow = document.querySelector<HTMLDivElement>(toolboxSelector);
toolboxRow?.click();
});
inlineBlock.addEventListener("keydown", e => fireClickOnEnter(e as any))
}
}
});
Expand Down