~ knotless Search/
↑↓ move↵ open⇧↵ all results

chadtmiller.com/hud

A remote MCP server that shows atproto records as interactive UI inside MCP Apps hosts

0
0

A question's button may say its own words

Open chadtmiller.com wants to merge into main from chadtmiller.com/hud:confirm-answer
.changeset/confirm-answer.mdnew+7−0
@@ -0,0 +1,7 @@
---
default: minor
---
# A question's button may say its own words
An `Action` or a `Link` that asks first (`confirm`) takes `answer`: the words of the alert's button that answers it, in place of its label, so a long label isn't said twice (a group's Make galleries members-only, answered by Make members-only). Its words may be made of the data, as a label's are; words that read nothing, or only blanks, leave the button its label. A kit older than 0.32.0 ignores it and answers with the label.
android/hudkit/src/main/java/place/hud/kit/tree/Acting.kt+9−3
@@ -195,6 +195,8 @@ internal data class ActionSpec(
val subject: JsonElement,
val existing: String?,
val confirm: String?,
/** The words of the alert's button that goes on (`answer`), where they are not its label. */
val answer: String? = null,
val danger: Boolean,
/** Its screen closes once it has written (`leave`), as deleting the gallery shown. */
val leave: Boolean,
@@ -242,6 +244,7 @@ internal data class ActionSpec(
subject = subject,
existing = p["existing"].string,
confirm = p.str("confirm"),
answer = p.str("answer"),
danger = p["tone"].string == "danger",
leave = p["leave"].isTrue,
reload = p["reload"].isTrue,
@@ -450,13 +453,15 @@ internal class ActionRun(ran: Ran = Ran(false, null), private val about: String?
* A question asked before something goes on, in the alert an `Action`'s
* `confirm` asks in, and a `Link`'s: a long question's first paragraph its
* title, the rest said under it, as an alert's message is on iOS
* (`confirmParts`), with `more` under that; Cancel, and `label` the button
* that goes on (`enabled`), in the danger colour where it is `danger`.
* (`confirmParts`), with `more` under that; Cancel, and the button that goes
* on (`enabled`), its words `answer` where it has some, else `label`, in the
* danger colour where it is `danger`.
*/
@Composable
internal fun ConfirmAlert(
question: String,
label: String,
answer: String? = null,
onConfirm: () -> Unit,
onDismiss: () -> Unit,
danger: Boolean = false,
@@ -477,7 +482,7 @@ internal fun ConfirmAlert(
},
confirmButton = {
TextButton(onClick = onConfirm, enabled = enabled) {
Text(label, color = if (danger && enabled) HudColors.danger else Color.Unspecified)
Text(answer?.takeIf { it.isNotBlank() } ?: label, color = if (danger && enabled) HudColors.danger else Color.Unspecified)
}
},
dismissButton = { TextButton(onClick = onDismiss) { Text("Cancel") } },
@@ -501,6 +506,7 @@ internal fun ActionAsks(run: ActionRun, spec: ActionSpec) {
ConfirmAlert(
question = spec.confirm ?: spec.label,
label = spec.label,
answer = spec.answer,
onConfirm = { run.send(call, spec, view, scope) },
onDismiss = { run.confirming = null },
danger = spec.danger,
android/hudkit/src/main/java/place/hud/kit/tree/Navigation.kt+7−5
@@ -173,7 +173,7 @@ fun ResolvedLink(p: JsonElement, modifier: Modifier = Modifier) {
val context = LocalContext.current
val strip = LocalStripItem.current
val label = p["label"].string ?: ""
val open = askedOpen(view.opener(p["open"]), p.str("confirm"), label)
val open = askedOpen(view.opener(p["open"]), p.str("confirm"), label, p.str("answer"))
val icon = p.str("icon")?.takeIf { Glyphs.has(it) }
val style = p["style"].string
val share = linkShare(p)
@@ -258,13 +258,14 @@ fun ResolvedLink(p: JsonElement, modifier: Modifier = Modifier) {
* `confirm`, `open` as it is.
*/
@Composable
private fun askedOpen(open: ViewContext.Opener?, confirm: String?, label: String): ViewContext.Opener? {
private fun askedOpen(open: ViewContext.Opener?, confirm: String?, label: String, answer: String? = null): ViewContext.Opener? {
var asking by remember { mutableStateOf(false) }
if (open == null || confirm == null) return open
if (asking) {
ConfirmAlert(
question = confirm,
label = label,
answer = answer,
onConfirm = {
asking = false
open.run()
@@ -765,7 +766,7 @@ internal fun BarItem(node: JsonElement) {
when (node["c"].string) {
"Link" -> {
val share = linkShare(p)
val open = view.opener(p["open"]).let { askedOpen(it, p.str("confirm"), p.str("label") ?: it?.label ?: "") }
val open = view.opener(p["open"]).let { askedOpen(it, p.str("confirm"), p.str("label") ?: it?.label ?: "", p.str("answer")) }
if (p["disabled"].isTrue) {
val label = p.str("label") ?: ""
BarFace(p.str("icon"), label, Modifier.semantics { disabled(); p.str("reason")?.let { stateDescription = it } }, tint = HudColors.muted)
@@ -842,7 +843,7 @@ internal fun BarFace(icon: String?, label: String, modifier: Modifier = Modifier
internal sealed interface MenuRow {
data class Action(val spec: ActionSpec) : MenuRow
/** Its label, what it opens, and what it asks first (`confirm`), if anything. */
data class Link(val label: String, val open: JsonElement, val confirm: String? = null) : MenuRow
data class Link(val label: String, val open: JsonElement, val confirm: String? = null, val answer: String? = null) : MenuRow
/** Its label, and the page it shares. */
data class Share(val label: String, val url: String) : MenuRow
/** Its label, and the text it copies. */
@@ -870,7 +871,7 @@ private fun menuRow(child: JsonElement, view: ViewContext): MenuRow? {
p["disabled"].isTrue -> MenuRow.Off(label, p.str("reason"))
linkShare(p) != null -> MenuRow.Share(label, linkShare(p)!!)
linkCopy(p) != null -> MenuRow.Copy(label, linkCopy(p)!!)
else -> p["open"]?.takeIf { view.opener(it) != null }?.let { MenuRow.Link(label, it, p.str("confirm")) }
else -> p["open"]?.takeIf { view.opener(it) != null }?.let { MenuRow.Link(label, it, p.str("confirm"), p.str("answer")) }
}
}
"Compose" -> if (composeOffered(p, view)) MenuRow.Compose(p) else null
@@ -1005,6 +1006,7 @@ private fun MenuView(node: JsonElement, modifier: Modifier, bar: Boolean) {
ConfirmAlert(
question = row.confirm ?: row.label,
label = row.label,
answer = row.answer,
onConfirm = {
confirming = null
view.opener(row.open)?.run?.invoke()
android/hudkit/src/test/java/place/hud/kit/LinkConfirmTest.kt+65−1
@@ -1,5 +1,9 @@
package place.hud.kit
import androidx.compose.runtime.getValue
import androidx.compose.runtime.key
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.test.hasAnyAncestor
import androidx.compose.ui.test.hasClickAction
@@ -39,10 +43,15 @@ class LinkConfirmTest {
trusted = true
onOpenLink = { opened += it }
onCall = { call, _ -> opened += call.name }
onAction = { opened += "acted"; null }
}
/** The alert's button that goes on, not the Link itself. */
private val goes get() = compose.onNode(hasText(label) and hasClickAction() and hasAnyAncestor(isDialog()))
private val goes get() = goesAs(label)
private fun goesAs(words: String) = compose.onNode(hasText(words) and hasClickAction() and hasAnyAncestor(isDialog()))
private val answer = "Make members-only"
@Test
fun anInlineLinkAsksBeforeItOpensItsPage() {
@@ -94,4 +103,59 @@ class LinkConfirmTest {
compose.onNodeWithText("Make your galleries members-only?").assertDoesNotExist()
assertEquals(listOf("describe_repo"), opened)
}
// With `answer`, the alert's button says it, not the label; the row still says the label.
@Test
fun anInlineLinksAnswerIsItsAlertsButton() {
val node = json("c" to "Link", "p" to mapOf("label" to label, "open" to mapOf("url" to page), "confirm" to question, "answer" to answer))
compose.setContent { CompositionLocalProvider(LocalViewContext provides view) { ResolvedNode(node) } }
compose.onNodeWithText(label).performClick()
goes.assertDoesNotExist()
goesAs(answer).performClick()
compose.waitForIdle()
assertEquals(listOf(page), opened)
}
@Test
fun aMenusLinkRowsAnswerIsItsAlertsButton() {
val node = json(
"c" to "Menu",
"p" to mapOf("label" to "Gallery settings"),
"k" to listOf(mapOf("c" to "Link", "p" to mapOf("label" to label, "open" to mapOf("url" to page), "confirm" to question, "answer" to answer))),
)
compose.setContent { CompositionLocalProvider(LocalViewContext provides view) { ResolvedNode(node) } }
compose.onNodeWithContentDescription("Gallery settings").performClick()
compose.onNodeWithText(label).performClick()
compose.waitForIdle()
goes.assertDoesNotExist()
goesAs(answer).performClick()
compose.waitForIdle()
assertEquals(listOf(page), opened)
}
@Test
fun anActionsAnswerIsItsAlertsButtonAndWithoutOneItsLabel() {
fun action(vararg more: Pair<String, Any?>) = json(
"c" to "Action",
"p" to mapOf("label" to label, "delete" to mapOf("uri" to "at://did:plc:a/social.grain.gallery/1"), "confirm" to question, *more),
)
var node by mutableStateOf(action("answer" to answer, "key" to "answered"))
compose.setContent { CompositionLocalProvider(LocalViewContext provides view) { key(node) { ResolvedNode(node) } } }
compose.onNodeWithText(label).performClick()
compose.waitForIdle()
goes.assertDoesNotExist()
goesAs(answer).performClick()
compose.waitForIdle()
assertEquals(listOf("acted"), opened)
opened.clear()
// Another action (its own key, as the first is done), without `answer`.
node = action("key" to "plain")
compose.waitForIdle()
compose.onNodeWithText(label).performClick()
compose.waitForIdle()
goes.performClick()
compose.waitForIdle()
assertEquals(listOf("acted"), opened)
}
}
crates/hud-core/src/ui/mod.rs+61−1
@@ -1861,7 +1861,16 @@ fn link(p: &Value, scope: &Value, ctx: &Ctx) -> R<Option<Value>> {
if question.is_none() && crate::catalog::words(&p["confirm"]).is_some() {
return Err(Fail::Missing);
}
let asked = question.map(|q| ("confirm".to_string(), Value::from(q)));
// The words of the button that answers it, where it says them, else
// its label's (a kit's own).
let answer = match question {
Some(_) => words(&p["answer"], scope, ctx.root)?.filter(|a| !a.trim().is_empty()),
None => None,
};
let asked: Vec<(String, Value)> = [("confirm", question), ("answer", answer)]
.into_iter()
.filter_map(|(k, v)| v.map(|v| (k.to_string(), v.into())))
.collect();
// Shared rather than opened, its address made whole by its template
// (a gallery's page on its app's site, its author's and its key).
if p["share"].is_object() {
@@ -2890,6 +2899,11 @@ fn action(p: &Value, scope: &Value, ctx: &Ctx) -> R<Option<Value>> {
}
if let Some(question) = question {
o.insert("confirm".into(), question.into());
// The words of the button that answers it, else its label's.
let answer = words(&p["answer"], scope, ctx.root)?;
if let Some(answer) = answer.filter(|a| !a.trim().is_empty()) {
o.insert("answer".into(), answer.into());
}
// The handle typed to confirm, as deleting an account asks.
if let Some(handle) = text_of(&p["handle"], scope)? {
o.insert("handle".into(), handle.into());
@@ -3958,6 +3972,52 @@ mod tests {
}
}
/// An Action's or a Link's `answer` is the words of the button that
/// answers its question, made of the data too, so a long label need
/// not be said twice: sent only with a question, and words that read
/// nothing, or only blanks, leave the button its label.
#[test]
fn a_question_is_answered_by_its_own_words() {
let root = json!({});
let c = ctx(&root, &[]);
let group = json!({ "group": { "displayName": "Riders", "blank": " " } });
let call = json!({ "method": "a.b.c", "service": "did:web:a.example#svc" });
let action = |answer: Value| {
json!({ "component": "Action", "props": { "label": "Leave group", "confirm": "Leave?",
"answer": answer, "call": call } })
};
let link = |answer: Value| {
json!({ "component": "Link", "props": { "label": "Make galleries members-only",
"href": "https://a.example/pool", "confirm": "Only members will see them.",
"answer": answer } })
};
let nodes: [&dyn Fn(Value) -> Value; 2] = [&action, &link];
for node in nodes {
let tree = resolve(
&node(json!({ "$join": ["Leave ", { "$": "group.displayName" }] })),
&group,
&c,
)
.unwrap();
check::checked(&tree);
assert_eq!(tree["p"]["answer"], "Leave Riders");
for unsaid in [json!({ "$": "group.blank" }), json!({ "$": "group.none" })] {
let tree = resolve(&node(unsaid), &group, &c).unwrap();
assert!(tree["p"].get("answer").is_none(), "{tree}");
assert!(tree["p"]["confirm"].is_string(), "{tree}");
}
}
// Without a question there is nothing to answer.
let unasked = json!({ "component": "Link", "props": { "label": "Pool",
"href": "https://a.example/pool", "answer": "Open" } });
let tree = resolve(&unasked, &group, &c).unwrap();
assert!(tree["p"].get("answer").is_none(), "{tree}");
let unasked = json!({ "component": "Action", "props": { "label": "Leave",
"answer": "Go", "call": call } });
let tree = resolve(&unasked, &group, &c).unwrap();
assert!(tree["p"].get("answer").is_none(), "{tree}");
}
/// Words made of the data read the view's own scope by `{"$root":
/// path}`, as a List row's question names the group its screen shows:
/// the whole words, a part, `$count`'s array and `$pick`'s value. A
crates/hud-core/src/catalog.rs+17−3
@@ -1263,9 +1263,16 @@ pub const COMPONENTS: &[Component] = &[
given: Given::Words,
since: "0.29.0",
},
Prop {
name: "answer",
ty: Ty::Short,
required: false,
given: Given::Words,
since: "0.32.0",
},
],
children: false,
notes: "Exactly one of href or open, but for a share made whole by its template. href: an at-uri opens the record in place; a DID or handle its repository; an https URL the host's browser. open takes List's forms, as a query to call ({ \"query\": \"com.example.getRepo\", \"params\": { \"repo\": { \"$\": \"uri\" } } }), and a link with open draws only when its label resolves, as its words alone where a param resolves to nothing; with sheet: true its screen opens over what is open (a story's comments over the story); with root: true (a List's open too) its screen is chosen in its tab's root's place, as a strip's tab is, where the strip its answer draws offers it and that tab's root (a feed opened from My feeds), else it opens over what is open. With compose its screen opens at a form: true its first Compose, a string the one of that label, or (since 0.25.0) { \"label\": \"New gallery\", \"values\": { \"to\": { \"$\": \"actor.did\" } } }, that form opened holding values, each a field's by its name, read as a param is: a text's or a line's words, a choice's option of that value picked (a group's Add a gallery, New gallery at Post to that group); a value no field takes, or a disabled option's, is left out, and one holding nothing too. A link whose open is the host's ({ \"host\": \"signOut\" }) draws nothing where its host does not do it. style button draws it as a button (a profile's Message), name as an account's name beside its picture (in the text's own colour, bold), muted in the muted text's colour and size, on one line cut with an ellipsis (a gallery's location under its author), icon as its icon alone, as quiet as a Stat beside it, its label read aloud (a gallery's Share after its favorites and comments), link (the default) as words. icon is drawn before its words, and alone in a Bar or over a Slides' picture, its label then read aloud. share, an https address that href's value ends, makes it a way to share that address (the host's share sheet, else copied, the web saying so) rather than to open it: a profile's Share ({ \"label\": \"Share profile\", \"href\": { \"$\": \"actor.handle\" }, \"share\": \"https://grain.social/profile/\" }); share may instead be the whole address, {\"$join\": [parts]} of strings and the item's templates, with no href: a gallery's Share ({ \"label\": \"Share\", \"icon\": \"send\", \"style\": \"icon\", \"share\": { \"$join\": [\"https://grain.social/profile/\", { \"$\": [\"creator.handle\", \"creator.did\"] }, \"/gallery/\", { \"$rkey\": \"uri\" }] } }), drawn only where every part resolves. copy, text put before href's value, makes it a way to copy that text rather than to open it: a profile's Copy handle ({ \"label\": \"Copy handle\", \"href\": { \"$\": \"actor.handle\" }, \"copy\": \"@\" }). fragment, a path to a DID, opens href's https address (with no fragment of its own) with that DID as its fragment, then + and the signed-in person's DID where one is signed in, as Germ asks of its messageMeUrl; where the path holds no DID, nothing is drawn ({ \"label\": \"Message on Germ\", \"href\": { \"$\": \"joins.profile.messageMe.messageMeUrl\" }, \"fragment\": \"actor.did\" }). disabled, true or a binding that holds something, draws it greyed, opening nothing, and reason, words or a binding, muted under it while it is disabled, as an Action's (a group's last admin's Leave group, { \"disabled\": { \"$\": \"lastAdmin\" }, \"reason\": \"You're the only admin. Make someone else an admin first.\" }); a kit older than their since is sent nothing in a disabled link's place. confirm (since 0.29.0), words or words made of the data, is asked first as an Action's confirm is, its label the button that opens it, on a link that opens something (not share or copy): a group's Make galleries members-only ({ \"label\": \"Make galleries members-only\", \"href\": { \"$\": \"viewer.membersOnlyUrl\" }, \"confirm\": \"Only members will see this group's galleries. This can't be undone.\" }); words that read nothing draw nothing, never a link that opens unasked, and a kit older than its since is sent nothing in its place.",
notes: "Exactly one of href or open, but for a share made whole by its template. href: an at-uri opens the record in place; a DID or handle its repository; an https URL the host's browser. open takes List's forms, as a query to call ({ \"query\": \"com.example.getRepo\", \"params\": { \"repo\": { \"$\": \"uri\" } } }), and a link with open draws only when its label resolves, as its words alone where a param resolves to nothing; with sheet: true its screen opens over what is open (a story's comments over the story); with root: true (a List's open too) its screen is chosen in its tab's root's place, as a strip's tab is, where the strip its answer draws offers it and that tab's root (a feed opened from My feeds), else it opens over what is open. With compose its screen opens at a form: true its first Compose, a string the one of that label, or (since 0.25.0) { \"label\": \"New gallery\", \"values\": { \"to\": { \"$\": \"actor.did\" } } }, that form opened holding values, each a field's by its name, read as a param is: a text's or a line's words, a choice's option of that value picked (a group's Add a gallery, New gallery at Post to that group); a value no field takes, or a disabled option's, is left out, and one holding nothing too. A link whose open is the host's ({ \"host\": \"signOut\" }) draws nothing where its host does not do it. style button draws it as a button (a profile's Message), name as an account's name beside its picture (in the text's own colour, bold), muted in the muted text's colour and size, on one line cut with an ellipsis (a gallery's location under its author), icon as its icon alone, as quiet as a Stat beside it, its label read aloud (a gallery's Share after its favorites and comments), link (the default) as words. icon is drawn before its words, and alone in a Bar or over a Slides' picture, its label then read aloud. share, an https address that href's value ends, makes it a way to share that address (the host's share sheet, else copied, the web saying so) rather than to open it: a profile's Share ({ \"label\": \"Share profile\", \"href\": { \"$\": \"actor.handle\" }, \"share\": \"https://grain.social/profile/\" }); share may instead be the whole address, {\"$join\": [parts]} of strings and the item's templates, with no href: a gallery's Share ({ \"label\": \"Share\", \"icon\": \"send\", \"style\": \"icon\", \"share\": { \"$join\": [\"https://grain.social/profile/\", { \"$\": [\"creator.handle\", \"creator.did\"] }, \"/gallery/\", { \"$rkey\": \"uri\" }] } }), drawn only where every part resolves. copy, text put before href's value, makes it a way to copy that text rather than to open it: a profile's Copy handle ({ \"label\": \"Copy handle\", \"href\": { \"$\": \"actor.handle\" }, \"copy\": \"@\" }). fragment, a path to a DID, opens href's https address (with no fragment of its own) with that DID as its fragment, then + and the signed-in person's DID where one is signed in, as Germ asks of its messageMeUrl; where the path holds no DID, nothing is drawn ({ \"label\": \"Message on Germ\", \"href\": { \"$\": \"joins.profile.messageMe.messageMeUrl\" }, \"fragment\": \"actor.did\" }). disabled, true or a binding that holds something, draws it greyed, opening nothing, and reason, words or a binding, muted under it while it is disabled, as an Action's (a group's last admin's Leave group, { \"disabled\": { \"$\": \"lastAdmin\" }, \"reason\": \"You're the only admin. Make someone else an admin first.\" }); a kit older than their since is sent nothing in a disabled link's place. confirm (since 0.29.0), words or words made of the data, is asked first as an Action's confirm is, its answer (since 0.32.0, words as its label is) the button that opens it, else its label, on a link that opens something (not share or copy): a group's Make galleries members-only ({ \"label\": \"Make galleries members-only\", \"href\": { \"$\": \"viewer.membersOnlyUrl\" }, \"confirm\": \"Only members will see this group's galleries. This can't be undone.\", \"answer\": \"Make members-only\" }); words that read nothing draw nothing, never a link that opens unasked, and a kit older than its since is sent nothing in its place.",
since: FIRST,
},
Component {
@@ -1748,6 +1755,13 @@ pub const COMPONENTS: &[Component] = &[
bound!("closed", Ty::Any, false),
lit!("style", Ty::OneOf(&["button", "row", "outline"])),
words!("confirm", Ty::Text),
Prop {
name: "answer",
ty: Ty::Short,
required: false,
given: Given::Words,
since: "0.32.0",
},
lit!("tone", Ty::OneOf(&["danger"])),
lit!("leave", Ty::Flag),
lit!("reload", Ty::Flag),
@@ -1757,7 +1771,7 @@ pub const COMPONENTS: &[Component] = &[
p!("reason", Ty::Text, since "0.23.0"),
],
children: false,
notes: "A button that writes as the signed-in account: create makes a record ({ collection, record, space? }; the record's values may be bindings, {\"$now\": true} for the current time, {\"$strongRef\": path} for { uri, cid } of the record or view at path, {\"$rkey\": path} for the record key of the at-uri at path, {\"$root\": path} read from the view's own scope, {\"$first\": [values]}, the first of 2 to 4 that resolves, or {\"$merge\": [values]}, 2 to 4 objects merged, the later's fields winning; the record may be bound whole too, a binding, {\"$root\": path} or a $merge, as a query join's answer holds it: { \"$merge\": [{ \"$root\": \"joins.crossPost.post\" }, { \"createdAt\": { \"$now\": true } }] }, drawn only where it is an object; space, in a bundled view alone, { type, at }, makes it in the account's repo in a permissioned space rather than its own repository: type the space's type (an NSID), at a binding or {\"$root\": path} to the space's at-uri or its authority's DID (its space of that type keyed self), as a favorite in a group's pool { \"type\": \"social.grain.group.pool\", \"at\": { \"$root\": \"joins.group.did\" } }; where at holds nothing, in the account's own repository, so one view serves both; one holding a space of another type draws an error and writes nothing; a kit before 0.25.0, which would not send the space, is sent no such Action), delete deletes the record whose uri it binds ({ uri: binding }, in the account's own repository or its repo in a space); exactly one of them, or, in a bundled view alone, interaction ({ event: app.bsky.feed.defs#requestMore or #requestLess }), which tells a feed more or less like the item, or call ({ method, service, input? }), which calls a procedure of the service through the account's PDS, its input a template as create's record is, as { \"method\": \"chat.bsky.convo.updateRead\", \"service\": \"did:web:api.bsky.chat#bsky_chat\", \"input\": { \"convoId\": { \"$\": \"id\" } } }, or deletes ({ method, service, params?, repeat?, collections?, then? }), which asks a query of the service, as the account, for a deletion plan, its params a template as call's input, and deletes what it answers, { writes: [{ collection, rkey }] }, the deletes of one com.atproto.repo.applyWrites, in the account's own repository at once, all or none (a gallery with its photos, as { \"method\": \"social.grain.gallery.getDeletionPlan\", \"service\": \"did:web:grain.social#grain_appview\", \"params\": { \"gallery\": { \"$\": \"response.gallery.uri\" } } }); with repeat true it asks again until a plan comes back empty, deleting an account's data a part at a time as the button counts the records gone, from the operator's own pages and apps alone; then ({ method, service, input? }, its input literal but {\"$did\": true}, the account's DID) is called once nothing is left, as the app's server forgetting the account; collections names the collections its deletes may reach beyond those the views write, which HUD asks at sign-in to delete. done is the label after it succeeds; a created record's button then deletes it again. existing (with create) binds the at-uri of the record the account already made, as an AppView's post.viewer.like: the button then starts done, and a click deletes that record. count binds how many there are, as post.likeCount: the button is then drawn as its icon and that number, counting it up or down as it is done or undone, its label read aloud, and where nothing can write it is drawn as a Stat of that number; no Stat of the same number goes beside it. closed binds whether it is closed (true): then it is drawn as a Stat of its count, or nothing. icon check and x (since 0.25.0, left out for an older kit, which draws its words alone) mark a group's Joined and a request's Cancel. style button draws it as a button of its own, filled until done and outlined once done, as a profile's Follow and Following; style outline (since 0.25.0) as a button of its own outlined, done or not, as a done one is, for a state a tap undoes, as a group's Requested with a call and a confirm (a kit before 0.25.0 draws it as style button); style row draws it as a row of a List with style rows, the whole width, its label a row's words, joining the rows of a List or of row Actions right before it in a Stack with gap none, as Settings' Delete account after Sign out. confirm is a question asked first (\"Block @alice?\"), in a bundled view too; tone danger draws it in the danger colour (Block, Delete). leave true closes the screen it is on once it succeeds, as deleting the gallery shown; reload true reads the view again once it succeeds, as deleting a comment in it. signOut true signs the account out of the app once it succeeds, as deleting one's account (an Action with it draws only where the host signs out); handle binds the account's handle, which the person types to confirm (with confirm). disabled, true or a binding that holds something, draws it greyed and doing nothing (in a Menu too, a row greyed), and reason, words or a binding, muted and smaller under it while it is disabled, read as its description (a group's last admin's Step down as admin, { \"disabled\": { \"$\": \"lastAdmin\" }, \"reason\": \"You're the only admin. Make someone else an admin first.\" }); a kit older than their since is sent nothing in a disabled action's place. A view that is not bundled asks the person to confirm, showing the record. Signed out, the first click asks the host to sign in. To write what a person types (a reply, a post), use Compose.",
notes: "A button that writes as the signed-in account: create makes a record ({ collection, record, space? }; the record's values may be bindings, {\"$now\": true} for the current time, {\"$strongRef\": path} for { uri, cid } of the record or view at path, {\"$rkey\": path} for the record key of the at-uri at path, {\"$root\": path} read from the view's own scope, {\"$first\": [values]}, the first of 2 to 4 that resolves, or {\"$merge\": [values]}, 2 to 4 objects merged, the later's fields winning; the record may be bound whole too, a binding, {\"$root\": path} or a $merge, as a query join's answer holds it: { \"$merge\": [{ \"$root\": \"joins.crossPost.post\" }, { \"createdAt\": { \"$now\": true } }] }, drawn only where it is an object; space, in a bundled view alone, { type, at }, makes it in the account's repo in a permissioned space rather than its own repository: type the space's type (an NSID), at a binding or {\"$root\": path} to the space's at-uri or its authority's DID (its space of that type keyed self), as a favorite in a group's pool { \"type\": \"social.grain.group.pool\", \"at\": { \"$root\": \"joins.group.did\" } }; where at holds nothing, in the account's own repository, so one view serves both; one holding a space of another type draws an error and writes nothing; a kit before 0.25.0, which would not send the space, is sent no such Action), delete deletes the record whose uri it binds ({ uri: binding }, in the account's own repository or its repo in a space); exactly one of them, or, in a bundled view alone, interaction ({ event: app.bsky.feed.defs#requestMore or #requestLess }), which tells a feed more or less like the item, or call ({ method, service, input? }), which calls a procedure of the service through the account's PDS, its input a template as create's record is, as { \"method\": \"chat.bsky.convo.updateRead\", \"service\": \"did:web:api.bsky.chat#bsky_chat\", \"input\": { \"convoId\": { \"$\": \"id\" } } }, or deletes ({ method, service, params?, repeat?, collections?, then? }), which asks a query of the service, as the account, for a deletion plan, its params a template as call's input, and deletes what it answers, { writes: [{ collection, rkey }] }, the deletes of one com.atproto.repo.applyWrites, in the account's own repository at once, all or none (a gallery with its photos, as { \"method\": \"social.grain.gallery.getDeletionPlan\", \"service\": \"did:web:grain.social#grain_appview\", \"params\": { \"gallery\": { \"$\": \"response.gallery.uri\" } } }); with repeat true it asks again until a plan comes back empty, deleting an account's data a part at a time as the button counts the records gone, from the operator's own pages and apps alone; then ({ method, service, input? }, its input literal but {\"$did\": true}, the account's DID) is called once nothing is left, as the app's server forgetting the account; collections names the collections its deletes may reach beyond those the views write, which HUD asks at sign-in to delete. done is the label after it succeeds; a created record's button then deletes it again. existing (with create) binds the at-uri of the record the account already made, as an AppView's post.viewer.like: the button then starts done, and a click deletes that record. count binds how many there are, as post.likeCount: the button is then drawn as its icon and that number, counting it up or down as it is done or undone, its label read aloud, and where nothing can write it is drawn as a Stat of that number; no Stat of the same number goes beside it. closed binds whether it is closed (true): then it is drawn as a Stat of its count, or nothing. icon check and x (since 0.25.0, left out for an older kit, which draws its words alone) mark a group's Joined and a request's Cancel. style button draws it as a button of its own, filled until done and outlined once done, as a profile's Follow and Following; style outline (since 0.25.0) as a button of its own outlined, done or not, as a done one is, for a state a tap undoes, as a group's Requested with a call and a confirm (a kit before 0.25.0 draws it as style button); style row draws it as a row of a List with style rows, the whole width, its label a row's words, joining the rows of a List or of row Actions right before it in a Stack with gap none, as Settings' Delete account after Sign out. confirm is a question asked first (\"Block @alice?\"), in a bundled view too, answered by a button of its answer (since 0.32.0: \"Block\") or else its label; tone danger draws it in the danger colour (Block, Delete). leave true closes the screen it is on once it succeeds, as deleting the gallery shown; reload true reads the view again once it succeeds, as deleting a comment in it. signOut true signs the account out of the app once it succeeds, as deleting one's account (an Action with it draws only where the host signs out); handle binds the account's handle, which the person types to confirm (with confirm). disabled, true or a binding that holds something, draws it greyed and doing nothing (in a Menu too, a row greyed), and reason, words or a binding, muted and smaller under it while it is disabled, read as its description (a group's last admin's Step down as admin, { \"disabled\": { \"$\": \"lastAdmin\" }, \"reason\": \"You're the only admin. Make someone else an admin first.\" }); a kit older than their since is sent nothing in a disabled action's place. A view that is not bundled asks the person to confirm, showing the record. Signed out, the first click asks the host to sign in. To write what a person types (a reply, a post), use Compose.",
since: FIRST,
},
Component {
@@ -2045,7 +2059,7 @@ pub fn to_json() -> Value {
"items": "a component with items draws each item with the item as its scope (a Rec, or an element of the array bound)",
"rec": "{ uri, cid, did (the repository's, from uri), value, joins: { <as>: Rec | null | { total, records: [Rec] } } }; a blob ref in value carries a url when the server serves it",
},
"bindings": "A prop is a literal JSON value or a binding {\"$\": \"path\"} or {\"$\": [\"pathA\", \"pathB\"]} (the first usable value wins). A path is keys joined by dots from the current scope, each [A-Za-z0-9_$]+, at most 10; an array takes a number as its key (records.0); \".\" is the scope itself (an item of an array of strings, such as a tag). No expressions. Media props take a blob ref; an https URL only of the view's origins. Where a prop says orRoot, in an open's params, and as a value in a List's literal items, {\"$root\": \"path\"} reads from the view's own scope rather than the item's. Where a prop says orWords (since 0.25.0: a Text's value, a Link's, an Action's or a Compose's label, an Action's confirm, a Compose's title and about, an Empty's title and text), it may be words made of the data, read to one string on the server: {\"$join\": [2 to 8 parts]}, the parts' words run together, nothing where any part reads nothing; {\"$sep\": [separator (1 to 8 characters), 2 to 8 parts]}, the parts that read something joined by the separator, those that read nothing (or \"\") left out, nothing where none does ({ \"$sep\": [\" · \", { \"$\": \"place\" }, { \"$\": \"camera\" }] }); {\"$count\": [a binding to an array, singular, plural]} (\"3 rules\"), nothing where no array is there; {\"$pick\": [a binding, { value: words }]}, the words for the value it holds (1 to 12 values, each word 1 to 64 characters; a number or true and false compared as written), nothing where it holds nothing or a value not named ({ \"$pick\": [{ \"$\": \"group.joinPolicy\" }, { \"open\": \"Open to join\", \"invite\": \"Invite only\" }] }). A part of a $join or a $sep is a string, a binding or another of these but its own form, nested at most 3 deep. The words themselves, and each binding in them, may be {\"$root\": \"path\"}, read from the view's own scope, as a List row's question names the group its screen shows ({ \"$join\": [\"Leave \", { \"$root\": \"response.group.displayName\" }, \"?\"] }). Where words read nothing they act as a binding that reads nothing, but an Action's confirm: an Action whose confirm's words read nothing is drawn nowhere, never acting unasked.",
"bindings": "A prop is a literal JSON value or a binding {\"$\": \"path\"} or {\"$\": [\"pathA\", \"pathB\"]} (the first usable value wins). A path is keys joined by dots from the current scope, each [A-Za-z0-9_$]+, at most 10; an array takes a number as its key (records.0); \".\" is the scope itself (an item of an array of strings, such as a tag). No expressions. Media props take a blob ref; an https URL only of the view's origins. Where a prop says orRoot, in an open's params, and as a value in a List's literal items, {\"$root\": \"path\"} reads from the view's own scope rather than the item's. Where a prop says orWords (since 0.25.0: a Text's value, a Link's, an Action's or a Compose's label, an Action's confirm, an Action's or a Link's answer, a Compose's title and about, an Empty's title and text), it may be words made of the data, read to one string on the server: {\"$join\": [2 to 8 parts]}, the parts' words run together, nothing where any part reads nothing; {\"$sep\": [separator (1 to 8 characters), 2 to 8 parts]}, the parts that read something joined by the separator, those that read nothing (or \"\") left out, nothing where none does ({ \"$sep\": [\" · \", { \"$\": \"place\" }, { \"$\": \"camera\" }] }); {\"$count\": [a binding to an array, singular, plural]} (\"3 rules\"), nothing where no array is there; {\"$pick\": [a binding, { value: words }]}, the words for the value it holds (1 to 12 values, each word 1 to 64 characters; a number or true and false compared as written), nothing where it holds nothing or a value not named ({ \"$pick\": [{ \"$\": \"group.joinPolicy\" }, { \"open\": \"Open to join\", \"invite\": \"Invite only\" }] }). A part of a $join or a $sep is a string, a binding or another of these but its own form, nested at most 3 deep. The words themselves, and each binding in them, may be {\"$root\": \"path\"}, read from the view's own scope, as a List row's question names the group its screen shows ({ \"$join\": [\"Leave \", { \"$root\": \"response.group.displayName\" }, \"?\"] }). Where words read nothing they act as a binding that reads nothing, but an Action's confirm: an Action whose confirm's words read nothing is drawn nowhere, never acting unasked.",
"actions": "Action's create: { collection: NSID, record: { ... } }, the record at most 4096 bytes as JSON, its values at any depth literal JSON, a binding, {\"$now\": true} (the current time, ISO 8601) or {\"$strongRef\": \"path\"} ({ uri, cid } of what path names, as \".\" for a Rec or \"post\" for a feed item); keys starting with $ are those alone and $type. The record may be bound whole, as a query join's answer holds it ({ \"$root\": \"joins.crossPost.post\" }), or objects merged, the later's fields winning ({ \"$merge\": [{ \"$root\": \"joins.crossPost.post\" }, { \"createdAt\": { \"$now\": true } }] }). delete: { uri: binding }. As app.bsky.feed.like: { collection: \"app.bsky.feed.like\", record: { subject: { \"$strongRef\": \".\" }, createdAt: { \"$now\": true } } }.",
"joins": {
"ref": "{ as, ref: path to an at-uri or strongRef, collection? } -> Rec | null",
docs/views.md+6−0
@@ -1401,6 +1401,12 @@ approval. Its words may be made of the data too, and a Link whose words read not
nowhere. One that shares or copies asks nothing. A kit older than 0.29.0 would open it unasked, so
it is sent nothing in its place.
The alert's button that answers an Action's or a Link's question reads its `answer` (since 0.32.0)
where it has one, else its label, so a long menu row need not be said again under its question:
Grain's Make galleries members-only is answered by Make members-only. Its words may be made of
the data, as a label's are. Words that read nothing, or only blanks, leave the button its label.
It is sent only with a question. A kit older than 0.32.0 ignores it and answers with the label.
What a person writes shows on every screen at once (since 0.24.0), with no view saying so and no
call made. Each client keeps what the account wrote this session (the web renderer's `writes`,
HUDKit's and hudkit's `Writes`), keyed by a record's collection and its `subject`: an at-uri or a
ios/HUDKit/Sources/HUDKit/Parts/ActionButton.swift+5−2
@@ -72,6 +72,8 @@ struct ActionSpec: Equatable {
let subject: JSON
let existing: String?
let confirm: String?
/// The words of the button that answers `confirm` yes (`answer`), else its label.
let answer: String
let danger: Bool
/// Its screen closes once it has written (`leave`), as deleting the gallery shown.
let leave: Bool
@@ -114,6 +116,7 @@ struct ActionSpec: Equatable {
self.subject = subject
existing = p["existing"]?.string
confirm = p.str("confirm")
answer = LinkAsk.answer(p) ?? label
danger = p["tone"]?.string == "danger"
leave = p["leave"] == .bool(true)
reload = p["reload"] == .bool(true)
@@ -354,7 +357,7 @@ private struct ActionAsks: ViewModifier {
content
.asksFirst(
spec.confirm ?? spec.label,
label: spec.label,
label: spec.answer,
danger: spec.danger,
isPresented: Binding(get: { run.confirming != nil && spec.handle == nil }, set: { if !$0 { run.confirming = nil } }),
go: { if let call = run.confirming { run.send(call, spec, view, toast) } },
@@ -372,7 +375,7 @@ private struct ActionAsks: ViewModifier {
.textInputAutocapitalization(.never)
.autocorrectionDisabled()
.keyboardType(.URL)
Button(spec.label, role: spec.danger ? .destructive : nil) {
Button(spec.answer, role: spec.danger ? .destructive : nil) {
if let call = run.confirming { run.send(call, spec, view, toast) }
}
.disabled(!ActionRun.matches(run.typed, handle))
ios/HUDKit/Sources/HUDKit/Tree/ResolvedBar.swift+1−1
@@ -92,7 +92,7 @@ struct BarItem: View {
} else if let open = view.opener(tree: p["open"]) {
let label = p.str("label") ?? open.label
Button {
ask.tap(label, confirm: p.str("confirm"), open.run)
ask.tap(label, confirm: p.str("confirm"), answer: LinkAsk.answer(p), open.run)
} label: {
BarFace(symbol: Icons.symbol(p.str("icon")), label: label)
}
ios/HUDKit/Sources/HUDKit/Tree/ResolvedMenu.swift+6−5
@@ -28,8 +28,9 @@ import SwiftUI
/// One row of a `Menu`.
enum MenuRow: Equatable {
case action(ActionSpec)
/// Its label, what it opens, and what it asks first (`confirm`).
case link(String, JSON, String?)
/// Its label, what it opens, what it asks first (`confirm`), and the
/// words of the button that answers yes (`answer`).
case link(String, JSON, String?, answer: String? = nil)
/// Its label, and the page it shares.
case share(String, URL)
/// Its label, and the text it copies.
@@ -80,7 +81,7 @@ struct ResolvedMenu: View {
if let url = Resolved.share(p) { return .share(label, url) }
if let text = Resolved.copy(p) { return .copy(label, text) }
guard let open = p["open"], view.opener(tree: open) != nil else { return nil }
return .link(label, open, p.str("confirm"))
return .link(label, open, p.str("confirm"), answer: LinkAsk.answer(p))
case "Compose":
guard ResolvedCompose.offered(p, ComposeField.all(p), view) else { return nil }
return .compose(p)
@@ -150,10 +151,10 @@ struct ResolvedMenu: View {
.disabled(run.busy || ran.finished || spec.disabled)
.accessibilityHint(spec.reason ?? "")
if let reason = spec.reason { Text(reason) }
case .link(let label, let open, let confirm):
case .link(let label, let open, let confirm, let answer):
Button(label) {
guard let run = view.opener(tree: open)?.run else { return }
links.tap(label, confirm: confirm, run)
links.tap(label, confirm: confirm, answer: answer, run)
}
case .off(let label, let reason):
Button(label) {}
ios/HUDKit/Sources/HUDKit/Tree/TreeView.swift+15−6
ios/HUDKit/Tests/HUDKitTests/HUDKitTests.swift+29−1
schemas/json/parts.json+30−2
schemas/json/view.json+30−2
schemas/place.hud.ui.json+3−1
web/renderer/src/tree/Action.svelte+1−1
web/renderer/src/tree/Link.svelte+1−1
web/renderer/src/tree/types.ts+5−1