包文件→ .shtukbase/packages/layout-studio/test/props-lens.html
test/props-lens.html
66 行, 3.0 KB.
文件按包中的原样显示:代码及其注释不做翻译。
- <!doctype html>
- <html lang="ru">
- <head>
- <meta charset="utf-8">
- <title>Свойства</title>
- <link rel="stylesheet" href="/_kit/kit.css">
- <link rel="stylesheet" href="/_kit/skins/calm.css">
- <link rel="stylesheet" href="/_kit/skins/desktop.css">
- <script src="/_pkg/layout-basic/lens.js"></script>
- <style>
- html, body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font); font-size: 13px; }
- .pp { padding: 12px 14px; }
- .pp h2 { margin: 0 0 10px; font-size: 14px; font-weight: 600; display: flex; gap: 6px; align-items: center; }
- .pp .path { color: var(--faint); font-family: var(--mono); font-size: 11px; margin: -6px 0 12px; word-break: break-all; }
- .pp dl { display: grid; grid-template-columns: 96px 1fr; gap: 6px 10px; margin: 0; }
- .pp dt { color: var(--lx-muted); overflow: hidden; text-overflow: ellipsis; }
- .pp dd { margin: 0; overflow-wrap: anywhere; }
- .pp .muted { color: var(--lx-muted); }
- </style>
- </head>
- <body>
- <div class="pp" id="out"><span class="muted">…</span></div>
- <script>
- // Demo panel lens: shows the meta of the page open in the focused main side.
- // It learns that page from the shell's {type:'focus', path} message (layout-studio addition);
- // the first path comes in its own URL (?path=), like any lens.
- var out = document.getElementById('out');
- var current = shtuk.path;
- var token = 0;
- function fmt(v) { return v == null ? '' : typeof v === 'object' ? JSON.stringify(v) : String(v); }
- function draw(path) {
- var my = ++token;
- if (!path || path === '/') { out.innerHTML = '<span class="muted">Нет открытой страницы</span>'; shtuk.ready(); return; }
- shtuk.call('records.read', { path: path }).then(function (r) {
- if (my !== token) return;
- out.textContent = '';
- var meta = r.meta || {};
- var h = document.createElement('h2');
- h.textContent = (meta.icon ? meta.icon + ' ' : '') + (meta.title || path.split('/').pop());
- var p = document.createElement('div'); p.className = 'path'; p.textContent = path;
- var dl = document.createElement('dl');
- Object.keys(meta).filter(function (k) { return k !== 'properties' && k !== 'items'; }).forEach(function (k) {
- var dt = document.createElement('dt'); dt.textContent = k;
- var dd = document.createElement('dd'); dd.textContent = fmt(meta[k]);
- dl.appendChild(dt); dl.appendChild(dd);
- });
- out.appendChild(h); out.appendChild(p); out.appendChild(dl);
- shtuk.ready();
- }, function (e) {
- if (my !== token) return;
- out.innerHTML = '<span class="muted"></span>';
- out.firstChild.textContent = String(e.message || e);
- shtuk.ready();
- });
- }
- window.addEventListener('message', function (e) {
- if (e.source !== window.parent || !e.data || e.data.type !== 'focus') return;
- if (e.data.path === current) return;
- current = e.data.path;
- draw(current);
- });
- shtuk.on('changed', function (m) { if (!m || !m.path || m.path === current) draw(current); });
- draw(current);
- </script>
- </body>
- </html>