- BlockTemplates::GROUPS, 'elements' => BlockTemplates::ELEMENT_GROUPS] as $kind => $groups): ?>
- = View::fragment('studio-library-panel', compact('kind', 'groups')) ?>
+ BlockTemplates::groups(), 'elements' => BlockTemplates::ELEMENT_GROUPS] as $kind => $groups): ?>
+ = View::fragment('studio-library-panel', compact('kind', 'groups', 'anchorForm')) ?>
= $layers ?>
diff --git a/public/assets/admin.css b/public/assets/admin.css
index cc6cab6..1aeac30 100644
--- a/public/assets/admin.css
+++ b/public/assets/admin.css
@@ -132,16 +132,19 @@
.studio-layers .studio-block-actions .button { min-height: 2.25rem; padding: .25rem .5rem; font-size: .8rem; }
.studio-media-sizing { position: absolute; z-index: 1; inset: auto .6rem .6rem auto; display: flex; flex-wrap: wrap; align-items: center; gap: .75rem; padding: .45rem .6rem; max-width: calc(100% - 1.2rem); background: var(--accent-light); border: 1px solid var(--line); border-radius: .45rem; }
.studio-element-tools {
- position: absolute; z-index: 3; display: flex; align-items: center; gap: .15rem; padding: .2rem;
- border: 1px solid #3f62e0; border-radius: .65rem; background: #244bc8;
- box-shadow: 0 .22rem .7rem #13297538;
+ position: absolute; z-index: 3; display: flex; align-items: center; gap: .12rem; padding: .18rem;
+ border: 1px solid #c7d6f3; border-radius: .52rem; background: var(--white);
+ box-shadow: 0 .22rem .85rem #16305230;
}
.studio-element-tools button {
- min-height: 2rem; padding: .22rem .6rem; border: 0; border-radius: .42rem;
- background: transparent; color: white; font-size: .84rem; white-space: nowrap; cursor: pointer;
+ display: grid; place-items: center; width: 2rem; height: 2rem; padding: 0;
+ border: 0; border-radius: .32rem; background: transparent; color: #35496d; cursor: pointer;
}
-.studio-element-tools button:hover, .studio-element-tools button:focus-visible { background: #ffffff32; }
-.studio-element-tools button:focus-visible { outline: 1px solid white; outline-offset: -2px; }
+.studio-element-tools button svg { width: 1rem; height: 1rem; pointer-events: none; }
+.studio-element-tools button:hover, .studio-element-tools button:focus-visible { background: var(--accent-light); color: var(--accent-deep); }
+.studio-element-tools button:focus-visible { outline: 1px solid var(--accent); outline-offset: -2px; }
+.studio-element-tools button[data-element-delete]:hover { color: #a12727; background: #fceeee; }
+.studio-element-tools.is-module [data-element-module-settings] { background: var(--accent-light); color: var(--accent-deep); }
.studio-media-handle {
position: absolute; z-index: 2; width: 1.4rem; height: 2.8rem; translate: -50% -50%;
display: grid; place-content: center; border: 2px solid white; border-radius: .42rem;
@@ -245,9 +248,8 @@
.article-editor-heading > .button { min-height: 2.1rem; padding: .25rem .6rem; }
.article-editor-help:empty { display: none; }
-.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; }
+.studio-element-align { display: flex; gap: .05rem; padding-inline-end: .15rem; border-inline-end: 1px solid var(--line); }
+.studio-element-align button[aria-pressed="true"] { background: var(--accent-light); color: var(--accent-deep); }
.admin-primary a { padding: .28rem .65rem; border-radius: .48rem; color: var(--muted); }
.admin-primary a[aria-current="page"] { background: var(--accent-light); color: var(--accent-deep); }
@@ -293,3 +295,19 @@
.dashboard-page-list li { grid-template-columns: minmax(0, 1fr) auto; }
.dashboard-page-actions { grid-column: 1 / -1; }
}
+
+.studio-page-meta { display: flex; flex-wrap: wrap; align-items: center; gap: .65rem; }
+.studio-page-meta code { color: var(--muted); font-size: .86rem; }
+.studio-anchor-create, .studio-hero-settings { padding: .55rem .65rem; border: 1px solid var(--line); border-radius: .45rem; }
+.studio-anchor-create { margin-top: .55rem; font-size: .84rem; }
+.studio-anchor-create summary, .studio-hero-settings summary { cursor: pointer; font-weight: 630; }
+.studio-anchor-create[open] form, .studio-hero-controls { margin-top: .6rem; }
+.studio-hero-controls { display: flex; flex-wrap: wrap; gap: .42rem; }
+.studio-hero-controls .button { min-height: 2.35rem; padding: .3rem .62rem; font-size: .85rem; }
+.studio-canvas-status:empty { display: none; }
+.canvas-module-settings { max-width: min(92vw, 40rem); }
+@media (pointer: coarse) {
+ .studio-element-tools button { width: 2.5rem; height: 2.5rem; }
+}
+.canvas-module-settings .category-checks { max-height: min(15rem, 27dvh); overflow-y: auto; }
+.canvas-module-settings .actions { position: sticky; bottom: 0; padding-block: .35rem; margin: 0; background: var(--white); }
diff --git a/public/assets/site.css b/public/assets/site.css
index b59c6b2..2c43050 100644
--- a/public/assets/site.css
+++ b/public/assets/site.css
@@ -725,3 +725,14 @@ progress { width: 100%; height: .8rem; accent-color: var(--accent); }
.studio-releases article:last-child { border-block-end: 1px solid var(--line); }
.studio-pricing { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (max-width: 36rem) { .studio-pricing { grid-template-columns: 1fr; } }
+
+.hero-directory-slot > [data-studio-part="body"] { min-height: 2.2rem; }
+[data-studio-editing] [data-studio-dynamic] { cursor: pointer; }
+[data-studio-editing] [data-studio-dynamic]:focus-visible { outline: 1px solid var(--accent); }
+.studio-module-note { margin: 1rem 0 0; color: var(--accent-deep); padding: .6rem .8rem; background: var(--accent-light); border-radius: .4rem; }
+.studio-badge { display: inline-flex; padding: .13rem .63rem; border-radius: 999px; background: var(--accent-light); color: var(--accent-deep); font-size: .85rem; }
+.studio-progress progress { width: min(100%, 28rem); accent-color: var(--accent); display: block; }
+.studio-progress p { margin-bottom: .3rem; }
+.studio-empty { text-align: center; border: 1px dashed var(--line); border-radius: .6rem; padding: clamp(1.25rem, 4vw, 2.7rem); }
+.studio-success-note { border-inline-start-color: #257b50; background: #e7f6ed; }
+.rich .hero-directory { border-bottom: 1px solid var(--line); border-radius: .85rem; }
diff --git a/public/assets/studio.js b/public/assets/studio.js
index 1ad9f85..7322f03 100644
--- a/public/assets/studio.js
+++ b/public/assets/studio.js
@@ -240,7 +240,7 @@ jQuery(function ($) {
$gallery.on('click', '[data-library-category]', function () {
const $panel = $(this).closest('[data-library-panel]');
$panel.data('categoryTrigger', this);
- $panel.find('[data-library-index]').prop('hidden', true);
+ $panel.find('[data-library-index], .studio-anchor-create').prop('hidden', true);
$panel.find('[data-library-content]').prop('hidden', false);
$panel.find('[data-library-title]').text(this.dataset.libraryLabel);
$panel.find('[data-template-search]').val('');
@@ -253,7 +253,7 @@ jQuery(function ($) {
}).on('click', '[data-library-back]', function () {
const $panel = $(this).closest('[data-library-panel]');
$panel.find('[data-library-content]').prop('hidden', true);
- $panel.find('[data-library-index]').prop('hidden', false);
+ $panel.find('[data-library-index], .studio-anchor-create').prop('hidden', false);
hidePeek();
$($panel.data('categoryTrigger')).trigger('focus');
}).on('input', '[data-template-search]', function () {
@@ -308,7 +308,7 @@ jQuery(function ($) {
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 bodyElements = 'a, article, blockquote, details, div, dl, dt, dd, figure, h1, h2, h3, h4, h5, h6, hr, li, ol, p, pre, progress, 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]');
const $mediaSize = $sizing.find('[data-media-size]');
@@ -355,6 +355,11 @@ jQuery(function ($) {
const $properties = $studio.find('[data-canvas-properties]');
const $propertyForm = $properties.find('form');
const $propertyError = $properties.find('[data-property-error]');
+ const $moduleDialog = $studio.find('[data-module-dialog]');
+ const $moduleForm = $moduleDialog.find('form');
+ const moduleInput = (name) => $moduleForm.find('[name="' + name + '"]');
+ let editedModule;
+ let deletedModules = [];
const propertyInput = (name) => $propertyForm.find('[name="' + name + '"]');
const pageInput = (name) => $settings.find('[name="' + name + '"]');
const settingsSnapshot = () => $settings.serializeArray()
@@ -368,7 +373,7 @@ jQuery(function ($) {
let saveComplete = false;
function sectionChanges(withEdits = true) {
- return sections.flatMap(({key, version, fields, source, template}) => {
+ const edits = sections.flatMap(({key, version, fields, source, template, copyOf, feed, initialFeed}) => {
const changes = {};
const aligned = {};
let alignmentChanged = false;
@@ -388,9 +393,16 @@ jQuery(function ($) {
changes[field] = withEdits && field === 'body' && version !== null ? bodyEdits(source, value) : value;
}
}
- if (!Object.keys(changes).length && !alignmentChanged) return [];
- return [{key, version, fields: changes, ...(alignmentChanged ? {alignments: aligned} : {}), ...(template ? {template} : {})}];
+ const feedChanged = feed && (version === null || JSON.stringify(feed) !== initialFeed);
+ if (!Object.keys(changes).length && !alignmentChanged && !feedChanged) return [];
+ const edit = {key, version, fields: changes};
+ if (alignmentChanged || (version === null && Object.keys(aligned).length)) edit.alignments = aligned;
+ if (template) edit.template = template;
+ if (copyOf) edit.copyOf = copyOf;
+ if (feedChanged) edit.feed = feed;
+ return [edit];
});
+ return [...edits, ...deletedModules];
}
$settings.on('studio:sync', () => pageInput('canvas_sections').val(JSON.stringify(sectionChanges())));
@@ -409,7 +421,7 @@ jQuery(function ($) {
function openProperties(heading, values, apply, mime = null, allowEmptyUrl = false) {
$properties.find('[data-property-heading]').text(heading);
$propertyError.prop('hidden', true);
- for (const key of ['label', 'url', 'alt', 'poster', 'quicklinks']) {
+ for (const key of ['label', 'note', 'url', 'alt', 'poster', 'quicklinks', 'value', 'max']) {
const visible = Object.hasOwn(values, key);
$propertyForm.find('[data-property-row="' + key + '"]').prop('hidden', !visible);
propertyInput(key).val(visible ? values[key] : '');
@@ -621,16 +633,40 @@ jQuery(function ($) {
function editResource(node) {
const tag = node.localName;
+ if (tag === 'progress') {
+ openProperties('进度条', {value: node.getAttribute('value') || '0', max: node.getAttribute('max') || '100'}, ({value, max}) => {
+ if (!/^\d+$/.test(value) || !/^\d+$/.test(max) || Number(max) < 1 || Number(value) > Number(max)) {
+ $propertyError.prop('hidden', false).text('请输入不超过最大值的非负整数。');
+ return false;
+ }
+ node.max = Number(max);
+ node.value = Number(value);
+ node.textContent = Math.round(100 * node.value / node.max) + '%';
+ });
+ return;
+ }
if (tag === 'a') {
+ const product = node.parentElement.matches('.hero-directory');
+ const title = product ? node.querySelector(':scope > span') : null;
+ const note = product ? node.querySelector(':scope > small') : null;
const onlyChild = node.firstElementChild;
- const text = node.childElementCount === 0 ? node : (
+ const text = title || (node.childElementCount === 0 ? node : (
node.childElementCount === 1 && onlyChild.matches('span, strong, b, em, i, small')
&& !onlyChild.childElementCount && node.textContent.trim() === onlyChild.textContent.trim() ? onlyChild : null
- );
+ ));
const values = text ? {label: text.textContent, url: node.getAttribute('href') || ''} : {url: node.getAttribute('href') || ''};
- openProperties('正文链接', values, ({label, url}) => {
+ if (title) values.note = note?.textContent || '';
+ openProperties(product ? '导航卡片' : '正文链接', values, ({label, note: description, url}) => {
+ if (text && !label) {
+ $propertyError.prop('hidden', false).text('请填写链接文案。');
+ return false;
+ }
node.setAttribute('href', url);
if (text && label !== values.label) text.textContent = label;
+ if (description !== undefined) {
+ if (note) $(note).text(description);
+ else if (description) $('').text(description).appendTo(node);
+ }
});
return;
}
@@ -653,17 +689,18 @@ jQuery(function ($) {
}, (tag === 'img' ? 'image' : tag) + '/');
}
- function registerSection(section, version = Number(section.dataset.studioSection)) {
+ function registerSection(section, version = Number(section.dataset.studioSection), metadata = {}) {
const fields = {};
+ const feed = section.dataset.studioFeed ? JSON.parse(section.dataset.studioFeed) : null;
for (const node of section.querySelectorAll('[data-studio-part]')) {
const part = node.dataset.studioPart;
const body = part === 'body';
const label = {title: '区块标题', lead: '添加区块简介', body: '区块正文'}[part];
- if (body) {
+ if (!feed && body) {
node.contentEditable = 'true';
node.setAttribute('aria-label', label);
node.dataset.studioPlaceholder = label;
- } else {
+ } else if (!feed && !node.hidden) {
configureText(node, label, part === 'lead');
}
fields[part] = {node, initial: body ? node.innerHTML : node.textContent, initialAlignment: body ? '' : getAlignment(node)};
@@ -671,7 +708,9 @@ jQuery(function ($) {
const source = new TextDecoder('utf-8', {ignoreBOM: true}).decode(Uint8Array.from(
atob(section.dataset.studioSource || ''), (byte) => byte.charCodeAt(0)
));
- sections.push({key: section.id, version, fields, source, template: section.dataset.studioTemplate});
+ const entry = {node: section, key: section.id, version, fields, source, feed, initialFeed: JSON.stringify(feed), ...metadata};
+ sections.push(entry);
+ return entry;
}
function setMediaWidth(node, width) {
@@ -779,6 +818,8 @@ jQuery(function ($) {
selectionObserver?.disconnect();
selectedElement?.removeAttribute('data-studio-selected');
selectedElement = node;
+ const dynamic = node?.hasAttribute('data-studio-dynamic');
+ $elementTools.toggleClass('is-module', Boolean(dynamic)).find('[data-element-module-settings]').prop('hidden', !dynamic);
selectedMedia = node?.matches(mediaTargets) ? node : null;
$sizing.prop('hidden', !selectedMedia);
if (node) {
@@ -786,12 +827,12 @@ jQuery(function ($) {
const target = sizingTarget();
const nav = node.hasAttribute('data-studio-nav-index');
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);
+ const canCopy = dynamic || inBody || (nav && $(node).siblings().length < 19);
+ const hasProperties = !dynamic && (selectedMedia || node.matches('a, progress'));
+ const aligned = dynamic ? null : 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-delete]').prop('hidden', !dynamic && !inBody && !selectedMedia && !node.matches(heroOrOptional));
$elementTools.find('[data-element-properties]').prop('hidden', !hasProperties);
if (target) showMediaWidth(currentMediaWidth(target));
selectionObserver?.observe(target || aligned || node);
@@ -802,6 +843,10 @@ jQuery(function ($) {
function changeElement(copy) {
const node = selectedElement;
if (!node?.isConnected) return;
+ if (node.hasAttribute('data-studio-dynamic')) {
+ changeModule(sections.find((section) => section.node === node), copy);
+ return;
+ }
const {studioField, studioAction, studioNavIndex} = node.dataset;
const inBody = node.closest('[data-studio-part="body"]') !== null;
selectElement(null);
@@ -853,13 +898,119 @@ jQuery(function ($) {
if (selectedMedia) replaceMedia();
else if (selectedElement?.matches('[data-studio-action], [data-studio-nav-index]')) {
$(selectedElement).triggerHandler('studio:properties');
- } else if (selectedElement?.matches('a')) {
+ } else if (selectedElement?.matches('a, progress')) {
editResource(selectedElement);
}
}).on('keydown', (event) => {
if (event.key === 'Escape') selectElement(null);
});
+ function noteModule(section, text) {
+ const $body = $(section).find('[data-studio-part="body"]');
+ let $note = $(section).find('[data-studio-module-note]');
+ if (!$note.length) $note = $('', {class: 'studio-module-note', 'data-studio-module-note': ''}).insertBefore($body);
+ $note.text(text);
+ }
+
+ $elementTools.on('click', '[data-element-module-settings]', () => {
+ editedModule = sections.find(({node}) => node === selectedElement);
+ if (!editedModule?.feed) return;
+ const {fields, feed} = editedModule;
+ moduleInput('module_title').val(fields.title.node.textContent);
+ moduleInput('module_lead').val(fields.lead.node.textContent);
+ moduleInput('feed_mode').val(feed.mode);
+ moduleInput('feed_limit').val(feed.limit);
+ moduleInput('feed_categories[]').each(function () {
+ this.checked = feed.categories.includes(this.value);
+ });
+ $moduleDialog.find('[data-module-error]').prop('hidden', true);
+ $moduleDialog.get(0).showModal();
+ });
+ $moduleDialog.on('click', '[data-module-close]', () => $moduleDialog.get(0).close());
+ $moduleForm.on('submit', (event) => {
+ event.preventDefault();
+ const categories = moduleInput('feed_categories[]').filter(':checked').map((_, node) => node.value).get();
+ const title = moduleInput('module_title').val().trim();
+ if (!title || !categories.length) {
+ $moduleDialog.find('[data-module-error]').text('请填写标题并至少选择一个分类。').prop('hidden', false);
+ return;
+ }
+ const {node, fields} = editedModule;
+ editedModule.feed = {mode: moduleInput('feed_mode').val(), categories, limit: Number(moduleInput('feed_limit').val())};
+ fields.title.node.textContent = title;
+ fields.lead.node.textContent = moduleInput('module_lead').val().trim();
+ noteModule(node, '模块设置将在保存页面后更新。');
+ $moduleDialog.get(0).close();
+ positionSelection();
+ });
+
+ function newSectionId() {
+ return 'block-' + Array.from(crypto.getRandomValues(new Uint8Array(16)), (byte) => byte.toString(16).padStart(2, '0')).join('');
+ }
+
+ function addPending(section) {
+ const $button = $('