UI: редактор ответа и записи – поле сразу под именем, «прикрепить» в нижней панели, миниатюры

Текст пишется в колонке справа от аватара сразу под именем (и строкой
«В канал …»), без пустого места; «прикрепить» – слева в нижней панели,
«Очистить» – в шапке, пока есть текст или вложения; счётчик символов
показывается только с 1500 знаков. Картинки и видео во вложениях – миниатюрами
с крестиком (видео со значком воспроизведения), прочие файлы – строкой.
Нижняя панель на flex: на 320 px ничего не выходит за край, выбор типа записи
сжимается.
This commit is contained in:
q
2026-10-11 23:55:41 +03:00
parent 58de6a025d
commit b5ce7b0fa0
4 changed files with 92 additions and 23 deletions
+1 -1
View File
@@ -1,2 +1,2 @@
client.version=1.18.5
client.version=1.18.6
server.version=1.14.0
+1 -1
View File
@@ -39,7 +39,7 @@
}());
</script>
<script>
window.__SHINE_BUILD_HASH__ = '20261012001500';
window.__SHINE_BUILD_HASH__ = '20261012004500';
window.__SHINE_CLIENT_VERSION__ = '1.2.10';
</script>
<script>
+58 -9
View File
@@ -6,6 +6,7 @@ import { state } from '../state.js';
import { toUserMessage } from '../services/ui-error-texts.js';
import { renderUserAvatar } from './avatar-image.js';
import { openAuthRequiredModal } from '../services/auth-required-modal.js';
import { resolvePublicFileUrl } from '../services/public-file-service.js';
const drafts = new Map();
@@ -14,6 +15,24 @@ function draftKey(key) {
return `${login}:${String(key || 'editor')}`;
}
// Превью вложения в редакторе: картинки и видео – миниатюрой (как в Threads), остальное – строкой с именем.
const previewUrls = new Map();
function attachmentKind(item) {
const name = String(item?.name || '').toLowerCase();
if (/\.(jpe?g|png|gif|webp|avif|heic|bmp)$/.test(name)) return 'image';
if (/\.(mp4|webm|mov|m4v|ogv)$/.test(name)) return 'video';
return 'file';
}
function attachmentPreviewUrl(item, login) {
const key = item?.ar ? `ar:${item.ar}` : `sha:${item?.sha256 || ''}`;
if (!previewUrls.has(key)) {
previewUrls.set(key, item?.ar
? Promise.resolve(`${String(state.entrySettings.arweaveServer || 'https://arweave.net').replace(/\/$/, '')}/${item.ar}`)
: resolvePublicFileUrl({ sha256: item?.sha256, authorLogin: login, solanaEndpoint: state.entrySettings.solanaServer, fallbackServerLogin: state.entrySettings.shineServerLogin }).catch(() => ''));
}
return previewUrls.get(key);
}
function attachmentLabel(item) {
const name = String(item?.name || 'Файл');
const size = Number(item?.size || 0);
@@ -88,7 +107,9 @@ export function openChannelEditor({
const draftMark = document.createElement('span');
draftMark.className = 'channel-editor__draft';
draftMark.textContent = 'Черновик';
header.append(closeButton, heading, draftMark);
const headerEnd = document.createElement('div');
headerEnd.className = 'channel-editor__header-end';
header.append(closeButton, heading, headerEnd);
const body = document.createElement('div');
body.className = 'channel-editor__body';
@@ -147,6 +168,7 @@ export function openChannelEditor({
const textarea = document.createElement('textarea');
textarea.className = 'channel-editor__input';
textarea.rows = 1;
textarea.maxLength = 2000;
textarea.placeholder = placeholder;
textarea.setAttribute('aria-label', placeholder);
@@ -163,7 +185,7 @@ export function openChannelEditor({
const clearButton = document.createElement('button');
clearButton.type = 'button';
clearButton.className = 'text-btn channel-editor__clear';
clearButton.textContent = 'Очистить черновик';
clearButton.textContent = 'Очистить';
const author = document.createElement('div');
author.className = 'channel-editor__author';
@@ -190,14 +212,13 @@ export function openChannelEditor({
attachButton.innerHTML = `${iconHtml('image')}<span class="sr-only">Прикрепить фото, видео или файл</span>`;
attachButton.title = 'Фото, видео или файл';
attachButton.hidden = !allowAttachments;
// Как в Threads: текст пишется прямо под именем, без рамки; под ним – вложения и иконка «прикрепить».
// Как в Threads: текст пишется прямо под именем, без рамки; под ним – вложения.
// «Прикрепить» – в нижней панели у кнопки отправки, «Очистить» – в шапке, пока есть что очищать.
const compose = document.createElement('div');
compose.className = 'channel-editor__compose';
const tools = document.createElement('div');
tools.className = 'channel-editor__tools';
tools.append(attachButton, clearButton);
compose.append(textarea, attachmentsBox, tools, error);
body.append(compose);
compose.append(textarea, attachmentsBox, error);
authorText.append(compose);
headerEnd.append(clearButton, draftMark);
const counter = document.createElement('span');
counter.className = 'channel-editor__counter';
const submitButton = document.createElement('button');
@@ -205,6 +226,7 @@ export function openChannelEditor({
submitButton.className = 'primary-btn channel-editor__submit';
submitButton.textContent = submitLabel;
submitButton.title = 'Отправить · Ctrl+Enter / ⌘+Enter';
footer.append(attachButton);
if (extraControl instanceof Node) {
footer.classList.add('has-extra');
footer.append(extraControl);
@@ -223,15 +245,42 @@ export function openChannelEditor({
const sync = () => {
textarea.style.height = 'auto';
textarea.style.height = `${Math.max(48, textarea.scrollHeight)}px`;
textarea.style.height = `${Math.max(24, textarea.scrollHeight)}px`;
const length = textarea.value.length;
counter.textContent = `${length} / 2000`;
counter.classList.toggle('is-near-limit', length >= 1800);
// Счётчик нужен только у предела, пустой «0 / 2000» лишь шумит.
counter.classList.toggle('is-hidden', length < 1500);
submitButton.disabled = inFlight || picking || length > textarea.maxLength || (!allowEmptyText && !textarea.value.trim() && attachments.length === 0);
dialog.setAttribute('aria-busy', String(inFlight || picking));
clearButton.hidden = !textarea.value && attachments.length === 0;
draftMark.hidden = !clearButton.hidden;
attachmentsBox.replaceChildren();
attachments.forEach((item, index) => {
const kind = attachmentKind(item);
if (kind !== 'file') {
const thumb = document.createElement('div');
thumb.className = `channel-editor__thumb channel-editor__thumb--${kind}`;
thumb.title = attachmentLabel(item);
const media = document.createElement(kind === 'image' ? 'img' : 'video');
if (kind === 'image') media.alt = String(item?.name || 'Изображение');
else { media.muted = true; media.preload = 'metadata'; media.playsInline = true; }
void attachmentPreviewUrl(item, login).then((url) => { if (url && media.isConnected !== false) media.src = url; });
const remove = document.createElement('button');
remove.type = 'button';
remove.className = 'channel-editor__thumb-remove';
remove.setAttribute('aria-label', `Убрать вложение ${item?.name || ''}`);
remove.innerHTML = iconHtml('close');
remove.disabled = inFlight;
remove.addEventListener('click', () => {
attachments.splice(index, 1);
saveDraft();
sync();
});
thumb.append(media, remove);
attachmentsBox.append(thumb);
return;
}
const card = document.createElement('div');
card.className = 'channel-editor__attachment';
const label = document.createElement('span');
+32 -12
View File
@@ -166,9 +166,8 @@
.channel-editor__footer {
min-height: calc(68px + env(safe-area-inset-bottom));
padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
padding: 12px 16px calc(12px + env(safe-area-inset-bottom)) 8px;
display: grid;
grid-template-columns: minmax(0, 1fr) auto;
align-items: center;
gap: 10px;
border-top: 1px solid var(--border-subtle);
@@ -192,7 +191,6 @@
background: var(--surface-selected);
}
.channel-editor__footer.has-extra { grid-template-columns: auto minmax(0, 1fr) auto; }
.channel-editor__type { display: block; min-width: 0; }
.channel-editor__type-select { min-height: 44px; width: auto; max-width: 9.5rem; padding-left: 12px; border-radius: 12px; font-size: .875rem; }
@@ -216,7 +214,6 @@
}
@media (max-width: 400px) {
.channel-editor__footer.has-extra .channel-editor__counter { display: none; }
}
@media (prefers-reduced-motion: reduce) {
@@ -227,12 +224,35 @@
.channel-editor__draft { justify-self: end; color: var(--text-secondary); font-size: .75rem; }
.channel-editor__close svg { width: 24px; height: 24px; }
/* Поле ввода как в Threads: без рамки, под именем автора, с отступом под аватар; вложения и «прикрепить» – ниже текста. */
.channel-editor__compose { display: grid; gap: 8px; margin: -8px 0 0 52px; }
.channel-editor__compose .channel-editor__input { min-height: 48px; padding: 0; border: 0; border-radius: 0; background: transparent; }
/* Поле ввода как в Threads: без рамки, в колонке справа от аватара – под именем (и строкой «В канал …»); вложения – ниже текста. */
.channel-editor__author { align-items: flex-start; }
.channel-editor__author-text { flex: 1; padding-top: 1px; }
.channel-editor__compose { display: grid; gap: 8px; margin-top: 4px; }
.channel-editor__compose .channel-editor__input { flex: none; min-height: 24px; padding: 0; border: 0; border-radius: 0; background: transparent; line-height: 24px; }
.channel-editor__compose .channel-editor__input:focus-visible { border: 0; }
.channel-editor__tools { display: flex; align-items: center; gap: 4px; margin-left: -10px; }
.channel-editor__tools .channel-editor__attach { width: 44px; height: 44px; padding: 0; display: grid; place-items: center; border: 0; border-radius: 50%; background: transparent; color: var(--text-secondary); }
.channel-editor__tools .channel-editor__attach:hover { color: var(--text-primary); }
.channel-editor__tools .channel-editor__clear { margin-left: auto; }
.channel-editor__tools .channel-editor__attach svg { width: 22px; height: 22px; }
.channel-editor__compose .channel-editor__error:empty { display: none; }
/* Нижняя панель: «прикрепить» и тип записи слева, счётчик (только у предела) и отправка – справа; ничего не вылезает за край. */
.channel-editor__footer { display: flex; align-items: center; gap: 8px; }
.channel-editor__footer .channel-editor__attach { flex: none; width: 44px; height: 44px; padding: 0; display: grid; place-items: center; border: 0; border-radius: 50%; background: transparent; color: var(--accent); }
.channel-editor__footer .channel-editor__attach:hover { background: var(--surface-selected); }
.channel-editor__footer .channel-editor__attach svg { width: 24px; height: 24px; }
.channel-editor__footer .channel-editor__type { flex: 0 1 auto; min-width: 0; }
.channel-editor__footer .channel-editor__type-select { width: 100%; max-width: 9.5rem; min-width: 0; text-overflow: ellipsis; }
/* Колонка редактора не должна раздуваться содержимым шире экрана. */
.channel-editor { grid-template-columns: minmax(0, 1fr); }
.channel-editor__footer, .channel-editor__body { min-width: 0; }
.channel-editor__footer .channel-editor__counter { margin-left: auto; }
.channel-editor__footer .channel-editor__counter.is-hidden { display: none; }
.channel-editor__footer .channel-editor__counter.is-hidden + .channel-editor__submit { margin-left: auto; }
.channel-editor__footer .channel-editor__submit { flex: none; }
/* Миниатюры картинок и видео – лентой, крестик в углу. */
.channel-editor__compose .channel-editor__attachments { display: flex; flex-wrap: wrap; gap: 8px; }
.channel-editor__compose .channel-editor__attachment { flex: 1 1 100%; }
.channel-editor__thumb { position: relative; width: 120px; height: 150px; overflow: hidden; border: 1px solid var(--border-subtle); border-radius: 12px; background: var(--surface-selected); }
.channel-editor__thumb img, .channel-editor__thumb video { display: block; width: 100%; height: 100%; object-fit: cover; }
.channel-editor__thumb-remove { position: absolute; top: 6px; right: 6px; width: 28px; height: 28px; padding: 0; display: grid; place-items: center; border: 0; border-radius: 50%; background: rgb(0 0 0 / .6); color: #fff; cursor: pointer; }
.channel-editor__thumb-remove svg { width: 16px; height: 16px; }
.channel-editor__thumb--video::after { content: ''; position: absolute; left: 8px; bottom: 8px; width: 24px; height: 24px; border-radius: 50%; background: rgb(0 0 0 / .6) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M9 7v10l8-5z' fill='white'/%3E%3C/svg%3E") center / 18px no-repeat; pointer-events: none; }
.channel-editor__header-end { justify-self: end; display: flex; align-items: center; }
.channel-editor__header-end .channel-editor__clear { min-height: 44px; padding: 0 4px; }
.channel-editor__header-end [hidden] { display: none; }