forked from laysense/laysite
Add page publication history and reusable blocks
This commit is contained in:
@@ -574,3 +574,7 @@ button.studio-layer-label[aria-expanded=true]::before { transform: rotate(45deg)
|
||||
.canvas-fill [data-gradient-angle] input[type=range] { min-height: 2.1rem; padding: 0; accent-color: var(--accent); }
|
||||
.canvas-fill [data-gradient-angle] output { font-variant-numeric: tabular-nums; }
|
||||
.studio-background-image-options { margin-top: .75rem; }
|
||||
|
||||
.studio-reuse-add { width: 100%; margin-block: .25rem .75rem; }
|
||||
.revision-list time { display: inline-block; margin: .3rem .6rem; color: var(--muted); font-size: .875rem; }
|
||||
.revision-list li { justify-content: space-between; flex-wrap: wrap; }
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 18 KiB |
@@ -287,3 +287,46 @@
|
||||
@media (max-width: 40rem) {
|
||||
.theme-harbor .hero { background: var(--paper); }
|
||||
}
|
||||
|
||||
.theme-fwnet {
|
||||
--white: #ffffff;
|
||||
--paper: #f6f6f7;
|
||||
--ink: #3c3c43;
|
||||
--muted: #67676c;
|
||||
--accent: #3451b2;
|
||||
--accent-deep: #28449d;
|
||||
--accent-light: #e9edfa;
|
||||
--line: #e2e2e3;
|
||||
--button-ink: #ffffff;
|
||||
}
|
||||
.theme-fwnet .hero { padding: 0; background: var(--white); }
|
||||
.theme-fwnet .hero h1 { margin: 0; max-width: 670px; font-size: clamp(2.5rem, 5vw, 3.625rem); line-height: 1.08; letter-spacing: -.035em; }
|
||||
.fwnet-nav, .fwnet-nav > div, .fwnet-brand { display: flex; align-items: center; gap: 1.25rem; }
|
||||
.fwnet-nav { min-height: 64px; justify-content: space-between; padding-block: .75rem; }
|
||||
.fwnet-nav a { color: var(--ink); text-decoration: none; }
|
||||
.fwnet-nav a:hover { color: var(--accent); }
|
||||
.fwnet-brand { gap: .5rem; font-weight: 700; }
|
||||
.fwnet-brand img { width: 26px; height: 26px; }
|
||||
.fwnet-hero { display: grid; grid-template-columns: 1.2fr 1fr; align-items: center; gap: 2rem; padding-block: clamp(2.5rem, 6vw, 5.5rem) clamp(1.5rem, 4vw, 3rem); }
|
||||
.fwnet-hero h1 span { color: var(--accent); }
|
||||
.fwnet-hero p { color: var(--muted); font-size: clamp(1.125rem, 2.2vw, 1.5rem); font-weight: 500; }
|
||||
.fwnet-hero > img { width: min(100%, 330px); height: auto; margin-inline: auto; }
|
||||
.fwnet-hero .button { border-radius: 999px; font-size: .9rem; }
|
||||
.fwnet-hero .button-outline { background: var(--paper); }
|
||||
.theme-fwnet #capabilities { padding-block: 1rem 3.5rem; }
|
||||
.fwnet-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1rem; }
|
||||
.fwnet-card { display: grid; align-content: start; gap: .6rem; padding: 1.4rem; border-radius: .85rem; background: var(--paper); }
|
||||
.fwnet-card h3, .fwnet-card p { margin: 0; }
|
||||
.fwnet-card h3 { font-size: 1rem; }
|
||||
.fwnet-card p { font-size: .875rem; line-height: 1.55; color: var(--muted); }
|
||||
.fwnet-card-icon { display: grid; place-items: center; width: 3rem; height: 3rem; margin-bottom: .25rem; background: var(--line); border-radius: .5rem; font-size: 1.35rem; }
|
||||
.fwnet-credit { padding: 1.5rem 1rem; border-top: 1px solid var(--line); color: var(--muted); text-align: center; font-size: .875rem; }
|
||||
@media (max-width: 900px) {
|
||||
.fwnet-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
|
||||
}
|
||||
@media (max-width: 620px) {
|
||||
.fwnet-hero { grid-template-columns: 1fr; text-align: center; }
|
||||
.fwnet-hero .actions { justify-content: center; }
|
||||
.fwnet-hero > img { grid-row: 1; width: 135px; }
|
||||
.fwnet-grid { grid-template-columns: 1fr; }
|
||||
}
|
||||
|
||||
@@ -739,3 +739,30 @@ img.studio-style-display-inline-block, .hero-visual.studio-style-display-inline-
|
||||
.studio-style-color-theme { color: var(--ink) !important; }
|
||||
|
||||
.studio-media-placeholder { display: block; width: min(100%, 24rem); height: auto; }
|
||||
|
||||
.studio-mirror-block { position: relative; isolation: isolate; }
|
||||
.studio-mirror-overlay {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
z-index: 2;
|
||||
display: grid;
|
||||
align-content: start;
|
||||
justify-items: center;
|
||||
padding: min(1rem, 3vw);
|
||||
background: repeating-linear-gradient(135deg, #64748b21 0 1px, #f8fafc55 1px 10px);
|
||||
}
|
||||
.studio-mirror-note {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: .4rem .75rem;
|
||||
padding: .5rem .7rem;
|
||||
border: 1px solid #cbd5e1;
|
||||
border-radius: .5rem;
|
||||
color: #1e293b;
|
||||
background: #f8fafc;
|
||||
font-size: .875rem;
|
||||
}
|
||||
.studio-mirror-note a, .studio-mirror-note button { display: inline-flex; align-items: center; min-height: 28px; color: #214ed7; text-decoration: underline; font: inherit; cursor: pointer; }
|
||||
.studio-mirror-note button { padding: .1rem; border: 0; background: transparent; }
|
||||
|
||||
+115
-23
@@ -632,6 +632,7 @@ jQuery(function ($) {
|
||||
|
||||
function sectionChanges(withEdits = true) {
|
||||
const edits = sections.flatMap((entry) => {
|
||||
if (entry.mirror) return [];
|
||||
const {key, version, fields, source, template, copyOf, feed, initialFeed, initialPresentation} = entry;
|
||||
const changes = {};
|
||||
const aligned = {};
|
||||
@@ -742,19 +743,18 @@ jQuery(function ($) {
|
||||
pageInput('canvas_order').val('');
|
||||
savedSettings = JSON.stringify(settingsSnapshot(true));
|
||||
|
||||
const published = saved.status === 'published';
|
||||
const status = published ? '已发布' : '草稿';
|
||||
const published = Boolean(saved.publication);
|
||||
const status = !published ? '草稿' : (saved.publication.version === saved.version ? '已发布' : '已发布 · 草稿有更新');
|
||||
$('[data-page-editor-title]').text('编辑 ' + saved.name);
|
||||
document.title = '编辑 ' + saved.name + ' CMS';
|
||||
$('[data-page-publication]').text(status).attr('data-published', String(published));
|
||||
const publicLink = $settings.attr('data-public-page') === '1' && published;
|
||||
const publicLink = published && saved.publication.layout_kind === null && ['page', 'home'].includes(saved.publication.page_type);
|
||||
$('[data-page-public]').prop('hidden', !publicLink);
|
||||
$('[data-page-preview]').prop('hidden', publicLink);
|
||||
$settings.find('[data-publish-button]').val(published ? 'draft' : 'published')
|
||||
.find('[data-publication-action]').each(function () {
|
||||
this.hidden = this.dataset.publicationAction === saved.status;
|
||||
});
|
||||
const message = submitter?.name === 'status' ? (published ? '页面已发布。' : '页面已转为草稿。') : '页面已保存。';
|
||||
if (publicLink) $('[data-page-public] a').attr('href', '/' + saved.publication.slug);
|
||||
$settings.find('[data-publish-label]').text(published ? '发布更新' : '发布');
|
||||
$settings.find('[data-unpublish-button]').prop('hidden', !published);
|
||||
const message = submitter?.name === 'status' ? (published ? '页面已发布。' : '已撤下公开版本。') : '草稿已保存。';
|
||||
if (pendingReuse) pendingReuse.saved = true;
|
||||
const $feedback = submitter && $studio.get(0).contains(submitter) ? $studio : $settings;
|
||||
$feedback.find('[data-page-save-feedback]').text(message).prop('hidden', false);
|
||||
|
||||
@@ -766,14 +766,74 @@ jQuery(function ($) {
|
||||
renderLayers();
|
||||
refreshDynamicSections(dynamic);
|
||||
});
|
||||
let pendingReuse = null;
|
||||
|
||||
function pageDirty() {
|
||||
return initialOrder !== undefined && (sectionChanges(false).length || pageInput('provider_secret').filter(':enabled').val()
|
||||
|| canvasOrder() !== initialOrder || JSON.stringify(settingsSnapshot(true)) !== savedSettings);
|
||||
}
|
||||
|
||||
function submitReuse(operation, value) {
|
||||
const url = $settings.attr('action').replace('/admin/pages/', '/admin/reuse-block/');
|
||||
const $status = $studio.find('[data-canvas-status]');
|
||||
$status.text('正在更新复用区块…');
|
||||
$layout.prop('inert', true);
|
||||
$settings.prop('inert', true);
|
||||
$.ajax({url, method: 'POST', dataType: 'json', data: {
|
||||
csrf: pageInput('csrf').val(), version: pageInput('version').val(), operation, value,
|
||||
}}).done((result) => {
|
||||
if (result.redirect) {
|
||||
const target = new URL(result.redirect, window.location.href);
|
||||
if (target.pathname === window.location.pathname && target.search === window.location.search) {
|
||||
window.history.replaceState(null, '', target);
|
||||
window.location.reload();
|
||||
} else {
|
||||
window.location.assign(target);
|
||||
}
|
||||
return;
|
||||
}
|
||||
$status.text('未收到更新结果。');
|
||||
}).fail((request) => {
|
||||
$status.text(request.responseJSON?.error || '复用区块更新失败。');
|
||||
}).always(() => {
|
||||
$layout.prop('inert', false);
|
||||
$settings.prop('inert', false);
|
||||
});
|
||||
}
|
||||
|
||||
function reuseBlock(operation, value) {
|
||||
if ($settings.attr('aria-busy') === 'true' || pendingReuse) return;
|
||||
if (!pageDirty()) {
|
||||
submitReuse(operation, value);
|
||||
return;
|
||||
}
|
||||
const form = $settings.get(0);
|
||||
if (!form.reportValidity()) return;
|
||||
pendingReuse = {operation, value};
|
||||
form.requestSubmit($settings.find('[data-save-draft]').get(0));
|
||||
}
|
||||
|
||||
const reuseDialog = $layout.find('[data-reuse-dialog]').get(0);
|
||||
$layout.on('click', '[data-reuse-open]', () => reuseDialog.showModal())
|
||||
.on('click', '[data-reuse-close]', () => reuseDialog.close())
|
||||
.on('submit', '[data-reuse-picker]', function (event) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
reuseDialog.close();
|
||||
reuseBlock('add', this.elements.source.value);
|
||||
});
|
||||
|
||||
$settings.on('studio:busy', (_event, busy) => {
|
||||
$layout.prop('inert', busy);
|
||||
$settings.prop('inert', busy);
|
||||
if (!busy && pendingReuse) {
|
||||
const {operation, value, saved} = pendingReuse;
|
||||
pendingReuse = null;
|
||||
if (saved) submitReuse(operation, value);
|
||||
}
|
||||
});
|
||||
$(window).on('beforeunload.studioPage', (event) => {
|
||||
if (sectionChanges(false).length || pageInput('provider_secret').filter(':enabled').val()
|
||||
|| initialOrder !== undefined && canvasOrder() !== initialOrder
|
||||
|| JSON.stringify(settingsSnapshot(true)) !== savedSettings) {
|
||||
if (pageDirty()) {
|
||||
event.preventDefault();
|
||||
event.originalEvent.returnValue = '';
|
||||
}
|
||||
@@ -1652,8 +1712,9 @@ jQuery(function ($) {
|
||||
atob(section.dataset.studioSource || ''), (byte) => byte.charCodeAt(0)
|
||||
));
|
||||
const entry = {node: section, key: section.dataset.studioKey, version, fields, source, feed, initialFeed: JSON.stringify(feed),
|
||||
parent: section.parentNode, fixed: section.classList.contains('hero-directory-slot'), ...metadata};
|
||||
entry.initialPresentation = JSON.stringify(sectionPresentation(entry));
|
||||
parent: section.parentNode, fixed: section.classList.contains('hero-directory-slot'),
|
||||
mirror: section.hasAttribute('data-studio-mirror'), main: section.hasAttribute('data-studio-main'), ...metadata};
|
||||
entry.initialPresentation = entry.mirror ? null : JSON.stringify(sectionPresentation(entry));
|
||||
sections.push(entry);
|
||||
return entry;
|
||||
}
|
||||
@@ -1708,7 +1769,7 @@ jQuery(function ($) {
|
||||
} else {
|
||||
$handle.prop('hidden', true);
|
||||
}
|
||||
if (!selectedElement?.isConnected) {
|
||||
if (!selectedElement?.isConnected || selectedElement.hasAttribute('data-studio-mirror')) {
|
||||
$elementTools.prop('hidden', true);
|
||||
return;
|
||||
}
|
||||
@@ -1958,8 +2019,8 @@ jQuery(function ($) {
|
||||
textRange = null;
|
||||
textHost = null;
|
||||
selectBody(body);
|
||||
$studio.get(0).scrollIntoView({block: 'start'});
|
||||
node.scrollIntoView({block: 'start'});
|
||||
$studio.get(0).scrollIntoView({block: 'start', behavior: 'instant'});
|
||||
node.scrollIntoView({block: 'start', behavior: 'instant'});
|
||||
selectElement(node);
|
||||
}
|
||||
|
||||
@@ -1967,7 +2028,7 @@ jQuery(function ($) {
|
||||
if (!node?.isConnected) return;
|
||||
const entry = sections.find((section) => section.node === node);
|
||||
const hero = node.hasAttribute('data-studio-hero');
|
||||
if (!entry && !hero) return;
|
||||
if ((!entry && !hero) || entry?.mirror) return;
|
||||
const parts = new Map();
|
||||
if (hero) {
|
||||
const target = node.querySelector('[data-studio-hero-source]');
|
||||
@@ -2102,6 +2163,7 @@ jQuery(function ($) {
|
||||
let layerTimer;
|
||||
let layerBranchId = 0;
|
||||
const layerActions = {
|
||||
main: ['link', '设为主区块'], detach: ['chain-break', '取消关联'],
|
||||
jump: ['target', '定位'], up: ['up', '上移'], down: ['down', '下移'],
|
||||
copy: ['copy', '复制'], delete: ['delete', '删除'], id: ['anchor', '设置 ID'], source: ['code', '编辑 HTML'],
|
||||
};
|
||||
@@ -2114,6 +2176,7 @@ jQuery(function ($) {
|
||||
}
|
||||
|
||||
function layerChildren(node) {
|
||||
if (node.hasAttribute('data-studio-mirror')) return [];
|
||||
const authored = node.closest('[data-studio-part="body"]');
|
||||
return [...node.children].flatMap((child) => {
|
||||
if (child.matches('meta, template, [data-studio-module-note], [data-studio-section]')
|
||||
@@ -2278,14 +2341,21 @@ jQuery(function ($) {
|
||||
title: [label || node.getAttribute('aria-label'), node.id && '#' + node.id].filter(Boolean).join(' · '),
|
||||
}).appendTo($caption);
|
||||
if (entry && entry.feed !== null) $('<span>', {class: 'studio-dynamic-badge', text: '动态'}).appendTo($caption);
|
||||
if (entry?.main) $('<span>', {class: 'studio-dynamic-badge', text: '主区块'}).appendTo($caption);
|
||||
const $actions = $('<div>', {class: 'studio-layer-actions'}).appendTo($row);
|
||||
$actions.append(layerButton('jump'), layerButton('copy'), layerButton('delete'), layerButton('id'));
|
||||
$actions.append(layerButton('jump'), layerButton('delete'));
|
||||
if (entry?.mirror) {
|
||||
$actions.append(layerButton('detach'));
|
||||
} else {
|
||||
$actions.append(layerButton('copy'), layerButton('id'));
|
||||
if (entry && !entry.fixed && !entry.main) $actions.append(layerButton('main'));
|
||||
}
|
||||
if (layerContext(node)) {
|
||||
$actions.append(layerButton('up', !canDropLayer(node, adjacentLayer(node, -1), 'before')),
|
||||
layerButton('down', !canDropLayer(node, adjacentLayer(node, 1), 'after')));
|
||||
}
|
||||
if (root && (entry || node.hasAttribute('data-studio-hero'))) $actions.append(layerButton('source'));
|
||||
if (entry?.version != null) {
|
||||
if (root && ((entry && !entry.mirror) || node.hasAttribute('data-studio-hero'))) $actions.append(layerButton('source'));
|
||||
if (entry && !entry.mirror && entry.version != null) {
|
||||
const icon = $layout.find('template[data-layer-icon="settings"]').get(0).content.cloneNode(true);
|
||||
$('<a>', {class: 'button button-outline', href: $settings.attr('action') + '/' + entry.key,
|
||||
title: '区块设置', 'aria-label': '区块设置'}).append(icon).appendTo($actions);
|
||||
@@ -2324,7 +2394,7 @@ jQuery(function ($) {
|
||||
if (hero) layerRow($layers, hero, '首屏', null, true);
|
||||
if (navigation) layerRow($layers, navigation, '本页目录', null, true);
|
||||
for (const entry of sections) {
|
||||
layerRow($layers, entry.node, plainText(entry.fields.title.node) || '未命名区块', entry, true);
|
||||
layerRow($layers, entry.node, (entry.mirror ? entry.node.dataset.studioMirrorTitle : plainText(entry.fields.title.node)) || '未命名区块', entry, true);
|
||||
if (entry.version === null) {
|
||||
const $cancel = $('<button>', {type: 'button', text: '取消新增:' + plainText(entry.fields.title.node)});
|
||||
$('<li>').append($cancel).appendTo($pending);
|
||||
@@ -2348,7 +2418,13 @@ jQuery(function ($) {
|
||||
const node = $(this).closest('.studio-layer-row').data('canvasNode');
|
||||
if (!node?.isConnected) return;
|
||||
const operation = this.dataset.layerOperation;
|
||||
if (operation === 'source') openSource(node);
|
||||
if (operation === 'delete' && node.hasAttribute('data-studio-mirror')) {
|
||||
const entry = sections.find((section) => section.node === node);
|
||||
if (entry) changeModule(entry, false);
|
||||
return;
|
||||
}
|
||||
if (operation === 'main' || operation === 'detach') reuseBlock(operation, node.dataset.studioKey);
|
||||
else if (operation === 'source') openSource(node);
|
||||
else if (operation === 'jump') {
|
||||
const dynamic = !node.closest('[data-studio-part]') && node.closest('[data-studio-dynamic]');
|
||||
locateLayer(dynamic || node, dynamic ? null : node.closest('[data-studio-part="body"]') || node.querySelector('[data-studio-part="body"]'));
|
||||
@@ -2848,6 +2924,9 @@ jQuery(function ($) {
|
||||
deletedSections = [];
|
||||
$doc.find('[data-studio-section]').each((_, section) => registerSection(section));
|
||||
renderLayers();
|
||||
const target = new URLSearchParams(window.location.search).get('block');
|
||||
const focused = sections.find((entry) => entry.key === target);
|
||||
if (focused) window.requestAnimationFrame(() => locateLayer(focused.node));
|
||||
initialOrder = canvasOrder();
|
||||
syncMemberSettings();
|
||||
syncPagePresentation();
|
||||
@@ -2871,6 +2950,14 @@ jQuery(function ($) {
|
||||
selectBody(this.dataset.studioPart === 'body' ? this : null);
|
||||
});
|
||||
$doc.on('selectionchange.canvas mouseup.canvas keyup.canvas', rememberSelection).on('scroll.canvas', positionSelection);
|
||||
$doc.on('click.canvas', '[data-studio-mirror-open]', function (event) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
window.open(this.href, '_blank', 'noopener,noreferrer');
|
||||
}).on('click.canvas', '[data-studio-mirror-detach]', function (event) {
|
||||
event.stopPropagation();
|
||||
reuseBlock('detach', this.closest('[data-studio-mirror]').dataset.studioKey);
|
||||
});
|
||||
$doc.on('click.canvas auxclick.canvas', 'a', (event) => event.preventDefault());
|
||||
$doc.on('click.canvas dblclick.canvas', mediaTargets, function (event) {
|
||||
event.preventDefault();
|
||||
@@ -2888,6 +2975,11 @@ jQuery(function ($) {
|
||||
$doc.on('click.canvas', (event) => {
|
||||
const node = event.target;
|
||||
if (node.nodeType !== 1) return;
|
||||
if (node.closest('[data-studio-mirror]')) {
|
||||
selectBody(null);
|
||||
selectElement(node.closest('[data-studio-mirror]'));
|
||||
return;
|
||||
}
|
||||
const dynamic = node.closest('[data-studio-dynamic]');
|
||||
if (dynamic && !node.closest('[data-studio-part]')) {
|
||||
selectBody(null);
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 9.3 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 682 B |
Reference in New Issue
Block a user