constMessage=UiSchema.TaggedEnum({RequestedShareAdd:{id:Schema.String,role:Schema.String},RequestedShareInvite:{request:Schema.String,emails:Schema.Array(Schema.String),role:Schema.String},RequestedShareRole:{id:Schema.String,role:Schema.String},RequestedShareRemove:{id:Schema.String},})// every change is a request; the app answers through `outcomes` and sends the new entries backexportconstPageSharing=(h:Html.H<typeofMessage.Type>,page:{readonly title: string;readonly entries:ReadonlyArray<ShareEntry>;readonly members:ReadonlyArray<ShareCandidate>;readonly outcomes:ReadonlyArray<Outcome>},)=>Share(h,{props:{objectName: page.title,roles:[{value:"view",label:"Can view"},{value:"edit",label:"Can edit"},],entries: page.entries,candidates: page.members,inviteEmails:true,can:["manage"],outcomes: page.outcomes,},onEmit:{RequestedAdd:({ id, role })=>Message.RequestedShareAdd({ id, role }),RequestedInvite:({ request, emails, role })=>Message.RequestedShareInvite({ request, emails, role }),RequestedRole:({ id, role })=>Message.RequestedShareRole({ id, role }),RequestedRemove:({ id })=>Message.RequestedShareRemove({ id }),RequestedGeneral:()=>undefined,RequestedInviteLink:()=>undefined,RequestedClose:()=>undefined,},})
import{UiSchema}from"@effect/ui"import{Html}from"@effect/ui/html"import{Schema}from"effect"import{Button}from"./ui/uicontext/components/Button.ts"import{Share,ShareEntry}from"./ui/uicontext/components/kit/Share.ts"import{ candidates, entries, generalOptions, link, roles }from"./people.ts"// The usual place for sharing: a Share button in the page header opens it as a dialog.constMessage=UiSchema.TaggedEnum({ToggledShare:{open:Schema.Boolean},Added:{id:Schema.String,role:Schema.String},Changed:{id:Schema.String,role:Schema.String},Removed:{id:Schema.String},})exportconstShareDialog=Html.component({name:"ShareDialog",model:Schema.Struct({open:Schema.Boolean,entries:Schema.Array(ShareEntry)}),message:Message,}).make({init:()=>({open:false, entries }),update:{ToggledShare:($,{ open })=> $.evolve({ open }),// accepted at once here; a real app sends each change and passes `outcomes`Added:($,{ id, role })=>{const who = candidates.find((c)=> c.id=== id)return who ===undefined? $.model: $.evolve({entries:(all)=>[...all,{...who, role }]})},Changed:($,{ id, role })=> $.evolve({entries:(all)=> all.map((e)=>(e.id=== id ?{...e, role }: e))}),Removed:($,{ id })=> $.evolve({entries:(all)=> all.filter((e)=> e.id!== id)}),},view:(h, model)=> h.div.children(Button(h,{tone:"primary"}).on("click",Message.ToggledShare({open:true})).children("Share"),Share(h,{props:{agentId:"share-dialog",objectName:"Checkout retries", roles,defaultRole:"comment",entries: model.entries,candidates: candidates.filter((c)=>!model.entries.some((e)=> e.id=== c.id)),general:{value:"invited",role:"view",options: generalOptions },can:["manage"],keepOne:{role:"full",message:"A page needs someone with full access."}, link,layout:"dialog",open: model.open,},onEmit:{RequestedAdd:({ id, role })=>Message.Added({ id, role }),RequestedInvite:()=>undefined,RequestedRole:({ id, role })=>Message.Changed({ id, role }),RequestedRemove:({ id })=>Message.Removed({ id }),RequestedGeneral:()=>undefined,RequestedInviteLink:()=>undefined,RequestedClose:()=>Message.ToggledShare({open:false}),},}),),})
Anyone in the workspace can find and open it. · Can comment
importtype{Html}from"@effect/ui/html"import*as stylex from"@stylexjs/stylex"import{Share}from"./ui/uicontext/components/kit/Share.ts"import{ sx }from"./ui/uicontext/components/Sx.ts"import{ entries, generalOptions, link, roles }from"./people.ts"// What someone with "Can view" sees: who has access and how wide it goes, with nothing to change.const styles = stylex.create({frame:{inlineSize:"min(100%, 34rem)"}})exportconstSharedWithMe=<M>(h:Html.H<M>)=> h.div.attrs(sx(styles.frame)).children(Share(h,{props:{agentId:"share-read-only",objectName:"Checkout retries",title:"Who can see this page", roles,entries: entries.map((e)=>({...e,you: e.id==="scout"})),general:{value:"workspace",role:"comment",options: generalOptions },can:[],readOnlyReason:"Only people with full access can change sharing. Ask Ada Lovelace.", link,},onEmit:{RequestedAdd:()=>undefined,RequestedInvite:()=>undefined,RequestedRole:()=>undefined,RequestedRemove:()=>undefined,RequestedGeneral:()=>undefined,RequestedInviteLink:()=>undefined,RequestedClose:()=>undefined,},}),)
API reference
ShareComponent
Props
Share props
Name
Type
Default
Description
agentId
string
—
This share control's id for agents, unique on the page: "share-page-q3"
objectNamerequired
string
—
What is shared: "Q3 plan"
title
string
Share "<objectName>"
"Share", "Share this agent"; Share "<objectName>" by default
rolesrequired
RoleOption[]
—
The roles that can be given, from least to most access: "Can view", "Can edit"
maxRole
string
—
The most the person may grant, by value; roles above it are disabled
entriesrequired
ShareEntry[]
—
The people, groups and domains that have access now, each with a role
candidates
ShareCandidate[]
—
Who can be added; empty or left out hides the add row unless inviteEmails is on
inviteEmails
boolean
—
People outside candidates can be invited by typing or pasting their email addresses
defaultRole
string
—
The role a new entry gets unless the person picks another
general
{ value, options, role }
—
Who else can open it, from narrowest to widest
canrequired
Can(["manage"])
—
What the person may do: "manage" changes sharing; without it everything is read-only with readOnlyReason
readOnlyReason
string
—
Why sharing can't be changed here, shown when can leaves out "manage"
keepOne
{ role, message }
—
At least one entry must keep this role: { role: "owner", message: "A workspace needs at least one owner." }
note
string
—
A line about what sharing means here: "People who run the agent get its access, not their own."
applying
string
—
A change is still being applied: "Applying to 12 subfolders…"
outcomes
Outcome[]
—
The app's answers to requests, one per request. The request id is the entry's (or candidate's) id for RequestedAdd, RequestedRole and RequestedRemove, "general" for RequestedGeneral and "invite-link" for RequestedInviteLink. A pending entry is busy, a pending "invite-link" says the link is being made, and the newest refusal shows its reason.
link
string
—
A link to the object, to copy
invite
{ label, url, note }
—
An invitation link: anyone who opens it can join. "Create invite link" asks the app (RequestedInviteLink); once the app has made one it passes url and the person copies it.
layout
"dialog" | "inline"
—
A native modal dialog (with open) or inline on the page
open
boolean
—
Whether the dialog is showing, with the dialog layout; closing it comes back as RequestedClose
Events
Share events
Event
Payload
Description
RequestedAdd
{ id: string; role: string }
Give this person or group access with this role
RequestedRole
{ id: string; role: string }
Change the role of someone who already has access
RequestedRemove
{ id: string }
Take away this person's or group's access
RequestedGeneral
{ value: string; role?: string }
Change who else can open it, to this general access option; role when its role changes