File size: 3,428 Bytes
ef987bb | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | <!doctype html>
<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>Paragraph Editor</title>
<style>
:root{font-family:Inter,-apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif;color:#1d2939;background:#f5f7fb}
*{box-sizing:border-box}body{max-width:860px;margin:0 auto;padding:64px 28px 80px}
h1{font-size:34px;letter-spacing:-.04em;margin:0 0 10px}.intro{color:#667085;line-height:1.7;margin:0 0 30px}
.toolbar{display:flex;align-items:center;gap:10px;padding:13px 18px;border:1px solid #e6eaf0;border-bottom:0;border-radius:16px 16px 0 0;background:#fff;color:#344054;font-size:13px;font-weight:700;letter-spacing:.03em}
.toolbar:before{content:"";width:8px;height:8px;border-radius:50%;background:#5865d9;box-shadow:0 0 0 4px #eef0ff}
.block{min-height:69px;margin:0;padding:21px 24px;border:1px solid #e6eaf0;border-bottom:0;background:#fff;line-height:1.6;white-space:pre-wrap;overflow-wrap:anywhere;cursor:text;transition:background .15s,border-color .15s}
.block:hover{background:#fbfcff}.block:focus-within{background:#fff;border-color:#a5aaf1;box-shadow:inset 3px 0 #5865d9}
.block:nth-of-type(4){border-bottom:1px solid #e6eaf0;border-radius:0 0 16px 16px;box-shadow:0 15px 40px rgba(28,44,75,.06)}
.empty::before{content:"Click to enter paragraph text…";color:#98a2b3}
textarea{display:block;width:100%;min-height:52px;padding:0;resize:vertical;border:0;outline:0;background:transparent;color:inherit;font:inherit}
footer.hint{margin-top:18px;color:#98a2b3;font-size:13px;text-align:right}
@media(max-width:600px){body{padding:36px 16px}h1{font-size:28px}.block{padding:18px}}
</style></head>
<body>
<h1>Notion-like editor</h1>
<p class="intro">Click any paragraph to edit it. Click outside the paragraph to finish editing; your text will be preserved.</p>
<div class="toolbar"><span>Paragraph Editor</span></div>
<div data-testid="block-1" class="block empty"></div>
<div data-testid="block-2" class="block empty"></div>
<div data-testid="block-3" class="block empty"></div>
<footer class="hint">3 paragraph blocks</footer>
<script>
let active = null;
function commit(block) {
if (!block) return;
const input = block.querySelector('[data-testid="active-input"]');
if (!input) return;
const value = input.value.trim();
block.textContent = value;
localStorage.setItem('review-block:'+block.dataset.testid,value);
block.classList.toggle('empty', value.length === 0);
}
document.querySelectorAll('.block').forEach(block => {
const old=localStorage.getItem('review-block:'+block.dataset.testid);if(old!==null){block.textContent=old;block.classList.toggle('empty',old.length===0);}
block.addEventListener('click', event => {
event.stopPropagation();
if (active && active !== block) commit(active);
if (!block.querySelector('[data-testid="active-input"]')) {
const value = block.classList.contains('empty') ? '' : block.textContent.trim();
block.classList.remove('empty');
block.textContent='';const editor=document.createElement('textarea');editor.dataset.testid='active-input';editor.value=value;block.appendChild(editor);
}
active = block;
});
});
document.addEventListener('click', () => { commit(active); active = null; });
</script>
</body></html>
|