Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
669c692
test(quick-edit): cover hlx6 source url, collab room, image upload an…
benpeter Oct 9, 2026
0a44144
fix(quick-edit): open hlx6 documents through the nx2 api
benpeter Oct 9, 2026
f495e87
test(quick-edit): keep media bus picture sources relative
benpeter Oct 10, 2026
29bd504
fix(quick-edit): keep media bus picture sources relative
benpeter Oct 10, 2026
f4f743b
test(quick-edit): keep the webp type of uploaded images
benpeter Nov 24, 2026
0151df5
fix(quick-edit): keep the webp type of uploaded images
benpeter Nov 24, 2026
98dd68b
test(quick-edit): preview with only the authorization header
benpeter Nov 24, 2026
feaecce
fix(quick-edit): preview with only the authorization header
benpeter Nov 24, 2026
78bd62a
test(quick-edit): start on source bus sites without a mountpoint url
benpeter Nov 24, 2026
ce2c23f
fix(quick-edit): start on source bus sites without a mountpoint url
benpeter Nov 24, 2026
38a7cd0
fix(quick-edit): retry opening the document after a failed start
benpeter Nov 24, 2026
2f6f048
test(quick-edit): keep linked media bus images relative
benpeter Nov 24, 2026
5ec2d9f
fix(quick-edit): keep linked media bus images relative
benpeter Nov 24, 2026
a0ddc42
refactor(quick-edit): head the document at the room url
benpeter Nov 24, 2026
13d44ef
docs(api): note the blob type fallback for legacy uploads
benpeter Nov 24, 2026
8086736
test(quick-edit): use owner and repo only on helix 6 sites
benpeter Nov 24, 2026
e1a47a2
fix(quick-edit): use owner and repo only on helix 6 sites
benpeter Nov 24, 2026
dbded81
test(quick-edit): ask for the image cookie once across retries
benpeter Nov 24, 2026
6fbe83c
fix(quick-edit): ask for the image cookie once across retries
benpeter Nov 24, 2026
34a05b4
test(quick-edit): report a missing sign-in on preview
benpeter Nov 24, 2026
4b78f7c
fix(quick-edit): report a missing sign-in on preview
benpeter Nov 24, 2026
bb12616
refactor(quick-edit): send the preview reply from one place
benpeter Nov 24, 2026
b1147ca
revert(quick-edit): move the start retry to its own branch
benpeter Nov 25, 2026
270f96f
revert(quick-edit): move the preview status code to its own branch
benpeter Nov 25, 2026
73a01d3
test(quick-edit): fall back to legacy da when the upgrade check fails
benpeter Nov 25, 2026
b83c1ca
fix(quick-edit): use legacy da when the upgrade check fails
benpeter Nov 25, 2026
7ca09e4
docs(quick-edit): describe the legacy fallback of a failed upgrade check
benpeter Nov 25, 2026
5ebc62c
refactor(quick-edit): keep source routing in the portal
benpeter Nov 28, 2026
368d409
Merge remote-tracking branch 'origin/main' into qehlx6
benpeter Nov 28, 2026
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
24 changes: 24 additions & 0 deletions docs/quick-edit-events.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,22 @@ parallel one. If you do add a new key:

---

### `INIT`

`config.mountpoint` is the site's content source: the sidekick passes its
`contentSourceUrl`, which is `https://content.da.live/{org}/{site}/` on DA sites and
`https://api.aem.live/{org}/sites/{site}/source` on hlx6 (source bus) sites. Some
sites build the DA shape themselves when there's no sidekick. A source bus site can also have
no url (site config `content.source` is just `{ type: 'sourcebus' }`), and then the sidekick
sends no mountpoint. In that case the portal uses `config.owner` / `config.repo` when the
upgrade check (nx2 `isHlx6`) says the site is on Helix 6. It ignores `apiUpgrade`: the sidekick
sends `true` for most legacy sites too. The standalone portal reads org/site from either url
shape and asks nx2 `api.js` (`isHlx6`) where the document lives,
so the payload shape doesn't decide the store. If the check fails (the ping gets no answer), the
portal treats the site as legacy DA, as it did before Helix 6 support: it opens, uploads and
previews through the legacy DA and Helix admin APIs. Quick edit and the canvas both use
the document's source URL as the collab room name.

### `DROP_TARGET`

da-live owns drags that start in another iframe (extension SDK drags and the AEM
Expand Down Expand Up @@ -235,6 +251,14 @@ upload. An out-of-date/missing index fails instead of choosing an image by URL.
For older iframes, a URL-only request is accepted only when it identifies
exactly one image.

Both hosts use nx2 `source.uploadMedia` on Helix 6. On legacy DA, the standalone portal
posts the multipart upload directly. Both reply with the url the upload returned:
a `content.da.live` url on DA sites, a media bus url on hlx6 sites (usually
relative, `./media_…`), which the iframe resolves against the page. In `SET_BODY` the
standalone portal keeps `./media_` refs relative in `<img>`, `<source srcset>` and linked
images (`<a data-edit-as="image">`), so the page resolves them against its own url like
delivered html (da-live's `prose2aem` would otherwise point them at the portal's origin).

Both hosts use `nx2/public/utils/quick-edit-images.js` for document versions,
image-position resolution, and replacement after upload. It accepts the host's
ProseMirror document/view without importing ProseMirror. Instrumentation and
Expand Down
27 changes: 7 additions & 20 deletions nx/blocks/quick-edit-portal/quick-edit-portal.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { checkPermissions, signIn, handlePreview, getImageCookie } from './src/utils.js';
import { signIn, handlePreview, getImageCookie } from './src/utils.js';
import { getInitSite, loadDocSource } from './src/source.js';
import createProse from './src/prose.js';
import {
updateDocument, updateCursors, updateState, handleUndoRedo, getEditor, handleCursorMove,
Expand Down Expand Up @@ -27,14 +28,10 @@ function onMessage(e, ctx) {
}

async function initProse(owner, repo, path, el, ctx) {
const sourceUrl = `https://admin.da.live/source/${owner}/${repo}/${
path.endsWith('/') ? `${path.replace(/^\//, '')}index.html` : `${path.replace(/^\//, '')}.html`
}`;

const resp = await checkPermissions(sourceUrl);
if (!resp.ok) return;

const { permissions } = resp;
const { sourceUrl, permissions, error } = await loadDocSource({
org: owner, site: repo, pathname: path,
});
if (error) return;

const { proseEl, wsProvider, view } = createProse({
path: sourceUrl,
Expand Down Expand Up @@ -75,18 +72,8 @@ export default async function decorate(el) {
const [port] = e.ports;

const { config, location } = e.data.payload ?? {};
const mountPoint = config?.mountpoint;
const path = location?.pathname;

if (!mountPoint) {
return;
}

// Parse the mountpoint URL to extract owner and repo
const url = new URL(mountPoint);
const pathSegments = url.pathname.split('/').filter(Boolean);
const owner = pathSegments[0];
const repo = pathSegments[1];
const { org: owner, site: repo } = await getInitSite(config);

if (!owner || !repo) {
return;
Expand Down
18 changes: 6 additions & 12 deletions nx/blocks/quick-edit-portal/src/images.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* eslint-disable import/prefer-default-export */
import { daFetch } from '../../../utils/daFetch.js';
import { DA_ORIGIN } from '../../../public/utils/constants.js';
import { uploadImage } from './source.js';
import { MESSAGE_TYPES } from '../../../utils/message-types.js';
import {
resolveImagePosition, updateImageInDocument,
Expand Down Expand Up @@ -46,23 +45,18 @@ export async function handleImageReplace(payload, ctx) {
const pageName = getPageName(ctx.path);
const parentPath = ctx.path === '/' ? '' : ctx.path.replace(/\/[^/]+$/, '');

// Construct the upload URL: /source/{owner}/{repo}{parent}/.{pageName}/{fileName}
const uploadPath = `${parentPath}/.${pageName}/${fileName}`;
const uploadUrl = `${DA_ORIGIN}/source/${ctx.owner}/${ctx.repo}${uploadPath}`;

// Upload the image
const formData = new FormData();
formData.append('data', blob, fileName);
const opts = { method: 'PUT', body: formData };
const resp = await daFetch(uploadUrl, opts);
const resp = await uploadImage({
org: ctx.owner, site: ctx.repo, path: uploadPath, body: blob,
});

if (!resp.ok) {
reply({ error: `Upload failed with status ${resp.status}` });
return;
}

// Construct the new image URL (AEM delivery URL)
const newSrc = `https://content.da.live/${ctx.owner}/${ctx.repo}${uploadPath}`;
const { source: { contentUrl: newSrc } = {} } = await resp.json();
if (!newSrc) throw new Error('The upload did not return an image URL.');

if (ctx.view !== view) throw new Error('Image editor changed during the upload. Please try again.');
updateImageInDocument({ view, target, newSrc });
Expand Down
4 changes: 2 additions & 2 deletions nx/blocks/quick-edit-portal/src/prose.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
ySyncPluginKey,
} from 'da-y-wrapper';
import { getSchema } from 'https://da.live/deps/da-parser/dist/index.js';
import { COLLAB_ORIGIN, DA_ORIGIN } from 'https://da.live/blocks/shared/constants.js';
import { COLLAB_ORIGIN } from 'https://da.live/blocks/shared/constants.js';
import { findChangedNodes, generateColor, findCommonEditableAncestor } from './utils.js';

function registerErrorHandler(ydoc) {
Expand Down Expand Up @@ -78,7 +78,7 @@ export default function initProse({ path, permissions, rerenderPage, updateCurso
const ydoc = new Y.Doc();

const server = COLLAB_ORIGIN;
const roomName = `${DA_ORIGIN}${new URL(path).pathname}`;
const roomName = path;

const opts = {};

Expand Down
3 changes: 2 additions & 1 deletion nx/blocks/quick-edit-portal/src/prose2aem.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import prose2aem from 'https://da.live/blocks/shared/prose2aem.js';
import { getImageDocumentVersion } from '../../../../nx2/public/utils/quick-edit-images.js';
import { EDITABLE_SELECTORS } from './editable-elements.js';
import { keepMediaBusImagesRelative } from './utils.js';

function isOutermostWysiwygEditable(el) {
if (!el?.matches?.(EDITABLE_SELECTORS)) return false;
Expand Down Expand Up @@ -109,5 +110,5 @@ export function getInstrumentedHTML(view) {
});

// Convert to an HTML string using prose2aem.
return prose2aem(editorClone, true, false, true);
return keepMediaBusImagesRelative(prose2aem(editorClone, true, false, true));
}
44 changes: 44 additions & 0 deletions nx/blocks/quick-edit-portal/src/source.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { daFetch, isHlx6, source } from '../../../../nx2/utils/api.js';
import { AEM_API, DA_ADMIN } from '../../../../nx2/utils/utils.js';

export async function checkSite(org, site) {
try {
return await isHlx6(org, site);
} catch {
return false;
}
}

export function getOrgSite(mountpoint) {
const segments = new URL(mountpoint).pathname.split('/').filter(Boolean);
const [org, sites, site, store] = segments;
if (segments.length === 4 && sites === 'sites' && store === 'source') return { org, site };
return { org, site: sites };
}

export async function getInitSite(config) {
const { mountpoint, owner, repo } = config ?? {};
const url = typeof mountpoint === 'string' ? mountpoint : mountpoint?.url;
if (url) return getOrgSite(url);
const hlx6 = owner && repo && await checkSite(owner, repo);
return hlx6 ? { org: owner, site: repo } : {};
}

const getDocPath = (pathname) => (pathname.endsWith('/') ? `${pathname}index.html` : `${pathname}.html`);

export async function loadDocSource({ org, site, pathname }) {
const path = getDocPath(pathname);
const sourceUrl = await checkSite(org, site)
? `${AEM_API}/${org}/sites/${site}/source${path}`
: `${DA_ADMIN}/source/${org}/${site}${path}`;
const resp = await daFetch({ url: sourceUrl, opts: { method: 'HEAD' } });
if (!resp.ok) return { error: `Could not load ${path}`, status: resp.status };
return { sourceUrl, permissions: resp.permissions ?? ['read', 'write'] };
}

export async function uploadImage({ org, site, path, body }) {
if (await checkSite(org, site)) return source.uploadMedia({ org, site, path, body });
const formData = new FormData();
formData.append('data', body);
return daFetch({ url: `${DA_ADMIN}/source/${org}/${site}${path}`, opts: { method: 'POST', body: formData } });
}
87 changes: 40 additions & 47 deletions nx/blocks/quick-edit-portal/src/utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { handleSignIn, loadIms } from '../../../utils/ims.js';
import { MESSAGE_TYPES } from '../../../utils/message-types.js';
import { loadIms as loadApiIms } from '../../../../nx2/utils/api.js';
import { AEM_API, HLX_ADMIN } from '../../../../nx2/utils/utils.js';
import { checkSite } from './source.js';
import { isRenderedBlock } from './rerender-scope.js';

const DA_LIVE_PREVIEW_ENVS = {
Expand Down Expand Up @@ -33,6 +36,26 @@ function getLivePreviewUrl(owner, repo) {
return `${protocol}://main--${repo}--${owner}.${domain}`;
}

// prose2aem resolves ./media_ refs against the portal (sources, linked images); keep them relative.
export function keepMediaBusImagesRelative(html) {
const base = new URL('./', document.baseURI).href;
if (!html.includes('src="./media_') && !html.includes(`${base}media_`)) return html;
const doc = new DOMParser().parseFromString(html, 'text/html');
doc.querySelectorAll('picture').forEach((picture) => {
const src = picture.querySelector('img')?.getAttribute('src');
if (!src?.startsWith('./media_')) return;
picture.querySelectorAll('source').forEach((source) => source.setAttribute('srcset', src));
});
doc.querySelectorAll('a[data-edit-as="image"]').forEach((link) => {
const href = link.getAttribute('href');
if (!href?.startsWith(`${base}media_`)) return;
const ref = `./${href.slice(base.length)}`;
if (link.textContent === href) link.textContent = ref;
link.setAttribute('href', ref);
});
return doc.documentElement.outerHTML;
}

export async function getImageCookie(owner, repo) {
const token = await getToken();
if (token) {
Expand Down Expand Up @@ -221,39 +244,6 @@ export function generateColor(name, hRange = [0, 360], sRange = [60, 80], lRange
return `#${f(0)}${f(8)}${f(4)}`;
}

export async function checkPermissions(sourceUrl) {
const token = await getToken();
const resp = await fetch(sourceUrl, {
method: 'HEAD',
headers: { Authorization: `Bearer ${token}` },
});

// If child actions header is present, use it.
// This is a hint as to what can be done with the children.
if (resp.headers?.get('x-da-child-actions')) {
resp.permissions = resp.headers
.get('x-da-child-actions')
.split('=')
.pop()
.split(',');
return resp;
}

// Use the self actions hint if child actions are not present.
if (resp.headers?.get('x-da-actions')) {
resp.permissions = resp.headers
?.get('x-da-actions')
?.split('=')
.pop()
.split(',');
return resp;
}

// Support legacy admin.role.all
resp.permissions = ['read', 'write'];
return resp;
}

export async function signIn() {
const token = await getToken();
if (!token) {
Expand All @@ -274,19 +264,22 @@ export async function signIn() {
}
}

// Not aem.preview: daFetch also sends the token in x-content-source-authorization (da-nx#866).
async function requestPreview({ owner, repo, path }) {
const { accessToken } = await loadApiIms();
if (!accessToken) return 'not signed in';
const page = path.endsWith('/') ? `${path}index` : path;
const url = await checkSite(owner, repo)
? `${AEM_API}/${owner}/sites/${repo}/preview${page}`
: `${HLX_ADMIN}/preview/${owner}/${repo}/main${page}`;
const resp = await fetch(url, { method: 'POST', headers: { Authorization: `Bearer ${accessToken.token}` } });
return resp.ok ? undefined : resp.statusText;
}

export async function handlePreview(ctx) {
const path = ctx.path.endsWith('/') ? `${ctx.path}index` : `${ctx.path}`;
const url = `https://admin.hlx.page/preview/${ctx.owner}/${ctx.repo}/main${path}`;
const token = await getToken();
const resp = await fetch(url, { method: 'POST', headers: { Authorization: `Bearer ${token}` } });
if (!resp.ok) {
// eslint-disable-next-line no-console
console.error('Failed to preview:', resp.statusText);
const error = `Failed to preview: ${resp.statusText}`;
ctx.port.postMessage({
type: MESSAGE_TYPES.PREVIEW, payload: { ok: false, error },
});
} else {
ctx.port.postMessage({ type: MESSAGE_TYPES.PREVIEW, payload: { ok: true } });
}
const error = await requestPreview(ctx).catch((e) => e.message);
const payload = error === undefined ? { ok: true } : { ok: false, error: `Failed to preview: ${error}` };
// eslint-disable-next-line no-console
if (!payload.ok) console.error(payload.error);
ctx.port.postMessage({ type: MESSAGE_TYPES.PREVIEW, payload });
}
2 changes: 1 addition & 1 deletion nx/utils/message-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// context (why a message exists, which host implementations wire it up).
export const MESSAGE_TYPES = Object.freeze({
// Host <-> iframe: handshake
INIT: 'init', // { config: { mountpoint }, location: { pathname } }
INIT: 'init', // { config: { mountpoint: DA content or hlx6 source bus url, owner, repo }, location: { pathname } }
READY: 'ready', // no payload

// Host -> iframe
Expand Down
2 changes: 1 addition & 1 deletion nx2/utils/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ export const source = {
method: 'POST',
body,
headers: {
'content-type': findContentType(path) || 'application/octet-stream',
'content-type': findContentType(path) || body?.type || 'application/octet-stream',
},
};
const resp = await daFetch({ url, opts });
Expand Down
Loading
Loading