Scope article feeds and expand canvas editing
@@ -234,3 +234,15 @@
|
||||
.article-editor-heading { display: flex; align-items: center; justify-content: space-between; gap: .6rem; margin-bottom: .45rem; }
|
||||
.article-editor-heading > .button { min-height: 2.1rem; padding: .25rem .6rem; }
|
||||
.article-editor-help:empty { display: none; }
|
||||
|
||||
.studio-element-library { padding: .55rem .65rem; border: 1px solid var(--line); border-radius: .5rem; }
|
||||
.studio-element-library summary { font-size: .9rem; font-weight: 650; cursor: pointer; }
|
||||
.studio-element-library [role="group"] { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .35rem; margin-top: .55rem; }
|
||||
.studio-element-library button {
|
||||
min-height: 2.35rem; padding: .2rem; border: 1px solid var(--line);
|
||||
border-radius: .4rem; color: var(--ink); background: var(--white); font-size: .8rem; cursor: pointer;
|
||||
}
|
||||
.studio-element-library .field-note { margin: .45rem 0 0; font-size: .78rem; }
|
||||
.studio-element-align { display: flex; gap: .05rem; padding-inline-end: .2rem; border-inline-end: 1px solid #ffffff55; }
|
||||
.studio-element-align button { padding-inline: .38rem; }
|
||||
.studio-element-align button[aria-pressed="true"] { background: white; color: #244bc8; }
|
||||
|
||||
@@ -647,3 +647,58 @@ progress { width: 100%; height: .8rem; accent-color: var(--accent); }
|
||||
.article-tabs button { padding: .38rem .8rem; background: white; border: 1px solid var(--line); border-radius: .45rem; color: inherit; cursor: pointer; }
|
||||
.article-tabs button[aria-selected="true"] { border-color: var(--accent); color: var(--accent); background: var(--accent-light); }
|
||||
.network-list .network-detail { min-height: 0; padding-block: .2rem; font-size: .85rem; }
|
||||
|
||||
.article-feed-archive { margin: 1rem 0 0; }
|
||||
.studio-notice { padding: clamp(1rem, 3vw, 1.8rem); border-inline-start: 3px solid var(--accent); border-radius: .55rem; background: var(--accent-light); }
|
||||
.studio-notice p, .studio-testimonials p:last-child, .studio-timeline li p:last-child { margin-bottom: 0; }
|
||||
.studio-gallery, .studio-metrics { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; }
|
||||
.studio-gallery img { width: 100%; aspect-ratio: 4 / 3; object-fit: contain; border: 1px solid var(--line); background: var(--paper); }
|
||||
.studio-split video { width: 100%; aspect-ratio: 16 / 9; border-radius: .6rem; background: var(--navy); object-fit: contain; }
|
||||
.studio-metrics { margin-block: 0 1rem; }
|
||||
.studio-metrics div { padding: 1rem; border-block-start: 1px solid var(--line); }
|
||||
.studio-metrics dd { margin: .4rem 0 0; color: var(--accent); font-size: clamp(1.65rem, 5vw, 3rem); font-weight: 700; }
|
||||
.studio-testimonials blockquote { margin: 0; padding: 1.1rem 1.3rem; border: 1px solid var(--line); border-radius: .6rem; }
|
||||
.studio-testimonials .studio-attribution { font-size: .88rem; color: var(--muted); }
|
||||
.rich .studio-timeline { padding-inline-start: 1.4rem; border-inline-start: 1px solid var(--line); }
|
||||
.studio-timeline li + li, .studio-checklist li + li { margin-top: .7rem; }
|
||||
.studio-timeline li::marker, .studio-checklist li::marker { color: var(--accent); font-weight: 700; }
|
||||
.studio-timeline h3 { font-size: 1.15rem; margin-bottom: .2rem; }
|
||||
.rich .studio-resources { list-style: none; padding: 0; border-block-start: 1px solid var(--line); }
|
||||
.studio-resources li { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: .35rem 1rem; padding: .7rem 0; border-block-end: 1px solid var(--line); }
|
||||
.studio-resources span { font-size: .875rem; color: var(--muted); }
|
||||
.studio-divider { width: 100%; margin-block: 1.25rem; border: 0; border-block-start: 1px solid var(--line); }
|
||||
.studio-code { max-width: 100%; overflow: auto; padding: .8rem 1rem; border: 1px solid var(--line); border-radius: .5rem; background: var(--paper); }
|
||||
@media (max-width: 36rem) {
|
||||
.studio-gallery { grid-template-columns: 1fr; }
|
||||
.studio-metrics { gap: .45rem; }
|
||||
.studio-metrics div { padding: .55rem .3rem; }
|
||||
}
|
||||
|
||||
.studio-align-left {
|
||||
--studio-margin-left: 0; --studio-margin-right: auto; --studio-justify: start;
|
||||
text-align: left; justify-self: start;
|
||||
}
|
||||
.studio-align-center {
|
||||
--studio-margin-left: auto; --studio-margin-right: auto; --studio-justify: center;
|
||||
text-align: center; justify-self: center;
|
||||
}
|
||||
.studio-align-right {
|
||||
--studio-margin-left: auto; --studio-margin-right: 0; --studio-justify: end;
|
||||
text-align: right; justify-self: end;
|
||||
}
|
||||
:is(.hero-lead, .section-heading > p, .rich > p)[class*="studio-align-"] {
|
||||
margin-left: var(--studio-margin-left);
|
||||
margin-right: var(--studio-margin-right);
|
||||
}
|
||||
.rich > p:is(.studio-align-left, .studio-align-center, .studio-align-right) { max-width: 47rem; }
|
||||
:is(.rich, .editor-preview) :is(img, video, audio, a, ol, ul)[class*="studio-align-"] {
|
||||
margin-left: var(--studio-margin-left);
|
||||
margin-right: var(--studio-margin-right);
|
||||
}
|
||||
:is(.rich, .editor-preview) :is(img, video, audio)[class*="studio-align-"] { display: block; max-width: 100%; }
|
||||
:is(.rich, .editor-preview) a[class*="studio-align-"] { display: flex; width: fit-content; max-width: 100%; }
|
||||
:is(.rich, .editor-preview) :is(ol, ul)[class*="studio-align-"] { width: fit-content; max-width: 100%; }
|
||||
.rich > img[class*="studio-align-"]:not([class*="studio-media-"]) { max-width: min(100%, 46rem); }
|
||||
.rich table[class*="studio-align-"] :is(th, td) { text-align: inherit; }
|
||||
.hero-visual[class*="studio-align-"] { justify-self: var(--studio-justify); }
|
||||
.hero-actions[class*="studio-align-"] { justify-content: var(--studio-justify); }
|
||||
|
||||
@@ -265,7 +265,11 @@ jQuery(function ($) {
|
||||
const $settings = $layout.find('.studio-inspector');
|
||||
const $sizing = $studio.find('[data-media-sizing]');
|
||||
const $elementTools = $studio.find('[data-element-tools]');
|
||||
const $alignTools = $elementTools.find('[data-element-align]');
|
||||
const alignments = ['left', 'center', 'right'];
|
||||
const alignmentClasses = alignments.map((value) => 'studio-align-' + value);
|
||||
const heroOrOptional = '[data-studio-field="accent"], [data-studio-field="lead"], [data-studio-part="lead"], [data-studio-action], [data-studio-nav-index]';
|
||||
const canvasFields = heroOrOptional + ', [data-studio-field="heading"], [data-studio-part="title"]';
|
||||
const bodyElements = 'a, article, blockquote, details, div, dl, dt, dd, figure, h1, h2, h3, h4, h5, h6, hr, li, ol, p, pre, table, ul';
|
||||
const mediaTargets = '[data-studio-hero-image], [data-studio-part="body"] img, [data-studio-part="body"] audio, [data-studio-part="body"] video';
|
||||
const $handle = $studio.find('[data-media-handle]');
|
||||
@@ -328,7 +332,14 @@ jQuery(function ($) {
|
||||
function sectionChanges(withEdits = true) {
|
||||
return sections.flatMap(({key, version, fields, source, template}) => {
|
||||
const changes = {};
|
||||
for (const [field, {node, initial}] of Object.entries(fields)) {
|
||||
const aligned = {};
|
||||
let alignmentChanged = false;
|
||||
for (const [field, {node, initial, initialAlignment}] of Object.entries(fields)) {
|
||||
if (field !== 'body') {
|
||||
const value = getAlignment(node);
|
||||
if (value) aligned[field] = value;
|
||||
if (value !== initialAlignment) alignmentChanged = true;
|
||||
}
|
||||
let value = field === 'body' ? node.innerHTML : node.textContent;
|
||||
if (field === 'body' && node.contains(selectedElement)) {
|
||||
const copy = node.cloneNode(true);
|
||||
@@ -339,7 +350,8 @@ jQuery(function ($) {
|
||||
changes[field] = withEdits && field === 'body' && version !== null ? bodyEdits(source, value) : value;
|
||||
}
|
||||
}
|
||||
return Object.keys(changes).length ? [{key, version, fields: changes, ...(template ? {template} : {})}] : [];
|
||||
if (!Object.keys(changes).length && !alignmentChanged) return [];
|
||||
return [{key, version, fields: changes, ...(alignmentChanged ? {alignments: aligned} : {}), ...(template ? {template} : {})}];
|
||||
});
|
||||
}
|
||||
|
||||
@@ -616,7 +628,7 @@ jQuery(function ($) {
|
||||
} else {
|
||||
configureText(node, label, part === 'lead');
|
||||
}
|
||||
fields[part] = {node, initial: body ? node.innerHTML : node.textContent};
|
||||
fields[part] = {node, initial: body ? node.innerHTML : node.textContent, initialAlignment: body ? '' : getAlignment(node)};
|
||||
}
|
||||
const source = new TextDecoder('utf-8', {ignoreBOM: true}).decode(Uint8Array.from(
|
||||
atob(section.dataset.studioSource || ''), (byte) => byte.charCodeAt(0)
|
||||
@@ -662,11 +674,12 @@ jQuery(function ($) {
|
||||
const node = sizingTarget();
|
||||
if (node) {
|
||||
const bounds = previewBounds(node);
|
||||
const x = getAlignment(node) === 'right' ? bounds.left : bounds.right;
|
||||
const y = (bounds.top + bounds.bottom) / 2;
|
||||
const visible = bounds.width > 0 && y >= 0 && y <= container.clientHeight
|
||||
&& bounds.right > 0 && bounds.right <= container.clientWidth + 1;
|
||||
&& x >= 0 && x <= container.clientWidth + 1;
|
||||
$handle.prop('hidden', !mediaDrag && !visible);
|
||||
$handle.css({left: Math.min(bounds.right, container.clientWidth - 11), top: y});
|
||||
$handle.css({left: Math.max(11, Math.min(x, container.clientWidth - 11)), top: y});
|
||||
} else {
|
||||
$handle.prop('hidden', true);
|
||||
}
|
||||
@@ -706,6 +719,24 @@ jQuery(function ($) {
|
||||
return element !== body && body.contains(element) ? element : null;
|
||||
}
|
||||
|
||||
function getAlignment(node) {
|
||||
return alignments.find((value) => node.classList.contains('studio-align-' + value)) || '';
|
||||
}
|
||||
|
||||
function alignmentTarget(node) {
|
||||
if (!node) return null;
|
||||
const hero = node.closest('[data-studio-align-field]');
|
||||
if (hero) return hero;
|
||||
return node.matches('[data-studio-part="title"], [data-studio-part="lead"]') || node.closest('[data-studio-part="body"]')
|
||||
? node : null;
|
||||
}
|
||||
|
||||
function syncAlignmentButtons(target) {
|
||||
$alignTools.prop('hidden', !target).find('[data-align]').each(function () {
|
||||
$(this).attr('aria-pressed', String(Boolean(target) && getAlignment(target) === this.dataset.align));
|
||||
});
|
||||
}
|
||||
|
||||
function selectElement(node) {
|
||||
selectionObserver?.disconnect();
|
||||
selectedElement?.removeAttribute('data-studio-selected');
|
||||
@@ -719,10 +750,13 @@ jQuery(function ($) {
|
||||
const inBody = node.closest('[data-studio-part="body"]') !== null;
|
||||
const canCopy = inBody || (nav && $(node).siblings().length < 19);
|
||||
const hasProperties = selectedMedia || node.matches('a');
|
||||
const aligned = alignmentTarget(node);
|
||||
syncAlignmentButtons(aligned);
|
||||
$elementTools.find('[data-element-copy]').prop('hidden', !canCopy);
|
||||
$elementTools.find('[data-element-delete]').prop('hidden', !inBody && !selectedMedia && !node.matches(heroOrOptional));
|
||||
$elementTools.find('[data-element-properties]').prop('hidden', !hasProperties);
|
||||
if (target) showMediaWidth(currentMediaWidth(target));
|
||||
selectionObserver?.observe(target || node);
|
||||
selectionObserver?.observe(target || aligned || node);
|
||||
}
|
||||
positionSelection();
|
||||
}
|
||||
@@ -760,7 +794,22 @@ jQuery(function ($) {
|
||||
}
|
||||
}
|
||||
|
||||
$elementTools.on('click', '[data-element-copy]', () => changeElement(true))
|
||||
$elementTools.on('click', '[data-align]', function () {
|
||||
const target = alignmentTarget(selectedElement);
|
||||
const alignment = this.dataset.align;
|
||||
if (!target || !alignments.includes(alignment)) return;
|
||||
target.classList.remove(...alignmentClasses);
|
||||
target.classList.add('studio-align-' + alignment);
|
||||
const field = target.dataset.studioAlignField;
|
||||
if (field) {
|
||||
const $value = pageInput('alignments');
|
||||
const values = {...JSON.parse($value.val())};
|
||||
values[field] = alignment;
|
||||
$value.val(JSON.stringify(values));
|
||||
}
|
||||
syncAlignmentButtons(target);
|
||||
positionSelection();
|
||||
}).on('click', '[data-element-copy]', () => changeElement(true))
|
||||
.on('click', '[data-element-delete]', () => changeElement(false))
|
||||
.on('click', '[data-element-properties]', () => {
|
||||
if (selectedMedia) replaceMedia();
|
||||
@@ -790,9 +839,10 @@ jQuery(function ($) {
|
||||
const narrow = node.getBoundingClientRect();
|
||||
if (classes === null) node.removeAttribute('class');
|
||||
else node.setAttribute('class', classes);
|
||||
const rightEdgeTravel = (full.right - narrow.right) / .9;
|
||||
const available = rightEdgeTravel > full.width * .15 ? rightEdgeTravel : full.width;
|
||||
return {available, initialWidth: width || Math.round(100 * natural / (full.width || natural || 1))};
|
||||
const fromLeft = getAlignment(node) === 'right';
|
||||
const edgeTravel = (fromLeft ? narrow.left - full.left : full.right - narrow.right) / .9;
|
||||
const available = edgeTravel > full.width * .15 ? edgeTravel : full.width;
|
||||
return {available, fromLeft, initialWidth: width || Math.round(100 * natural / (full.width || natural || 1))};
|
||||
}
|
||||
|
||||
function resizeMedia(width) {
|
||||
@@ -817,7 +867,8 @@ jQuery(function ($) {
|
||||
if (!mediaDrag || mediaDrag.id !== pointer.pointerId || !mediaDrag.available) return;
|
||||
if (pointer.clientX !== mediaDrag.x || mediaDrag.moved) {
|
||||
mediaDrag.moved = true;
|
||||
resizeMedia(mediaDrag.initialWidth + 100 * (pointer.clientX - mediaDrag.x) / (mediaDrag.available * mediaDrag.scale));
|
||||
const distance = (pointer.clientX - mediaDrag.x) * (mediaDrag.fromLeft ? -1 : 1);
|
||||
resizeMedia(mediaDrag.initialWidth + 100 * distance / (mediaDrag.available * mediaDrag.scale));
|
||||
}
|
||||
}).on('lostpointercapture', () => {
|
||||
mediaDrag = null;
|
||||
@@ -836,7 +887,44 @@ jQuery(function ($) {
|
||||
$layout.on('click', '[data-hero-control]', function () {
|
||||
heroControls.get(this.dataset.heroControl)?.();
|
||||
});
|
||||
$presets.on('mousedown', '[data-canvas-template]', (event) => event.preventDefault());
|
||||
function insertInBody(markup, body, range) {
|
||||
if (!body.isConnected) return;
|
||||
const insertion = doc.createRange();
|
||||
// Insert between blocks so the browser doesn't split a paragraph or duplicate its ID.
|
||||
let node = range?.endContainer;
|
||||
if (!node || !body.contains(node)) {
|
||||
insertion.selectNodeContents(body);
|
||||
insertion.collapse(false);
|
||||
} else if (node === body) {
|
||||
insertion.setStart(body, range.endOffset);
|
||||
} else {
|
||||
while (node.parentNode !== body) node = node.parentNode;
|
||||
insertion.setStartAfter(node);
|
||||
}
|
||||
editBody(body, insertion, 'insertHTML', markup);
|
||||
}
|
||||
|
||||
$presets.on('mousedown', '[data-canvas-template], [data-canvas-element]', (event) => event.preventDefault());
|
||||
$presets.on('click', '[data-canvas-element]', function () {
|
||||
const $status = $presets.find('[data-element-status]');
|
||||
const body = activeBody;
|
||||
const range = savedRange?.cloneRange();
|
||||
if (!body) {
|
||||
$status.text('请先在画布中选中要插入的正文。');
|
||||
return;
|
||||
}
|
||||
const add = (markup) => {
|
||||
if (!markup) return;
|
||||
insertInBody(markup, body, range);
|
||||
selectElement(null);
|
||||
$status.text('已插入' + $(this).text() + '。');
|
||||
};
|
||||
if (this.dataset.elementMime) {
|
||||
openPicker(this.dataset.elementMime, (file) => add(mediaMarkup(file)));
|
||||
} else {
|
||||
add($presets.find('template[data-element="' + this.dataset.canvasElement + '"]').get(0).innerHTML);
|
||||
}
|
||||
});
|
||||
$presets.on('click', '[data-canvas-template]', function () {
|
||||
const markup = $presets.find('template[data-preset="' + this.dataset.canvasTemplate + '"]').get(0).innerHTML;
|
||||
const template = this.dataset.canvasTemplate;
|
||||
@@ -849,10 +937,8 @@ jQuery(function ($) {
|
||||
$templateStatus.text('先在画布中选择要插入的区块正文。');
|
||||
return;
|
||||
}
|
||||
// Insert at the saved caret without replacing any selected text.
|
||||
const insertion = savedRange?.cloneRange();
|
||||
insertion?.collapse(false);
|
||||
editBody(activeBody, insertion, 'insertHTML', markup);
|
||||
insertInBody(markup, activeBody, savedRange);
|
||||
selectElement(null);
|
||||
$templateStatus.text('已插入当前正文。');
|
||||
return;
|
||||
}
|
||||
@@ -920,8 +1006,8 @@ jQuery(function ($) {
|
||||
});
|
||||
$doc.on('click.canvas', (event) => {
|
||||
const node = event.target;
|
||||
const optional = node.closest?.(heroOrOptional);
|
||||
selectElement(doc.getSelection()?.isCollapsed ? optional || editableBodyElement(node) : null);
|
||||
const field = node.closest?.(canvasFields);
|
||||
selectElement(doc.getSelection()?.isCollapsed ? field || editableBodyElement(node) : null);
|
||||
});
|
||||
$doc.on('dblclick.canvas', '[data-studio-part="body"] a', function (event) {
|
||||
event.preventDefault();
|
||||
@@ -950,7 +1036,7 @@ jQuery(function ($) {
|
||||
});
|
||||
$toolbar.prop('hidden', false);
|
||||
$layout.find('[data-canvas-jump]').prop('hidden', false);
|
||||
$layout.find('[data-canvas-template], [data-hero-control]').prop('disabled', false);
|
||||
$layout.find('[data-canvas-template], [data-canvas-element], [data-hero-control]').prop('disabled', false);
|
||||
$presets.triggerHandler('studio:canvas-ready');
|
||||
}
|
||||
|
||||
|
||||
|
After Width: | Height: | Size: 4.1 KiB |
|
After Width: | Height: | Size: 13 KiB |
|
After Width: | Height: | Size: 5.8 KiB |
|
After Width: | Height: | Size: 5.2 KiB |
|
After Width: | Height: | Size: 5.2 KiB |
|
After Width: | Height: | Size: 6.4 KiB |
|
After Width: | Height: | Size: 6.0 KiB |
|
After Width: | Height: | Size: 11 KiB |