generated from adobe/aem-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
193 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import { createTag } from '../../../utils/utils.js'; | ||
import createCopy from '../library-utils.js'; | ||
import { getTable, decorateImages, handleLinks } from './blocks.js'; | ||
|
||
function createSpace() { | ||
const br = createTag('br'); | ||
return createTag('p', null, br); | ||
} | ||
|
||
function formatDom(aemDom, path) { | ||
// Decorate Links | ||
handleLinks(aemDom, path); | ||
|
||
// Decorate Images | ||
decorateImages(aemDom, path); | ||
|
||
// Decorate Blocks | ||
const divs = aemDom.querySelectorAll('main > div > div'); | ||
divs.forEach((div) => { | ||
// Give table some space | ||
div.insertAdjacentElement('afterend', createSpace()); | ||
|
||
const table = getTable(div, true); | ||
div.parentElement.replaceChild(table, div); | ||
}); | ||
|
||
// Decorate Sections | ||
const sections = aemDom.body.querySelectorAll('main > div'); | ||
const formattedSections = [...sections].map((section, idx) => { | ||
const fragment = new DocumentFragment(); | ||
if (idx > 0) { | ||
const divider = createTag('p', null, '---'); | ||
fragment.append(divider, createSpace()); | ||
} | ||
fragment.append(...section.querySelectorAll(':scope > *')); | ||
|
||
return fragment; | ||
}); | ||
const flattedDom = createTag('div'); | ||
flattedDom.append(...formattedSections); | ||
return flattedDom; | ||
} | ||
|
||
async function formatTemplate(path) { | ||
const resp = await fetch(path); | ||
if (!resp.ok) window.lana.log('Could not fetch template path', { tags: 'errorType=info,module=sidekick-templates' }); | ||
|
||
const html = await resp.text(); | ||
const dom = new DOMParser().parseFromString(html, 'text/html'); | ||
return formatDom(dom, path); | ||
} | ||
|
||
export default async function loadTemplates(templates, list) { | ||
templates.forEach(async (template) => { | ||
const titleText = createTag('p', { class: 'item-title' }, template.name); | ||
const title = createTag('li', { class: 'template' }, titleText); | ||
const previewButton = createTag('button', { class: 'preview-group' }, 'Preview'); | ||
const copy = createTag('button', { class: 'copy' }); | ||
const formatted = await formatTemplate(template.path); | ||
|
||
list.append(title); | ||
title.append(previewButton, copy); | ||
|
||
previewButton.addEventListener('click', (e) => { | ||
e.stopPropagation(); | ||
window.open(template.path, '_templatepreview'); | ||
}); | ||
|
||
copy.addEventListener('click', (e) => { | ||
e.target.classList.add('copied'); | ||
setTimeout(() => { e.target.classList.remove('copied'); }, 3000); | ||
const blob = new Blob([formatted.outerHTML], { type: 'text/html' }); | ||
createCopy(blob); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
.locui.container { | ||
margin: 0 auto; | ||
margin-top: 10vh; | ||
max-width: 700px; | ||
border-radius: 10px; | ||
border: 10px solid #eee; | ||
padding: 10px 30px 30px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { createTag } from '../../utils/utils.js'; | ||
|
||
export default function init(el) { | ||
el.classList.add('container'); | ||
const heading = createTag('h2', null, 'Missing project details'); | ||
const paragraph = createTag('p', null, 'The project details were removed after you logged in. To resolve this:'); | ||
const steps = createTag('ol', null); | ||
const stepList = ['Close this window or tab.', 'Open your project Excel file.', 'Click "Localize..." in Sidekick again.']; | ||
stepList.forEach((step) => steps.append(createTag('li', null, step))); | ||
const learnmore = createTag('a', { | ||
class: 'con-button', | ||
href: 'https://milo.adobe.com/docs/authoring/localization#:~:text=at%20render%20time.-,Troubleshooting,-Error%20matrix', | ||
target: '_blank', | ||
}, 'Learn More'); | ||
el.append(heading, paragraph, steps, learnmore); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.