ShtukbaseStandard
包文件→ .shtukbase/packages/layout-studio/test/props-lens.html

test/props-lens.html

66 行, 3.0 KB.

文件按包中的原样显示:代码及其注释不做翻译。

  1. <!doctype html>
  2. <html lang="ru">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>Свойства</title>
  6. <link rel="stylesheet" href="/_kit/kit.css">
  7. <link rel="stylesheet" href="/_kit/skins/calm.css">
  8. <link rel="stylesheet" href="/_kit/skins/desktop.css">
  9. <script src="/_pkg/layout-basic/lens.js"></script>
  10. <style>
  11. html, body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font); font-size: 13px; }
  12. .pp { padding: 12px 14px; }
  13. .pp h2 { margin: 0 0 10px; font-size: 14px; font-weight: 600; display: flex; gap: 6px; align-items: center; }
  14. .pp .path { color: var(--faint); font-family: var(--mono); font-size: 11px; margin: -6px 0 12px; word-break: break-all; }
  15. .pp dl { display: grid; grid-template-columns: 96px 1fr; gap: 6px 10px; margin: 0; }
  16. .pp dt { color: var(--lx-muted); overflow: hidden; text-overflow: ellipsis; }
  17. .pp dd { margin: 0; overflow-wrap: anywhere; }
  18. .pp .muted { color: var(--lx-muted); }
  19. </style>
  20. </head>
  21. <body>
  22. <div class="pp" id="out"><span class="muted">…</span></div>
  23. <script>
  24. // Demo panel lens: shows the meta of the page open in the focused main side.
  25. // It learns that page from the shell's {type:'focus', path} message (layout-studio addition);
  26. // the first path comes in its own URL (?path=), like any lens.
  27. var out = document.getElementById('out');
  28. var current = shtuk.path;
  29. var token = 0;
  30. function fmt(v) { return v == null ? '' : typeof v === 'object' ? JSON.stringify(v) : String(v); }
  31. function draw(path) {
  32. var my = ++token;
  33. if (!path || path === '/') { out.innerHTML = '<span class="muted">Нет открытой страницы</span>'; shtuk.ready(); return; }
  34. shtuk.call('records.read', { path: path }).then(function (r) {
  35. if (my !== token) return;
  36. out.textContent = '';
  37. var meta = r.meta || {};
  38. var h = document.createElement('h2');
  39. h.textContent = (meta.icon ? meta.icon + ' ' : '') + (meta.title || path.split('/').pop());
  40. var p = document.createElement('div'); p.className = 'path'; p.textContent = path;
  41. var dl = document.createElement('dl');
  42. Object.keys(meta).filter(function (k) { return k !== 'properties' && k !== 'items'; }).forEach(function (k) {
  43. var dt = document.createElement('dt'); dt.textContent = k;
  44. var dd = document.createElement('dd'); dd.textContent = fmt(meta[k]);
  45. dl.appendChild(dt); dl.appendChild(dd);
  46. });
  47. out.appendChild(h); out.appendChild(p); out.appendChild(dl);
  48. shtuk.ready();
  49. }, function (e) {
  50. if (my !== token) return;
  51. out.innerHTML = '<span class="muted"></span>';
  52. out.firstChild.textContent = String(e.message || e);
  53. shtuk.ready();
  54. });
  55. }
  56. window.addEventListener('message', function (e) {
  57. if (e.source !== window.parent || !e.data || e.data.type !== 'focus') return;
  58. if (e.data.path === current) return;
  59. current = e.data.path;
  60. draw(current);
  61. });
  62. shtuk.on('changed', function (m) { if (!m || !m.path || m.path === current) draw(current); });
  63. draw(current);
  64. </script>
  65. </body>
  66. </html>