view.html 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8" />
  5. <title>E2E entries view</title>
  6. <style>
  7. :root {
  8. color-scheme: light dark;
  9. }
  10. body {
  11. margin: 0;
  12. padding: 16px;
  13. font:
  14. 13px/1.5 system-ui,
  15. sans-serif;
  16. color: var(--color-text-primary, #1f2328);
  17. background: var(--color-background-primary, transparent);
  18. }
  19. h1 {
  20. margin: 0 0 8px;
  21. font-size: 15px;
  22. }
  23. dl {
  24. display: grid;
  25. grid-template-columns: max-content 1fr;
  26. gap: 4px 12px;
  27. margin: 0;
  28. }
  29. dt {
  30. color: var(--color-text-secondary, #59636e);
  31. }
  32. dd {
  33. margin: 0;
  34. font-family: ui-monospace, monospace;
  35. word-break: break-all;
  36. }
  37. </style>
  38. </head>
  39. <body data-ready="0">
  40. <h1 id="title">E2E entries view</h1>
  41. <dl>
  42. <dt>view</dt>
  43. <dd id="view">loading</dd>
  44. <dt>scope</dt>
  45. <dd id="scope"></dd>
  46. <dt>input</dt>
  47. <dd id="input"></dd>
  48. </dl>
  49. <script>
  50. // 页面脚本的错误记进 DOM,E2E 失败时能直接读到原因。
  51. window.__e2eErrors = [];
  52. window.addEventListener("error", (event) => window.__e2eErrors.push(String(event.message)));
  53. window.addEventListener("unhandledrejection", (event) =>
  54. window.__e2eErrors.push(String(event.reason?.message ?? event.reason)),
  55. );
  56. </script>
  57. <script>
  58. // 页面只经 window.zcode 读写;window.zcode 是不可配置的全局属性,顶层不再声明同名变量。
  59. const host = window.zcode;
  60. const applyHostStyles = () => {
  61. const variables = host.hostContext?.styles?.variables ?? {};
  62. for (const [name, value] of Object.entries(variables)) {
  63. if (typeof value === "string") document.documentElement.style.setProperty(name, value);
  64. }
  65. document.documentElement.dataset.theme = host.theme ?? "";
  66. };
  67. host.subscribe(applyHostStyles);
  68. host.ready().then(async () => {
  69. applyHostStyles();
  70. const result = await host.callTool("describe", {});
  71. const data = result.structuredContent ?? {};
  72. document.getElementById("title").textContent =
  73. data.viewId === "file" ? "E2E file viewer" : "E2E nav view";
  74. document.getElementById("view").textContent = data.viewId ?? "";
  75. document.getElementById("scope").textContent = data.scope ?? "";
  76. document.getElementById("input").textContent = data.input
  77. ? `${data.input.kind}: ${data.input.path}`
  78. : "none";
  79. Object.assign(document.body.dataset, {
  80. ready: "1",
  81. viewId: data.viewId ?? "",
  82. scope: data.scope ?? "",
  83. inputKind: data.input?.kind ?? "",
  84. inputPath: data.input?.path ?? "",
  85. inputWorkspace: data.input?.workspace?.workspacePath ?? "",
  86. });
  87. });
  88. </script>
  89. </body>
  90. </html>