@velocity-astro/cms-admin 0.1.0-beta.7 → 0.1.0-beta.9

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.
Files changed (117) hide show
  1. package/app-dist/assets/{RichTextEditor-BpltDhwX.js → RichTextEditor-2qfS1RuO.js} +1 -1
  2. package/app-dist/assets/index-DFJEnfa1.css +2 -0
  3. package/app-dist/assets/index-Dgzgv7yT.js +80 -0
  4. package/app-dist/index.html +2 -2
  5. package/dist/app/AdminLayout.d.ts.map +1 -1
  6. package/dist/app/AdminLayout.js +99 -54
  7. package/dist/app/AdminLayout.js.map +1 -1
  8. package/dist/app/RouteError.d.ts +9 -0
  9. package/dist/app/RouteError.d.ts.map +1 -0
  10. package/dist/app/RouteError.js +16 -0
  11. package/dist/app/RouteError.js.map +1 -0
  12. package/dist/app/routes.d.ts.map +1 -1
  13. package/dist/app/routes.js +31 -20
  14. package/dist/app/routes.js.map +1 -1
  15. package/dist/client/queries.d.ts +4 -0
  16. package/dist/client/queries.d.ts.map +1 -1
  17. package/dist/client/queries.js +20 -0
  18. package/dist/client/queries.js.map +1 -1
  19. package/dist/fields/BlocksControl.d.ts.map +1 -1
  20. package/dist/fields/BlocksControl.js +2 -0
  21. package/dist/fields/BlocksControl.js.map +1 -1
  22. package/dist/fields/FieldSetEditor.js +1 -1
  23. package/dist/fields/FieldSetEditor.js.map +1 -1
  24. package/dist/fields/controls.d.ts.map +1 -1
  25. package/dist/fields/controls.js +21 -2
  26. package/dist/fields/controls.js.map +1 -1
  27. package/dist/fields/field-control.d.ts +5 -0
  28. package/dist/fields/field-control.d.ts.map +1 -1
  29. package/dist/fields/field-control.js.map +1 -1
  30. package/dist/fields/page-focus.d.ts +2 -0
  31. package/dist/fields/page-focus.d.ts.map +1 -1
  32. package/dist/fields/page-focus.js +7 -2
  33. package/dist/fields/page-focus.js.map +1 -1
  34. package/dist/fields/settings.d.ts.map +1 -1
  35. package/dist/fields/settings.js +7 -0
  36. package/dist/fields/settings.js.map +1 -1
  37. package/dist/lib/load-fresh.d.ts +8 -0
  38. package/dist/lib/load-fresh.d.ts.map +1 -0
  39. package/dist/lib/load-fresh.js +51 -0
  40. package/dist/lib/load-fresh.js.map +1 -0
  41. package/dist/lib/use-command-key.d.ts +16 -0
  42. package/dist/lib/use-command-key.d.ts.map +1 -0
  43. package/dist/lib/use-command-key.js +30 -0
  44. package/dist/lib/use-command-key.js.map +1 -0
  45. package/dist/lib/use-escapes.d.ts +7 -0
  46. package/dist/lib/use-escapes.d.ts.map +1 -0
  47. package/dist/lib/use-escapes.js +19 -0
  48. package/dist/lib/use-escapes.js.map +1 -0
  49. package/dist/lib/use-panel-sizes.d.ts +7 -0
  50. package/dist/lib/use-panel-sizes.d.ts.map +1 -0
  51. package/dist/lib/use-panel-sizes.js +33 -0
  52. package/dist/lib/use-panel-sizes.js.map +1 -0
  53. package/dist/messages/en.d.ts +56 -3
  54. package/dist/messages/en.d.ts.map +1 -1
  55. package/dist/messages/en.js +58 -3
  56. package/dist/messages/en.js.map +1 -1
  57. package/dist/page-bridge/preview-bridge.d.ts.map +1 -1
  58. package/dist/page-bridge/preview-bridge.js +287 -3
  59. package/dist/page-bridge/preview-bridge.js.map +1 -1
  60. package/dist/screens/Contact/ContactDeals.js +1 -1
  61. package/dist/screens/Contact/ContactDeals.js.map +1 -1
  62. package/dist/screens/Contact/ContactScreen.js +14 -2
  63. package/dist/screens/Contact/ContactScreen.js.map +1 -1
  64. package/dist/screens/Contacts/ContactsScreen.js +16 -10
  65. package/dist/screens/Contacts/ContactsScreen.js.map +1 -1
  66. package/dist/screens/Contacts/StagesDialog.d.ts.map +1 -1
  67. package/dist/screens/Contacts/StagesDialog.js +4 -1
  68. package/dist/screens/Contacts/StagesDialog.js.map +1 -1
  69. package/dist/screens/ContentList/ContentListScreen.js +3 -3
  70. package/dist/screens/ContentList/ContentListScreen.js.map +1 -1
  71. package/dist/screens/ContentType/ContentTypeScreen.js +10 -3
  72. package/dist/screens/ContentType/ContentTypeScreen.js.map +1 -1
  73. package/dist/screens/ContentTypes/ContentTypesScreen.js +3 -3
  74. package/dist/screens/ContentTypes/ContentTypesScreen.js.map +1 -1
  75. package/dist/screens/Deals/DealsScreen.d.ts.map +1 -1
  76. package/dist/screens/Deals/DealsScreen.js +28 -4
  77. package/dist/screens/Deals/DealsScreen.js.map +1 -1
  78. package/dist/screens/EntryEditor/EntryForm.d.ts.map +1 -1
  79. package/dist/screens/EntryEditor/EntryForm.js +64 -18
  80. package/dist/screens/EntryEditor/EntryForm.js.map +1 -1
  81. package/dist/screens/EntryEditor/PagePane.d.ts +3 -1
  82. package/dist/screens/EntryEditor/PagePane.d.ts.map +1 -1
  83. package/dist/screens/EntryEditor/PagePane.js +8 -5
  84. package/dist/screens/EntryEditor/PagePane.js.map +1 -1
  85. package/dist/screens/EntryEditor/SectionOutline.d.ts +11 -0
  86. package/dist/screens/EntryEditor/SectionOutline.d.ts.map +1 -0
  87. package/dist/screens/EntryEditor/SectionOutline.js +46 -0
  88. package/dist/screens/EntryEditor/SectionOutline.js.map +1 -0
  89. package/dist/screens/EntryEditor/ThemeCard.d.ts.map +1 -1
  90. package/dist/screens/EntryEditor/ThemeCard.js +5 -1
  91. package/dist/screens/EntryEditor/ThemeCard.js.map +1 -1
  92. package/dist/screens/Form/FormScreen.js +10 -2
  93. package/dist/screens/Form/FormScreen.js.map +1 -1
  94. package/dist/screens/Form/Submissions.js +1 -1
  95. package/dist/screens/Form/Submissions.js.map +1 -1
  96. package/dist/screens/Forms/FormsScreen.d.ts.map +1 -1
  97. package/dist/screens/Forms/FormsScreen.js +6 -3
  98. package/dist/screens/Forms/FormsScreen.js.map +1 -1
  99. package/dist/screens/Home/FollowUps.d.ts.map +1 -1
  100. package/dist/screens/Home/FollowUps.js +3 -3
  101. package/dist/screens/Home/FollowUps.js.map +1 -1
  102. package/dist/screens/Home/HomeScreen.d.ts +1 -1
  103. package/dist/screens/Home/HomeScreen.d.ts.map +1 -1
  104. package/dist/screens/Home/HomeScreen.js +109 -25
  105. package/dist/screens/Home/HomeScreen.js.map +1 -1
  106. package/dist/screens/Media/MediaScreen.js +1 -1
  107. package/dist/screens/Media/MediaScreen.js.map +1 -1
  108. package/dist/screens/People/PeopleScreen.js +1 -1
  109. package/dist/screens/People/PeopleScreen.js.map +1 -1
  110. package/dist/screens/Trash/TrashScreen.js +2 -2
  111. package/dist/screens/Trash/TrashScreen.js.map +1 -1
  112. package/dist/testing/admin-client-contract.d.ts.map +1 -1
  113. package/dist/testing/admin-client-contract.js +6 -0
  114. package/dist/testing/admin-client-contract.js.map +1 -1
  115. package/package.json +5 -5
  116. package/app-dist/assets/index-Bx7Xh90l.js +0 -80
  117. package/app-dist/assets/index-DLXIqdLb.css +0 -2
@@ -588,6 +588,7 @@ export function previewBridge(page) {
588
588
  link: ['M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71', 'M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71'],
589
589
  bold: ['M6 12h9a4 4 0 0 1 0 8H7a1 1 0 0 1-1-1V5a1 1 0 0 1 1-1h7a4 4 0 0 1 0 8'],
590
590
  italic: ['M19 4h-9', 'M14 20H5', 'M15 4 9 20'],
591
+ reorder: ['m21 16-4 4-4-4', 'M17 20V4', 'm3 8 4-4 4 4', 'M7 4v16'],
591
592
  drag: ['M9 5h.01', 'M9 12h.01', 'M9 19h.01', 'M15 5h.01', 'M15 12h.01', 'M15 19h.01'],
592
593
  };
593
594
  const drawing = (name) => {
@@ -670,6 +671,16 @@ export function previewBridge(page) {
670
671
  more.append(drawing('add'));
671
672
  press(more, 'addAfter');
672
673
  bar.append(more);
674
+ // The page's sections by name, to put in another order.
675
+ const sorter = doc.createElement('button');
676
+ sorter.type = 'button';
677
+ sorter.tabIndex = -1;
678
+ sorter.setAttribute('data-cms-tool', 'reorder');
679
+ Object.assign(sorter.style, { display: 'none', placeItems: 'center', width: '28px', height: '28px', padding: '0', border: '0', borderRadius: '6px', background: 'transparent', color: 'inherit', cursor: 'pointer' });
680
+ sorter.append(drawing('reorder'));
681
+ sorter.addEventListener('mousedown', (event) => event.preventDefault());
682
+ sorter.addEventListener('click', () => openStack(null, true, 0));
683
+ bar.append(sorter);
673
684
  // Swatches: a look of the section chosen among a few of the site's colours has a dot for each
674
685
  // choice on the bar. The page changes nothing: it says which was pressed.
675
686
  const dots = doc.createElement('span');
@@ -1235,6 +1246,8 @@ export function previewBridge(page) {
1235
1246
  }
1236
1247
  // At the section's top corner, and at the top of the page while the section's own top is above it:
1237
1248
  // under what the site keeps there, so the bar never covers the site's own header.
1249
+ sorter.title = word(tools.labels['reorder']);
1250
+ sorter.style.display = word(about.list) === '' && pageOrder().length > 1 ? 'grid' : 'none';
1238
1251
  more.title = word(tools.labels['addAfter']);
1239
1252
  more.style.display = about.add === true ? 'grid' : 'none';
1240
1253
  Object.assign(bar.style, { display: 'flex', top: at(Math.min(Math.max(rect.top, kept()) + 12 * grow, Math.max(rect.bottom - 44 * grow, 0))), left: 'auto', right: at(Math.max(page.innerWidth - rect.right, 0) + 12 * grow) });
@@ -1348,6 +1361,13 @@ export function previewBridge(page) {
1348
1361
  // A few pixels of give, so a press that was only a press moves nothing.
1349
1362
  if (Math.abs(drag.y - drag.from) > 4)
1350
1363
  drag.moved = true;
1364
+ // A section of the page itself is moved among the page's sections by name.
1365
+ if (drag.moved && word(tools?.sections[drag.id]?.list) === '') {
1366
+ const { id } = drag;
1367
+ endDrag(false);
1368
+ openStack(id, false, event.clientY);
1369
+ return;
1370
+ }
1351
1371
  if (drag.moved)
1352
1372
  aim();
1353
1373
  }, true);
@@ -1357,6 +1377,255 @@ export function previewBridge(page) {
1357
1377
  if (drag && event.key === 'Escape')
1358
1378
  endDrag(false);
1359
1379
  }, true);
1380
+ const ROW = 44;
1381
+ const STEP = 50;
1382
+ let stacked = null;
1383
+ let stackWords = { names: {}, title: '', done: '', up: '', down: '' };
1384
+ let shift = 0;
1385
+ const stackKey = `velocity-cms:stack:${page.location.pathname}`;
1386
+ const pageOrder = () => movable().filter((section) => word(tools?.sections[section.dataset['cmsSection'] ?? '']?.list) === '').map((section) => section.dataset['cmsSection'] ?? '');
1387
+ const stack = doc.createElement('div');
1388
+ stack.setAttribute('data-cms-stack', '');
1389
+ Object.assign(stack.style, { position: 'absolute', inset: '0', display: 'none', overflow: 'hidden', background: 'rgb(14 14 16 / 0.82)', backdropFilter: 'blur(6px)', color: '#fff', font: `500 14px/1 ${FONT}`, pointerEvents: 'auto', userSelect: 'none' });
1390
+ // The rows are as large on the person's screen as the bar is, so their places are counted in their own size.
1391
+ const column = grows(doc.createElement('div'));
1392
+ Object.assign(column.style, { position: 'absolute', top: '0', left: '50%', width: 'min(26rem, calc(100% - 32px))' });
1393
+ stack.append(column);
1394
+ layer.append(stack);
1395
+ const headOf = (now) => (now.stays ? 56 : 0);
1396
+ /** Which row the held one would land before: as many as there are rows for after the last. */
1397
+ const landing = (now) => Math.min(Math.max(Math.round(((now.y - shift) / grow - headOf(now)) / STEP), 0), now.order.length);
1398
+ const drawStack = () => {
1399
+ const now = stacked;
1400
+ stack.style.display = now ? 'block' : 'none';
1401
+ if (!now)
1402
+ return;
1403
+ const head = headOf(now);
1404
+ const dragging = now.held !== null && now.moved;
1405
+ const own = now.held === null ? -1 : now.order.indexOf(now.held);
1406
+ const to = landing(now);
1407
+ column.replaceChildren();
1408
+ Object.assign(column.style, { height: `${head + now.order.length * STEP}px`, transform: `translate(-50%, ${shift / grow}px)` });
1409
+ if (now.stays) {
1410
+ const top = doc.createElement('div');
1411
+ Object.assign(top.style, { position: 'absolute', top: '0', left: '0', right: '0', height: '40px', display: 'flex', alignItems: 'center', justifyContent: 'space-between', font: `600 15px/1 ${FONT}` });
1412
+ const title = doc.createElement('span');
1413
+ title.textContent = stackWords.title;
1414
+ const done = doc.createElement('button');
1415
+ done.type = 'button';
1416
+ done.tabIndex = -1;
1417
+ done.setAttribute('data-cms-stack-done', '');
1418
+ done.textContent = stackWords.done;
1419
+ Object.assign(done.style, { height: '32px', padding: '0 14px', border: '0', borderRadius: '8px', background: ACCENT, color: ACCENT_INK, font: `600 13px/1 ${FONT}`, cursor: 'pointer' });
1420
+ done.addEventListener('click', () => closeStack());
1421
+ top.append(title, done);
1422
+ column.append(top);
1423
+ }
1424
+ const rowLook = { position: 'absolute', left: '0', right: '0', height: `${ROW}px`, boxSizing: 'border-box', display: 'flex', alignItems: 'center', gap: '10px', padding: '0 8px 0 12px', borderRadius: '10px' };
1425
+ now.order.forEach((id, at) => {
1426
+ const row = doc.createElement('div');
1427
+ row.setAttribute('data-cms-stack-row', id);
1428
+ const isHeld = dragging && id === now.held;
1429
+ Object.assign(row.style, rowLook, {
1430
+ top: `${head + at * STEP}px`,
1431
+ background: isHeld ? 'transparent' : 'rgb(255 255 255 / 0.1)',
1432
+ border: isHeld ? '1px dashed rgb(255 255 255 / 0.35)' : '1px solid rgb(255 255 255 / 0.14)',
1433
+ color: isHeld ? 'rgb(255 255 255 / 0.35)' : '#fff',
1434
+ cursor: now.stays ? 'grab' : 'grabbing',
1435
+ });
1436
+ const count = doc.createElement('span');
1437
+ count.textContent = String(at + 1);
1438
+ Object.assign(count.style, { width: '20px', textAlign: 'right', opacity: '0.55', font: `500 12px/1 ${FONT}` });
1439
+ const name = doc.createElement('span');
1440
+ name.textContent = stackWords.names[id] ?? '';
1441
+ Object.assign(name.style, { flex: '1', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' });
1442
+ row.append(drawing('drag'), count, name);
1443
+ if (now.stays) {
1444
+ for (const [way, label, able] of [['up', stackWords.up, at > 0], ['down', stackWords.down, at < now.order.length - 1]]) {
1445
+ const nudge = doc.createElement('button');
1446
+ nudge.type = 'button';
1447
+ nudge.tabIndex = -1;
1448
+ nudge.title = label;
1449
+ nudge.disabled = !able;
1450
+ nudge.setAttribute('data-cms-stack-nudge', way);
1451
+ Object.assign(nudge.style, { display: 'grid', placeItems: 'center', width: '30px', height: '30px', padding: '0', border: '0', borderRadius: '6px', background: 'transparent', color: 'inherit', opacity: able ? '1' : '0.3', cursor: able ? 'pointer' : 'default' });
1452
+ nudge.append(drawing(way));
1453
+ nudge.addEventListener('mousedown', (event) => event.stopPropagation());
1454
+ nudge.addEventListener('click', () => {
1455
+ if (able)
1456
+ land(id, way === 'up' ? at - 1 : at + 2);
1457
+ });
1458
+ row.append(nudge);
1459
+ }
1460
+ row.addEventListener('mousedown', (event) => {
1461
+ if (event.button !== 0)
1462
+ return;
1463
+ event.preventDefault();
1464
+ Object.assign(now, { held: id, from: event.clientY, y: event.clientY, moved: false });
1465
+ });
1466
+ }
1467
+ column.append(row);
1468
+ });
1469
+ if (!dragging || now.held === null)
1470
+ return;
1471
+ // Where it would land: nowhere new before itself or before the one after it.
1472
+ if (to !== own && to !== own + 1) {
1473
+ const mark = doc.createElement('div');
1474
+ mark.setAttribute('data-cms-stack-line', String(to));
1475
+ Object.assign(mark.style, { position: 'absolute', left: '-10px', right: '-10px', top: `${head + to * STEP - 6}px`, height: '6px', borderRadius: '3px', background: ACCENT, boxShadow: `0 0 0 3px color-mix(in srgb, ${ACCENT} 30%, transparent)` });
1476
+ column.append(mark);
1477
+ }
1478
+ const ghost = doc.createElement('div');
1479
+ ghost.setAttribute('data-cms-stack-held', now.held);
1480
+ Object.assign(ghost.style, rowLook, { top: `${(now.y - shift) / grow - ROW / 2}px`, left: '40px', right: '-40px', background: ACCENT, color: ACCENT_INK, font: `600 14px/1 ${FONT}`, boxShadow: '0 12px 32px rgb(0 0 0 / 0.45)', transform: 'rotate(-1deg)', pointerEvents: 'none', cursor: 'grabbing' });
1481
+ const held = doc.createElement('span');
1482
+ held.textContent = stackWords.names[now.held] ?? '';
1483
+ Object.assign(held.style, { flex: '1', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' });
1484
+ ghost.append(drawing('drag'), held);
1485
+ column.append(ghost);
1486
+ };
1487
+ const wordsNow = () => {
1488
+ if (!tools)
1489
+ return;
1490
+ const { labels, sections } = tools;
1491
+ stackWords = { names: Object.fromEntries(pageOrder().map((id) => [id, word(sections[id]?.name)])), title: word(labels['reorder']), done: word(labels['done']), up: word(labels['up']), down: word(labels['down']) };
1492
+ };
1493
+ const keepStack = () => {
1494
+ try {
1495
+ if (stacked?.stays)
1496
+ page.sessionStorage.setItem(stackKey, JSON.stringify({ order: stacked.order, words: stackWords }));
1497
+ else
1498
+ page.sessionStorage.removeItem(stackKey);
1499
+ }
1500
+ catch {
1501
+ // A page that may keep nothing opens the rows again from the bar.
1502
+ }
1503
+ };
1504
+ const closeStack = () => {
1505
+ stacked = null;
1506
+ keepStack();
1507
+ draw();
1508
+ drawStack();
1509
+ };
1510
+ /** The held section goes before the row at `to`, and the editor is told; the rows stay if they were opened to stay. */
1511
+ const land = (id, to) => {
1512
+ const now = stacked;
1513
+ if (!now)
1514
+ return false;
1515
+ const own = now.order.indexOf(id);
1516
+ if (own < 0 || to === own || to === own + 1)
1517
+ return false;
1518
+ const before = now.order[to] ?? null;
1519
+ const rest = now.order.filter((other) => other !== id);
1520
+ rest.splice(before === null ? rest.length : rest.indexOf(before), 0, id);
1521
+ now.order = rest;
1522
+ if (now.stays)
1523
+ keepStack();
1524
+ say({ type: 'move', id, before });
1525
+ drawStack();
1526
+ return true;
1527
+ };
1528
+ const openStack = (held, stays, y, order = pageOrder()) => {
1529
+ if (order.length < 2)
1530
+ return;
1531
+ wordsNow();
1532
+ stacked = { order, stays, held, from: y, y, moved: held !== null };
1533
+ const total = (headOf(stacked) + order.length * STEP) * grow;
1534
+ // Opened by a drag, the held section's own row is under the pointer; opened from the bar, the rows are in the middle.
1535
+ shift = held === null ? Math.max((page.innerHeight - total) / 2, 24) : y - (order.indexOf(held) * STEP + ROW / 2) * grow;
1536
+ tooled = null;
1537
+ forget();
1538
+ draw();
1539
+ drawStack();
1540
+ if (held !== null)
1541
+ page.setTimeout(creepStack, 16);
1542
+ };
1543
+ // Near the top or the bottom, rows out of sight come within reach.
1544
+ const creepStack = () => {
1545
+ const now = stacked;
1546
+ if (!now || now.held === null)
1547
+ return;
1548
+ const total = (headOf(now) + now.order.length * STEP) * grow;
1549
+ const by = now.y < 72 && shift < 24 ? 12 : now.y > page.innerHeight - 72 && shift + total > page.innerHeight - 24 ? -12 : 0;
1550
+ if (by !== 0 && now.moved) {
1551
+ shift += by;
1552
+ drawStack();
1553
+ }
1554
+ page.setTimeout(creepStack, 16);
1555
+ };
1556
+ doc.addEventListener('mousemove', (event) => {
1557
+ const now = stacked;
1558
+ if (!now || now.held === null)
1559
+ return;
1560
+ now.y = event.clientY;
1561
+ if (!now.moved && Math.abs(now.y - now.from) > 4) {
1562
+ now.moved = true;
1563
+ page.setTimeout(creepStack, 16);
1564
+ }
1565
+ if (now.moved)
1566
+ drawStack();
1567
+ }, true);
1568
+ const letGo = (drop) => {
1569
+ const now = stacked;
1570
+ if (!now || now.held === null)
1571
+ return;
1572
+ const { held, moved } = now;
1573
+ const to = landing(now);
1574
+ now.held = null;
1575
+ now.moved = false;
1576
+ const landed = drop && moved && land(held, to);
1577
+ if (now.stays)
1578
+ drawStack();
1579
+ // Dropped, the rows stay in their new order until the page drawn from it takes their place.
1580
+ else if (landed)
1581
+ page.setTimeout(() => stacked === now && closeStack(), 4000);
1582
+ else
1583
+ closeStack();
1584
+ };
1585
+ doc.addEventListener('mouseup', () => letGo(true), true);
1586
+ doc.documentElement.addEventListener('mouseleave', () => letGo(false));
1587
+ doc.addEventListener('keydown', (event) => {
1588
+ if (!stacked || event.key !== 'Escape')
1589
+ return;
1590
+ event.stopPropagation();
1591
+ if (stacked.held !== null && stacked.stays)
1592
+ letGo(false);
1593
+ else
1594
+ closeStack();
1595
+ }, true);
1596
+ // A press beside the rows closes them.
1597
+ stack.addEventListener('mousedown', (event) => {
1598
+ if (event.target === stack && stacked?.stays)
1599
+ closeStack();
1600
+ });
1601
+ stack.addEventListener('wheel', (event) => {
1602
+ const now = stacked;
1603
+ if (!now)
1604
+ return;
1605
+ event.preventDefault();
1606
+ const total = (headOf(now) + now.order.length * STEP) * grow;
1607
+ shift = Math.min(Math.max(shift - event.deltaY, Math.min(page.innerHeight - total - 24, 24)), 24);
1608
+ drawStack();
1609
+ }, { passive: false });
1610
+ // Rows that were open when a move drew the page again are open on it at once, in the new order.
1611
+ try {
1612
+ const read = JSON.parse(page.sessionStorage.getItem(stackKey) ?? 'null');
1613
+ const was = typeof read === 'object' && read !== null ? read : {};
1614
+ if (Array.isArray(was.order) && was.order.every((id) => typeof id === 'string') && typeof was.words === 'object' && was.words !== null) {
1615
+ const words = was.words;
1616
+ const names = typeof words.names === 'object' && words.names !== null ? words.names : {};
1617
+ stackWords = { names: Object.fromEntries(Object.entries(names).map(([id, name]) => [id, word(name)])), title: word(words.title), done: word(words.done), up: word(words.up), down: word(words.down) };
1618
+ const order = was.order;
1619
+ if (order.length > 1) {
1620
+ stacked = { order, stays: true, held: null, from: 0, y: 0, moved: false };
1621
+ shift = Math.max((page.innerHeight - (56 + order.length * STEP) * grow) / 2, 24);
1622
+ drawStack();
1623
+ }
1624
+ }
1625
+ }
1626
+ catch {
1627
+ // Nothing kept, or nothing that can be read: the rows are opened from the bar.
1628
+ }
1360
1629
  // Events.
1361
1630
  doc.addEventListener('mouseover', (event) => {
1362
1631
  // Over the layer's own bar and buttons, what they are for stays as it was.
@@ -1407,6 +1676,12 @@ export function previewBridge(page) {
1407
1676
  typable = typeof places === 'object' && places !== null ? places : {};
1408
1677
  return;
1409
1678
  }
1679
+ if (event.data.type === 'escape') {
1680
+ // Escape pressed in the editor around the page: the page takes it as its own, so a drag is dropped
1681
+ // and the list of sections closed wherever the keyboard was.
1682
+ doc.dispatchEvent(new page.KeyboardEvent('keydown', { key: 'Escape', bubbles: true }));
1683
+ return;
1684
+ }
1410
1685
  if (event.data.type === 'linkAnswer') {
1411
1686
  answerLink(event.data.href);
1412
1687
  return;
@@ -1441,6 +1716,14 @@ export function previewBridge(page) {
1441
1716
  }
1442
1717
  if (tools)
1443
1718
  again = null;
1719
+ if (stacked && stacked.held === null && tools) {
1720
+ // The page as it is now says the order and the names.
1721
+ const order = pageOrder();
1722
+ if (order.length > 1)
1723
+ stacked.order = order;
1724
+ wordsNow();
1725
+ drawStack();
1726
+ }
1444
1727
  draw();
1445
1728
  return;
1446
1729
  }
@@ -1454,9 +1737,10 @@ export function previewBridge(page) {
1454
1737
  return;
1455
1738
  marks.chosen = mark;
1456
1739
  const rect = mark.element.getBoundingClientRect();
1457
- // What is already in view stays where it is: the page does not jump while someone types. Nor
1458
- // does a page drawn again, which is where the person left it: the editor says so (`still`).
1459
- if (event.data.still !== true && (rect.bottom <= 0 || rect.top >= page.innerHeight)) {
1740
+ // A section asked for is brought to the top of the window, unless its top is there already (in the
1741
+ // upper half): the page does not jump for what is in view. Nor does a page drawn again, which is
1742
+ // where the person left it: the editor says so (`still`).
1743
+ if (event.data.still !== true && (rect.top < 0 || rect.top >= page.innerHeight / 2)) {
1460
1744
  // Room for a header that stays at the top of the page.
1461
1745
  mark.element.style.scrollMarginTop = '6rem';
1462
1746
  settled = true;