chadtmiller.com/hud
A remote MCP server that shows atproto records as interactive UI inside MCP Apps hosts
place.hud.hudkit 0.6.0 Latest 5 packages
0
0
A knotless pull's pictures draw in its body, private ones too
crates/hud-core/src/testdata/knotless/dev.knotless.defs.json+21−0
| @@ -502,9 +502,25 @@ | ||
"type": "array", | ||
"description": "The labels it carries, as the repository defines them, in the order it does. Absent when it carries none.", | ||
"items": { "type": "ref", "ref": "dev.knotless.repo#label" } | ||
}, | ||
"attachments": { | ||
"type": "array", | ||
"description": "The pictures its record attaches (dev.knotless.defs#image), in its order, each where any reader loads it. Given where the view is made for someone asking, as dev.knotless.getThread's `item`; absent when it attaches none.", | ||
"items": { "type": "ref", "ref": "#attachmentView" } | ||
} | ||
} | ||
}, | ||
"attachmentView": { | ||
"type": "object", | ||
"description": "A picture a pull, an issue or a comment attaches, as readers load it: from this appview, with no cookie or header needed.", | ||
"required": ["cid", "url"], | ||
"properties": { | ||
"cid": { "type": "string", "format": "cid", "description": "The attached blob." }, | ||
"url": { "type": "string", "format": "uri", "description": "An absolute URL on this appview's public origin that serves it: dev.knotless.getAttachment's. For a private repository it carries a `token` for the account that asked, lasting about an hour and ended by their logging out here: theirs alone, not to be shared or kept." }, | ||
"width": { "type": "integer", "minimum": 1, "description": "How wide it is drawn, in CSS pixels, as its record's dev.knotless.defs#image says." }, | ||
"height": { "type": "integer", "minimum": 1, "description": "How high it is drawn, in CSS pixels, as its record's dev.knotless.defs#image says." } | ||
} | ||
}, | ||
"commentView": { | ||
"type": "object", | ||
"description": "Something said on a pull or an issue.", | ||
| @@ -527,6 +543,11 @@ | ||
"type": "array", | ||
"description": "How accounts reacted to it, by content, in the order dev.knotless.defs#reactionContent lists them. Absent when none did.", | ||
"items": { "type": "ref", "ref": "#reactionCountView" } | ||
}, | ||
"attachments": { | ||
"type": "array", | ||
"description": "The pictures its record attaches (dev.knotless.defs#image), in its order, each where any reader loads it. Absent when it attaches none.", | ||
"items": { "type": "ref", "ref": "#attachmentView" } | ||
} | ||
} | ||
}, | ||
crates/hud-core/src/ui/document.rs+179−19
| @@ -4,8 +4,11 @@ | ||
//! (Leaflet's pages of blocks, markpub's markdown, else its plain text as | ||
//! paragraphs, else the content itself as JSON), as the web renderer's | ||
//! Markdown and document/ components read them. Markdown's HTML stays text | ||
//! but for `<details>` and its `<summary>`, its pictures show their alt text | ||
//! and load nothing, and its links open only pages (http or https). | ||
//! but for `<details>` and its `<summary>`, its links open only pages (http | ||
//! or https), and its pictures show their alt text and load nothing, but | ||
//! those the text's `pictures` name (`Picture`), drawn as blocks of their | ||
//! own where a block may be (not in a heading, a table, a link or a | ||
//! summary). | ||
//! | ||
//! A block is `{ kind, … }`, any of them with `align` (center, right or | ||
//! justify, a Leaflet block's own): | ||
| @@ -20,7 +23,9 @@ | ||
//! order they are first referred to (a reference reads `[n]`). | ||
//! - `details { runs, blocks, expanded? }`: markdown's `<details>`, `runs` | ||
//! its summary, `blocks` what it hides, `expanded` where it starts open. | ||
//! - `image { src, alt, ratio }`, `gallery { images: [{ src, alt, ratio }] }`. | ||
//! - `image { src, alt, ratio, width? }`, `width` the most CSS pixels it is | ||
//! drawn across, where its picture says; `gallery { images: [{ src, alt, | ||
//! ratio }] }`. | ||
//! - `card { kicker, title, description?, image, open? }`, a link to | ||
//! something outside the text; `button { label, open? }`. | ||
//! - `bskyPost { uri, quote?, fallback }`: a Bluesky post, `quote` the | ||
| @@ -74,8 +79,57 @@ fn unsupported(text: String) -> Value { | ||
| ||
// Markdown. | ||
| ||
/// Markdown as blocks: CommonMark, or with `gfm` GitHub's extensions. | ||
/// A picture markdown's images may name, by its blob's CID (an image whose | ||
/// URL is `com.atproto.sync.getBlob`'s with that `cid`, on whatever host) | ||
/// or by its own URL: drawn from `src`, at `ratio`, no wider than `width`. | ||
pub(super) struct Picture { | ||
cid: String, | ||
url: String, | ||
src: Value, | ||
ratio: f64, | ||
width: Option<u64>, | ||
} | ||
| ||
impl Picture { | ||
/// The pictures a value lists, each `{ cid, url, width?, height? }` | ||
/// (`width` and `height` in CSS pixels), those whose URL the view may | ||
/// load. | ||
pub(super) fn all(found: Option<&Value>, ctx: &Ctx) -> Vec<Picture> { | ||
let listed = found.and_then(Value::as_array).into_iter().flatten(); | ||
listed | ||
.filter_map(|p| { | ||
let src = source_of(Some(&p["url"]), ctx, false); | ||
let cid = str_at(p, "cid").filter(|_| !src.is_null())?; | ||
Some(Picture { | ||
cid: cid.to_string(), | ||
url: p["url"].as_str().unwrap_or_default().to_string(), | ||
src, | ||
ratio: ratio_of(p).unwrap_or(4.0 / 3.0), | ||
width: whole(&p["width"]), | ||
}) | ||
}) | ||
.collect() | ||
} | ||
} | ||
| ||
/// The CID a `com.atproto.sync.getBlob` URL names; none for another URL. | ||
fn blob_cid(dest: &str) -> Option<String> { | ||
let url = url::Url::parse(dest) | ||
.ok() | ||
.filter(|u| u.path().ends_with("/xrpc/com.atproto.sync.getBlob"))?; | ||
url.query_pairs() | ||
.find(|(k, _)| k == "cid") | ||
.map(|(_, v)| v.into_owned()) | ||
} | ||
| ||
/// Markdown as blocks: CommonMark, or with `gfm` GitHub's extensions; no | ||
/// picture drawn. | ||
pub(super) fn markdown(source: &str, gfm: bool) -> Vec<Value> { | ||
pictured(source, gfm, &[]) | ||
} | ||
| ||
/// Markdown as blocks, its images that name one of `pictures` drawn. | ||
pub(super) fn pictured(source: &str, gfm: bool, pictures: &[Picture]) -> Vec<Value> { | ||
let options = if gfm { | ||
Options::ENABLE_TABLES | ||
| Options::ENABLE_STRIKETHROUGH | ||
| @@ -86,6 +140,7 @@ pub(super) fn markdown(source: &str, gfm: bool) -> Vec<Value> { | ||
}; | ||
let mut reader = Reader { | ||
gfm, | ||
pictures, | ||
..Reader::default() | ||
}; | ||
for event in Parser::new_ext(source, options) { | ||
| @@ -142,8 +197,9 @@ struct Style { | ||
/// Markdown's events read into blocks. Text is gathered while its style | ||
/// holds, so a bare link split across events is found whole. | ||
#[derive(Default)] | ||
struct Reader { | ||
struct Reader<'p> { | ||
gfm: bool, | ||
pictures: &'p [Picture], | ||
blocks: Vec<Value>, | ||
open: Vec<Open>, | ||
runs: Vec<Value>, | ||
| @@ -154,9 +210,13 @@ struct Reader { | ||
strike: u32, | ||
/// The links the text is in, each the page it opens (None for one that opens none). | ||
links: Vec<Option<String>>, | ||
/// How many pictures the text is in, and their alt text so far. | ||
/// How many pictures the text is in, and the outermost's alt text so | ||
/// far and URL. | ||
images: u32, | ||
alt: Option<String>, | ||
image: String, | ||
/// Whether the text is a heading's or a table's, where no block goes. | ||
runs_only: bool, | ||
code: Option<(Option<String>, String)>, | ||
html: Option<String>, | ||
table: Table, | ||
| @@ -165,7 +225,7 @@ struct Reader { | ||
refs: Vec<String>, | ||
} | ||
| ||
impl Reader { | ||
impl<'p> Reader<'p> { | ||
fn style(&self) -> Style { | ||
Style { | ||
marks: Marks { | ||
| @@ -235,7 +295,10 @@ impl Reader { | ||
*tight = false; | ||
} | ||
} | ||
Tag::Heading { .. } | Tag::Table(_) => self.settle(), | ||
Tag::Heading { .. } | Tag::Table(_) => { | ||
self.settle(); | ||
self.runs_only = true; | ||
} | ||
Tag::BlockQuote(_) => self.enter(Opened::Quote), | ||
Tag::CodeBlock(kind) => { | ||
self.settle(); | ||
| @@ -262,10 +325,11 @@ impl Reader { | ||
Tag::Link { dest_url, .. } => self | ||
.links | ||
.push(http_url(&dest_url).then(|| dest_url.to_string())), | ||
Tag::Image { .. } => { | ||
Tag::Image { dest_url, .. } => { | ||
self.images += 1; | ||
if self.alt.is_none() { | ||
self.alt = Some(String::new()); | ||
self.image = dest_url.to_string(); | ||
} | ||
} | ||
_ => {} | ||
| @@ -275,6 +339,7 @@ impl Reader { | ||
fn end(&mut self, tag: TagEnd) { | ||
match tag { | ||
TagEnd::Heading(level) => { | ||
self.runs_only = false; | ||
let runs = self.take_runs(); | ||
self.push(json!({ "kind": "heading", "level": level as u8, "runs": runs })); | ||
} | ||
| @@ -317,6 +382,7 @@ impl Reader { | ||
self.table.rows.push(Value::Array(row)); | ||
} | ||
TagEnd::Table => { | ||
self.runs_only = false; | ||
let t = std::mem::take(&mut self.table); | ||
self.push(json!({ "kind": "table", "head": t.head, "rows": t.rows })); | ||
} | ||
| @@ -330,15 +396,18 @@ impl Reader { | ||
self.images = self.images.saturating_sub(1); | ||
if self.images == 0 | ||
&& let Some(alt) = self.alt.take() | ||
&& !alt.is_empty() | ||
{ | ||
self.piece( | ||
&format!("[{alt}]"), | ||
Marks { | ||
alt: true, | ||
..Marks::default() | ||
}, | ||
); | ||
match self.picture() { | ||
Some(p) => self.draw(p, alt), | ||
None if alt.is_empty() => {} | ||
None => self.piece( | ||
&format!("[{alt}]"), | ||
Marks { | ||
alt: true, | ||
..Marks::default() | ||
}, | ||
), | ||
} | ||
} | ||
} | ||
// A paragraph's end: its text made one. No other ends come, as | ||
| @@ -347,6 +416,39 @@ impl Reader { | ||
} | ||
} | ||
| ||
/// The picture the image just read names, where a block of its own | ||
/// may go: not in a heading, a table, a link or a details' summary. | ||
fn picture(&self) -> Option<&'p Picture> { | ||
let summary = matches!( | ||
self.open.last(), | ||
Some(Open { | ||
kind: Opened::Details { | ||
in_summary: true, | ||
.. | ||
}, | ||
.. | ||
}) | ||
); | ||
if self.runs_only || !self.links.is_empty() || summary { | ||
return None; | ||
} | ||
let pictures = self.pictures; | ||
let cid = blob_cid(&self.image); | ||
pictures | ||
.iter() | ||
.find(|p| p.url == self.image || cid.as_deref() == Some(p.cid.as_str())) | ||
} | ||
| ||
/// A picture as a block of its own, the text before it a paragraph. | ||
fn draw(&mut self, p: &Picture, alt: String) { | ||
self.settle(); | ||
let mut b = json!({ "kind": "image", "src": p.src, "alt": alt, "ratio": p.ratio }); | ||
if let Some(w) = p.width { | ||
b["width"] = w.into(); | ||
} | ||
self.push(b); | ||
} | ||
| ||
/// Text where it is: a code block's, an HTML block's, a picture's alt, | ||
/// or a run's, gathered while its style holds. | ||
fn text(&mut self, s: &str) { | ||
| @@ -594,9 +696,18 @@ impl Reader { | ||
while self.close_detail() {} | ||
} | ||
| ||
/// Text left outside a paragraph (a tight list item's) made one. | ||
/// Text left outside a paragraph (a tight list item's, a picture's | ||
/// neighbours) made one, without the space at its ends: none if that | ||
/// is all it is. | ||
fn settle(&mut self) { | ||
let runs = self.take_runs(); | ||
let mut runs = self.take_runs(); | ||
if let Some(Value::String(t)) = runs.first_mut().map(|r| &mut r["text"]) { | ||
*t = t.trim_start().to_string(); | ||
} | ||
if let Some(Value::String(t)) = runs.last_mut().map(|r| &mut r["text"]) { | ||
*t = t.trim_end().to_string(); | ||
} | ||
runs.retain(|r| r["text"] != ""); | ||
if !runs.is_empty() { | ||
self.push(paragraph(runs)); | ||
} | ||
| @@ -1240,6 +1351,55 @@ mod tests { | ||
); | ||
} | ||
| ||
/// Markdown's images that name a picture it is given, by its blob's CID | ||
/// on whatever PDS or by its URL, are drawn, each a block of its own | ||
/// splitting the paragraph it was in, at its size; one it is not given, | ||
/// one whose URL the view may not load, or one where no block goes (a | ||
/// heading, a table, a link, a summary) is its alt text. | ||
#[test] | ||
fn markdown_draws_the_pictures_it_is_given_where_a_block_goes() { | ||
let root = json!({}); | ||
let origins = vec!["https://k.test".to_string()]; | ||
let c = ctx(&root, &origins); | ||
let given = json!([ | ||
{ "cid": "bafa", "url": "https://k.test/a", "width": 400, "height": 200 }, | ||
{ "cid": "bafb", "url": "https://k.test/b" }, | ||
{ "cid": "bafc", "url": "https://evil.test/c" }, | ||
{ "url": "https://k.test/d" }, | ||
]); | ||
let pictures = Picture::all(Some(&given), &c); | ||
let blob = |cid: &str| { | ||
format!("https://pds.test/xrpc/com.atproto.sync.getBlob?did=did:plc:a&cid={cid}") | ||
}; | ||
let a = blob("bafa"); | ||
let source = format!( | ||
"Before \n after\n\n  \n\n# \n\n[](https://w.test)\n\n|  |\n|---|\n| x |\n\n<details><summary>\n\n\n\n</summary>\n\n- \n\n</details>", | ||
c = blob("bafc"), | ||
); | ||
let blocks = pictured(&source, true, &pictures); | ||
checked_markdown(&blocks); | ||
let src = |u: &str| json!({ "src": u, "fallback": null }); | ||
let alt = |t: &str| json!({ "text": format!("[{t}]"), "alt": true }); | ||
let shot = |alt: &str| json!({ "kind": "image", "src": src("https://k.test/a"), "alt": alt, "ratio": 2.0, "width": 400 }); | ||
assert_eq!( | ||
Value::Array(blocks), | ||
json!([ | ||
paragraph(vec![run("Before", None)]), | ||
shot("shot"), | ||
{ "kind": "image", "src": src("https://k.test/b"), "alt": "", "ratio": 4.0 / 3.0 }, | ||
paragraph(vec![run("after", None)]), | ||
paragraph(vec![alt("evil"), run(" ", None), alt("rel"), run(" ", None), alt("get")]), | ||
{ "kind": "heading", "level": 1, "runs": [alt("h")] }, | ||
paragraph(vec![json!({ "text": "[l]", "link": "https://w.test", "alt": true })]), | ||
{ "kind": "table", "head": [[alt("t")]], "rows": [[[{ "text": "x" }]]] }, | ||
{ "kind": "details", "runs": [alt("s")], "blocks": [ | ||
{ "kind": "list", "ordered": false, "tight": true, "items": [{ "blocks": [shot("in")] }] }, | ||
] }, | ||
]) | ||
); | ||
assert!(markdown(&source, true).iter().all(|b| b["kind"] != "image")); | ||
} | ||
| ||
#[test] | ||
fn gfm_finds_bare_links_tasks_and_tables_where_commonmark_does_not() { | ||
let source = "see www.a.test/x. and (https://b.test/y)\n\n- [x] done\n- todo\n\n| h | ~~s~~ |\n|---|---|\n| `c` | d |"; | ||
crates/hud-core/src/ui/mod.rs+15−8
| @@ -710,10 +710,10 @@ fn rich_text(p: &Value, scope: &Value, ctx: &Ctx) -> R<Option<Value>> { | ||
let mut o = Map::new(); | ||
match p["format"].as_str() { | ||
Some(format @ ("markdown" | "gfm")) => { | ||
o.insert( | ||
"blocks".into(), | ||
Value::Array(document::markdown(value, format == "gfm")), | ||
); | ||
let pictures = value_or_none(&p["pictures"], scope, Value::is_array)?; | ||
let pictures = document::Picture::all(pictures, ctx); | ||
let blocks = document::pictured(value, format == "gfm", &pictures); | ||
o.insert("blocks".into(), Value::Array(blocks)); | ||
} | ||
Some("facets") => { | ||
let facets = value_or_none(&p["facets"], scope, Value::is_array)?; | ||
| @@ -2243,9 +2243,10 @@ mod tests { | ||
); | ||
} | ||
| ||
/// Rich text as markdown is blocks, with no format its words as they | ||
/// are (no links read), detected its links found in them; a value that | ||
/// is no text is an error, as a time's that is no timestamp is. | ||
/// Rich text as markdown is blocks, its pictures those it is given; | ||
/// with no format its words as they are (no links read), detected its | ||
/// links found in them; a value that is no text is an error, as a | ||
/// time's that is no timestamp is. | ||
#[test] | ||
fn rich_text_reads_its_format_and_times_their_timestamp() { | ||
let root = json!({}); | ||
| @@ -2259,8 +2260,10 @@ mod tests { | ||
{ "component": "Time", "props": { "value": { "$": "n" } } }, | ||
{ "component": "Image", "props": { "src": "https://cdn.bsky.app/a.jpg", "fit": "contain" } }, | ||
rich(json!({ "value": "see https://a.example", "format": "detect" })), | ||
rich(json!({ "value": "", "format": "gfm", "pictures": { "$": "pics" } })), | ||
] }); | ||
let tree = resolve(&layout, &json!({ "n": 1 }), &c).unwrap(); | ||
let scope = json!({ "n": 1, "pics": [{ "cid": "bafa", "url": "https://cdn.bsky.app/p", "width": 10, "height": 5 }] }); | ||
let tree = resolve(&layout, &scope, &c).unwrap(); | ||
check::checked(&tree); | ||
let k = &tree["k"]; | ||
assert_eq!( | ||
| @@ -2284,6 +2287,10 @@ mod tests { | ||
k[5]["p"], | ||
json!({ "runs": [{ "text": "see " }, { "text": "https://a.example", "link": "https://a.example" }] }) | ||
); | ||
assert_eq!( | ||
k[6]["p"]["blocks"], | ||
json!([{ "kind": "image", "src": { "src": "https://cdn.bsky.app/p", "fallback": null }, "alt": "a", "ratio": 2.0, "width": 10 }]) | ||
); | ||
} | ||
| ||
/// An href opens a record (with the inline view, of its collection), a | ||
crates/hud-core/src/catalog.rs+2−1
| @@ -418,11 +418,12 @@ pub const COMPONENTS: &[Component] = &[ | ||
Ty::OneOf(&["plain", "markdown", "gfm", "facets", "detect"]) | ||
), | ||
p!("facets", Ty::Any), | ||
p!("pictures", Ty::Any), | ||
lit!("clamp", Ty::Int), | ||
lit!("style", Ty::OneOf(&["body", "muted"])), | ||
], | ||
children: false, | ||
notes: "Markdown drawn safely (no HTML but <details> and its <summary>, drawn as a disclosure): markdown is CommonMark, gfm GitHub's (tables, task lists, strikethrough, bare links), as a pull's or a README's; or text with Bluesky richtext facets (links, mentions, tags); or detect, text written with none (a profile's description), its links, @mentions and #tags found as Bluesky's app finds them. clamp is about the most lines shown before \"Show more\", as a README's first 20. style muted draws its runs smaller and quieter, as Text's muted: a feed's description under its name.", | ||
notes: "Markdown drawn safely (no HTML but <details> and its <summary>, drawn as a disclosure): markdown is CommonMark, gfm GitHub's (tables, task lists, strikethrough, bare links), as a pull's or a README's; or text with Bluesky richtext facets (links, mentions, tags); or detect, text written with none (a profile's description), its links, @mentions and #tags found as Bluesky's app finds them. Markdown's pictures show their alt text, but those pictures names: an array of { cid, url, width?, height? } (width and height in CSS pixels), each an https URL of the view's origins, drawn in place of an image whose URL is that url or a com.atproto.sync.getBlob URL with that cid, as a pull's attachments. clamp is about the most lines shown before \"Show more\", as a README's first 20. style muted draws its runs smaller and quieter, as Text's muted: a feed's description under its name.", | ||
}, | ||
Component { | ||
name: "Time", | ||
docs/knotless.md+2−2
| @@ -51,7 +51,7 @@ Signed out, HUD makes every query to knotless.dev as no one, so it reads public | ||
| ||
Signed in, the query goes through the account's PDS with `atproto-proxy: did:web:knotless.dev#knotless_appview`. The PDS signs a service token for it (`aud` is knotless's DID, `lxm` the method), and knotless takes the token's account as the asker. So notifications answer, and answers say what the account may do. | ||
| ||
A service token alone reads no private repository. For those, knotless asks for a member's session or a space delegation token. | ||
knotless reads a private repository as the token's account, so a member reads theirs. A picture its pulls, issues and comments attach comes with a URL that carries a token for that account, lasting about an hour, so the view loads it with no cookie. | ||
| ||
`listNotifications` needs an asker. Signed out, knotless refuses it (`AuthenticationRequired`). With sign-in on, HUD answers the challenge and describes it in the view's own words (`signIn`: "Sign in to see your notifications"). With sign-in off, it's a tool error. | ||
| ||
| @@ -72,7 +72,7 @@ The views use components made for them, and each one is generic. | ||
- `List` takes `title`, `empty`, `{"$root": path}` items and `where`. A commit's checks use `where`, from the answer's array of every commit's checks. A list given `"open": false` opens nothing. | ||
- A `List`'s items may be a literal array of at most 20 objects, a menu's fixed rows. Each value is literal or `{"$root": path}`, and each row opens its own `open`. | ||
- `Text` takes `words` and `chars`. | ||
- `RichText` takes `gfm`. | ||
- `RichText` takes `gfm`, and `pictures`: the pictures its Markdown may show, as `getThread` lists a pull's, issue's or comment's `attachments` (`{ cid, url, width, height }`). An image whose URL is `com.atproto.sync.getBlob`'s with one's CID, on whatever PDS, draws from that picture's `url` on knotless.dev, no wider than its `width`. Any other image shows its alt text. | ||
- `Stat` of an array counts it. With `more` bound to a cursor that holds one, it draws `N+`. | ||
| ||
### Params of an `open` | ||
ios/HUDKit/Sources/HUDKit/Tree/ResolvedBlocks.swift+10−0
| @@ -162,10 +162,20 @@ struct ResolvedBlock: View { | ||
case "details": | ||
DetailsBlock(block: block, look: look) | ||
case "image": | ||
// No wider than its picture says, where it says (a screenshot at the size it was seen); | ||
// in markdown inside a hairline, so a white screenshot keeps its edge on a white tile. | ||
EmbedFrame(ratio: block["ratio"]?.number ?? 4 / 3, maxHeight: 560) { | ||
Picture(source: Resolved.source(block["src"]), alt: block["alt"]?.string ?? "", fit: .fit, side: 1000) | ||
.clipShape(.rect(cornerRadius: EmbedRules.corner, style: .continuous)) | ||
.overlay { | ||
if look == .markdown { | ||
RoundedRectangle(cornerRadius: EmbedRules.corner, style: .continuous) | ||
.strokeBorder(.hairline, lineWidth: 1) | ||
} | ||
} | ||
} | ||
.frame(maxWidth: block["width"]?.number.map { CGFloat($0) } ?? .infinity) | ||
.frame(maxWidth: .infinity, alignment: .leading) | ||
case "gallery": | ||
let images = block["images"]?.array ?? [] | ||
if images.isEmpty { | ||
schemas/place.hud.ui.json+2−1
| @@ -532,7 +532,7 @@ | ||
}, | ||
"block": { | ||
"type": "object", | ||
"description": "A block of text with structure, by kind: paragraph { runs }; heading { level, runs }; list { ordered, start?, tight?, items }; code { text, lang? }; quote { blocks }; rule; table { head, rows }; footnotes { items }, in the order they are first referred to; details { runs, blocks, expanded? }, markdown's <details>, its summary's runs and the blocks it hides; image { src, alt, ratio }; gallery { images }; card { kicker, title, description?, image, open? }; button { label, open? }; bskyPost { uri, quote?, fallback }; gap; unsupported { text }; json { value }. An image's ratio, width over height, is a number with a fraction, and a json block's value anything at all, so neither is declared here.", | ||
"description": "A block of text with structure, by kind: paragraph { runs }; heading { level, runs }; list { ordered, start?, tight?, items }; code { text, lang? }; quote { blocks }; rule; table { head, rows }; footnotes { items }, in the order they are first referred to; details { runs, blocks, expanded? }, markdown's <details>, its summary's runs and the blocks it hides; image { src, alt, ratio, width? }; gallery { images }; card { kicker, title, description?, image, open? }; button { label, open? }; bskyPost { uri, quote?, fallback }; gap; unsupported { text }; json { value }. An image's ratio, width over height, is a number with a fraction, and a json block's value anything at all, so neither is declared here.", | ||
"required": ["kind"], | ||
"nullable": ["src", "image"], | ||
"properties": { | ||
| @@ -552,6 +552,7 @@ | ||
"rows": { "type": "array", "items": { "type": "unknown" }, "description": "A table's rows, each an array of cells, each an array of #run." }, | ||
"src": { "type": "ref", "ref": "#picture", "description": "An image's; null for a value that is no blob." }, | ||
"alt": { "type": "string" }, | ||
"width": { "type": "integer", "minimum": 1, "description": "An image's: the most CSS pixels it is drawn across, where its picture says; absent, as wide as its place." }, | ||
"images": { "type": "array", "items": { "type": "ref", "ref": "#blockImage" } }, | ||
"kicker": { "type": "string" }, | ||
"title": { "type": "string" }, | ||
views/knotless-thread.json+2−2
| @@ -80,7 +80,7 @@ | ||
} | ||
] | ||
}, | ||
{ "component": "RichText", "props": { "value": { "$": "response.body" }, "format": "gfm" } }, | ||
{ "component": "RichText", "props": { "value": { "$": "response.body" }, "format": "gfm", "pictures": { "$": "response.item.attachments" } } }, | ||
{ | ||
"component": "List", | ||
"props": { "items": { "$": "response.reviews" }, "style": "inline", "title": "Reviews", "open": false }, | ||
| @@ -131,7 +131,7 @@ | ||
] | ||
}, | ||
{ "component": "Text", "props": { "value": { "$": "line.path" }, "prefix": "On ", "style": "mono" } }, | ||
{ "component": "RichText", "props": { "value": { "$": "body" }, "format": "gfm" } } | ||
{ "component": "RichText", "props": { "value": { "$": "body" }, "format": "gfm", "pictures": { "$": "attachments" } } } | ||
] | ||
}, | ||
{ | ||
web/renderer/src/tree/Blocks.svelte+1−1
| @@ -117,7 +117,7 @@ | ||
<Blocks blocks={b.blocks} {look} /> | ||
</details> | ||
{:else if b.kind === 'image'} | ||
<figure class="image" style:--ratio={b.ratio}><Picture src={b.src} alt={b.alt} fit="contain" /></figure> | ||
<figure class="image" style:--ratio={b.ratio} style:--width={b.width ? `${b.width}px` : undefined}><Picture src={b.src} alt={b.alt} fit="contain" /></figure> | ||
{:else if b.kind === 'gallery'} | ||
<Gallery items={b.images} /> | ||
{:else if b.kind === 'card'} | ||
web/renderer/src/tree/types.ts+1−1
| @@ -124,7 +124,7 @@ export type UiBlock = ( | ||
| { kind: 'table'; head: UiRun[][]; rows: UiRun[][][] } | ||
| { kind: 'footnotes'; items: { blocks: UiBlock[] }[] } | ||
| { kind: 'details'; runs: UiRun[]; blocks: UiBlock[]; expanded?: boolean } | ||
| { kind: 'image'; src: Source | null; alt: string; ratio: number } | ||
| { kind: 'image'; src: Source | null; alt: string; ratio: number; width?: number } | ||
| { kind: 'gallery'; images: { src: Source | null; alt: string | null; ratio: number | null }[] } | ||
| { kind: 'card'; kicker: string; title: string; description?: string; image: Source | null; open?: UiOpen } | ||
| { kind: 'button'; label: string; open?: UiOpen } | ||