Skip to content

Commit

Permalink
Fix for 113 (#116)
Browse files Browse the repository at this point in the history
  • Loading branch information
sselvara authored Oct 7, 2024
1 parent 4c2d011 commit 6dc1c3c
Showing 1 changed file with 27 additions and 17 deletions.
44 changes: 27 additions & 17 deletions src/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

0 comments on commit 6dc1c3c

Please sign in to comment.