@astryxdesign/richtext 0.7.2-canary.3fb6d7f → 0.7.2-canary.405bb94
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"editorTheme.d.ts","sourceRoot":"","sources":["../src/editorTheme.ts"],"names":[],"mappings":"AA2BA,OAAO,KAAK,EAAC,kBAAkB,EAAC,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"editorTheme.d.ts","sourceRoot":"","sources":["../src/editorTheme.ts"],"names":[],"mappings":"AA2BA,OAAO,KAAK,EAAC,kBAAkB,EAAC,MAAM,SAAS,CAAC;AA0bhD;;;GAGG;AACH,wBAAgB,iBAAiB,IAAI,kBAAkB,CAgEtD"}
|
package/dist/editorTheme.js
CHANGED
|
@@ -179,6 +179,9 @@ const editorTheme = {
|
|
|
179
179
|
table: {
|
|
180
180
|
kLvRdT: "x1mwwwfo",
|
|
181
181
|
kzqmXN: "xh8yej3",
|
|
182
|
+
kMzoRj: "x1litavf",
|
|
183
|
+
ksu8eU: "x1y0btm7",
|
|
184
|
+
kVAM5u: "x14i3s5s",
|
|
182
185
|
$$css: true
|
|
183
186
|
},
|
|
184
187
|
tableRow: {
|
|
@@ -194,6 +197,9 @@ const editorTheme = {
|
|
|
194
197
|
k9WMMc: "x1yc453h",
|
|
195
198
|
kXLuUW: "xxymvpz",
|
|
196
199
|
kHjlTd: "x1mzt3pk",
|
|
200
|
+
ke9TFa: "xw8tdv1 x1qlsc9e",
|
|
201
|
+
k8ry5P: "x18b5jzi",
|
|
202
|
+
kBCPoo: "x1gejf6u",
|
|
197
203
|
$$css: true
|
|
198
204
|
},
|
|
199
205
|
tableCellHeader: {
|
package/dist/richtext.css
CHANGED
|
@@ -43,6 +43,9 @@
|
|
|
43
43
|
.xwmxj5m:not(#\#):not(#\#):not(#\#){background-color:var(--color-background-muted)}
|
|
44
44
|
.xzyc27v:not(#\#):not(#\#):not(#\#){background-color:var(--color-syntax-background)}
|
|
45
45
|
.x1mwwwfo:not(#\#):not(#\#):not(#\#){border-collapse:collapse}
|
|
46
|
+
.x1gejf6u:not(#\#):not(#\#):not(#\#){border-inline-end-color:var(--color-border)}
|
|
47
|
+
.x18b5jzi:not(#\#):not(#\#):not(#\#){border-inline-end-style:solid}
|
|
48
|
+
.xw8tdv1:not(#\#):not(#\#):not(#\#){border-inline-end-width:var(--border-width)}
|
|
46
49
|
.x14ydlgx:not(#\#):not(#\#):not(#\#){border-inline-start-color:var(--color-border-emphasized)}
|
|
47
50
|
.x1t7ytsu:not(#\#):not(#\#):not(#\#){border-inline-start-style:solid}
|
|
48
51
|
.xyumdvf:not(#\#):not(#\#):not(#\#){border-inline-start-width:2px}
|
|
@@ -139,6 +142,7 @@
|
|
|
139
142
|
.x1kuvm45:is([data-richtext-task]):not(#\#):not(#\#):not(#\#){padding-inline-start:calc(20px + var(--spacing-2))}
|
|
140
143
|
.x81k3mc:has(ul):not(#\#):not(#\#):not(#\#){list-style-type:none}
|
|
141
144
|
.xovwveo:has(ol):not(#\#):not(#\#):not(#\#){list-style-type:none}
|
|
145
|
+
.x1qlsc9e:last-child:not(#\#):not(#\#):not(#\#){border-inline-end-width:0}
|
|
142
146
|
@supports (-webkit-touch-callout: none){@media (pointer: coarse){.xf9zqsd.xf9zqsd.xf9zqsd:not(#\#):not(#\#):not(#\#){font-size:max(1rem,var(--text-body-size))}}}
|
|
143
147
|
.xw8gpjh:not(#\#):not(#\#):not(#\#):not(#\#){border-bottom-color:var(--color-border)}
|
|
144
148
|
.x1q0q8m5:not(#\#):not(#\#):not(#\#):not(#\#){border-bottom-style:solid}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astryxdesign/richtext",
|
|
3
3
|
"displayName": "Rich Text",
|
|
4
|
-
"version": "0.7.2-canary.
|
|
4
|
+
"version": "0.7.2-canary.405bb94",
|
|
5
5
|
"description": "Astryx rich text — a Lexical-based rich text editor and viewer, styled with Astryx design tokens.",
|
|
6
6
|
"author": "Meta Open Source",
|
|
7
7
|
"license": "MIT",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
},
|
|
54
54
|
"peerDependencies": {
|
|
55
55
|
"@stylexjs/stylex": ">=0.10.0",
|
|
56
|
-
"@astryxdesign/core": "0.7.2-canary.
|
|
56
|
+
"@astryxdesign/core": "0.7.2-canary.405bb94",
|
|
57
57
|
"react": ">=19.0.0",
|
|
58
58
|
"react-dom": ">=19.0.0",
|
|
59
59
|
"lexical": "^0.52.0",
|
|
@@ -112,8 +112,8 @@
|
|
|
112
112
|
}
|
|
113
113
|
},
|
|
114
114
|
"devDependencies": {
|
|
115
|
-
"@astryxdesign/a11y-spec": "0.7.2-canary.
|
|
116
|
-
"@astryxdesign/cli": "0.7.2-canary.
|
|
115
|
+
"@astryxdesign/a11y-spec": "0.7.2-canary.405bb94",
|
|
116
|
+
"@astryxdesign/cli": "0.7.2-canary.405bb94",
|
|
117
117
|
"@babel/cli": "^7.29.7",
|
|
118
118
|
"@babel/core": "^7.29.7",
|
|
119
119
|
"@babel/preset-react": "^7.29.7",
|
|
@@ -42,7 +42,10 @@ test.afterAll(async () => {
|
|
|
42
42
|
await storybook?.close();
|
|
43
43
|
});
|
|
44
44
|
|
|
45
|
-
async function openStory(
|
|
45
|
+
async function openStory(
|
|
46
|
+
page: Page,
|
|
47
|
+
direction: 'ltr' | 'rtl' = 'ltr',
|
|
48
|
+
): Promise<string[]> {
|
|
46
49
|
const errors: string[] = [];
|
|
47
50
|
page.on('pageerror', error => errors.push(String(error)));
|
|
48
51
|
page.on('console', message => {
|
|
@@ -52,7 +55,7 @@ async function openStory(page: Page): Promise<string[]> {
|
|
|
52
55
|
});
|
|
53
56
|
await page.setViewportSize({width: 1440, height: 900});
|
|
54
57
|
await page.goto(
|
|
55
|
-
`${storybook.origin}/iframe.html?id=${STORY}&viewMode=story&globals=astryxTheme:neutral;colorMode:light;direction
|
|
58
|
+
`${storybook.origin}/iframe.html?id=${STORY}&viewMode=story&globals=astryxTheme:neutral;colorMode:light;direction:${direction}`,
|
|
56
59
|
{waitUntil: 'load'},
|
|
57
60
|
);
|
|
58
61
|
await expect(page.locator(EDITOR)).toBeVisible();
|
|
@@ -177,7 +180,7 @@ test("the endContent controls disable with the editor, like the toolbar's own",
|
|
|
177
180
|
}) => {
|
|
178
181
|
const errors = await openStory(page);
|
|
179
182
|
const editor = page.locator(EDITOR);
|
|
180
|
-
const inserts = ['Table', 'Rule', 'Mention'].map(name =>
|
|
183
|
+
const inserts = ['Table', 'Rule', 'Mention', 'Image'].map(name =>
|
|
181
184
|
page.getByRole('button', {name, exact: true}),
|
|
182
185
|
);
|
|
183
186
|
const bold = page.getByRole('button', {name: 'Bold', exact: true});
|
|
@@ -283,6 +286,440 @@ const AXE_DISABLED_RULES = [
|
|
|
283
286
|
'region',
|
|
284
287
|
];
|
|
285
288
|
|
|
289
|
+
/* ------------------------------------------------------------------ *
|
|
290
|
+
* The image plugin
|
|
291
|
+
* ------------------------------------------------------------------ */
|
|
292
|
+
|
|
293
|
+
/** The image the editor holds, as the plugin draws it. */
|
|
294
|
+
const IMAGE = '[data-playground-editor] [data-playground-image] img';
|
|
295
|
+
|
|
296
|
+
/** Inserts the dialog's default sample image into the one editor. */
|
|
297
|
+
async function insertSampleImage(page: Page): Promise<void> {
|
|
298
|
+
await page.locator(EDITOR).click();
|
|
299
|
+
await page.keyboard.press('ControlOrMeta+End');
|
|
300
|
+
await page.getByRole('button', {name: 'Image', exact: true}).click();
|
|
301
|
+
// The dialog opens on its sample source, so this is one click away.
|
|
302
|
+
await expect(page.getByRole('heading', {name: 'Insert image'})).toBeVisible();
|
|
303
|
+
await page.getByRole('button', {name: 'Insert image', exact: true}).click();
|
|
304
|
+
await expect(page.locator(IMAGE)).toHaveCount(1);
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/** The image's rendered width, which is what a resize moves. */
|
|
308
|
+
async function imageWidth(page: Page): Promise<number> {
|
|
309
|
+
const box = await page.locator(IMAGE).boundingBox();
|
|
310
|
+
return box?.width ?? 0;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
test('the image plugin inserts an image through the editor nodes prop', async ({
|
|
314
|
+
page,
|
|
315
|
+
}) => {
|
|
316
|
+
const errors = await openStory(page);
|
|
317
|
+
await insertSampleImage(page);
|
|
318
|
+
|
|
319
|
+
// The alt text the sample carries reaches the DOM, so the picture is not
|
|
320
|
+
// silent to a screen reader.
|
|
321
|
+
await expect(page.locator(IMAGE)).toHaveAttribute(
|
|
322
|
+
'alt',
|
|
323
|
+
/illustration of layered hills/,
|
|
324
|
+
);
|
|
325
|
+
// One editor still, with the image inside the editable surface.
|
|
326
|
+
await expect(
|
|
327
|
+
page.locator('[role="textbox"][data-lexical-editor]'),
|
|
328
|
+
).toHaveCount(1);
|
|
329
|
+
await expect(page.locator('[data-playground-stats]')).toContainText(
|
|
330
|
+
'1 image',
|
|
331
|
+
);
|
|
332
|
+
expect(errors).toEqual([]);
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
test('a selected image resizes by its handle and by its controls, and removes itself', async ({
|
|
336
|
+
page,
|
|
337
|
+
}) => {
|
|
338
|
+
const errors = await openStory(page);
|
|
339
|
+
await insertSampleImage(page);
|
|
340
|
+
const image = page.locator(IMAGE);
|
|
341
|
+
// The width the image draws at before anything resizes it, which is what
|
|
342
|
+
// "Reset size" must restore.
|
|
343
|
+
const natural = await imageWidth(page);
|
|
344
|
+
|
|
345
|
+
// Nothing is offered until the image is selected: the controls and the
|
|
346
|
+
// resize handle belong to a selected image, like Lexical's own.
|
|
347
|
+
await expect(page.locator('[data-playground-image-actions]')).toHaveCount(0);
|
|
348
|
+
await image.click();
|
|
349
|
+
await expect(page.locator('[data-playground-image-actions]')).toHaveCount(1);
|
|
350
|
+
|
|
351
|
+
const started = await imageWidth(page);
|
|
352
|
+
await page.getByRole('button', {name: 'Larger', exact: true}).click();
|
|
353
|
+
await expect
|
|
354
|
+
.poll(() => imageWidth(page), {message: 'Larger widens the image'})
|
|
355
|
+
.toBeGreaterThan(started + 1);
|
|
356
|
+
|
|
357
|
+
const widened = await imageWidth(page);
|
|
358
|
+
await page.getByRole('button', {name: 'Smaller', exact: true}).click();
|
|
359
|
+
await expect
|
|
360
|
+
.poll(() => imageWidth(page), {message: 'Smaller narrows the image'})
|
|
361
|
+
.toBeLessThan(widened - 1);
|
|
362
|
+
|
|
363
|
+
// Dragging the handle resizes too, and commits the width to the node: the
|
|
364
|
+
// editor state carries it after the pointer is lifted.
|
|
365
|
+
const handle = page.locator('[data-playground-image-handle]');
|
|
366
|
+
const box = await handle.boundingBox();
|
|
367
|
+
const before = await imageWidth(page);
|
|
368
|
+
await page.mouse.move(box!.x + box!.width / 2, box!.y + box!.height / 2);
|
|
369
|
+
await page.mouse.down();
|
|
370
|
+
await page.mouse.move(box!.x + box!.width / 2 + 80, box!.y, {steps: 8});
|
|
371
|
+
await page.mouse.up();
|
|
372
|
+
await expect
|
|
373
|
+
.poll(() => imageWidth(page), {message: 'the handle widens the image'})
|
|
374
|
+
.toBeGreaterThan(before + 40);
|
|
375
|
+
|
|
376
|
+
await page.getByRole('tab', {name: 'Editor state'}).click();
|
|
377
|
+
await expect(page.locator('[data-playground-output]')).toContainText(
|
|
378
|
+
/"width":\s*\d+/,
|
|
379
|
+
);
|
|
380
|
+
|
|
381
|
+
// Reset size puts the image back to the width it drew at when it arrived.
|
|
382
|
+
await page.getByRole('button', {name: 'Reset size', exact: true}).click();
|
|
383
|
+
await expect
|
|
384
|
+
.poll(() => imageWidth(page), {message: 'Reset size restores the image'})
|
|
385
|
+
.toBeCloseTo(natural, 0);
|
|
386
|
+
|
|
387
|
+
await page.getByRole('button', {name: 'Remove image', exact: true}).click();
|
|
388
|
+
await expect(page.locator(IMAGE)).toHaveCount(0);
|
|
389
|
+
expect(errors).toEqual([]);
|
|
390
|
+
});
|
|
391
|
+
|
|
392
|
+
test("Enter opens a selected image's controls, activates them, and Escape leaves", async ({
|
|
393
|
+
page,
|
|
394
|
+
}) => {
|
|
395
|
+
const errors = await openStory(page);
|
|
396
|
+
await insertSampleImage(page);
|
|
397
|
+
await page.locator(IMAGE).click();
|
|
398
|
+
|
|
399
|
+
// Tab indents inside the editor, so Enter is the keyboard route into the
|
|
400
|
+
// controls of the selected image — without it they are mouse-only.
|
|
401
|
+
await page.keyboard.press('Enter');
|
|
402
|
+
await expect(
|
|
403
|
+
page.getByRole('button', {name: 'Smaller', exact: true}),
|
|
404
|
+
).toBeFocused();
|
|
405
|
+
|
|
406
|
+
// Enter pressed ON a control bubbles back to the editor, where the image is
|
|
407
|
+
// still the selected node: the handler that opened the controls has to let
|
|
408
|
+
// that keystroke through, or every control is dead to the keyboard.
|
|
409
|
+
const before = await imageWidth(page);
|
|
410
|
+
await page.keyboard.press('Enter');
|
|
411
|
+
await expect
|
|
412
|
+
.poll(() => imageWidth(page), {message: 'Enter on Smaller narrows it'})
|
|
413
|
+
.toBeLessThan(before - 1);
|
|
414
|
+
|
|
415
|
+
const narrowed = await imageWidth(page);
|
|
416
|
+
await page.keyboard.press('Tab');
|
|
417
|
+
await expect(
|
|
418
|
+
page.getByRole('button', {name: 'Larger', exact: true}),
|
|
419
|
+
).toBeFocused();
|
|
420
|
+
await page.keyboard.press('Enter');
|
|
421
|
+
await expect
|
|
422
|
+
.poll(() => imageWidth(page), {message: 'Enter on Larger widens it'})
|
|
423
|
+
.toBeGreaterThan(narrowed + 1);
|
|
424
|
+
|
|
425
|
+
await page.keyboard.press('Escape');
|
|
426
|
+
await expect(page.locator(EDITOR)).toBeFocused();
|
|
427
|
+
expect(errors).toEqual([]);
|
|
428
|
+
});
|
|
429
|
+
|
|
430
|
+
test('the resize handle follows the drag in a right-to-left document', async ({
|
|
431
|
+
page,
|
|
432
|
+
}) => {
|
|
433
|
+
// The handle sits on the inline end, which is the image's LEFT edge here,
|
|
434
|
+
// so dragging it outward lowers clientX. A width that followed the axis
|
|
435
|
+
// rather than the drag would shrink the image instead.
|
|
436
|
+
const errors = await openStory(page, 'rtl');
|
|
437
|
+
await insertSampleImage(page);
|
|
438
|
+
await page.locator(IMAGE).click();
|
|
439
|
+
// Narrow it first: at its own width the picture is already near the
|
|
440
|
+
// measure, and `max-width: 100%` would absorb the drag.
|
|
441
|
+
await page.getByRole('button', {name: 'Smaller', exact: true}).click();
|
|
442
|
+
await page.getByRole('button', {name: 'Smaller', exact: true}).click();
|
|
443
|
+
const before = await imageWidth(page);
|
|
444
|
+
|
|
445
|
+
const handle = page.locator('[data-playground-image-handle]');
|
|
446
|
+
const box = await handle.boundingBox();
|
|
447
|
+
await page.mouse.move(box!.x + box!.width / 2, box!.y + box!.height / 2);
|
|
448
|
+
await page.mouse.down();
|
|
449
|
+
await page.mouse.move(box!.x + box!.width / 2 - 80, box!.y, {steps: 8});
|
|
450
|
+
await page.mouse.up();
|
|
451
|
+
await expect
|
|
452
|
+
.poll(() => imageWidth(page), {message: 'dragging outward widens it'})
|
|
453
|
+
.toBeGreaterThan(before + 40);
|
|
454
|
+
expect(errors).toEqual([]);
|
|
455
|
+
});
|
|
456
|
+
|
|
457
|
+
test('an image reaches the state, the HTML and RichTextView, and says why it is not in the Markdown', async ({
|
|
458
|
+
page,
|
|
459
|
+
}) => {
|
|
460
|
+
const errors = await openStory(page);
|
|
461
|
+
await insertSampleImage(page);
|
|
462
|
+
const output = page.locator('[data-playground-output]');
|
|
463
|
+
|
|
464
|
+
await page.getByRole('tab', {name: 'Editor state'}).click();
|
|
465
|
+
await expect(output).toContainText('"playground-image"');
|
|
466
|
+
|
|
467
|
+
await page.getByRole('tab', {name: 'Node tree'}).click();
|
|
468
|
+
await expect(output).toContainText('playground-image alt=');
|
|
469
|
+
|
|
470
|
+
await page.getByRole('tab', {name: 'HTML'}).click();
|
|
471
|
+
await expect(output).toContainText('<img');
|
|
472
|
+
|
|
473
|
+
await page.getByRole('tab', {name: 'RichTextView'}).click();
|
|
474
|
+
await expect(output.locator('img')).toHaveCount(1);
|
|
475
|
+
|
|
476
|
+
// The Markdown readout does NOT carry the image, because RichText's default
|
|
477
|
+
// transformer array is internal and `transformers` replaces it whole. A
|
|
478
|
+
// readout that silently dropped content would read as a bug, so the
|
|
479
|
+
// playground says so where the content is missing.
|
|
480
|
+
await page.getByRole('tab', {name: 'Markdown'}).click();
|
|
481
|
+
await expect(output).not.toContainText('![');
|
|
482
|
+
await expect(output).toContainText('missing from this Markdown');
|
|
483
|
+
expect(errors).toEqual([]);
|
|
484
|
+
});
|
|
485
|
+
|
|
486
|
+
test('turning the image node off takes the document back through Markdown', async ({
|
|
487
|
+
page,
|
|
488
|
+
}) => {
|
|
489
|
+
const errors = await openStory(page);
|
|
490
|
+
await insertSampleImage(page);
|
|
491
|
+
await expect(page.locator(IMAGE)).toHaveCount(1);
|
|
492
|
+
|
|
493
|
+
// Every switch that re-imports the document from Markdown drops the images
|
|
494
|
+
// with it, so each one says so where a reader decides to flip it.
|
|
495
|
+
await expect(settings(page)).toContainText(
|
|
496
|
+
'Markdown, where images do not survive',
|
|
497
|
+
);
|
|
498
|
+
|
|
499
|
+
// `nodes` is read at construction, so the switch rebuilds the editor. State
|
|
500
|
+
// holding an image cannot be parsed without the node registered, so the
|
|
501
|
+
// document round-trips through Markdown — and the image does not survive.
|
|
502
|
+
await toggle(page, 'Images').click();
|
|
503
|
+
await expect(page.locator(EDITOR)).toBeVisible();
|
|
504
|
+
await expect(page.locator(IMAGE)).toHaveCount(0);
|
|
505
|
+
await expect(
|
|
506
|
+
page.getByRole('button', {name: 'Image', exact: true}),
|
|
507
|
+
).toHaveCount(0);
|
|
508
|
+
// The document itself is still here.
|
|
509
|
+
await expect(page.locator(`${EDITOR} table`)).toHaveCount(1);
|
|
510
|
+
|
|
511
|
+
await toggle(page, 'Images').click();
|
|
512
|
+
await expect(
|
|
513
|
+
page.getByRole('button', {name: 'Image', exact: true}),
|
|
514
|
+
).toBeVisible();
|
|
515
|
+
expect(errors).toEqual([]);
|
|
516
|
+
});
|
|
517
|
+
|
|
518
|
+
test('an image file dropped or pasted into the editor becomes an image', async ({
|
|
519
|
+
page,
|
|
520
|
+
}) => {
|
|
521
|
+
const errors = await openStory(page);
|
|
522
|
+
await page.locator(EDITOR).click();
|
|
523
|
+
await page.keyboard.press('ControlOrMeta+End');
|
|
524
|
+
|
|
525
|
+
// A real drop and a real paste cannot be driven from the test runner, so the
|
|
526
|
+
// events are built with the same shapes a browser delivers: a DragEvent and
|
|
527
|
+
// a ClipboardEvent, each carrying one image file.
|
|
528
|
+
const deliverFile = (type: 'drop' | 'paste') =>
|
|
529
|
+
page.evaluate(async (eventType: string) => {
|
|
530
|
+
const pixel =
|
|
531
|
+
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==';
|
|
532
|
+
const blob = await (await fetch(pixel)).blob();
|
|
533
|
+
const transfer = new DataTransfer();
|
|
534
|
+
transfer.items.add(
|
|
535
|
+
new File([blob], `${eventType}ped.png`, {type: 'image/png'}),
|
|
536
|
+
);
|
|
537
|
+
const target = document.querySelector(
|
|
538
|
+
'[data-playground-editor] [role="textbox"]',
|
|
539
|
+
);
|
|
540
|
+
target?.dispatchEvent(
|
|
541
|
+
eventType === 'drop'
|
|
542
|
+
? new DragEvent('drop', {
|
|
543
|
+
bubbles: true,
|
|
544
|
+
cancelable: true,
|
|
545
|
+
dataTransfer: transfer,
|
|
546
|
+
})
|
|
547
|
+
: new ClipboardEvent('paste', {
|
|
548
|
+
bubbles: true,
|
|
549
|
+
cancelable: true,
|
|
550
|
+
clipboardData: transfer,
|
|
551
|
+
}),
|
|
552
|
+
);
|
|
553
|
+
}, type);
|
|
554
|
+
|
|
555
|
+
await deliverFile('drop');
|
|
556
|
+
await expect(page.locator(IMAGE)).toHaveCount(1);
|
|
557
|
+
// The file's name is the alt text until someone says better.
|
|
558
|
+
await expect(page.locator(IMAGE)).toHaveAttribute('alt', 'dropped.png');
|
|
559
|
+
|
|
560
|
+
await deliverFile('paste');
|
|
561
|
+
await expect(page.locator(IMAGE)).toHaveCount(2);
|
|
562
|
+
expect(errors).toEqual([]);
|
|
563
|
+
});
|
|
564
|
+
|
|
565
|
+
test('a dropped image lands where it was dropped, not at the caret', async ({
|
|
566
|
+
page,
|
|
567
|
+
}) => {
|
|
568
|
+
const errors = await openStory(page);
|
|
569
|
+
// The caret is at the very start of the document…
|
|
570
|
+
await page.locator(EDITOR).click();
|
|
571
|
+
await page.keyboard.press('ControlOrMeta+Home');
|
|
572
|
+
|
|
573
|
+
// …and the file is dropped on the last paragraph, far from it. The plugin
|
|
574
|
+
// consumes DROP_COMMAND ahead of the rich-text handler that would have
|
|
575
|
+
// moved the selection to the drop point, so it has to do that itself.
|
|
576
|
+
const target = page.locator(`${EDITOR} > p`).last();
|
|
577
|
+
// The drop point is a VIEWPORT coordinate, which is what the browser gives
|
|
578
|
+
// a real drop and what `caretPositionFromPoint` reads; the seeded document
|
|
579
|
+
// is taller than the viewport, so the target has to be on screen first.
|
|
580
|
+
await target.scrollIntoViewIfNeeded();
|
|
581
|
+
const box = await target.boundingBox();
|
|
582
|
+
const dropAt = {x: box!.x + box!.width / 2, y: box!.y + box!.height / 2};
|
|
583
|
+
await page.evaluate(async ({x, y}: {x: number; y: number}) => {
|
|
584
|
+
const pixel =
|
|
585
|
+
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==';
|
|
586
|
+
const blob = await (await fetch(pixel)).blob();
|
|
587
|
+
const transfer = new DataTransfer();
|
|
588
|
+
transfer.items.add(new File([blob], 'placed.png', {type: 'image/png'}));
|
|
589
|
+
document
|
|
590
|
+
.querySelector('[data-playground-editor] [role="textbox"]')
|
|
591
|
+
?.dispatchEvent(
|
|
592
|
+
new DragEvent('drop', {
|
|
593
|
+
bubbles: true,
|
|
594
|
+
cancelable: true,
|
|
595
|
+
clientX: x,
|
|
596
|
+
clientY: y,
|
|
597
|
+
dataTransfer: transfer,
|
|
598
|
+
}),
|
|
599
|
+
);
|
|
600
|
+
}, dropAt);
|
|
601
|
+
|
|
602
|
+
await expect(page.locator(IMAGE)).toHaveCount(1);
|
|
603
|
+
// Where it was dropped. Position, not block identity: inserting at a caret
|
|
604
|
+
// inside a paragraph splits it, so the image lands in a paragraph of its
|
|
605
|
+
// own between the halves — which is correct, and is not the element that
|
|
606
|
+
// was dropped on.
|
|
607
|
+
const landed = await page.locator(IMAGE).boundingBox();
|
|
608
|
+
expect(
|
|
609
|
+
Math.abs(landed!.y - dropAt.y),
|
|
610
|
+
'the image is at the drop point, not at the caret',
|
|
611
|
+
).toBeLessThan(80);
|
|
612
|
+
// The caret was in the heading, at the top of a document taller than this.
|
|
613
|
+
const heading = await page.locator(`${EDITOR} h1`).boundingBox();
|
|
614
|
+
expect(landed!.y - heading!.y).toBeGreaterThan(200);
|
|
615
|
+
expect(errors).toEqual([]);
|
|
616
|
+
});
|
|
617
|
+
|
|
618
|
+
test('a file dropped onto a decorator lands beside it, not at the top', async ({
|
|
619
|
+
page,
|
|
620
|
+
}) => {
|
|
621
|
+
const errors = await openStory(page);
|
|
622
|
+
// An image to drop onto, with the caret left near it rather than at the top
|
|
623
|
+
// of the document, so "landed at the top" cannot pass by accident.
|
|
624
|
+
await insertSampleImage(page);
|
|
625
|
+
const existing = page.locator(IMAGE);
|
|
626
|
+
await existing.scrollIntoViewIfNeeded();
|
|
627
|
+
const box = await existing.boundingBox();
|
|
628
|
+
|
|
629
|
+
// A point inside a decorator resolves to no Lexical position, and a fresh
|
|
630
|
+
// range selection then sits at the root's offset 0 — the top of the
|
|
631
|
+
// document, nowhere near the drop.
|
|
632
|
+
await page.evaluate(
|
|
633
|
+
async ({x, y}: {x: number; y: number}) => {
|
|
634
|
+
const pixel =
|
|
635
|
+
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==';
|
|
636
|
+
const blob = await (await fetch(pixel)).blob();
|
|
637
|
+
const transfer = new DataTransfer();
|
|
638
|
+
transfer.items.add(new File([blob], 'beside.png', {type: 'image/png'}));
|
|
639
|
+
document
|
|
640
|
+
.querySelector('[data-playground-editor] [role="textbox"]')
|
|
641
|
+
?.dispatchEvent(
|
|
642
|
+
new DragEvent('drop', {
|
|
643
|
+
bubbles: true,
|
|
644
|
+
cancelable: true,
|
|
645
|
+
clientX: x,
|
|
646
|
+
clientY: y,
|
|
647
|
+
dataTransfer: transfer,
|
|
648
|
+
}),
|
|
649
|
+
);
|
|
650
|
+
},
|
|
651
|
+
{x: box!.x + box!.width / 2, y: box!.y + box!.height / 2},
|
|
652
|
+
);
|
|
653
|
+
|
|
654
|
+
await expect(page.locator(IMAGE)).toHaveCount(2);
|
|
655
|
+
const dropped = page.locator(`${EDITOR} img[alt="beside.png"]`);
|
|
656
|
+
await expect(dropped).toHaveCount(1);
|
|
657
|
+
// Beside the image it was dropped on, not above the document's heading.
|
|
658
|
+
const landed = await dropped.boundingBox();
|
|
659
|
+
const heading = await page.locator(`${EDITOR} h1`).boundingBox();
|
|
660
|
+
expect(
|
|
661
|
+
landed!.y - heading!.y,
|
|
662
|
+
'the file landed beside the decorator, not at the top',
|
|
663
|
+
).toBeGreaterThan(200);
|
|
664
|
+
expect(errors).toEqual([]);
|
|
665
|
+
});
|
|
666
|
+
|
|
667
|
+
test('the insert dialog is tabbable, outside the toolbar roving tab stop', async ({
|
|
668
|
+
page,
|
|
669
|
+
}) => {
|
|
670
|
+
const errors = await openStory(page);
|
|
671
|
+
const button = page.getByRole('button', {name: 'Image', exact: true});
|
|
672
|
+
await button.focus();
|
|
673
|
+
await expect(button).toHaveAttribute('aria-haspopup', 'dialog');
|
|
674
|
+
await page.keyboard.press('Enter');
|
|
675
|
+
await expect(page.getByRole('heading', {name: 'Insert image'})).toBeVisible();
|
|
676
|
+
|
|
677
|
+
// A Toolbar is a roving tab stop: everything inside it is tabindex="-1", so
|
|
678
|
+
// a dialog rendered in its endContent could not be tabbed through at all.
|
|
679
|
+
// The dialog goes in the editor's plugins slot instead, beside the toolbar
|
|
680
|
+
// — which is where RichTextEditorToolbar puts its own link dialog.
|
|
681
|
+
const insert = page.getByRole('button', {name: 'Insert image', exact: true});
|
|
682
|
+
for (let press = 0; press < 12; press += 1) {
|
|
683
|
+
if (await insert.evaluate(el => el === document.activeElement)) {
|
|
684
|
+
break;
|
|
685
|
+
}
|
|
686
|
+
await page.keyboard.press('Tab');
|
|
687
|
+
}
|
|
688
|
+
await expect(insert).toBeFocused();
|
|
689
|
+
|
|
690
|
+
await page.keyboard.press('Enter');
|
|
691
|
+
await expect(page.locator(IMAGE)).toHaveCount(1);
|
|
692
|
+
// And focus lands back in the editor, not on the button that opened the
|
|
693
|
+
// dialog: a Dialog returns focus to its invoker as it closes, so the next
|
|
694
|
+
// keystroke would otherwise reopen it instead of typing.
|
|
695
|
+
await expect(page.locator(EDITOR)).toBeFocused();
|
|
696
|
+
await page.keyboard.type('after the image');
|
|
697
|
+
await expect(page.locator(EDITOR)).toContainText('after the image');
|
|
698
|
+
expect(errors).toEqual([]);
|
|
699
|
+
});
|
|
700
|
+
|
|
701
|
+
test('the RichTextView readout survives the image node arriving under it', async ({
|
|
702
|
+
page,
|
|
703
|
+
}) => {
|
|
704
|
+
const errors = await openStory(page);
|
|
705
|
+
const output = page.locator('[data-playground-output]');
|
|
706
|
+
|
|
707
|
+
// The view reads `nodes` once, when it builds its own editor. Opened while
|
|
708
|
+
// images are off, it would then fail to parse state holding one and render
|
|
709
|
+
// its empty fallback — the whole document gone, not just the image.
|
|
710
|
+
await toggle(page, 'Images').click();
|
|
711
|
+
await page.getByRole('tab', {name: 'RichTextView'}).click();
|
|
712
|
+
await expect(output.locator('table')).toHaveCount(1);
|
|
713
|
+
|
|
714
|
+
await toggle(page, 'Images').click();
|
|
715
|
+
await insertSampleImage(page);
|
|
716
|
+
await page.getByRole('tab', {name: 'RichTextView'}).click();
|
|
717
|
+
await expect(output.locator('img')).toHaveCount(1);
|
|
718
|
+
// The document is still under it, not an empty fallback.
|
|
719
|
+
await expect(output.locator('table')).toHaveCount(1);
|
|
720
|
+
expect(errors).toEqual([]);
|
|
721
|
+
});
|
|
722
|
+
|
|
286
723
|
test('the story has no axe violations', async ({page}) => {
|
|
287
724
|
const errors = await openStory(page);
|
|
288
725
|
const results = await new AxeBuilder({page})
|
|
@@ -296,3 +733,22 @@ test('the story has no axe violations', async ({page}) => {
|
|
|
296
733
|
).toEqual([]);
|
|
297
734
|
expect(errors).toEqual([]);
|
|
298
735
|
});
|
|
736
|
+
|
|
737
|
+
test('the story has no axe violations with a selected image in it', async ({
|
|
738
|
+
page,
|
|
739
|
+
}) => {
|
|
740
|
+
const errors = await openStory(page);
|
|
741
|
+
await insertSampleImage(page);
|
|
742
|
+
await page.locator(IMAGE).click();
|
|
743
|
+
await expect(page.locator('[data-playground-image-actions]')).toHaveCount(1);
|
|
744
|
+
const results = await new AxeBuilder({page})
|
|
745
|
+
.disableRules(AXE_DISABLED_RULES)
|
|
746
|
+
.analyze();
|
|
747
|
+
expect(
|
|
748
|
+
results.violations.map(violation => [
|
|
749
|
+
violation.id,
|
|
750
|
+
violation.nodes.map(node => node.target.join(' ')),
|
|
751
|
+
]),
|
|
752
|
+
).toEqual([]);
|
|
753
|
+
expect(errors).toEqual([]);
|
|
754
|
+
});
|
package/src/editorTheme.ts
CHANGED
|
@@ -317,6 +317,13 @@ const editorTheme = stylex.create({
|
|
|
317
317
|
table: {
|
|
318
318
|
borderCollapse: 'collapse',
|
|
319
319
|
width: '100%',
|
|
320
|
+
// The grid's outer edge, matching core Markdown's table: the row and
|
|
321
|
+
// column lines stop at the table's rim, so without this the top, bottom,
|
|
322
|
+
// and sides stay open. `border-collapse: collapse` merges it with the
|
|
323
|
+
// cell lines into one 1px rule rather than doubling up at the edge.
|
|
324
|
+
borderWidth: borderVars['--border-width'],
|
|
325
|
+
borderStyle: 'solid',
|
|
326
|
+
borderColor: colorVars['--color-border'],
|
|
320
327
|
},
|
|
321
328
|
tableRow: {
|
|
322
329
|
borderBottomWidth: '1px',
|
|
@@ -335,6 +342,17 @@ const editorTheme = stylex.create({
|
|
|
335
342
|
textAlign: 'start',
|
|
336
343
|
verticalAlign: 'middle',
|
|
337
344
|
overflowWrap: 'break-word',
|
|
345
|
+
// A line on every cell edge, as core Markdown's table draws with
|
|
346
|
+
// `dividers="grid"`. The row lines come from `tableRow`; this is the
|
|
347
|
+
// column half. The last column draws none, so the rim is the `table`
|
|
348
|
+
// rule's own border rather than two lines stacked at the edge — the
|
|
349
|
+
// same rule core `TableCell` follows (`:last-child` → 0).
|
|
350
|
+
borderInlineEndWidth: {
|
|
351
|
+
default: borderVars['--border-width'],
|
|
352
|
+
':last-child': 0,
|
|
353
|
+
},
|
|
354
|
+
borderInlineEndStyle: 'solid',
|
|
355
|
+
borderInlineEndColor: colorVars['--color-border'],
|
|
338
356
|
},
|
|
339
357
|
tableCellHeader: {
|
|
340
358
|
fontWeight: fontWeightVars['--font-weight-semibold'],
|