@kerf-js/veneer 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +16 -0
- package/README.md +1338 -2
- package/package.json +56 -3
- package/plugin.d.mts +187 -0
- package/plugin.mjs +399 -0
- package/src/Accordion.tsx +98 -0
- package/src/Alert.tsx +55 -0
- package/src/Badge.tsx +39 -0
- package/src/Button.tsx +175 -0
- package/src/Calendar-month.tsx +140 -0
- package/src/Calendar.tsx +335 -0
- package/src/Canvas.tsx +221 -0
- package/src/Card.tsx +85 -0
- package/src/Chart.tsx +278 -0
- package/src/Charts.tsx +158 -0
- package/src/Chip.tsx +61 -0
- package/src/Choice-checkbox.tsx +53 -0
- package/src/Choice-parts.tsx +7 -0
- package/src/Choice-radio.tsx +78 -0
- package/src/Choice-segmented.tsx +76 -0
- package/src/Choice-switch.tsx +51 -0
- package/src/Choice.tsx +4 -0
- package/src/CloseX.tsx +14 -0
- package/src/CodeBlock.tsx +81 -0
- package/src/CodeInput.tsx +256 -0
- package/src/Combobox.tsx +281 -0
- package/src/CommandPalette-controller.ts +314 -0
- package/src/CommandPalette-rows.tsx +137 -0
- package/src/CommandPalette.tsx +196 -0
- package/src/DataGrid-actions.ts +119 -0
- package/src/DataGrid-body.tsx +58 -0
- package/src/DataGrid-controller.ts +145 -0
- package/src/DataGrid-header.tsx +108 -0
- package/src/DataGrid-model.ts +248 -0
- package/src/DataGrid-pivot.tsx +108 -0
- package/src/DataGrid-rows.tsx +296 -0
- package/src/DataGrid-toolbar.tsx +127 -0
- package/src/DataGrid-tree.ts +149 -0
- package/src/DataGrid-viewport.tsx +37 -0
- package/src/DataGrid.tsx +145 -0
- package/src/DateField-presets.tsx +27 -0
- package/src/DateField-range.tsx +370 -0
- package/src/DateField.tsx +295 -0
- package/src/Dither.tsx +313 -0
- package/src/Drawer.tsx +123 -0
- package/src/DurationField.tsx +227 -0
- package/src/Feed.tsx +78 -0
- package/src/Field/view.tsx +147 -0
- package/src/Field.tsx +238 -0
- package/src/HamburgerMenu.tsx +119 -0
- package/src/Icon.tsx +15 -0
- package/src/Kbd.tsx +6 -0
- package/src/KeyValueEditor/actions.ts +75 -0
- package/src/KeyValueEditor/rows.tsx +104 -0
- package/src/KeyValueEditor.tsx +112 -0
- package/src/Layout.tsx +221 -0
- package/src/Markdown.tsx +127 -0
- package/src/MentionsInput/actions.ts +161 -0
- package/src/MentionsInput/end.tsx +82 -0
- package/src/MentionsInput.tsx +103 -0
- package/src/Menu.tsx +221 -0
- package/src/Modal.tsx +109 -0
- package/src/MonthPicker/month.tsx +117 -0
- package/src/MonthPicker/period.tsx +197 -0
- package/src/MonthPicker/shared.tsx +272 -0
- package/src/MonthPicker/week.tsx +103 -0
- package/src/MonthPicker.tsx +11 -0
- package/src/MultiSelect.tsx +139 -0
- package/src/Nav.tsx +36 -0
- package/src/NumberField.tsx +156 -0
- package/src/Pagination.tsx +335 -0
- package/src/PaymentCard.tsx +111 -0
- package/src/Picker.tsx +228 -0
- package/src/PlaceField.tsx +285 -0
- package/src/Popover.tsx +88 -0
- package/src/Presence.tsx +37 -0
- package/src/Progress.tsx +71 -0
- package/src/RecurrenceField.tsx +372 -0
- package/src/RichSelect/codes.tsx +94 -0
- package/src/RichSelect/list.tsx +380 -0
- package/src/RichSelect/phone-view.tsx +114 -0
- package/src/RichSelect/phone.tsx +305 -0
- package/src/RichSelect/search-keys.ts +28 -0
- package/src/RichSelect/timezone.tsx +53 -0
- package/src/RichSelect.tsx +13 -0
- package/src/RichTextEditor/controller.tsx +305 -0
- package/src/RichTextEditor/editor.tsx +61 -0
- package/src/RichTextEditor/tools.tsx +132 -0
- package/src/RichTextEditor/view.tsx +210 -0
- package/src/RichTextEditor.tsx +9 -0
- package/src/ScrollGrid/measure.ts +39 -0
- package/src/ScrollGrid/parts.tsx +112 -0
- package/src/ScrollGrid.tsx +375 -0
- package/src/ScrollRail.tsx +114 -0
- package/src/ScrollView.tsx +57 -0
- package/src/Segments/controller.tsx +148 -0
- package/src/Segments/events.ts +99 -0
- package/src/Segments/view.tsx +77 -0
- package/src/Segments.tsx +2 -0
- package/src/Select.tsx +343 -0
- package/src/Shape.tsx +41 -0
- package/src/Shell/branches.tsx +108 -0
- package/src/Shell/button.tsx +33 -0
- package/src/Shell/shared.tsx +220 -0
- package/src/Shell/shell.tsx +25 -0
- package/src/Shell/state.ts +138 -0
- package/src/Shell/view.tsx +280 -0
- package/src/Shell.tsx +17 -0
- package/src/SideNav/sections.tsx +50 -0
- package/src/SideNav/state.ts +140 -0
- package/src/SideNav.tsx +130 -0
- package/src/SideNavTitle.tsx +25 -0
- package/src/SignaturePad/state.ts +172 -0
- package/src/SignaturePad/view.tsx +69 -0
- package/src/SignaturePad.tsx +76 -0
- package/src/Skeleton.tsx +46 -0
- package/src/Slider.tsx +81 -0
- package/src/Spinner.tsx +21 -0
- package/src/Stage-director.ts +361 -0
- package/src/Stage-look.ts +75 -0
- package/src/Stage-poster.tsx +62 -0
- package/src/Stage-types.ts +206 -0
- package/src/Stage.tsx +147 -0
- package/src/TabBar.tsx +114 -0
- package/src/Table-actions.tsx +51 -0
- package/src/Table-base.ts +70 -0
- package/src/Table-body.tsx +84 -0
- package/src/Table-columns.tsx +58 -0
- package/src/Table-details.tsx +66 -0
- package/src/Table-editor.tsx +66 -0
- package/src/Table-head.tsx +52 -0
- package/src/Table-model.ts +82 -0
- package/src/Table-notice.ts +39 -0
- package/src/Table-paging.ts +50 -0
- package/src/Table-rows.tsx +308 -0
- package/src/Table-selection.ts +63 -0
- package/src/Table-sortbar.tsx +41 -0
- package/src/Table-source.ts +66 -0
- package/src/Table-toolbar.tsx +71 -0
- package/src/Table-types.ts +115 -0
- package/src/Table-view.tsx +87 -0
- package/src/Table.tsx +31 -0
- package/src/Tabs.tsx +129 -0
- package/src/Tag.tsx +40 -0
- package/src/Ticker.tsx +42 -0
- package/src/TimeField-date-model.ts +77 -0
- package/src/TimeField-date-view.tsx +152 -0
- package/src/TimeField-model.ts +80 -0
- package/src/TimeField-options.tsx +224 -0
- package/src/TimeField-slots.tsx +32 -0
- package/src/TimeField-types.ts +33 -0
- package/src/TimeField-view.tsx +124 -0
- package/src/TimeField.tsx +126 -0
- package/src/Toast.tsx +143 -0
- package/src/Toggle.tsx +75 -0
- package/src/Tooltip.tsx +69 -0
- package/src/Type.tsx +136 -0
- package/src/VirtualList-controls.ts +105 -0
- package/src/VirtualList-data.ts +43 -0
- package/src/VirtualList-measure.ts +169 -0
- package/src/VirtualList-metrics.ts +41 -0
- package/src/VirtualList-mount.ts +145 -0
- package/src/VirtualList-rows.tsx +91 -0
- package/src/VirtualList-types.ts +76 -0
- package/src/VirtualList-view.tsx +123 -0
- package/src/VirtualList.tsx +81 -0
- package/src/admin/ApiKeys-actions.ts +124 -0
- package/src/admin/ApiKeys-form.tsx +64 -0
- package/src/admin/ApiKeys-view.tsx +101 -0
- package/src/admin/ApiKeys.tsx +224 -0
- package/src/admin/Audit.tsx +246 -0
- package/src/admin/Billing.tsx +307 -0
- package/src/admin/Cart.tsx +177 -0
- package/src/admin/Checkout-address.tsx +125 -0
- package/src/admin/Checkout-cart.tsx +78 -0
- package/src/admin/Checkout-coupon.ts +34 -0
- package/src/admin/Checkout-done.tsx +31 -0
- package/src/admin/Checkout-model.ts +33 -0
- package/src/admin/Checkout-navigation.ts +76 -0
- package/src/admin/Checkout-payment-view.tsx +49 -0
- package/src/admin/Checkout-payment.ts +80 -0
- package/src/admin/Checkout-review.tsx +60 -0
- package/src/admin/Checkout-shipping.tsx +47 -0
- package/src/admin/Checkout-state.ts +122 -0
- package/src/admin/Checkout-steps.ts +10 -0
- package/src/admin/Checkout-summary.tsx +97 -0
- package/src/admin/Checkout-types.ts +60 -0
- package/src/admin/Checkout-view.tsx +51 -0
- package/src/admin/Checkout.tsx +72 -0
- package/src/admin/CsvImport-actions.ts +131 -0
- package/src/admin/CsvImport.tsx +379 -0
- package/src/admin/Danger.tsx +240 -0
- package/src/admin/Integrations/Card.tsx +82 -0
- package/src/admin/Integrations/Webhooks.tsx +341 -0
- package/src/admin/Integrations.tsx +169 -0
- package/src/admin/InviteDialog.tsx +153 -0
- package/src/admin/Members/columns.tsx +181 -0
- package/src/admin/Members.tsx +316 -0
- package/src/admin/Order.tsx +115 -0
- package/src/admin/PlainTable.tsx +34 -0
- package/src/admin/Plans.tsx +375 -0
- package/src/admin/SaveBar/actions.ts +86 -0
- package/src/admin/SaveBar.tsx +153 -0
- package/src/admin/Secret.tsx +74 -0
- package/src/admin/Settings.tsx +145 -0
- package/src/admin/StepBar.tsx +66 -0
- package/src/admin/TagsInput/actions.ts +60 -0
- package/src/admin/TagsInput.tsx +95 -0
- package/src/admin/atoms.tsx +73 -0
- package/src/admin/index.ts +67 -0
- package/src/agent/Actions/reasons.tsx +38 -0
- package/src/agent/Actions.tsx +166 -0
- package/src/agent/AgentPlan.tsx +86 -0
- package/src/agent/ArtifactPanel.tsx +299 -0
- package/src/agent/Assistant.tsx +168 -0
- package/src/agent/Checkpoint.tsx +19 -0
- package/src/agent/Cite.tsx +70 -0
- package/src/agent/ContextMeter.tsx +70 -0
- package/src/agent/Conversation.tsx +70 -0
- package/src/agent/Message.tsx +92 -0
- package/src/agent/ModelPicker.tsx +167 -0
- package/src/agent/Prompt-model.ts +118 -0
- package/src/agent/Prompt-view.tsx +246 -0
- package/src/agent/Prompt.tsx +128 -0
- package/src/agent/Prose.tsx +118 -0
- package/src/agent/Question.tsx +137 -0
- package/src/agent/Reasoning.tsx +31 -0
- package/src/agent/Shimmer.tsx +11 -0
- package/src/agent/Sources.tsx +23 -0
- package/src/agent/SpeechInput.tsx +243 -0
- package/src/agent/Suggestions.tsx +36 -0
- package/src/agent/ToolCall.tsx +219 -0
- package/src/agent/TraceViewer.tsx +96 -0
- package/src/agent/bits.tsx +88 -0
- package/src/agent/index.ts +38 -0
- package/src/bind.ts +57 -0
- package/src/collab/AutoTrack.tsx +91 -0
- package/src/collab/Comments.tsx +204 -0
- package/src/collab/Composer/state.ts +125 -0
- package/src/collab/Composer/view.tsx +155 -0
- package/src/collab/Composer.tsx +141 -0
- package/src/collab/ConversationList.tsx +120 -0
- package/src/collab/Cursors.tsx +71 -0
- package/src/collab/DataIntegrity.tsx +103 -0
- package/src/collab/Kanban-card.ts +74 -0
- package/src/collab/Kanban.tsx +368 -0
- package/src/collab/Lock.tsx +36 -0
- package/src/collab/PresenceStack.tsx +176 -0
- package/src/collab/ShareDialog.tsx +273 -0
- package/src/collab/Status.tsx +101 -0
- package/src/collab/SyncedForm.tsx +42 -0
- package/src/collab/Thread/Message.tsx +265 -0
- package/src/collab/Thread/rows.tsx +56 -0
- package/src/collab/Thread.tsx +323 -0
- package/src/collab/VersionHistory.tsx +173 -0
- package/src/collab/ViewportRail.tsx +73 -0
- package/src/collab/index.ts +37 -0
- package/src/collab/peer.tsx +42 -0
- package/src/fields.ts +5 -0
- package/src/flow/AuthScreen.tsx +81 -0
- package/src/flow/AuthSteps.tsx +296 -0
- package/src/flow/Checklist.tsx +211 -0
- package/src/flow/ConnBanner.tsx +304 -0
- package/src/flow/Flow.tsx +97 -0
- package/src/flow/MfaSetup.tsx +244 -0
- package/src/flow/Otp.tsx +243 -0
- package/src/flow/ReauthDialog.tsx +79 -0
- package/src/flow/ShortcutsOverlay.tsx +121 -0
- package/src/flow/SignGate.tsx +184 -0
- package/src/flow/SignIn.tsx +136 -0
- package/src/flow/SignUp.tsx +149 -0
- package/src/flow/Sso.tsx +96 -0
- package/src/flow/SystemPage/accounts.tsx +74 -0
- package/src/flow/SystemPage/art.tsx +113 -0
- package/src/flow/SystemPage.tsx +395 -0
- package/src/flow/Tour.tsx +207 -0
- package/src/flow/index.ts +29 -0
- package/src/flow/kit.tsx +334 -0
- package/src/index.ts +237 -0
- package/src/layout.css +4 -0
- package/src/links.css +4 -0
- package/src/live/ActivityFeed.tsx +88 -0
- package/src/live/Bell.tsx +108 -0
- package/src/live/Connection.tsx +113 -0
- package/src/live/Inbox.tsx +113 -0
- package/src/live/InboxFeed.tsx +67 -0
- package/src/live/InboxGestures.ts +41 -0
- package/src/live/InboxHandlers.ts +102 -0
- package/src/live/InboxHeader.tsx +81 -0
- package/src/live/InboxModel.ts +81 -0
- package/src/live/InboxRow.tsx +125 -0
- package/src/live/MeetingRoom.tsx +22 -0
- package/src/live/MeetingRoomControlBar.tsx +197 -0
- package/src/live/MeetingRoomHandlers.ts +53 -0
- package/src/live/MeetingRoomLayout.tsx +27 -0
- package/src/live/MeetingRoomModel.ts +49 -0
- package/src/live/MeetingRoomMount.ts +49 -0
- package/src/live/MeetingRoomParts.tsx +178 -0
- package/src/live/MeetingRoomPerson.tsx +21 -0
- package/src/live/MeetingRoomState.ts +88 -0
- package/src/live/MeetingRoomTile.tsx +84 -0
- package/src/live/MeetingRoomTypes.ts +68 -0
- package/src/live/MeetingRoomView.tsx +36 -0
- package/src/live/NotificationPreferences.tsx +99 -0
- package/src/live/NotificationPreferencesActions.ts +55 -0
- package/src/live/NotificationPreferencesCell.tsx +26 -0
- package/src/live/NotificationPreferencesCells.tsx +59 -0
- package/src/live/NotificationPreferencesGrid.tsx +129 -0
- package/src/live/NotificationPreferencesModel.tsx +91 -0
- package/src/live/NotificationPreferencesSave.ts +85 -0
- package/src/live/NotificationPreferencesWatch.ts +31 -0
- package/src/live/Prejoin.tsx +238 -0
- package/src/live/PrejoinMeter.tsx +26 -0
- package/src/live/PrejoinPreview.tsx +53 -0
- package/src/live/PushSoftAsk.tsx +63 -0
- package/src/live/TransportPicker.tsx +341 -0
- package/src/live/TransportPickerDetails.tsx +130 -0
- package/src/live/index.ts +31 -0
- package/src/live/notify.tsx +22 -0
- package/src/live/shared.tsx +110 -0
- package/src/parts.tsx +199 -0
- package/src/plugin/catalog.mjs +129 -0
- package/src/plugin/dtcg.mjs +79 -0
- package/src/plugin/icons.mjs +7 -0
- package/src/plugin/seed.mjs +40 -0
- package/src/plugin/theme-context.mjs +44 -0
- package/src/plugin/theme-css.mjs +143 -0
- package/src/plugin/theme-motion.mjs +43 -0
- package/src/plugin/theme-parts.d.mts +41 -0
- package/src/plugin/theme-parts.mjs +224 -0
- package/src/plugin/theme-text.mjs +93 -0
- package/src/plugin/theme-values.mjs +15 -0
- package/src/plugin/theme.d.mts +82 -0
- package/src/plugin/theme.mjs +316 -0
- package/src/schedule/Agenda.tsx +124 -0
- package/src/schedule/AgendaActions.ts +31 -0
- package/src/schedule/AgendaDay.tsx +124 -0
- package/src/schedule/AgendaGestures.ts +27 -0
- package/src/schedule/AgendaKeys.ts +52 -0
- package/src/schedule/AgendaModel.ts +82 -0
- package/src/schedule/AgendaNavigation.ts +38 -0
- package/src/schedule/AgendaPage.tsx +39 -0
- package/src/schedule/AgendaStrip.tsx +55 -0
- package/src/schedule/AvailabilityEditor-actions.ts +146 -0
- package/src/schedule/AvailabilityEditor-day.tsx +119 -0
- package/src/schedule/AvailabilityEditor-view.tsx +205 -0
- package/src/schedule/AvailabilityEditor.tsx +113 -0
- package/src/schedule/BookingCalendar.tsx +121 -0
- package/src/schedule/BookingCalendarActions.ts +85 -0
- package/src/schedule/BookingCalendarModel.ts +86 -0
- package/src/schedule/BookingCalendarParts.tsx +87 -0
- package/src/schedule/Calendar/AgendaView.tsx +45 -0
- package/src/schedule/Calendar/CalendarDialogs.tsx +105 -0
- package/src/schedule/Calendar/CalendarMain.tsx +47 -0
- package/src/schedule/Calendar/CalendarToolbar.tsx +106 -0
- package/src/schedule/Calendar/Column.tsx +129 -0
- package/src/schedule/Calendar/EventBlock.tsx +71 -0
- package/src/schedule/Calendar/MiniMonth.tsx +169 -0
- package/src/schedule/Calendar/MonthGrid.tsx +296 -0
- package/src/schedule/Calendar/TimeGrid.tsx +252 -0
- package/src/schedule/Calendar/Timeline.tsx +287 -0
- package/src/schedule/Calendar/ZoneChip.tsx +73 -0
- package/src/schedule/Calendar/calendar-shell.ts +160 -0
- package/src/schedule/Calendar/calendar-state.ts +30 -0
- package/src/schedule/Calendar/now-spans.tsx +33 -0
- package/src/schedule/Calendar/shared.ts +3 -0
- package/src/schedule/Calendar/state-actions.ts +189 -0
- package/src/schedule/Calendar/state-base.ts +143 -0
- package/src/schedule/Calendar/state-keys.ts +128 -0
- package/src/schedule/Calendar/time-fit.ts +84 -0
- package/src/schedule/Calendar.tsx +182 -0
- package/src/schedule/EventEditor.tsx +267 -0
- package/src/schedule/EventPopover.tsx +190 -0
- package/src/schedule/MeetingPlanner-model.ts +222 -0
- package/src/schedule/MeetingPlanner-view.tsx +310 -0
- package/src/schedule/MeetingPlanner.tsx +122 -0
- package/src/schedule/MoveSheet.tsx +168 -0
- package/src/schedule/YearView-model.ts +164 -0
- package/src/schedule/YearView-parts.tsx +147 -0
- package/src/schedule/YearView.tsx +100 -0
- package/src/schedule/bits.tsx +65 -0
- package/src/schedule/index.ts +25 -0
- package/src/skeleton-css.ts +4 -0
- package/src/styles.ts +13 -0
- package/src/type.css +15 -0
- package/src/ui.ts +41 -0
- package/src/use-ui.ts +10 -0
- package/tailwind.css +38 -0
- package/tokens/color.mjs +87 -0
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
import { CopyIcon, LinkIcon } from '@kerf-js/veneer-icons'
|
|
2
|
+
import { announce, arrivalTracker, installSweep, type Peer } from '@kerf-js/veneer-core'
|
|
3
|
+
import { derived, state, untrack, type State } from '@kerf-js/core'
|
|
4
|
+
import { Button } from '../Button'
|
|
5
|
+
import { ComboField } from '../Combobox'
|
|
6
|
+
import { Modal } from '../Modal'
|
|
7
|
+
import { CompactSelect } from '../Select'
|
|
8
|
+
import { Tag } from '../Tag'
|
|
9
|
+
import { PeerAvatar, read, type Live } from './peer'
|
|
10
|
+
import '../styles'
|
|
11
|
+
import '@kerf-js/veneer-core/styles/app/tokens.css'
|
|
12
|
+
import '@kerf-js/veneer-core/styles/app/base.css'
|
|
13
|
+
import '@kerf-js/veneer-core/styles/app/share.css'
|
|
14
|
+
import '@kerf-js/veneer-core/styles/components/share.css'
|
|
15
|
+
|
|
16
|
+
/** What someone may do with the document. */
|
|
17
|
+
export type ShareRole = 'viewer' | 'commenter' | 'editor' | 'owner'
|
|
18
|
+
const ROLES: [ShareRole, string][] = [
|
|
19
|
+
['viewer', 'Viewer'],
|
|
20
|
+
['commenter', 'Commenter'],
|
|
21
|
+
['editor', 'Editor'],
|
|
22
|
+
]
|
|
23
|
+
/** Someone the document is shared with. */
|
|
24
|
+
export type ShareMember = Peer & { email: string; role: ShareRole }
|
|
25
|
+
/** Someone it could be shared with. */
|
|
26
|
+
export type ShareContact = Peer & { email: string }
|
|
27
|
+
/** Who a link lets in, and as what. */
|
|
28
|
+
export interface ShareLink {
|
|
29
|
+
access: 'restricted' | 'anyone'
|
|
30
|
+
role: ShareRole
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Props for ShareDialog. */
|
|
34
|
+
export interface ShareDialogProps {
|
|
35
|
+
open: State<boolean>
|
|
36
|
+
/** The object's title: "Q4 brief". */
|
|
37
|
+
title: string
|
|
38
|
+
members: Live<ShareMember[]>
|
|
39
|
+
/** People the invite field suggests; any email address works too. */
|
|
40
|
+
people?: ShareContact[]
|
|
41
|
+
link: Live<ShareLink>
|
|
42
|
+
/** The URL Copy link writes. */
|
|
43
|
+
url: string
|
|
44
|
+
onInvite: (emails: string[], role: ShareRole) => void
|
|
45
|
+
/** A role, or null to remove the person. */
|
|
46
|
+
onRoleChange: (m: ShareMember, role: ShareRole | null) => void
|
|
47
|
+
onLinkAccess: (link: ShareLink) => void
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const ROLE_OPTIONS = ROLES.map(([value, label]) => ({ value, label }))
|
|
51
|
+
const MEMBER_OPTIONS = [...ROLE_OPTIONS, { value: 'remove', label: 'Remove' }]
|
|
52
|
+
const ACCESS_OPTIONS = [
|
|
53
|
+
{ value: 'restricted', label: 'Restricted' },
|
|
54
|
+
{ value: 'anyone', label: 'Anyone with link' },
|
|
55
|
+
]
|
|
56
|
+
|
|
57
|
+
type ShareViewContext = {
|
|
58
|
+
readonly open: State<boolean>
|
|
59
|
+
readonly title: string
|
|
60
|
+
list: { readonly value: ShareMember[] }
|
|
61
|
+
access: { readonly value: ShareLink }
|
|
62
|
+
fresh: { readonly value: string[] }
|
|
63
|
+
typed: State<string>
|
|
64
|
+
chips: State<string[]>
|
|
65
|
+
role: State<ShareRole>
|
|
66
|
+
copied: State<boolean>
|
|
67
|
+
add: (email: string) => void
|
|
68
|
+
find: (q: string) => Promise<ShareContact[]>
|
|
69
|
+
invite: () => void
|
|
70
|
+
submit: (e: Event) => void
|
|
71
|
+
copyLink: (e: MouseEvent) => void
|
|
72
|
+
setCopy: (n: HTMLElement) => void
|
|
73
|
+
onRoleChange: ShareDialogProps['onRoleChange']
|
|
74
|
+
onLinkAccess: ShareDialogProps['onLinkAccess']
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function memberRole(ctx: ShareViewContext, m: ShareMember) {
|
|
78
|
+
return m.role === 'owner' ? (
|
|
79
|
+
<span>Owner</span>
|
|
80
|
+
) : (
|
|
81
|
+
<>
|
|
82
|
+
<CompactSelect
|
|
83
|
+
label={`Role for ${m.name}`}
|
|
84
|
+
value={m.role}
|
|
85
|
+
options={MEMBER_OPTIONS}
|
|
86
|
+
onValueChange={(v) => ctx.onRoleChange(m, v === 'remove' ? null : (v as ShareRole))}
|
|
87
|
+
/>
|
|
88
|
+
</>
|
|
89
|
+
)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function shareChips(ctx: ShareViewContext) {
|
|
93
|
+
return (
|
|
94
|
+
ctx.chips.value.length > 0 && (
|
|
95
|
+
<div style="display:flex;flex-wrap:wrap;gap:6px;margin-block-start:8px">
|
|
96
|
+
{ctx.chips.value.map((c) => (
|
|
97
|
+
<Tag key={c} onRemove={() => (ctx.chips.value = ctx.chips.value.filter((x) => x !== c))}>
|
|
98
|
+
{c}
|
|
99
|
+
</Tag>
|
|
100
|
+
))}
|
|
101
|
+
</div>
|
|
102
|
+
)
|
|
103
|
+
)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function shareLinkRole(ctx: ShareViewContext) {
|
|
107
|
+
return (
|
|
108
|
+
ctx.access.value.access === 'anyone' && (
|
|
109
|
+
<CompactSelect
|
|
110
|
+
label="Link role"
|
|
111
|
+
value={ctx.access.value.role}
|
|
112
|
+
options={ROLE_OPTIONS}
|
|
113
|
+
onValueChange={(v) => ctx.onLinkAccess({ ...ctx.access.value, role: v as ShareRole })}
|
|
114
|
+
/>
|
|
115
|
+
)
|
|
116
|
+
)
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function shareView(ctx: ShareViewContext) {
|
|
120
|
+
return (
|
|
121
|
+
<Modal
|
|
122
|
+
open={ctx.open}
|
|
123
|
+
title={`Share “${ctx.title}”`}
|
|
124
|
+
footer={<Button onClick={() => (ctx.open.value = false)}>Done</Button>}
|
|
125
|
+
>
|
|
126
|
+
<div data-scope="share">
|
|
127
|
+
<form
|
|
128
|
+
style="display:flex;gap:8px;align-items:center"
|
|
129
|
+
onSubmit={(e: Event) => ctx.submit(e)}
|
|
130
|
+
>
|
|
131
|
+
<div style="flex:1;min-inline-size:0">
|
|
132
|
+
<ComboField
|
|
133
|
+
label="Add people or email"
|
|
134
|
+
minChars={1}
|
|
135
|
+
text={() => ctx.typed.value}
|
|
136
|
+
onText={(t) => (ctx.typed.value = t)}
|
|
137
|
+
find={ctx.find}
|
|
138
|
+
row={(p: ShareContact) => ({ main: p.name, sub: p.email })}
|
|
139
|
+
onPick={(p: ShareContact) => ctx.add(p.email)}
|
|
140
|
+
/>
|
|
141
|
+
</div>
|
|
142
|
+
<CompactSelect
|
|
143
|
+
label="Role for new people"
|
|
144
|
+
value={ctx.role.value}
|
|
145
|
+
options={ROLE_OPTIONS}
|
|
146
|
+
onValueChange={(v) => (ctx.role.value = v as ShareRole)}
|
|
147
|
+
/>
|
|
148
|
+
<Button onClick={ctx.invite}>Invite</Button>
|
|
149
|
+
</form>
|
|
150
|
+
{shareChips(ctx)}
|
|
151
|
+
<div>
|
|
152
|
+
{ctx.list.value.map((m) => (
|
|
153
|
+
<div
|
|
154
|
+
key={m.id}
|
|
155
|
+
data-part="person"
|
|
156
|
+
data-arrive={ctx.fresh.value.includes(m.id) ? '' : undefined}
|
|
157
|
+
>
|
|
158
|
+
<PeerAvatar peer={m} size="sm" />
|
|
159
|
+
<span>
|
|
160
|
+
{m.name}
|
|
161
|
+
<small>{m.email}</small>
|
|
162
|
+
</span>
|
|
163
|
+
{memberRole(ctx, m)}
|
|
164
|
+
</div>
|
|
165
|
+
))}
|
|
166
|
+
</div>
|
|
167
|
+
<div data-part="link">
|
|
168
|
+
<LinkIcon />
|
|
169
|
+
<CompactSelect
|
|
170
|
+
label="Link access"
|
|
171
|
+
value={ctx.access.value.access}
|
|
172
|
+
options={ACCESS_OPTIONS}
|
|
173
|
+
onValueChange={(v) =>
|
|
174
|
+
ctx.onLinkAccess({ ...ctx.access.value, access: v as ShareLink['access'] })
|
|
175
|
+
}
|
|
176
|
+
/>
|
|
177
|
+
{shareLinkRole(ctx)}
|
|
178
|
+
<span data-part="spacer" style="flex:1"></span>
|
|
179
|
+
<span ref={(n) => ctx.setCopy(n)} style="display:contents">
|
|
180
|
+
<Button
|
|
181
|
+
emphasis="outline"
|
|
182
|
+
tone="neutral"
|
|
183
|
+
size="sm"
|
|
184
|
+
onClick={(e: MouseEvent) => ctx.copyLink(e)}
|
|
185
|
+
>
|
|
186
|
+
<CopyIcon /> {ctx.copied.value ? 'Copied' : 'Copy link'}
|
|
187
|
+
</Button>
|
|
188
|
+
</span>
|
|
189
|
+
</div>
|
|
190
|
+
</div>
|
|
191
|
+
</Modal>
|
|
192
|
+
)
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* The share dialog (07 §6.2): the invite combobox with chips, a role per person, link access, Copy link with one
|
|
197
|
+
* confirm sweep, and invited rows arriving.
|
|
198
|
+
*/
|
|
199
|
+
export function ShareDialog({
|
|
200
|
+
open,
|
|
201
|
+
title,
|
|
202
|
+
members,
|
|
203
|
+
people,
|
|
204
|
+
link,
|
|
205
|
+
url,
|
|
206
|
+
onInvite,
|
|
207
|
+
onRoleChange,
|
|
208
|
+
onLinkAccess,
|
|
209
|
+
}: ShareDialogProps) {
|
|
210
|
+
const list = derived(() => read(members))
|
|
211
|
+
const access = derived(() => read(link))
|
|
212
|
+
const mark = arrivalTracker()
|
|
213
|
+
const fresh = derived(() => mark(list.value.map((m) => m.id)))
|
|
214
|
+
const typed = state('')
|
|
215
|
+
const chips = state<string[]>([])
|
|
216
|
+
const role = state<ShareRole>('editor')
|
|
217
|
+
const copied = state(false)
|
|
218
|
+
let copy: HTMLElement | undefined
|
|
219
|
+
const add = (email: string) => {
|
|
220
|
+
const e = email.trim()
|
|
221
|
+
if (e && !chips.value.includes(e)) chips.value = [...chips.value, e]
|
|
222
|
+
typed.value = ''
|
|
223
|
+
}
|
|
224
|
+
// oxlint-disable-next-line typescript/require-await -- `find` is typed to return a promise, and Promise.resolve costs bytes for nothing
|
|
225
|
+
const find = async (q: string) =>
|
|
226
|
+
untrack(() =>
|
|
227
|
+
(people ?? []).filter((p) => `${p.name} ${p.email}`.toLowerCase().includes(q.toLowerCase())),
|
|
228
|
+
)
|
|
229
|
+
const invite = () => {
|
|
230
|
+
const all = typed.value.includes('@')
|
|
231
|
+
? [...new Set([...chips.value, typed.value.trim()])]
|
|
232
|
+
: chips.value
|
|
233
|
+
if (!all.length) return
|
|
234
|
+
onInvite(all, role.value)
|
|
235
|
+
announce(copy!.ownerDocument, `Invited ${all.length === 1 ? all[0] : `${all.length} people`}`)
|
|
236
|
+
chips.value = []
|
|
237
|
+
typed.value = ''
|
|
238
|
+
}
|
|
239
|
+
const submit = (e: Event) => {
|
|
240
|
+
e.preventDefault()
|
|
241
|
+
if (typed.value.includes('@')) add(typed.value)
|
|
242
|
+
else invite()
|
|
243
|
+
}
|
|
244
|
+
const copyLink = (e: MouseEvent) => {
|
|
245
|
+
void navigator.clipboard?.writeText(url).catch(() => {})
|
|
246
|
+
copied.value = true
|
|
247
|
+
installSweep().confirm(e.currentTarget as Element)
|
|
248
|
+
announce((e.currentTarget as Element).ownerDocument, 'Link copied')
|
|
249
|
+
}
|
|
250
|
+
return shareView({
|
|
251
|
+
get open() {
|
|
252
|
+
return open
|
|
253
|
+
},
|
|
254
|
+
get title() {
|
|
255
|
+
return title
|
|
256
|
+
},
|
|
257
|
+
list,
|
|
258
|
+
access,
|
|
259
|
+
fresh,
|
|
260
|
+
typed,
|
|
261
|
+
chips,
|
|
262
|
+
role,
|
|
263
|
+
copied,
|
|
264
|
+
add,
|
|
265
|
+
find,
|
|
266
|
+
invite,
|
|
267
|
+
submit,
|
|
268
|
+
copyLink,
|
|
269
|
+
setCopy: (n) => (copy = n),
|
|
270
|
+
onRoleChange: (m, value) => onRoleChange(m, value),
|
|
271
|
+
onLinkAccess: (value) => onLinkAccess(value),
|
|
272
|
+
})
|
|
273
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { AlertIcon, CheckIcon, ClockIcon } from '@kerf-js/veneer-icons'
|
|
2
|
+
import { announce, firstName, type Peer } from '@kerf-js/veneer-core'
|
|
3
|
+
import { derived } from '@kerf-js/core'
|
|
4
|
+
import { Alert } from '../Alert'
|
|
5
|
+
import { Button } from '../Button'
|
|
6
|
+
import '../styles'
|
|
7
|
+
import '@kerf-js/veneer-core/styles/app/tokens.css'
|
|
8
|
+
import '@kerf-js/veneer-core/styles/app/sync.css'
|
|
9
|
+
import '@kerf-js/veneer-core/styles/app/conflict.css'
|
|
10
|
+
|
|
11
|
+
/** Where a document's saving stands. */
|
|
12
|
+
export type SyncState = 'saved' | 'saving' | 'offline'
|
|
13
|
+
const SYNC = { saved: 'Saved', saving: 'Saving…', offline: 'Offline · changes kept' } as const
|
|
14
|
+
|
|
15
|
+
/** Next to the title (07 §6.1): "Saved", "Saving…", "Offline · changes kept"; map `channel.status` onto it. */
|
|
16
|
+
export function SyncIndicator({ state }: { state: SyncState }) {
|
|
17
|
+
const icon = derived(() => (state === 'saved' ? 'check' : state === 'saving' ? 'clock' : 'alert'))
|
|
18
|
+
return (
|
|
19
|
+
<span data-scope="sync" data-state={state} role="status">
|
|
20
|
+
{icon.value === 'check' ? (
|
|
21
|
+
<CheckIcon />
|
|
22
|
+
) : icon.value === 'clock' ? (
|
|
23
|
+
<ClockIcon />
|
|
24
|
+
) : (
|
|
25
|
+
<AlertIcon />
|
|
26
|
+
)}{' '}
|
|
27
|
+
{SYNC[state]}
|
|
28
|
+
</span>
|
|
29
|
+
)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* A conflict (07 §6.1): a caution alert with both versions side by side, and Use theirs, Keep mine, Compare. Nothing
|
|
34
|
+
* is discarded silently: the caller holds both values until one of these fires.
|
|
35
|
+
*/
|
|
36
|
+
export function ConflictAlert({
|
|
37
|
+
field,
|
|
38
|
+
peer,
|
|
39
|
+
time,
|
|
40
|
+
theirs,
|
|
41
|
+
yours,
|
|
42
|
+
onUseTheirs,
|
|
43
|
+
onKeepMine,
|
|
44
|
+
onCompare,
|
|
45
|
+
}: {
|
|
46
|
+
field: string
|
|
47
|
+
peer: Peer
|
|
48
|
+
time: string
|
|
49
|
+
theirs: unknown
|
|
50
|
+
yours: unknown
|
|
51
|
+
onUseTheirs: () => void
|
|
52
|
+
onKeepMine: () => void
|
|
53
|
+
onCompare?: () => void
|
|
54
|
+
}) {
|
|
55
|
+
let box: HTMLDivElement | undefined
|
|
56
|
+
const settle = (fn: () => void) => () => {
|
|
57
|
+
fn()
|
|
58
|
+
if (box) announce(box.ownerDocument, 'Conflict resolved')
|
|
59
|
+
}
|
|
60
|
+
const compare = derived(() => onCompare !== undefined)
|
|
61
|
+
const first = () => firstName(peer.name)
|
|
62
|
+
const actions = derived(() => (
|
|
63
|
+
<>
|
|
64
|
+
<Button size="sm" onClick={settle(onUseTheirs)}>
|
|
65
|
+
Use theirs
|
|
66
|
+
</Button>
|
|
67
|
+
<Button size="sm" emphasis="outline" tone="neutral" onClick={settle(onKeepMine)}>
|
|
68
|
+
Keep mine
|
|
69
|
+
</Button>
|
|
70
|
+
{compare.value && (
|
|
71
|
+
<Button size="sm" emphasis="ghost" tone="neutral" onClick={() => onCompare!()}>
|
|
72
|
+
Compare
|
|
73
|
+
</Button>
|
|
74
|
+
)}
|
|
75
|
+
</>
|
|
76
|
+
))
|
|
77
|
+
return (
|
|
78
|
+
<div ref={(n) => (box = n)}>
|
|
79
|
+
<Alert
|
|
80
|
+
tone="caution"
|
|
81
|
+
live
|
|
82
|
+
title={`${first()} changed “${field}” while you were editing`}
|
|
83
|
+
actions={actions.value}
|
|
84
|
+
>
|
|
85
|
+
Pick a version. Nothing is lost either way.
|
|
86
|
+
<div data-scope="conflict">
|
|
87
|
+
<div>
|
|
88
|
+
<small>
|
|
89
|
+
Theirs · {first()} · {time}
|
|
90
|
+
</small>
|
|
91
|
+
<ins>{theirs}</ins>
|
|
92
|
+
</div>
|
|
93
|
+
<div>
|
|
94
|
+
<small>Yours · unsaved</small>
|
|
95
|
+
<del>{yours}</del>
|
|
96
|
+
</div>
|
|
97
|
+
</div>
|
|
98
|
+
</Alert>
|
|
99
|
+
</div>
|
|
100
|
+
)
|
|
101
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { syncedForm, type FormOp } from '@kerf-js/veneer-core'
|
|
2
|
+
import { derived } from '@kerf-js/core'
|
|
3
|
+
import { use } from '@kerf-js/veneer-core/kerf'
|
|
4
|
+
import { read, type Live } from './peer'
|
|
5
|
+
import '../styles'
|
|
6
|
+
import '@kerf-js/veneer-core/styles/app/tokens.css'
|
|
7
|
+
import '@kerf-js/veneer-core/styles/app/base.css'
|
|
8
|
+
import '@kerf-js/veneer-core/styles/app/synced-form.css'
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* All-inputs sync (07 §6.4): every named control inside is shared. `ops` are the channel's remote edits, oldest first;
|
|
12
|
+
* `onSend` hears each local one. A remote edit rings the field and names the peer for 1.4 s; a focused field queues it.
|
|
13
|
+
*/
|
|
14
|
+
export function SyncedForm({
|
|
15
|
+
ops,
|
|
16
|
+
onSend,
|
|
17
|
+
label,
|
|
18
|
+
children,
|
|
19
|
+
}: {
|
|
20
|
+
ops: Live<FormOp[]>
|
|
21
|
+
onSend?: ((name: string, value: string | boolean) => void) | undefined
|
|
22
|
+
label: string
|
|
23
|
+
children?: unknown
|
|
24
|
+
}) {
|
|
25
|
+
const list = derived(() => read(ops))
|
|
26
|
+
let form: HTMLFormElement | undefined
|
|
27
|
+
use(
|
|
28
|
+
syncedForm,
|
|
29
|
+
() => form,
|
|
30
|
+
() => ({ ops: list.value, onSend }),
|
|
31
|
+
)
|
|
32
|
+
return (
|
|
33
|
+
<form
|
|
34
|
+
ref={(n) => (form = n)}
|
|
35
|
+
data-scope="synced-form"
|
|
36
|
+
aria-label={label}
|
|
37
|
+
onSubmit={(e: Event) => e.preventDefault()}
|
|
38
|
+
>
|
|
39
|
+
{children}
|
|
40
|
+
</form>
|
|
41
|
+
)
|
|
42
|
+
}
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AlertIcon,
|
|
3
|
+
CheckIcon,
|
|
4
|
+
ChecksIcon,
|
|
5
|
+
ClockIcon,
|
|
6
|
+
CopyIcon,
|
|
7
|
+
QuoteIcon,
|
|
8
|
+
SmileIcon,
|
|
9
|
+
} from '@kerf-js/veneer-icons'
|
|
10
|
+
import { reactionName, textParts } from '@kerf-js/veneer-core'
|
|
11
|
+
import { derived, untrack } from '@kerf-js/core'
|
|
12
|
+
import { Text } from '@kerf-js/core/text'
|
|
13
|
+
import { Button } from '../../Button'
|
|
14
|
+
import { PeerAvatar, SWEEP } from '../peer'
|
|
15
|
+
import type { MessageProps } from '../Thread'
|
|
16
|
+
import '../../styles'
|
|
17
|
+
import '@kerf-js/veneer-core/styles/components/button.css'
|
|
18
|
+
import '@kerf-js/veneer-core/styles/app/tokens.css'
|
|
19
|
+
import '@kerf-js/veneer-core/styles/app/base.css'
|
|
20
|
+
import '@kerf-js/veneer-core/styles/app/thread.css'
|
|
21
|
+
import '@kerf-js/veneer-core/styles/app/message.css'
|
|
22
|
+
import '@kerf-js/veneer-core/styles/app/reactions.css'
|
|
23
|
+
import '@kerf-js/veneer-core/styles/app/thread-replies.css'
|
|
24
|
+
import '@kerf-js/veneer-core/styles/app/avatar-stack.css'
|
|
25
|
+
|
|
26
|
+
function messageState(p: MessageProps) {
|
|
27
|
+
const who = () => (p.message.mine ? 'You' : p.message.author.name)
|
|
28
|
+
const quoted = derived(() => {
|
|
29
|
+
const q = p.message.quote
|
|
30
|
+
if (!q) return null
|
|
31
|
+
const src = p.source
|
|
32
|
+
const author = src ? (src.mine ? 'You' : src.author.name) : q.author
|
|
33
|
+
const deleted = q.deleted || (!src && !q.author && !q.channel)
|
|
34
|
+
return {
|
|
35
|
+
text: q.text,
|
|
36
|
+
author,
|
|
37
|
+
by: deleted
|
|
38
|
+
? 'Original message deleted'
|
|
39
|
+
: q.channel
|
|
40
|
+
? `In ${q.channel}${author ? ` · ${author}` : ''}`
|
|
41
|
+
: `${author} · ${src?.time ?? q.time ?? ''}`,
|
|
42
|
+
ref: src ? q.ref : undefined,
|
|
43
|
+
deleted,
|
|
44
|
+
}
|
|
45
|
+
})
|
|
46
|
+
const parts = derived(() => textParts(p.message.text, p.message.mentions))
|
|
47
|
+
const state_ = derived(() => p.message.state)
|
|
48
|
+
const delivery = derived(() => {
|
|
49
|
+
const s = state_.value
|
|
50
|
+
return !p.message.mine
|
|
51
|
+
? null
|
|
52
|
+
: s === 'failed' || s === 'sending'
|
|
53
|
+
? s
|
|
54
|
+
: p.last
|
|
55
|
+
? s === 'read'
|
|
56
|
+
? 'read'
|
|
57
|
+
: 'sent'
|
|
58
|
+
: null
|
|
59
|
+
})
|
|
60
|
+
return { who, quoted, parts, state_, delivery }
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function messageReactions(p: MessageProps) {
|
|
64
|
+
return (
|
|
65
|
+
(p.message.reactions?.length ?? 0) > 0 && (
|
|
66
|
+
<div data-scope="reactions">
|
|
67
|
+
{p.message.reactions!.map((r) => (
|
|
68
|
+
<button
|
|
69
|
+
key={r.emoji}
|
|
70
|
+
type="button"
|
|
71
|
+
aria-pressed={r.mine ? 'true' : 'false'}
|
|
72
|
+
aria-label={reactionName(r)}
|
|
73
|
+
onClick={() => p.onReact?.(p.message, r)}
|
|
74
|
+
>
|
|
75
|
+
{r.emoji} <span>{r.count}</span>
|
|
76
|
+
</button>
|
|
77
|
+
))}
|
|
78
|
+
<button
|
|
79
|
+
type="button"
|
|
80
|
+
aria-label="Add reaction"
|
|
81
|
+
onClick={() => p.onReact?.(p.message, null)}
|
|
82
|
+
>
|
|
83
|
+
<SmileIcon />
|
|
84
|
+
</button>
|
|
85
|
+
</div>
|
|
86
|
+
)
|
|
87
|
+
)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function messageReplies(p: MessageProps) {
|
|
91
|
+
return (
|
|
92
|
+
p.message.replies && (
|
|
93
|
+
<button data-scope="thread-replies" type="button" onClick={() => p.onReplies?.(p.message)}>
|
|
94
|
+
<span data-scope="avatar-stack">
|
|
95
|
+
{(p.message.replies.people ?? []).map((peer) => (
|
|
96
|
+
<PeerAvatar key={peer.id} peer={peer} />
|
|
97
|
+
))}
|
|
98
|
+
</span>
|
|
99
|
+
{p.message.replies.count} {p.message.replies.count === 1 ? 'reply' : 'replies'}
|
|
100
|
+
{p.message.replies.last ? ` · last ${p.message.replies.last}` : ''}
|
|
101
|
+
</button>
|
|
102
|
+
)
|
|
103
|
+
)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function messageFailed(p: MessageProps) {
|
|
107
|
+
return (
|
|
108
|
+
<span data-part="status">
|
|
109
|
+
<AlertIcon /> Not sent.{' '}
|
|
110
|
+
<Button emphasis="link" tone="critical" onClick={() => p.onRetry?.(p.message)}>
|
|
111
|
+
Retry
|
|
112
|
+
</Button>
|
|
113
|
+
</span>
|
|
114
|
+
)
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function messageSending() {
|
|
118
|
+
return (
|
|
119
|
+
<span data-part="status">
|
|
120
|
+
<ClockIcon /> Sending…
|
|
121
|
+
</span>
|
|
122
|
+
)
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function messageSent(p: MessageProps) {
|
|
126
|
+
return (
|
|
127
|
+
<span data-part="status">
|
|
128
|
+
<CheckIcon /> Sent {p.message.time}
|
|
129
|
+
</span>
|
|
130
|
+
)
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function messageRead(p: MessageProps) {
|
|
134
|
+
return (
|
|
135
|
+
<span data-part="status">
|
|
136
|
+
<ChecksIcon /> Read {p.message.readAt ?? p.message.time}
|
|
137
|
+
</span>
|
|
138
|
+
)
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function messageBy(p: MessageProps) {
|
|
142
|
+
return (
|
|
143
|
+
<div data-part="by">
|
|
144
|
+
<b>{p.message.author.name}</b>
|
|
145
|
+
<time>{p.message.time}</time>
|
|
146
|
+
</div>
|
|
147
|
+
)
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function messageJump(ctx: ReturnType<typeof messageState>) {
|
|
151
|
+
return (
|
|
152
|
+
<Button emphasis="link" tone="neutral" data-part="quote-jump" data-jump={ctx.quoted.value!.ref}>
|
|
153
|
+
Jump to original
|
|
154
|
+
</Button>
|
|
155
|
+
)
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function messageAttachment(p: MessageProps) {
|
|
159
|
+
return (
|
|
160
|
+
<div data-part="attachment">
|
|
161
|
+
<i>{p.message.attachment!.kind}</i>
|
|
162
|
+
<b>{p.message.attachment!.name}</b>
|
|
163
|
+
<small>{p.message.attachment!.meta}</small>
|
|
164
|
+
</div>
|
|
165
|
+
)
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function messageQuote(ctx: ReturnType<typeof messageState>) {
|
|
169
|
+
return (
|
|
170
|
+
<blockquote data-part="quote">
|
|
171
|
+
<span data-part="quote-by">
|
|
172
|
+
<span data-part="sr-only">Quoting </span>
|
|
173
|
+
{ctx.quoted.value!.by}
|
|
174
|
+
</span>
|
|
175
|
+
{!ctx.quoted.value!.deleted && <span data-part="quote-text">{ctx.quoted.value!.text}</span>}
|
|
176
|
+
</blockquote>
|
|
177
|
+
)
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function messageView(p: MessageProps, ctx: ReturnType<typeof messageState>) {
|
|
181
|
+
return (
|
|
182
|
+
<div
|
|
183
|
+
data-scope="message"
|
|
184
|
+
data-focus=""
|
|
185
|
+
role="article"
|
|
186
|
+
tabindex="-1"
|
|
187
|
+
data-mid={p.message.id}
|
|
188
|
+
aria-label={`${ctx.who()}, ${p.message.time}${ctx.quoted.value?.author ? `, quoting ${ctx.quoted.value.author}` : ''}`}
|
|
189
|
+
data-mine={p.message.mine ? '' : undefined}
|
|
190
|
+
data-continued={p.continued ? '' : undefined}
|
|
191
|
+
data-state={ctx.state_.value}
|
|
192
|
+
data-arrive={p.arrive ? '' : undefined}
|
|
193
|
+
data-mentions-me={p.message.mentions?.includes('you') ? '' : undefined}
|
|
194
|
+
>
|
|
195
|
+
{!p.message.mine && <PeerAvatar peer={p.message.author} />}
|
|
196
|
+
<div data-part="body">
|
|
197
|
+
{!p.continued && !p.message.mine && messageBy(p)}
|
|
198
|
+
<div data-part="actions" role="toolbar" aria-label="Message actions">
|
|
199
|
+
<Button
|
|
200
|
+
emphasis="ghost"
|
|
201
|
+
tone="neutral"
|
|
202
|
+
size="sm"
|
|
203
|
+
label="Quote reply"
|
|
204
|
+
data-icon-only=""
|
|
205
|
+
data-quote=""
|
|
206
|
+
tabindex="-1"
|
|
207
|
+
aria-keyshortcuts="Q"
|
|
208
|
+
>
|
|
209
|
+
<QuoteIcon />
|
|
210
|
+
</Button>
|
|
211
|
+
<Button
|
|
212
|
+
emphasis="ghost"
|
|
213
|
+
tone="neutral"
|
|
214
|
+
size="sm"
|
|
215
|
+
label="Copy text"
|
|
216
|
+
data-icon-only=""
|
|
217
|
+
data-copytext=""
|
|
218
|
+
tabindex="-1"
|
|
219
|
+
>
|
|
220
|
+
<CopyIcon />
|
|
221
|
+
</Button>
|
|
222
|
+
</div>
|
|
223
|
+
<div data-part="bubble" data-sweep="">
|
|
224
|
+
<SWEEP />
|
|
225
|
+
{ctx.quoted.value && messageQuote(ctx)}
|
|
226
|
+
{p.message.streaming ? (
|
|
227
|
+
<Text stream as="div">
|
|
228
|
+
{p.message.text}
|
|
229
|
+
</Text>
|
|
230
|
+
) : (
|
|
231
|
+
<span data-part="text" data-measure="">
|
|
232
|
+
{ctx.parts.value.map((part) =>
|
|
233
|
+
part.mention ? (
|
|
234
|
+
<span key={part.at} data-part="mention">
|
|
235
|
+
{part.text}
|
|
236
|
+
</span>
|
|
237
|
+
) : (
|
|
238
|
+
<span key={part.at}>{part.text}</span>
|
|
239
|
+
),
|
|
240
|
+
)}
|
|
241
|
+
</span>
|
|
242
|
+
)}
|
|
243
|
+
</div>
|
|
244
|
+
{ctx.quoted.value?.ref && messageJump(ctx)}
|
|
245
|
+
{p.message.attachment && messageAttachment(p)}
|
|
246
|
+
{messageReactions(p)}
|
|
247
|
+
{messageReplies(p)}
|
|
248
|
+
{ctx.delivery.value === 'failed' && messageFailed(p)}
|
|
249
|
+
{ctx.delivery.value === 'sending' && messageSending()}
|
|
250
|
+
{ctx.delivery.value === 'sent' && messageSent(p)}
|
|
251
|
+
{ctx.delivery.value === 'read' && messageRead(p)}
|
|
252
|
+
</div>
|
|
253
|
+
</div>
|
|
254
|
+
)
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* One message (07 §5.1, §5.2): avatar, author, Actions toolbar, bubble (quote, text with mention chips), Jump to
|
|
259
|
+
* original, attachment, reactions, thread replies, delivery. Continued messages hide avatar and author.
|
|
260
|
+
*/
|
|
261
|
+
export function Message(props: MessageProps) {
|
|
262
|
+
const p = untrack(() => props)
|
|
263
|
+
const ctx = messageState(p)
|
|
264
|
+
return messageView(p, ctx)
|
|
265
|
+
}
|