From 87e4ef3baa894980987c29b88ddd20ff13e057b5 Mon Sep 17 00:00:00 2001 From: Denis Skripchenko Date: Sun, 1 Nov 2026 14:36:03 +0300 Subject: [PATCH 1/3] feat: print views without a dialog, for hosts printing their own page Co-Authored-By: Claude Opus 5.5 --- .changeset/print-view.md | 5 +++++ docs/de/reference.md | 9 +++++++++ docs/en/reference.md | 8 ++++++++ docs/ru/reference.md | 8 ++++++++ docs/zh/reference.md | 6 ++++++ src/vue/OpenApiOperation.vue | 11 +++++++++-- src/vue/OpenApiReference.vue | 9 +++++++-- src/vue/index.ts | 2 +- src/vue/print.ts | 37 +++++++++++++++++++++++++++++------- tests/print.spec.ts | 31 ++++++++++++++++++++++++++++++ 10 files changed, 114 insertions(+), 12 deletions(-) create mode 100644 .changeset/print-view.md diff --git a/.changeset/print-view.md b/.changeset/print-view.md new file mode 100644 index 0000000..02c93ad --- /dev/null +++ b/.changeset/print-view.md @@ -0,0 +1,5 @@ +--- +'@dskripchenko/openapi': minor +--- + +Print views for a host printing its own page: `printView()` on `` and `` (through a template ref), and `documentPrintView(ctx)` / `operationPrintView(entry, ctx)`, resolve with `{ html, css, title }` — the static markup `printDocument` / `printOperation` print, a stylesheet for a shadow root, and the title — without opening a dialog. The reference's ref also exposes `print()`. diff --git a/docs/de/reference.md b/docs/de/reference.md index 5f26326..0d82733 100644 --- a/docs/de/reference.md +++ b/docs/de/reference.md @@ -648,6 +648,15 @@ Kontext der Referenz entgegen (siehe [den Kontext](#der-kontext)). `url` ist die mit der Operation gedruckte Adresse, `base` die Seite, an die die Anker der Operationen angehängt werden. +Eine Anwendung, die ihre eigene Seite druckt — mit der Referenz darin —, +bekommt dieselbe Ansicht ohne Dialog: `printView()` an `` +(die ganze Spezifikation) und an `` (seine Operation), über +eine Template-Ref, liefert `{ html, css, title }` — statisches Markup, ein +Stylesheet für die Shadow Root, in die es kommt, und den Titel — oder null, +solange die Spezifikation nicht geladen ist. Aus Code: +`documentPrintView(ctx, { base? })` und `operationPrintView(entry, ctx, { url? })`. +Die Ref der Referenz hat auch `print()`. + ## Anfragebeispiele Die Auswahl der Beispiele bietet die Sprachen aus `snippetTargets` in der diff --git a/docs/en/reference.md b/docs/en/reference.md index 7097d7c..a280960 100644 --- a/docs/en/reference.md +++ b/docs/en/reference.md @@ -607,6 +607,14 @@ reference context (see [the context](#the-context)). `url` is the address printed with the operation, `base` the page the operation anchors are appended to. +A host that prints its own page — with the reference in it — takes the same +view without a dialog: `printView()` on `` (the whole spec) +and on `` (its operation), through a template ref, resolves +with `{ html, css, title }` — static markup, a stylesheet for a shadow root to +put it in, and the title — or null before the spec is loaded. +`documentPrintView(ctx, { base? })` and `operationPrintView(entry, ctx, { url? })` +do it from code. The reference's ref also has `print()`. + ## Request samples The samples select offers the languages of `snippetTargets`, in the order diff --git a/docs/ru/reference.md b/docs/ru/reference.md index 9f62c6c..8661a73 100644 --- a/docs/ru/reference.md +++ b/docs/ru/reference.md @@ -618,6 +618,14 @@ PDF» — один из принтеров: справочника (см. [контекст](#контекст)). `url` — адрес, печатаемый вместе с операцией, `base` — страница, к которой добавляются якоря операций. +Программа, которая печатает свою страницу целиком — со справочником на ней, — +берёт тот же вид без диалога: `printView()` у `` (вся +спецификация) и у `` (его операция), через ref шаблона, +возвращает `{ html, css, title }` — статическую разметку, стили для shadow +root, в который её кладут, и заголовок — или null, пока спецификация не +загружена. Из кода — `documentPrintView(ctx, { base? })` и +`operationPrintView(entry, ctx, { url? })`. У ref справочника есть и `print()`. + ## Примеры запроса Выбор примеров предлагает языки из `snippetTargets` в заданном порядке; diff --git a/docs/zh/reference.md b/docs/zh/reference.md index 6dba9d2..175e602 100644 --- a/docs/zh/reference.md +++ b/docs/zh/reference.md @@ -514,6 +514,12 @@ OpenID Connect 访问令牌及其有效期(过期的不会恢复),以及 b `printDocument(ctx, { base?, mode? })` 在代码中完成同样的事;它们接收参考页的上下文 (见 [上下文](#上下文))。`url` 是随操作一起打印的地址,`base` 是操作锚点所追加到的页面。 +自行打印整个页面(页面中包含参考文档)的宿主程序,可以不经对话框获得同样的视图:通过模板 ref 调用 +``(整个规范)或 ``(其操作)上的 `printView()`,返回 +`{ html, css, title }`——静态标记、放置它的 shadow root 所用的样式表以及标题;规范尚未加载时返回 null。 +在代码中可使用 `documentPrintView(ctx, { base? })` 和 `operationPrintView(entry, ctx, { url? })`。 +参考文档的 ref 也提供 `print()`。 + ## 请求示例 示例选择器按给定顺序提供 `snippetTargets` 中的语言;`defaultSnippet` diff --git a/src/vue/OpenApiOperation.vue b/src/vue/OpenApiOperation.vue index 0c95855..c08f8fc 100644 --- a/src/vue/OpenApiOperation.vue +++ b/src/vue/OpenApiOperation.vue @@ -23,7 +23,7 @@ import type { OpenApiLabels } from './labels' import OaAuth from './OaAuth.vue' import OaOperation from './OaOperation.vue' import OaServers from './OaServers.vue' -import { printOperation } from './print' +import { operationPrintView, printOperation, type PrintView } from './print' import { useReferenceContext } from './useReferenceContext' const props = withDefaults( @@ -111,7 +111,14 @@ function print(): void { void printOperation(entry.value, ctx, url ? { url } : {}) } -defineExpose({ spec: loaded, entry, print }) +/** The operation as a static print view, for a host printing its own page; null before it loads. */ +async function printView(): Promise { + if (!entry.value) return null + const url = referenceLink.value ? new URL(referenceLink.value, window.location.href).href : undefined + return operationPrintView(entry.value, ctx, url ? { url } : {}) +} + +defineExpose({ spec: loaded, entry, print, printView })