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

Sidekick Library RC #666

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
44 changes: 27 additions & 17 deletions tools/sidekick/library/plugins/blocks/blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,23 +288,8 @@ function loadBlock(context, event, container) {
// Set block title & description in UI
updateDetailsContainer(content, authoredBlockName, blockDescription);

const disableCopyButton = sectionLibraryMetadata.disablecopy
?? defaultLibraryMetadata.disablecopy
?? false;

const copyButton = container.querySelector('.content .copy-button');
copyButton.removeAttribute('disabled');
if (disableCopyButton) {
copyButton.setAttribute('disabled', 'true');
}

const hideDetailsView = sectionLibraryMetadata.hidedetailsview
?? defaultLibraryMetadata.hidedetailsview
?? context.hidedetailsview
?? false;

const splitView = container.querySelector('.content sp-split-view');
splitView.primarySize = hideDetailsView ? '100%' : '75%';
handleCopyButton(container, sectionLibraryMetadata, defaultLibraryMetadata);
handleSplitView(container, sectionLibraryMetadata, defaultLibraryMetadata, context);

const blockRenderer = content.querySelector('block-renderer');

Expand Down Expand Up @@ -358,6 +343,9 @@ function loadTemplate(context, event, container) {
// Set template title & description in UI
updateDetailsContainer(content, authoredTemplateName, templateDescription);

handleCopyButton(container, sectionLibraryMetadata, defaultLibraryMetadata);
handleSplitView(container, sectionLibraryMetadata, defaultLibraryMetadata, context);

const blockRenderer = content.querySelector('block-renderer');

// If the block element exists, load the block
Expand Down Expand Up @@ -387,6 +375,28 @@ function loadTemplate(context, event, container) {
sampleRUM('library:blockviewed', { target: blockData.url });
}

function handleCopyButton(container, sectionLibraryMetadata, defaultLibraryMetadata) {
const disableCopyButton = sectionLibraryMetadata?.disablecopy
?? defaultLibraryMetadata?.disablecopy
?? false;

const copyButton = container.querySelector('.content .copy-button');
copyButton.removeAttribute('disabled');
if (disableCopyButton) {
copyButton.setAttribute('disabled', 'true');
}
}

function handleSplitView(container, sectionLibraryMetadata, defaultLibraryMetadata, context) {
const hideDetailsView = sectionLibraryMetadata?.hidedetailsview
?? defaultLibraryMetadata?.hidedetailsview
?? context?.hidedetailsview
?? false;

const splitView = container.querySelector('.content sp-split-view');
splitView.primarySize = hideDetailsView ? '100%' : '75%';
}

/**
* Called when a user tries to load the plugin
* @param {HTMLElement} container The container to render the plugin in
Expand Down