-
Notifications
You must be signed in to change notification settings - Fork 48
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
Improved CMS capabilities - edit content from a webpage #1000
Comments
---
/**
* A wrapper component that enables alt+click editing functionality for Atomic Data resources.
* When holding Alt, the wrapped content will show an outline and clicking will redirect to the edit page.
*
* @component
* @example
* ```astro
* <ResourceClickWrapper subject="https://example.com/resource">
* <SomeContent />
* </ResourceClickWrapper>
* ```
*/
type Props = {
subject: string;
};
const { subject } = Astro.props;
const editLink = `https://atomicdata.dev/app/edit?subject=${subject}`;
---
<div class='block-container' data-edit-link={editLink}>
<slot />
</div>
<script>
const blocks = document.querySelectorAll('.block-container');
const toggleAltClass = (show: boolean) =>
blocks.forEach(el => el.classList.toggle('alt-active', show));
document.addEventListener('keydown', (e: KeyboardEvent) =>
toggleAltClass(e.altKey),
);
document.addEventListener('keyup', (e: KeyboardEvent) =>
toggleAltClass(e.altKey),
);
window.addEventListener('blur', () => toggleAltClass(false));
window.addEventListener('focus', e => toggleAltClass(e.altKey));
blocks.forEach(el =>
el.addEventListener('click', (e: MouseEvent) => {
if (e.altKey)
window.location.href = el.getAttribute('data-edit-link') || '';
}),
);
</script>
<style>
.block-container.alt-active {
outline: 2px dashed #666;
cursor: pointer;
}
.block-container.alt-active:hover {
outline-color: blue;
background-color: rgba(0, 0, 0, 0.03);
}
</style> How about this? |
The extension doesn't need to manage an agent or have any settings or even a UI (Maybe only for usage instructions). When the user clicks the extension icon a script will be injected in the current tab. The script will look for any nodes with a We could also publish this script on a cdn and have the developer include it on the page instead. Personally I'd go for the extension because I don't like including dev/admin stuff in a production app. It's also means every visitor will send a request to a cdn for a script that doesn't get used by them att all |
This is to specific for astro. We should make it generic so it works with every possible framework |
Hmm yeah. Would be better to make it generic. |
We're now using AtomicServer + front-end frameworks (sveltekit, astro) in production for a couple of customers, and I think there is one common usecase that requires some improvement: see a resource in your deployed website, and decide you want to change it.
Let's dive into how we can improve this:
Browser extension with editing capabilities
When the browser extension is installed, user can hover over a resource to see an edit button. Clicking that opens a resource form overlay. The extension manages the secret of the Agent. The extension queries the dom for some attribute (e.g
atomic-subject
) and injects a button on hover.Add alt-click action to compiled front-end
When the user holds the
alt
oroption
key, show borders of resources (can be the sameatomic-subject
) on hover. Clicking opens that resource onatomicdata.dev
in edit mode in a new tab.alt
keys default behavior, can be odd to users who aren't adminsThe text was updated successfully, but these errors were encountered: