components
All repositories: gitoria
7.3 KB
// tests/md-paste.mjs — components#20: copy / cut / paste in the MdEditor, with REAL keys (Ctrl+C / X / V as editing commands on the// browser's own clipboard) and with pasted clipboards that carry plain text only or text/html too (as when copied from a rendered page).// The page must be /md-editor (editor 2, "summary", starts empty). mdPaste(page, { check, sleep, label }) runs in that one tab.export async function mdPaste(page, { check, sleep, label = '' }) {const L = label ? `[${label}] ` : '';const send = (m, p) => page.send(m, p);const CTRL = 2;const key = async (k, code, vk, text, modifiers = 0, commands) => {await send('Input.dispatchKeyEvent', { type: text !== undefined ? 'keyDown' : 'rawKeyDown', key: k, code, windowsVirtualKeyCode: vk, text, modifiers, commands });await send('Input.dispatchKeyEvent', { type: 'keyUp', key: k, code, windowsVirtualKeyCode: vk, modifiers });await sleep(40);};const chord = (ch, command) => key(ch, 'Key' + ch.toUpperCase(), ch.toUpperCase().charCodeAt(0), undefined, CTRL, command ? [command] : undefined);const ev = (e) => page.evaluate(e);const E = `document.querySelectorAll('md-editor')[1]`;const val = () => ev(`${E}.querySelector('input.value').value`);const focusEditor = async () => {await page.click('md-editor:nth-of-type(2) article');await page.waitFor(`${E}.querySelector('article').contains(document.activeElement)`, { label: 'editor focused' });};// the editor emptied through its Markdown source (real clicks and keys), like tests/md-keys.mjsconst fresh = async () => {await page.click('md-editor:nth-of-type(2) footer button'); await sleep(200);await page.click('md-editor:nth-of-type(2) textarea');await chord('a'); await key('Backspace', 'Backspace', 8); await sleep(120);await page.click('md-editor:nth-of-type(2) footer button'); await sleep(250);await focusEditor(); await sleep(60);};// a paste the way a browser delivers it: a real paste event with a DataTransfer that holds exactly these formats// (Input.insertText has no clipboard event; this is the one place a clipboard with text/html is made, for the page-copied case)const pasteData = (formats) => ev(`(() => {const a = ${E}.querySelector('article'); a.focus();const dt = new DataTransfer(); for (const [k, v] of Object.entries(${JSON.stringify(formats)})) dt.setData(k, v);a.dispatchEvent(new ClipboardEvent('paste', { clipboardData: dt, bubbles: true, cancelable: true }));})()`);const plain = 'first line\nsecond line\nthird line';await focusEditor(); await fresh();// 1. real type, select all, Ctrl+C, collapse to the end, Ctrl+V twice: the text comes backfor (const ch of 'alpha beta') await key(ch, '', undefined, ch);await chord('a'); await chord('c', 'copy');await key('End', 'End', 35); await chord('v', 'paste'); await sleep(250);const v1 = await val();check(L + 'copy all then paste at the end gives the text twice', v1.replace(/\s+/g, ' ').trim() === 'alpha betaalpha beta', JSON.stringify(v1));// 2. Ctrl+X then Ctrl+V puts the cut text backawait fresh();for (const ch of 'gamma delta') await key(ch, '', undefined, ch);await chord('a'); await chord('x', 'cut'); await sleep(150);const cutLeft = await val();await chord('v', 'paste'); await sleep(250);const v2 = await val();check(L + 'cut empties the editor', cutLeft.trim() === '', JSON.stringify(cutLeft));check(L + 'cut then paste gives the cut text back', v2.trim() === 'gamma delta', JSON.stringify(v2));// 3. plain text with several lines, cursor in the middle of existing textawait fresh();for (const ch of 'startend') await key(ch, '', undefined, ch);for (let i = 0; i < 3; i++) await key('ArrowLeft', 'ArrowLeft', 37);await pasteData({ 'text/plain': 'one\ntwo\nthree' }); await sleep(250);const v3 = await val();check(L + 'plain multi-line paste in the middle of text keeps all the words', ['start', 'one', 'two', 'three', 'end'].every(w => v3.includes(w)) && v3.indexOf('start') < v3.indexOf('one') && v3.indexOf('three') < v3.indexOf('end'), JSON.stringify(v3));// 4. text copied from a rendered page (text/html + text/plain), several lines, in the middle of textawait fresh();for (const ch of 'headtail') await key(ch, '', undefined, ch);for (let i = 0; i < 4; i++) await key('ArrowLeft', 'ArrowLeft', 37);await pasteData({ 'text/plain': plain, 'text/html': '<meta charset="utf-8"><p>first line</p><p>second line</p><p>third line</p>' }); await sleep(250);const v4 = await val();check(L + 'html+plain paste in the middle of text keeps the lines in order', v4.indexOf('head') < v4.indexOf('first line') && v4.indexOf('first line') < v4.indexOf('second line') && v4.indexOf('second line') < v4.indexOf('third line') && v4.indexOf('third line') < v4.indexOf('tail'), JSON.stringify(v4));// 5. empty editor, plain text equals the valueawait fresh();await pasteData({ 'text/plain': plain }); await sleep(250);const v5 = await val();check(L + 'multi-line plain paste into an empty editor equals the text', v5.trim() === plain || v5.replace(/\n+/g, '\n').trim() === plain, JSON.stringify(v5));// 6. a document with a heading, bold, a link, code, lists: select all, Ctrl+C, empty the editor, Ctrl+V -> the same Markdown// (the browser's own plain text of the selection has the marks stripped and the lists run together)const doc = '# Head\n\nSome `code` and a [link](https://x.org) and **bold** words.\n\n- one\n- two\n\n1. a\n2. b';await fresh();await page.click('md-editor:nth-of-type(2) footer button'); await sleep(200);await page.click('md-editor:nth-of-type(2) textarea');await send('Input.insertText', { text: doc }); await sleep(250);await page.click('md-editor:nth-of-type(2) footer button'); await sleep(300);await focusEditor();await chord('a'); await chord('c', 'copy'); await sleep(100);await ev(`(() => { const a = ${E}.querySelector('article'); a.focus(); const r = document.createRange(); r.selectNodeContents(a); getSelection().removeAllRanges(); getSelection().addRange(r); })()`);await key('Backspace', 'Backspace', 8); await sleep(150);await ev(`(() => { const a = ${E}.querySelector('article'); a.innerHTML = '<p><br></p>'; a.focus(); })()`);await chord('v', 'paste'); await sleep(300);const v6 = await val();check(L + 'copy a formatted document, paste it into an emptied editor: the same Markdown', v6.trim() === doc, JSON.stringify(v6));// 7. cut one word with a real Shift+Arrow selection, paste it back at the end: the word comes backawait fresh();for (const ch of 'say loud') await key(ch, '', undefined, ch);for (let i = 0; i < 4; i++) await key('ArrowLeft', 'ArrowLeft', 37, undefined, 8);await chord('x', 'cut'); await sleep(200);const cutRest = await val();await key('End', 'End', 35); await chord('v', 'paste'); await sleep(300);const v7 = await val();check(L + 'cut a word, paste it at the end: it comes back', cutRest.trim() === 'say' && v7.replace(/\s+/g, '').includes('sayloud'), JSON.stringify([cutRest, v7]));// 8. a clipboard with text/html and no text/plain (copied from some apps and pages): the pasted text arrivesawait fresh();await pasteData({ 'text/html': '<meta charset="utf-8"><p>first line</p><p>second line</p>' }); await sleep(250);const v8 = await val();check(L + 'html-only paste gives the text of its blocks', v8.includes('first line') && v8.includes('second line'), JSON.stringify(v8));}
Branches
Latest commits
- b2980734Merge mp-player: the media player (components/media-player), its demo and the media iconsmre
- 1c41293eMediaPlayer: back / forward 10 s as replay / forward 10 icons (circular arrow with a 10), the play button keeps its surface background on audio and video, the media route's range end is a letmre
- 9e1ab228MP: report, LOG line, STATUS entrymre
- dd003e5dMediaPlayer: audio and video in one phone-first player (components/media-player), its demo /media-player with a queue, the media icons in components/icons, the demo's media files served with ranges (lib/media.hl), 35 gate checksmre
- e54f83adMdEditor: text typed before the editor is built is kept (the build takes it in once, the input handler no longer writes it to the field first), tickets#35mre
- 8c920932gate: the 11 old drop-zone checks now test the one-box pick mode (drop anywhere in the box, Choose files button inside it, no drop zone)mre
- 626de199MdEditor: copy and cut put the selection's Markdown on the clipboard, a clipboard with HTML only pastes its text, gate checks for copy, cut and paste (components#20)mre
- 5228126dUX: components synced from the tickets/layouts UX mission (comments: State select in the footer and button words; files-upload: one-box pick mode; modal: footer rule for its own footer). WIP: the gate's #18 pick-mode checks still expect the old drop zone (11 fail), see the UX2 reportmre
- 0a9216fbMdEditor: a Table button in the toolbar, a typed pipe row fills the cells, tables take the page theme's look; gate checks updated for 12 toolbar buttonsmre
- f9d405c8comments: reactions row half as far from its comment (creator 2026-10-24: 'half this distance please'); the 44 px tap targets staymre
- 4922f9cfsessions last 99 years (creator 2026-10-23: logins never expire; only sign out ends them)mre
- 0355975areports/MC-mobile.md, LOG, STATUS (MC)mre
- 3f0a7229Month view, date picker, range picker: names follow the page language (English by default, not the browser's), weekday/month names formatted in UTC (a UTC+12 zone showed Tue first), 44 px day cells and buttons, Send row air; gate checks at 390 px for every page, popup and dialog (MC)mre
- 29eb07eaPhone: 44 px targets on the site (brand, home links, buttons), comments, modal and pagination; the header is the brand alone on a phone; comments demo: labelled 'You are' group with the chosen user pressed (MC)mre
- d1cc83e2reports/E2-toolbar.mdmre
- 214c3183MdEditor on a phone: toolbar as two even rows of 44 px targets (no clipped icon, no swipe), 'Markdown source' label 15 px, table head 16 px; gate checks (E2)mre
- 9215bbaareports/F5-empty.mdmre
- 134b4e3eMdEditor: an editor the framework puts into the page is built at once (page observer), a surface put in anew under a built editor is redrawn; gates for both (hybriel#211)mre
- 0dce2899reports/K1-bubble.mdmre
- 6b0936a0comments: 'edited' foldable also drops the theme's border, margin and radius (display: contents alone left them computed)mre