(() => {
const isDev = location.hostname === 'localhost';
const isNext = location.hostname === 'next.shoelace.style';
const customElements = fetch('/dist/custom-elements.json')
.then(res => res.json())
.catch(err => console.error(err));
function createPropsTable(props) {
const table = document.createElement('table');
table.innerHTML = `
Name
Description
Reflects
Type
Default
${escapeHtml(prop.attribute)}
${escapeHtml(prop.name)}
${attributeInfo}
${escapeHtml(prop.type?.text || '')}
` : '-'}${escapeHtml(prop.default)}
` : '-'}${escapeHtml(event.name)}
${escapeHtml(event.type?.text)}` : '-'}
${escapeHtml(method.name)}
${escapeHtml(
method.parameters.map(param => `${param.name}: ${param.type.text}`).join(', ')
)}
`
: '-'
}
${escapeHtml(slot.name)}
` : '(default)'}${escapeHtml(style.name)}
${escapeHtml(part.name)}
${escapeHtml(animation.name)}
<${tag}>
`;
ul.appendChild(li);
});
return ul.outerHTML;
}
function escapeHtml(html) {
return (html + '')
.replace(/&/g, '&')
.replace(//g, '>')
.replace(/"/g, '"')
.replace(/'/g, ''')
.replace(/`(.*?)`/g, '$1
');
}
function getAllComponents(metadata) {
const allComponents = [];
metadata.modules?.map(module => {
module.declarations?.map(declaration => {
if (declaration.customElement) {
// Generate the dist path based on the src path and attach it to the component
declaration.path = module.path.replace(/^src\//, 'dist/').replace(/\.ts$/, '.js');
allComponents.push(declaration);
}
});
});
return allComponents;
}
function getComponent(metadata, tagName) {
return getAllComponents(metadata).find(component => component.tagName === tagName);
}
if (!window.$docsify) {
throw new Error('Docsify must be loaded before installing this plugin.');
}
window.$docsify.plugins.push((hook, vm) => {
hook.mounted(async function () {
const metadata = await customElements;
const target = document.querySelector('.app-name');
// Add version
const version = document.createElement('div');
version.classList.add('sidebar-version');
version.textContent = isDev ? 'Development' : isNext ? 'Next' : metadata.package.version;
target.appendChild(version);
// Store version for reuse
sessionStorage.setItem('sl-version', metadata.package.version);
// Add repo buttons
const buttons = document.createElement('div');
buttons.classList.add('sidebar-buttons');
buttons.innerHTML = `
<${component.tagName}> | ${component.name}