Manage dynamic blocks and expand the editor library
@@ -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); }
|
||||
|
||||
@@ -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; }
|
||||
|
||||
@@ -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) $('<small>').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 = $('<p>', {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 = $('<button>', {type: 'button', text: '取消新增:' + section.fields.title.node.textContent});
|
||||
section.$pending = $('<li>').append($button).appendTo($pending);
|
||||
$pending.prop('hidden', false);
|
||||
$button.on('click', () => removeSection(section));
|
||||
}
|
||||
|
||||
function removeSection(section) {
|
||||
if (section.node.contains(activeBody)) selectBody(null);
|
||||
if (section.node.contains(selectedElement)) selectElement(null);
|
||||
if (section.version !== null) deletedModules.push({key: section.key, version: section.version, delete: true});
|
||||
section.node.remove();
|
||||
sections = sections.filter((entry) => entry !== section);
|
||||
section.$pending?.remove();
|
||||
$pending.prop('hidden', !$pending.children().length);
|
||||
}
|
||||
|
||||
function scopeTemplateIds(root, prefix, oldKey = '') {
|
||||
const ids = new Map();
|
||||
$(root).find('[id]').addBack('[id]').each(function () {
|
||||
const next = oldKey && this.id.includes(oldKey) ? this.id.replace(oldKey, prefix) : prefix + '-' + this.id;
|
||||
ids.set(this.id, next);
|
||||
this.id = next;
|
||||
});
|
||||
$(root).find('[aria-labelledby], [aria-controls], [href^="#"]').addBack('[aria-labelledby]').each(function () {
|
||||
for (const attribute of ['aria-labelledby', 'aria-controls', 'href']) {
|
||||
const value = this.getAttribute(attribute);
|
||||
if (!value) continue;
|
||||
if (attribute === 'href') {
|
||||
const target = ids.get(value.slice(1));
|
||||
if (value.startsWith('#') && target) this.setAttribute('href', '#' + target);
|
||||
} else {
|
||||
this.setAttribute(attribute, value.split(' ').map((part) => ids.get(part) || part).join(' '));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function changeModule(section, copy) {
|
||||
if (!section) return;
|
||||
if (!copy) {
|
||||
if (window.confirm('删除此模块?保存页面后生效。')) {
|
||||
removeSection(section);
|
||||
$studio.find('[data-canvas-status]').text('模块已移除,保存页面后生效。');
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (sections.filter(({version}) => version === null).length >= 50) return;
|
||||
selectElement(null);
|
||||
const clone = section.node.cloneNode(true);
|
||||
const id = newSectionId();
|
||||
scopeTemplateIds(clone, id, section.key);
|
||||
clone.dataset.studioFeed = JSON.stringify(section.feed);
|
||||
doc.querySelector('[data-studio-section-end]').before(clone);
|
||||
const copyOf = section.copyOf || (section.version === null ? null : {key: section.key, version: section.version});
|
||||
const entry = registerSection(clone, null, {template: copyOf ? null : section.template, copyOf});
|
||||
addPending(entry);
|
||||
noteModule(clone, '模块副本将在保存页面后生效。');
|
||||
clone.scrollIntoView({block: 'start'});
|
||||
selectElement(clone);
|
||||
$studio.find('[data-canvas-status]').text('已复制模块,保存页面后生效。');
|
||||
}
|
||||
|
||||
function replaceMedia() {
|
||||
if (!selectedMedia?.isConnected) return;
|
||||
if (selectedMedia.hasAttribute('data-studio-hero-image')) heroControls.get('image')();
|
||||
@@ -939,7 +1090,10 @@ jQuery(function ($) {
|
||||
while (node.parentNode !== body) node = node.parentNode;
|
||||
insertion.setStartAfter(node);
|
||||
}
|
||||
editBody(body, insertion, 'insertHTML', markup);
|
||||
const template = doc.createElement('template');
|
||||
template.innerHTML = markup;
|
||||
if (template.content.querySelector('[id]')) scopeTemplateIds(template.content, newSectionId());
|
||||
editBody(body, insertion, 'insertHTML', template.innerHTML);
|
||||
}
|
||||
|
||||
$presets.on('mousedown', '[data-canvas-template], [data-canvas-element]', (event) => event.preventDefault());
|
||||
@@ -966,9 +1120,10 @@ jQuery(function ($) {
|
||||
$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;
|
||||
const feed = this.dataset.templateFeed;
|
||||
if ($presets.find('[data-template-inline]').prop('checked')) {
|
||||
if (template === 'articles') {
|
||||
$templateStatus.text('分类文章需要作为独立区块添加。');
|
||||
if (feed) {
|
||||
$templateStatus.text('动态模块需要作为独立区块添加。');
|
||||
return;
|
||||
}
|
||||
if (!activeBody) {
|
||||
@@ -986,34 +1141,29 @@ jQuery(function ($) {
|
||||
}
|
||||
const end = doc.querySelector('[data-studio-section-end]');
|
||||
const section = end.content.firstElementChild.cloneNode(true);
|
||||
const id = 'block-' + Array.from(crypto.getRandomValues(new Uint8Array(16)), (byte) => byte.toString(16).padStart(2, '0')).join('');
|
||||
const id = newSectionId();
|
||||
section.id = id;
|
||||
section.classList.replace('section-plain', 'section-' + this.dataset.templateStyle);
|
||||
const title = section.querySelector('[data-studio-part="title"]');
|
||||
title.id = 'heading-' + id;
|
||||
title.textContent = this.dataset.templateTitle;
|
||||
section.setAttribute('aria-labelledby', title.id);
|
||||
section.querySelector('[data-studio-part="body"]').innerHTML = markup;
|
||||
if (template === 'articles') {
|
||||
section.dataset.studioTemplate = template;
|
||||
$('<p>', {class: 'empty-state', text: '保存页面后可在图层的区块设置中选择分类和展示方式。'})
|
||||
.insertBefore($(section).find('[data-studio-part="body"]'));
|
||||
section.querySelector('[data-studio-part="lead"]').textContent = this.dataset.templateLead || '';
|
||||
const body = section.querySelector('[data-studio-part="body"]');
|
||||
body.innerHTML = markup;
|
||||
scopeTemplateIds(body, id);
|
||||
if (feed) {
|
||||
section.dataset.studioDynamic = '';
|
||||
section.dataset.studioFeed = feed;
|
||||
section.tabIndex = 0;
|
||||
noteModule(section, '保存页面后将加载动态内容。');
|
||||
}
|
||||
end.before(section);
|
||||
registerSection(section, null);
|
||||
const entry = registerSection(section, null, {template});
|
||||
addPending(entry);
|
||||
section.scrollIntoView({block: 'start'});
|
||||
section.querySelector('[data-studio-part="body"]').focus({preventScroll: true});
|
||||
const $cancel = $('<button>', {type: 'button', text: '取消新增:' + title.textContent});
|
||||
const $item = $('<li>').append($cancel).appendTo($pending);
|
||||
$pending.prop('hidden', false);
|
||||
$cancel.on('click', () => {
|
||||
if (section.contains(activeBody)) selectBody(null);
|
||||
if (section.contains(selectedElement)) selectElement(null);
|
||||
section.remove();
|
||||
sections = sections.filter(({key}) => key !== id);
|
||||
$item.remove();
|
||||
$pending.prop('hidden', !$pending.children().length);
|
||||
$templateStatus.text('已取消新增区块。');
|
||||
});
|
||||
if (feed) selectElement(section);
|
||||
else entry.fields.body.node.focus({preventScroll: true});
|
||||
$templateStatus.text('已添加 ' + title.textContent + ' 区块。');
|
||||
});
|
||||
|
||||
@@ -1028,6 +1178,7 @@ jQuery(function ($) {
|
||||
selectElement(null);
|
||||
$pending.empty().prop('hidden', true);
|
||||
sections = [];
|
||||
deletedModules = [];
|
||||
$doc.find('[data-studio-section]').each((_, section) => registerSection(section));
|
||||
|
||||
$doc.on('focusin.canvas', '[contenteditable]', function () {
|
||||
@@ -1038,22 +1189,42 @@ jQuery(function ($) {
|
||||
$doc.on('click.canvas dblclick.canvas', mediaTargets, function (event) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
const dynamic = this.closest('[data-studio-dynamic]');
|
||||
if (dynamic) {
|
||||
selectBody(null);
|
||||
selectElement(dynamic);
|
||||
return;
|
||||
}
|
||||
selectBody(this.closest('[data-studio-part="body"]'));
|
||||
selectElement(this);
|
||||
if (event.type === 'dblclick') replaceMedia();
|
||||
});
|
||||
$doc.on('click.canvas', (event) => {
|
||||
const node = event.target;
|
||||
const dynamic = node.closest?.('[data-studio-dynamic]');
|
||||
if (dynamic) {
|
||||
selectBody(null);
|
||||
selectElement(dynamic);
|
||||
return;
|
||||
}
|
||||
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();
|
||||
if (!event.target.closest(mediaTargets)) editResource(this);
|
||||
if (!this.closest('[data-studio-dynamic]') && !event.target.closest(mediaTargets)) editResource(this);
|
||||
});
|
||||
$doc.on('keydown.canvas', (event) => {
|
||||
if (event.key === 'Escape') selectElement(null);
|
||||
});
|
||||
$doc.on('keydown.canvas', '[data-studio-dynamic]', function (event) {
|
||||
if ((event.key === 'Enter' || event.key === ' ') && event.target === this) {
|
||||
event.preventDefault();
|
||||
selectBody(null);
|
||||
selectElement(this);
|
||||
$elementTools.find('[data-element-module-settings]').trigger('focus');
|
||||
}
|
||||
});
|
||||
$doc.on('keydown.canvas', '[data-studio-hero-image]', function (event) {
|
||||
if (event.key === 'Enter' || event.key === ' ') {
|
||||
event.preventDefault();
|
||||
@@ -1086,7 +1257,8 @@ jQuery(function ($) {
|
||||
if (!body) return;
|
||||
$studio.get(0).scrollIntoView({block: 'start'});
|
||||
section.scrollIntoView({block: 'start'});
|
||||
body.focus({preventScroll: true});
|
||||
if (section.hasAttribute('data-studio-dynamic')) selectElement(section);
|
||||
else body.focus({preventScroll: true});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
After Width: | Height: | Size: 27 KiB |
|
After Width: | Height: | Size: 23 KiB |
|
After Width: | Height: | Size: 7.3 KiB |
|
After Width: | Height: | Size: 15 KiB |
|
After Width: | Height: | Size: 17 KiB |
|
After Width: | Height: | Size: 25 KiB |
|
After Width: | Height: | Size: 22 KiB |
|
After Width: | Height: | Size: 13 KiB |
|
After Width: | Height: | Size: 3.9 KiB |
|
After Width: | Height: | Size: 15 KiB |
|
After Width: | Height: | Size: 22 KiB |
|
After Width: | Height: | Size: 17 KiB |
|
After Width: | Height: | Size: 27 KiB |
|
After Width: | Height: | Size: 15 KiB |
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 28 KiB |
|
After Width: | Height: | Size: 27 KiB |
|
After Width: | Height: | Size: 11 KiB |
|
After Width: | Height: | Size: 18 KiB |
|
After Width: | Height: | Size: 11 KiB |
|
After Width: | Height: | Size: 17 KiB |
|
After Width: | Height: | Size: 17 KiB |
|
After Width: | Height: | Size: 19 KiB |
|
After Width: | Height: | Size: 27 KiB |
|
After Width: | Height: | Size: 9.2 KiB |
|
After Width: | Height: | Size: 21 KiB |
|
After Width: | Height: | Size: 19 KiB |
|
After Width: | Height: | Size: 11 KiB |
|
After Width: | Height: | Size: 18 KiB |
|
After Width: | Height: | Size: 11 KiB |
|
After Width: | Height: | Size: 20 KiB |
|
After Width: | Height: | Size: 17 KiB |
|
After Width: | Height: | Size: 19 KiB |
|
After Width: | Height: | Size: 28 KiB |
|
After Width: | Height: | Size: 19 KiB |
|
After Width: | Height: | Size: 29 KiB |
|
After Width: | Height: | Size: 21 KiB |
|
After Width: | Height: | Size: 7.8 KiB |
|
After Width: | Height: | Size: 8.0 KiB |