Add canvas element tools and categorized article editing

This commit is contained in:
2026-11-21 22:24:58 +08:00
parent 6efcdefadf
commit a5b3408358
45 changed files with 1607 additions and 660 deletions
+32 -1
View File
@@ -131,7 +131,25 @@
.studio-layers .studio-blocks li { display: grid; gap: .4rem; }
.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-media-sizing select { margin-inline-start: .3rem; }
.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;
}
.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;
}
.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-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;
background: var(--accent); box-shadow: 0 0 0 1px var(--accent); color: white; cursor: ew-resize;
touch-action: none; user-select: none;
}
.studio-media-handle::after { content: ''; width: .38rem; height: .9rem; border-inline: 1px solid currentColor; }
.studio-media-sizing output { font-size: .85rem; font-variant-numeric: tabular-nums; }
.studio-media-sizing .button { min-height: 2.2rem; padding: .25rem .7rem; }
@media (max-width: 54rem) {
.studio-layout { grid-template-columns: minmax(0, 1fr); grid-template-areas: "library" "workspace" "settings"; }
@@ -203,3 +221,16 @@
@media (prefers-reduced-motion: reduce) {
.studio-template-image img { transition: none; }
}
.category-checks { min-width: 0; padding: .75rem 1rem; border: 1px solid var(--line); border-radius: .5rem; }
.category-checks > div { display: flex; flex-wrap: wrap; gap: .45rem 1.25rem; }
.admin-form .category-checks label { display: inline-flex; align-items: center; gap: .35rem; }
.admin-form .category-checks input { min-height: 0; width: auto; }
.admin-options { padding: .7rem 1rem; border: 1px solid var(--line); border-radius: .5rem; }
.admin-options > summary { font-weight: 650; cursor: pointer; }
.admin-options[open] > summary { margin-bottom: .85rem; }
.admin-options .form-grid + .category-checks { margin-top: .8rem; }
.article-editor { min-width: 0; }
.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; }
+56
View File
@@ -0,0 +1,56 @@
'use strict';
jQuery(function ($) {
$('[data-article-editor]').each(function () {
const Editor = window.toastui?.Editor;
if (!Editor) return;
const $field = $(this);
const $source = $field.find('textarea');
const $format = $field.find('input[name="body_format"]');
const $host = $field.find('[data-editor-host]');
const $status = $field.find('[data-article-editor-status]');
const originalFormat = $format.val();
const original = $source.val();
$host.prop('hidden', false);
let editor;
try {
editor = new Editor({
el: $host.get(0),
height: '34rem',
initialEditType: originalFormat === 'html' ? 'wysiwyg' : 'markdown',
initialValue: originalFormat === 'markdown' ? original : '',
previewStyle: 'vertical',
language: 'zh-CN',
usageStatistics: false,
autofocus: false,
hooks: {
addImageBlobHook() {
$status.text('请先上传图片到媒体库,再从媒体库插入。');
}
}
});
if (originalFormat === 'html') editor.setHTML(original);
} catch (error) {
$host.prop('hidden', true);
return;
}
const snapshot = originalFormat === 'html' ? editor.getHTML() : editor.getMarkdown();
$source.prop('hidden', true);
$field.find('[data-article-editor-label]').removeAttr('for');
$field.find('[data-insert-article-image]').prop('hidden', false).on('click', () => {
$('#media-picker').triggerHandler('studio:pick', ['image/', (file) => {
const alt = window.prompt('图片替代文本(装饰图可留空)', file.label);
if (alt === null) return;
$status.empty();
editor.focus();
editor.exec('addImage', {imageUrl: file.url, altText: alt});
}]);
});
$field.closest('form').on('studio:sync', function () {
const format = editor.isMarkdownMode() ? 'markdown' : 'html';
const content = format === 'html' ? editor.getHTML() : editor.getMarkdown();
$format.val(format);
$source.val(format === originalFormat && content === snapshot ? original : content);
});
});
});
+119 -38
View File
@@ -500,39 +500,28 @@ progress { width: 100%; height: .8rem; accent-color: var(--accent); }
.home-pipe-flow {
position: absolute;
inset: clamp(.45rem, 1.8vw, 1.7rem);
width: calc(100% - 2 * clamp(.45rem, 1.8vw, 1.7rem));
height: calc(100% - 2 * clamp(.45rem, 1.8vw, 1.7rem));
pointer-events: none;
}
.home-pipe-flow span {
position: absolute;
width: clamp(.3rem, .68vw, .63rem);
aspect-ratio: 1;
border-radius: 50%;
background: #e3fbff;
box-shadow: 0 0 .4rem .1rem #78d7ff, 0 0 .8rem .16rem #3882ff;
translate: -50% -50%;
animation: home-pipe-pulse 2.8s linear 2 both;
}
.home-pipe-flow span:nth-child(1) {
--pipe-start: 72% auto auto 27.4%; --pipe-turn: 64% auto auto 38.3%; --pipe-end: 59.1% auto auto 42.1%;
}
.home-pipe-flow span:nth-child(2) {
--pipe-start: 59.2% auto auto 64%; --pipe-turn: 64.2% auto auto 67.1%; --pipe-end: 70% auto auto 78.2%;
animation-delay: .35s;
}
.home-pipe-flow span:nth-child(3) {
--pipe-start: 42% auto auto 18.7%; --pipe-turn: 46.9% auto auto 23.4%; --pipe-end: 51% auto auto 29.8%;
animation-delay: .65s;
}
.home-pipe-flow span:nth-child(4) {
--pipe-start: 37% auto auto 77%; --pipe-turn: 42.5% auto auto 77%; --pipe-end: 47.7% auto auto 68.3%;
animation-delay: .9s;
}
@keyframes home-pipe-pulse {
0%, 16% { inset: var(--pipe-start); opacity: 0; }
21%, 67% { opacity: 1; }
40% { inset: var(--pipe-turn); }
72%, 100% { inset: var(--pipe-end); opacity: 0; }
.home-pipe-route { opacity: 0; animation: pipe-visibility 7s linear 2 both; }
.home-pipe-route use {
fill: none;
stroke: #2985fa;
stroke-width: 3;
stroke-linecap: round;
stroke-dasharray: 17 110;
stroke-dashoffset: 19;
opacity: .48;
animation: pipe-travel 7s linear 2 both;
}
.home-pipe-route use + use { stroke: #ecffff; stroke-width: 1.3; stroke-dasharray: 11 116; opacity: .95; }
.home-pipe-route:nth-of-type(2) { --pipe-delay: .85s; }
.home-pipe-route:nth-of-type(3) { --pipe-delay: 2.35s; }
.home-pipe-route:nth-of-type(4) { --pipe-delay: 3.2s; }
.home-pipe-route, .home-pipe-route use { animation-delay: var(--pipe-delay, 0s); }
@keyframes pipe-travel { 0%, 6% { stroke-dashoffset: 19; } 45%, 100% { stroke-dashoffset: -104; } }
@keyframes pipe-visibility { 0%, 6%, 45%, 100% { opacity: 0; } 13%, 37% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
.home-cursor { animation: none; }
.home-pipe-flow { display: none; }
@@ -544,16 +533,101 @@ progress { width: 100%; height: .8rem; accent-color: var(--accent); }
@media (max-width: 44rem) { .studio-split { grid-template-columns: 1fr; } }
:where(img, video, audio, .hero-visual)[class*="studio-media-"] { max-width: 100%; }
:is(.rich, .hero-inner, .editor-preview) .studio-media-25 { --studio-media-width: 25%; width: var(--studio-media-width); }
:is(.rich, .hero-inner, .editor-preview) .studio-media-40 { --studio-media-width: 40%; width: var(--studio-media-width); }
:is(.rich, .hero-inner, .editor-preview) .studio-media-50 { --studio-media-width: 50%; width: var(--studio-media-width); }
:is(.rich, .hero-inner, .editor-preview) .studio-media-60 { --studio-media-width: 60%; width: var(--studio-media-width); }
:is(.rich, .hero-inner, .editor-preview) .studio-media-75 { --studio-media-width: 75%; width: var(--studio-media-width); }
:is(.rich, .hero-inner, .editor-preview) .studio-media-85 { --studio-media-width: 85%; width: var(--studio-media-width); }
:is(.rich, .hero-inner, .editor-preview) .studio-media-100 { --studio-media-width: 100%; width: var(--studio-media-width); }
:is(.rich, .hero-inner, .editor-preview) [class*="studio-media-"] { width: var(--studio-media-width, auto); }
.studio-media-10 { --studio-media-width: 10%; }
.studio-media-11 { --studio-media-width: 11%; }
.studio-media-12 { --studio-media-width: 12%; }
.studio-media-13 { --studio-media-width: 13%; }
.studio-media-14 { --studio-media-width: 14%; }
.studio-media-15 { --studio-media-width: 15%; }
.studio-media-16 { --studio-media-width: 16%; }
.studio-media-17 { --studio-media-width: 17%; }
.studio-media-18 { --studio-media-width: 18%; }
.studio-media-19 { --studio-media-width: 19%; }
.studio-media-20 { --studio-media-width: 20%; }
.studio-media-21 { --studio-media-width: 21%; }
.studio-media-22 { --studio-media-width: 22%; }
.studio-media-23 { --studio-media-width: 23%; }
.studio-media-24 { --studio-media-width: 24%; }
.studio-media-25 { --studio-media-width: 25%; }
.studio-media-26 { --studio-media-width: 26%; }
.studio-media-27 { --studio-media-width: 27%; }
.studio-media-28 { --studio-media-width: 28%; }
.studio-media-29 { --studio-media-width: 29%; }
.studio-media-30 { --studio-media-width: 30%; }
.studio-media-31 { --studio-media-width: 31%; }
.studio-media-32 { --studio-media-width: 32%; }
.studio-media-33 { --studio-media-width: 33%; }
.studio-media-34 { --studio-media-width: 34%; }
.studio-media-35 { --studio-media-width: 35%; }
.studio-media-36 { --studio-media-width: 36%; }
.studio-media-37 { --studio-media-width: 37%; }
.studio-media-38 { --studio-media-width: 38%; }
.studio-media-39 { --studio-media-width: 39%; }
.studio-media-40 { --studio-media-width: 40%; }
.studio-media-41 { --studio-media-width: 41%; }
.studio-media-42 { --studio-media-width: 42%; }
.studio-media-43 { --studio-media-width: 43%; }
.studio-media-44 { --studio-media-width: 44%; }
.studio-media-45 { --studio-media-width: 45%; }
.studio-media-46 { --studio-media-width: 46%; }
.studio-media-47 { --studio-media-width: 47%; }
.studio-media-48 { --studio-media-width: 48%; }
.studio-media-49 { --studio-media-width: 49%; }
.studio-media-50 { --studio-media-width: 50%; }
.studio-media-51 { --studio-media-width: 51%; }
.studio-media-52 { --studio-media-width: 52%; }
.studio-media-53 { --studio-media-width: 53%; }
.studio-media-54 { --studio-media-width: 54%; }
.studio-media-55 { --studio-media-width: 55%; }
.studio-media-56 { --studio-media-width: 56%; }
.studio-media-57 { --studio-media-width: 57%; }
.studio-media-58 { --studio-media-width: 58%; }
.studio-media-59 { --studio-media-width: 59%; }
.studio-media-60 { --studio-media-width: 60%; }
.studio-media-61 { --studio-media-width: 61%; }
.studio-media-62 { --studio-media-width: 62%; }
.studio-media-63 { --studio-media-width: 63%; }
.studio-media-64 { --studio-media-width: 64%; }
.studio-media-65 { --studio-media-width: 65%; }
.studio-media-66 { --studio-media-width: 66%; }
.studio-media-67 { --studio-media-width: 67%; }
.studio-media-68 { --studio-media-width: 68%; }
.studio-media-69 { --studio-media-width: 69%; }
.studio-media-70 { --studio-media-width: 70%; }
.studio-media-71 { --studio-media-width: 71%; }
.studio-media-72 { --studio-media-width: 72%; }
.studio-media-73 { --studio-media-width: 73%; }
.studio-media-74 { --studio-media-width: 74%; }
.studio-media-75 { --studio-media-width: 75%; }
.studio-media-76 { --studio-media-width: 76%; }
.studio-media-77 { --studio-media-width: 77%; }
.studio-media-78 { --studio-media-width: 78%; }
.studio-media-79 { --studio-media-width: 79%; }
.studio-media-80 { --studio-media-width: 80%; }
.studio-media-81 { --studio-media-width: 81%; }
.studio-media-82 { --studio-media-width: 82%; }
.studio-media-83 { --studio-media-width: 83%; }
.studio-media-84 { --studio-media-width: 84%; }
.studio-media-85 { --studio-media-width: 85%; }
.studio-media-86 { --studio-media-width: 86%; }
.studio-media-87 { --studio-media-width: 87%; }
.studio-media-88 { --studio-media-width: 88%; }
.studio-media-89 { --studio-media-width: 89%; }
.studio-media-90 { --studio-media-width: 90%; }
.studio-media-91 { --studio-media-width: 91%; }
.studio-media-92 { --studio-media-width: 92%; }
.studio-media-93 { --studio-media-width: 93%; }
.studio-media-94 { --studio-media-width: 94%; }
.studio-media-95 { --studio-media-width: 95%; }
.studio-media-96 { --studio-media-width: 96%; }
.studio-media-97 { --studio-media-width: 97%; }
.studio-media-98 { --studio-media-width: 98%; }
.studio-media-99 { --studio-media-width: 99%; }
.studio-media-100 { --studio-media-width: 100%; }
.rich :is(img, video)[class*="studio-media-"] { height: auto; max-width: 100%; }
.hero-visual[class*="studio-media-"] { justify-self: center; }
[data-studio-editing] [data-studio-selected] { outline: 2px solid #4477f9; outline-offset: 3px; }
[data-studio-editing] [data-studio-selected] { outline: 1px dashed #315ef0; outline-offset: 3px; }
.rich .studio-intro { max-width: 47rem; }
.rich .studio-intro h3, .rich .studio-cover h3 { font-size: clamp(1.75rem, 4vw, 2.8rem); }
@@ -566,3 +640,10 @@ progress { width: 100%; height: .8rem; accent-color: var(--accent); }
@media (max-width: 44rem) {
.rich .studio-cover, .rich .studio-two-column { grid-template-columns: minmax(0, 1fr); }
}
.article-feed-note { margin-top: 1.15rem; }
.article-cover { display: block; max-height: 28rem; width: auto; margin-bottom: 1.75rem; object-fit: contain; }
.article-tabs { margin-bottom: .85rem; }
.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; }
+31
View File
@@ -22,6 +22,37 @@ jQuery(function ($) {
});
}
$('[data-article-tabs]').each(function () {
const $feed = $(this);
const $list = $feed.children('[data-tab-list]');
const $panels = $feed.children('[data-tab-panel]');
const $tabs = $list.children('[role="tab"]');
function selectTab(index, focus = false) {
$tabs.each(function (number) {
$(this).attr({'aria-selected': String(index === number), tabindex: index === number ? '0' : '-1'});
});
$panels.prop('hidden', true).eq(index).prop('hidden', false);
if (focus) $tabs.eq(index).trigger('focus');
}
$panels.each(function (index) {
$(this).attr({role: 'tabpanel', 'aria-labelledby': $tabs.eq(index).attr('id'), tabindex: '0'});
}).children('[data-tab-heading]').prop('hidden', true);
$list.prop('hidden', false);
selectTab(0);
$tabs.on('click', function () {
selectTab($tabs.index(this));
}).on('keydown', function (event) {
const index = $tabs.index(this);
const last = $tabs.length - 1;
const destinations = {ArrowLeft: index === 0 ? last : index - 1, ArrowRight: index === last ? 0 : index + 1, Home: 0, End: last};
if (!Object.hasOwn(destinations, event.key)) return;
event.preventDefault();
selectTab(destinations[event.key], true);
});
});
if ('IntersectionObserver' in window && !matchMedia('(prefers-reduced-motion: reduce)').matches) {
const observer = new IntersectionObserver((entries) => {
for (const entry of entries) {
+267 -49
View File
@@ -62,6 +62,7 @@ jQuery(function ($) {
});
}
$picker.on('studio:pick', (_event, type, callback) => openPicker(type, callback));
$picker.on('input', '[data-media-query]', renderPicker);
$picker.on('click', '[data-close-picker]', () => $picker.get(0).close());
$picker.on('click', '.picker-item', function () {
@@ -260,6 +261,17 @@ jQuery(function ($) {
const $studio = $(this);
const $frame = $studio.find('iframe');
const $window = $studio.find('.studio-frame-window');
const $layout = $studio.closest('.studio-layout');
const $settings = $layout.find('.studio-inspector');
const $sizing = $studio.find('[data-media-sizing]');
const $elementTools = $studio.find('[data-element-tools]');
const heroOrOptional = '[data-studio-field="accent"], [data-studio-field="lead"], [data-studio-part="lead"], [data-studio-action], [data-studio-nav-index]';
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]');
const $mediaSize = $sizing.find('[data-media-size]');
const mediaWidthClass = /^studio-media-\d+$/;
function fitPreview() {
const width = $window.width();
const height = $window.height();
@@ -273,24 +285,22 @@ jQuery(function ($) {
left: (width - viewport * scale) / 2,
transform: 'scale(' + scale + ')'
});
positionSelection();
}
const $presets = $layout.find('[data-canvas-presets]');
const $templateStatus = $presets.find('[data-template-status]');
const $pending = $presets.find('[data-template-pending]');
const heroControls = new Map();
let selectedElement;
let selectedMedia;
let mediaDrag;
const selectionObserver = 'ResizeObserver' in window ? new ResizeObserver(positionSelection) : null;
if ('ResizeObserver' in window) {
new ResizeObserver(fitPreview).observe($window.get(0));
} else {
$(window).on('resize', fitPreview);
}
fitPreview();
const $layout = $studio.closest('.studio-layout');
const $settings = $layout.find('.studio-inspector');
const $sizing = $studio.find('[data-media-sizing]');
const $width = $sizing.find('[data-media-width]');
const availableWidths = Array.from($width.get(0).options, ({value}) => value).filter((value) => value !== '0');
const sizeClasses = availableWidths.map((value) => 'studio-media-' + value);
const $presets = $layout.find('[data-canvas-presets]');
const $templateStatus = $presets.find('[data-template-status]');
const $pending = $presets.find('[data-template-pending]');
const heroControls = new Map();
let selectedMedia;
$studio.on('click', '[data-preview-size]', function () {
const $button = $(this);
$studio.toggleClass('studio-phone', $button.data('preview-size') === 'phone');
@@ -316,15 +326,20 @@ jQuery(function ($) {
let saveComplete = false;
function sectionChanges(withEdits = true) {
return sections.flatMap(({key, version, fields, source}) => {
return sections.flatMap(({key, version, fields, source, template}) => {
const changes = {};
for (const [field, {node, initial}] of Object.entries(fields)) {
const value = field === 'body' ? node.innerHTML : node.textContent;
let value = field === 'body' ? node.innerHTML : node.textContent;
if (field === 'body' && node.contains(selectedElement)) {
const copy = node.cloneNode(true);
$(copy).find('[data-studio-selected]').removeAttr('data-studio-selected');
value = copy.innerHTML;
}
if (version === null || value !== initial) {
changes[field] = withEdits && field === 'body' && version !== null ? bodyEdits(source, value) : value;
}
}
return Object.keys(changes).length ? [{key, version, fields: changes}] : [];
return Object.keys(changes).length ? [{key, version, fields: changes, ...(template ? {template} : {})}] : [];
});
}
@@ -459,6 +474,11 @@ jQuery(function ($) {
$image.attr('alt', pageInput('alt').val());
}
$settings.find('[name="image"], [name="alt"]').on('input.canvas', syncImage);
heroControls.set('remove-image', () => {
pageInput('alt').val('');
pageInput('image_scale').val(0);
pageInput('image').val('').trigger('input');
});
syncImage();
$image.attr({tabindex: '0', role: 'button', 'aria-label': '编辑首屏图片'});
heroControls.set('image', () => {
@@ -491,7 +511,7 @@ jQuery(function ($) {
}, null, true);
};
heroControls.set(index, editButton);
$button.on('click', (event) => {
$button.on('dblclick studio:properties', (event) => {
event.preventDefault();
editButton();
});
@@ -513,7 +533,8 @@ jQuery(function ($) {
const link = doc.createElement('a');
link.href = safeLink(url) ? url : '#';
link.textContent = label || url;
link.addEventListener('click', (event) => {
link.dataset.studioNavIndex = index;
$(link).on('dblclick studio:properties', (event) => {
event.preventDefault();
openProperties('本页目录链接', {label, url}, (next) => {
if (!next.label || /[|\r\n]/.test(next.label)) {
@@ -530,6 +551,14 @@ jQuery(function ($) {
}
$navigation.prop('hidden', !$navContent.children().length);
}
heroControls.set('change-nav', (index, copy) => {
const lines = navLines();
if (copy && $navContent.children().length >= 20) return null;
lines.splice(index + (copy ? 1 : 0), copy ? 0 : 1, ...(copy ? [lines[index]] : []));
$navInput.val(lines.join('\n'));
syncNavigation();
return $navContent.find('[data-studio-nav-index="' + (index + 1) + '"]').get(0);
});
$navInput.on('input.canvas', syncNavigation);
heroControls.set('navigation', () => {
openProperties('本页目录', {quicklinks: $navInput.val()}, ({quicklinks}) => {
@@ -592,48 +621,230 @@ 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});
sections.push({key: section.id, version, fields, source, template: section.dataset.studioTemplate});
}
function setMediaWidth(node, width) {
node.classList.remove(...sizeClasses);
if (availableWidths.includes(width)) node.classList.add('studio-media-' + width);
for (const token of Array.from(node.classList).filter((name) => mediaWidthClass.test(name))) {
node.classList.remove(token);
}
if (Number(width)) node.classList.add('studio-media-' + width);
else if (!node.classList.length) node.removeAttribute('class');
}
function selectMedia(node) {
selectedMedia?.removeAttribute('data-studio-selected');
selectedMedia = node;
if (!node) {
$sizing.prop('hidden', true);
function sizingTarget() {
if (!selectedMedia?.isConnected) return null;
return selectedMedia.hasAttribute('data-studio-hero-image') ? selectedMedia.parentElement : selectedMedia;
}
function frameScale() {
const frame = $frame.get(0);
return frame.getBoundingClientRect().width / frame.offsetWidth;
}
function previewBounds(node) {
const frame = $frame.get(0).getBoundingClientRect();
const container = $window.get(0);
const origin = container.getBoundingClientRect();
const bounds = node.getBoundingClientRect();
const scale = frameScale();
const x = frame.left - origin.left - container.clientLeft;
const y = frame.top - origin.top - container.clientTop;
return {
left: x + bounds.left * scale, right: x + bounds.right * scale,
top: y + bounds.top * scale, bottom: y + bounds.bottom * scale,
width: bounds.width * scale, height: bounds.height * scale,
};
}
function positionSelection() {
const container = $window.get(0);
const node = sizingTarget();
if (node) {
const bounds = previewBounds(node);
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;
$handle.prop('hidden', !mediaDrag && !visible);
$handle.css({left: Math.min(bounds.right, container.clientWidth - 11), top: y});
} else {
$handle.prop('hidden', true);
}
if (!selectedElement?.isConnected) {
$elementTools.prop('hidden', true);
return;
}
node.setAttribute('data-studio-selected', '');
const width = node.hasAttribute('data-studio-hero-image') ? pageInput('image_scale').val()
: availableWidths.find((value) => node.classList.contains('studio-media-' + value)) || '0';
$width.val(width);
$sizing.prop('hidden', false);
const bounds = previewBounds(selectedElement);
const visible = bounds.width > 0 && bounds.height > 0 && bounds.right > 0
&& bounds.left < container.clientWidth && bounds.bottom > 0 && bounds.top < container.clientHeight;
$elementTools.prop('hidden', !visible);
if (!visible) return;
const maxX = container.clientWidth - $elementTools.outerWidth() - 5;
const height = $elementTools.outerHeight();
const above = bounds.top - height - 5;
const below = bounds.bottom + 5;
const y = above >= 5 || below + height > container.clientHeight ? above : below;
$elementTools.css({
left: Math.max(5, Math.min(bounds.left, maxX)),
top: Math.max(5, Math.min(y, container.clientHeight - height - 5)),
});
}
function currentMediaWidth(node) {
return Number(Array.from(node.classList).find((name) => mediaWidthClass.test(name))?.slice('studio-media-'.length)) || 0;
}
function showMediaWidth(width) {
$mediaSize.text(width ? width + '%' : '原始尺寸');
$handle.attr({'aria-valuenow': width || 100, 'aria-valuetext': width ? width + '%' : '原始尺寸'});
}
function editableBodyElement(node) {
const body = node.closest('[data-studio-part="body"]');
if (!body) return null;
const element = node.closest(bodyElements);
return element !== body && body.contains(element) ? element : null;
}
function selectElement(node) {
selectionObserver?.disconnect();
selectedElement?.removeAttribute('data-studio-selected');
selectedElement = node;
selectedMedia = node?.matches(mediaTargets) ? node : null;
$sizing.prop('hidden', !selectedMedia);
if (node) {
node.setAttribute('data-studio-selected', '');
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');
$elementTools.find('[data-element-copy]').prop('hidden', !canCopy);
$elementTools.find('[data-element-properties]').prop('hidden', !hasProperties);
if (target) showMediaWidth(currentMediaWidth(target));
selectionObserver?.observe(target || node);
}
positionSelection();
}
function changeElement(copy) {
const node = selectedElement;
if (!node?.isConnected) return;
const {studioField, studioAction, studioNavIndex} = node.dataset;
const inBody = node.closest('[data-studio-part="body"]') !== null;
selectElement(null);
if (inBody) {
if (copy) {
const $clone = $(node.cloneNode(true));
$clone.find('[id]').addBack('[id]').removeAttr('id');
$(node).after($clone);
selectElement($clone.get(0));
} else {
$(node).remove();
savedRange = null;
}
} else if (studioNavIndex !== undefined) {
const next = heroControls.get('change-nav')(Number(studioNavIndex), copy);
if (copy && next) selectElement(next);
} else if (!copy) {
if (node.hasAttribute('data-studio-hero-image')) {
heroControls.get('remove-image')();
} else if (studioAction) {
pageInput('label' + studioAction).val('');
pageInput('url' + studioAction).val('').trigger('input');
} else if (studioField) {
pageInput(studioField).val('').trigger('input');
} else {
$(node).text('');
}
}
}
$elementTools.on('click', '[data-element-copy]', () => changeElement(true))
.on('click', '[data-element-delete]', () => changeElement(false))
.on('click', '[data-element-properties]', () => {
if (selectedMedia) replaceMedia();
else if (selectedElement?.matches('[data-studio-action], [data-studio-nav-index]')) {
$(selectedElement).triggerHandler('studio:properties');
} else if (selectedElement?.matches('a')) {
editResource(selectedElement);
}
}).on('keydown', (event) => {
if (event.key === 'Escape') selectElement(null);
});
function replaceMedia() {
if (!selectedMedia?.isConnected) return;
if (selectedMedia.hasAttribute('data-studio-hero-image')) heroControls.get('image')();
else editResource(selectedMedia);
}
$width.on('change', function () {
if (!selectedMedia?.isConnected) return;
const hero = selectedMedia.hasAttribute('data-studio-hero-image');
if (hero) pageInput('image_scale').val(this.value);
setMediaWidth(hero ? selectedMedia.parentElement : selectedMedia, this.value);
function measureMedia() {
const node = sizingTarget();
const width = currentMediaWidth(node);
const natural = node.getBoundingClientRect().width;
const classes = node.getAttribute('class');
setMediaWidth(node, 100);
const full = node.getBoundingClientRect();
setMediaWidth(node, 10);
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))};
}
function resizeMedia(width) {
const node = sizingTarget();
if (!node) return;
const next = width === null ? 0 : Math.round(Math.max(10, Math.min(100, width)));
if (selectedMedia.hasAttribute('data-studio-hero-image')) pageInput('image_scale').val(next);
if (next !== currentMediaWidth(node)) setMediaWidth(node, next);
showMediaWidth(next);
positionSelection();
}
$handle.on('pointerdown', function (event) {
const pointer = event.originalEvent;
if (pointer.button !== 0 || !sizingTarget()) return;
event.preventDefault();
this.focus({preventScroll: true});
mediaDrag = {...measureMedia(), x: pointer.clientX, scale: frameScale(), id: pointer.pointerId};
this.setPointerCapture(pointer.pointerId);
}).on('pointermove', (event) => {
const pointer = event.originalEvent;
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));
}
}).on('lostpointercapture', () => {
mediaDrag = null;
positionSelection();
}).on('keydown', (event) => {
if (!sizingTarget() || !['ArrowLeft', 'ArrowDown', 'ArrowRight', 'ArrowUp', 'Home', 'End'].includes(event.key)) return;
event.preventDefault();
const step = event.shiftKey ? 10 : 1;
const {initialWidth} = measureMedia();
const increase = ['ArrowRight', 'ArrowUp'].includes(event.key);
const next = {Home: 10, End: 100}[event.key] ?? initialWidth + (increase ? step : -step);
resizeMedia(next);
});
$sizing.on('click', '[data-replace-media]', replaceMedia);
$sizing.on('click', '[data-replace-media]', replaceMedia)
.on('click', '[data-reset-media]', () => resizeMedia(null));
$layout.on('click', '[data-hero-control]', function () {
heroControls.get(this.dataset.heroControl)?.();
});
$presets.on('mousedown', '[data-canvas-template]', (event) => event.preventDefault());
$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;
if ($presets.find('[data-template-inline]').prop('checked')) {
if (template === 'articles') {
$templateStatus.text('分类文章需要作为独立区块添加。');
return;
}
if (!activeBody) {
$templateStatus.text('先在画布中选择要插入的区块正文。');
return;
@@ -658,6 +869,11 @@ jQuery(function ($) {
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"]'));
}
end.before(section);
registerSection(section, null);
section.scrollIntoView({block: 'start'});
@@ -667,7 +883,7 @@ jQuery(function ($) {
$pending.prop('hidden', false);
$cancel.on('click', () => {
if (section.contains(activeBody)) selectBody(null);
if (section.contains(selectedMedia)) selectMedia(null);
if (section.contains(selectedElement)) selectElement(null);
section.remove();
sections = sections.filter(({key}) => key !== id);
$item.remove();
@@ -685,7 +901,7 @@ jQuery(function ($) {
$settings.find(':input').off('.canvas');
bindPage($doc);
selectBody(null);
selectMedia(null);
selectElement(null);
$pending.empty().prop('hidden', true);
sections = [];
$doc.find('[data-studio-section]').each((_, section) => registerSection(section));
@@ -693,30 +909,32 @@ jQuery(function ($) {
$doc.on('focusin.canvas', '[contenteditable]', function () {
selectBody(this.dataset.studioPart === 'body' ? this : null);
});
$doc.on('selectionchange.canvas', rememberSelection);
$doc.on('click.canvas', (event) => {
if (!event.target.closest?.('[data-studio-selected]')) selectMedia(null);
});
$doc.on('selectionchange.canvas', rememberSelection).on('scroll.canvas', positionSelection);
$doc.on('click.canvas auxclick.canvas', 'a', (event) => event.preventDefault());
const mediaTargets = '[data-studio-hero-image], [data-studio-part="body"] img, [data-studio-part="body"] audio, [data-studio-part="body"] video';
$doc.on('click.canvas dblclick.canvas', mediaTargets, function (event) {
event.preventDefault();
event.stopPropagation();
selectBody(this.closest('[data-studio-part="body"]'));
selectMedia(this);
selectElement(this);
if (event.type === 'dblclick') replaceMedia();
});
$doc.on('click.canvas', '[data-studio-part="body"] a', function (event) {
$doc.on('click.canvas', (event) => {
const node = event.target;
const optional = node.closest?.(heroOrOptional);
selectElement(doc.getSelection()?.isCollapsed ? optional || editableBodyElement(node) : null);
});
$doc.on('dblclick.canvas', '[data-studio-part="body"] a', function (event) {
event.preventDefault();
if ($(this).find('img, audio, video').length && event.target.closest('img, audio, video')) return;
selectBody(this.closest('[data-studio-part="body"]'));
editResource(this);
if (!event.target.closest(mediaTargets)) editResource(this);
});
$doc.on('keydown.canvas', (event) => {
if (event.key === 'Escape') selectElement(null);
});
$doc.on('keydown.canvas', '[data-studio-hero-image]', function (event) {
if (event.key === 'Enter' || event.key === ' ') {
event.preventDefault();
selectMedia(this);
$width.trigger('focus');
selectElement(this);
$handle.trigger('focus');
}
});
$doc.on('beforeinput.canvas', '[contenteditable="plaintext-only"]', (event) => {
Binary file not shown.

After

Width:  |  Height:  |  Size: 7.4 KiB

+21
View File
@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2020 NHN Cloud Corp.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+162
View File
@@ -0,0 +1,162 @@
/*!
* TOAST UI Editor : i18n
* @version 3.2.2
* @author NHN Cloud FE Development Lab <dl_javascript@nhn.com>
* @license MIT
*/
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory(require("@toast-ui/editor"));
else if(typeof define === 'function' && define.amd)
define(["@toast-ui/editor"], factory);
else {
var a = typeof exports === 'object' ? factory(require("@toast-ui/editor")) : factory(root["toastui"]["Editor"]);
for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];
}
})(self, function(__WEBPACK_EXTERNAL_MODULE__213__) {
return /******/ (function() { // webpackBootstrap
/******/ "use strict";
/******/ var __webpack_modules__ = ({
/***/ 213:
/***/ (function(module) {
module.exports = __WEBPACK_EXTERNAL_MODULE__213__;
/***/ })
/******/ });
/************************************************************************/
/******/ // The module cache
/******/ var __webpack_module_cache__ = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache
/******/ var cachedModule = __webpack_module_cache__[moduleId];
/******/ if (cachedModule !== undefined) {
/******/ return cachedModule.exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = __webpack_module_cache__[moduleId] = {
/******/ // no module.id needed
/******/ // no module.loaded needed
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/************************************************************************/
/******/ /* webpack/runtime/compat get default export */
/******/ !function() {
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function() { return module['default']; } :
/******/ function() { return module; };
/******/ __webpack_require__.d(getter, { a: getter });
/******/ return getter;
/******/ };
/******/ }();
/******/
/******/ /* webpack/runtime/define property getters */
/******/ !function() {
/******/ // define getter functions for harmony exports
/******/ __webpack_require__.d = function(exports, definition) {
/******/ for(var key in definition) {
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
/******/ }
/******/ }
/******/ };
/******/ }();
/******/
/******/ /* webpack/runtime/hasOwnProperty shorthand */
/******/ !function() {
/******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }
/******/ }();
/******/
/******/ /* webpack/runtime/make namespace object */
/******/ !function() {
/******/ // define __esModule on exports
/******/ __webpack_require__.r = function(exports) {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/ }();
/******/
/************************************************************************/
var __webpack_exports__ = {};
// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
!function() {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _editorCore__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(213);
/* harmony import */ var _editorCore__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_editorCore__WEBPACK_IMPORTED_MODULE_0__);
/**
* @fileoverview I18N for Chinese
* @author NHN Cloud FE Development Lab <dl_javascript@nhn.com>
*/
_editorCore__WEBPACK_IMPORTED_MODULE_0___default().setLanguage('zh-CN', {
Markdown: 'Markdown',
WYSIWYG: '所见即所得',
Write: '编辑',
Preview: '预览',
Headings: '标题',
Paragraph: '文本',
Bold: '加粗',
Italic: '斜体字',
Strike: '删除线',
Code: '内嵌代码',
Line: '水平线',
Blockquote: '引用块',
'Unordered list': '无序列表',
'Ordered list': '有序列表',
Task: '任务',
Indent: '缩进',
Outdent: '减少缩进',
'Insert link': '插入链接',
'Insert CodeBlock': '插入代码块',
'Insert table': '插入表格',
'Insert image': '插入图片',
Heading: '标题',
'Image URL': '图片网址',
'Select image file': '选择图片文件',
'Choose a file': '选择一个文件',
'No file': '没有文件',
Description: '说明',
OK: '确认',
More: '更多',
Cancel: '取消',
File: '文件',
URL: 'URL',
'Link text': '链接文本',
'Add row to up': '向上添加行',
'Add row to down': '在下方添加行',
'Add column to left': '在左侧添加列',
'Add column to right': '在右侧添加列',
'Remove row': '删除行',
'Remove column': '删除列',
'Align column to left': '左对齐',
'Align column to center': '居中对齐',
'Align column to right': '右对齐',
'Remove table': '删除表格',
'Would you like to paste as table?': '需要粘贴为表格吗?',
'Text color': '文字颜色',
'Auto scroll enabled': '自动滚动已启用',
'Auto scroll disabled': '自动滚动已禁用',
'Choose language': '选择语言',
});
}();
/******/ return __webpack_exports__;
/******/ })()
;
});