@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,240 @@
|
|
|
1
|
+
import { TrashIcon, type IconComponent } from '@kerf-js/veneer-icons'
|
|
2
|
+
import { confirmMatches } from '@kerf-js/veneer-core'
|
|
3
|
+
import { derived, state, type State, untrack, watch } from '@kerf-js/core'
|
|
4
|
+
import { Button, type Tone } from '../Button'
|
|
5
|
+
import { Input } from '../Field'
|
|
6
|
+
import { Modal } from '../Modal'
|
|
7
|
+
import { Glyph } from '../parts'
|
|
8
|
+
import { toast } from '../Toast'
|
|
9
|
+
import { latch } from './atoms'
|
|
10
|
+
import { SettingsSection } from './Settings'
|
|
11
|
+
import '../styles'
|
|
12
|
+
import '@kerf-js/veneer-core/styles/flows/tokens.css'
|
|
13
|
+
import '@kerf-js/veneer-core/styles/flows/base.css'
|
|
14
|
+
import '@kerf-js/veneer-core/styles/rich/helpers.css'
|
|
15
|
+
import '@kerf-js/veneer-core/styles/layout/tokens.css'
|
|
16
|
+
import '@kerf-js/veneer-core/styles/layout/row.css'
|
|
17
|
+
import '@kerf-js/veneer-core/styles/layout/stack.css'
|
|
18
|
+
import '@kerf-js/veneer-core/styles/flows/confirm.css'
|
|
19
|
+
|
|
20
|
+
/** The danger zone (09 §4.4): the one critical-bordered section. Rows are SettingRows. */
|
|
21
|
+
export function DangerZone({
|
|
22
|
+
id = 'danger',
|
|
23
|
+
title = 'Danger zone',
|
|
24
|
+
description,
|
|
25
|
+
children,
|
|
26
|
+
}: {
|
|
27
|
+
id?: string
|
|
28
|
+
title?: unknown
|
|
29
|
+
description?: unknown
|
|
30
|
+
children: unknown
|
|
31
|
+
}) {
|
|
32
|
+
return (
|
|
33
|
+
<SettingsSection id={id} title={title} description={description} tone="critical">
|
|
34
|
+
{children}
|
|
35
|
+
</SettingsSection>
|
|
36
|
+
)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Props for ConfirmDialog. */
|
|
40
|
+
export interface ConfirmDialogProps {
|
|
41
|
+
open: State<boolean>
|
|
42
|
+
title: unknown
|
|
43
|
+
description?: unknown
|
|
44
|
+
/** The confirm button: says what it does, with the count on a batch ("Remove 2 members"). */
|
|
45
|
+
action: unknown
|
|
46
|
+
cancel?: string
|
|
47
|
+
tone?: Tone | undefined
|
|
48
|
+
/** Drawn at the top of the body, in the result mark. */
|
|
49
|
+
glyph?: string | IconComponent
|
|
50
|
+
children?: unknown
|
|
51
|
+
onConfirm: () => Promise<void> | void
|
|
52
|
+
onCancel?: () => void
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const failed = (retry: () => unknown) =>
|
|
56
|
+
toast.show({
|
|
57
|
+
title: 'That didn’t go through',
|
|
58
|
+
description: 'Nothing changed. Try again.',
|
|
59
|
+
tone: 'critical',
|
|
60
|
+
action: { label: 'Retry', onClick: retry },
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
/** A plain AlertDialog (05 §3): focus on Cancel. Pending on the confirm button; the dialog closes when it's done. */
|
|
64
|
+
export function ConfirmDialog({
|
|
65
|
+
open,
|
|
66
|
+
title,
|
|
67
|
+
description,
|
|
68
|
+
action,
|
|
69
|
+
cancel = 'Cancel',
|
|
70
|
+
tone,
|
|
71
|
+
glyph,
|
|
72
|
+
children,
|
|
73
|
+
onConfirm,
|
|
74
|
+
onCancel,
|
|
75
|
+
}: ConfirmDialogProps) {
|
|
76
|
+
const armed = latch(untrack(() => open))
|
|
77
|
+
const busy = state(false)
|
|
78
|
+
const go = async () => {
|
|
79
|
+
if (busy.value) return
|
|
80
|
+
busy.value = true
|
|
81
|
+
try {
|
|
82
|
+
await onConfirm()
|
|
83
|
+
open.value = false
|
|
84
|
+
} catch {
|
|
85
|
+
failed(go)
|
|
86
|
+
} finally {
|
|
87
|
+
busy.value = false
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return (
|
|
91
|
+
<>
|
|
92
|
+
{armed.value && (
|
|
93
|
+
<Modal
|
|
94
|
+
open={open}
|
|
95
|
+
alert
|
|
96
|
+
size="sm"
|
|
97
|
+
title={title}
|
|
98
|
+
description={description}
|
|
99
|
+
mark={
|
|
100
|
+
glyph ? (
|
|
101
|
+
<span data-part="mark" data-tone={tone === 'critical' ? 'critical' : undefined}>
|
|
102
|
+
{typeof glyph === 'string' ? <Glyph d={glyph} /> : glyph({})}
|
|
103
|
+
</span>
|
|
104
|
+
) : undefined
|
|
105
|
+
}
|
|
106
|
+
footer={
|
|
107
|
+
<>
|
|
108
|
+
<Button emphasis="frame" autofocus data-close="" onClick={() => onCancel?.()}>
|
|
109
|
+
{cancel}
|
|
110
|
+
</Button>
|
|
111
|
+
<Button tone={tone} loading={busy.value} onClick={go}>
|
|
112
|
+
{action}
|
|
113
|
+
</Button>
|
|
114
|
+
</>
|
|
115
|
+
}
|
|
116
|
+
>
|
|
117
|
+
{children}
|
|
118
|
+
</Modal>
|
|
119
|
+
)}
|
|
120
|
+
</>
|
|
121
|
+
)
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** Props for TypeToConfirm. */
|
|
125
|
+
export interface TypeToConfirmProps {
|
|
126
|
+
open: State<boolean>
|
|
127
|
+
title: unknown
|
|
128
|
+
description?: unknown
|
|
129
|
+
/** The exact text to type: the project's or key's name. */
|
|
130
|
+
confirmText: string
|
|
131
|
+
/** What goes, listed. */
|
|
132
|
+
items?: string[]
|
|
133
|
+
action: unknown
|
|
134
|
+
glyph?: string | IconComponent
|
|
135
|
+
onConfirm: () => Promise<void> | void
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function confirmActions({
|
|
139
|
+
open,
|
|
140
|
+
ok,
|
|
141
|
+
busy,
|
|
142
|
+
confirm,
|
|
143
|
+
}: {
|
|
144
|
+
open: () => State<boolean>
|
|
145
|
+
ok: { readonly value: boolean }
|
|
146
|
+
busy: State<boolean>
|
|
147
|
+
confirm: () => Promise<void> | void
|
|
148
|
+
}) {
|
|
149
|
+
const go = async () => {
|
|
150
|
+
if (!ok.value || busy.value) return
|
|
151
|
+
busy.value = true
|
|
152
|
+
try {
|
|
153
|
+
await confirm()
|
|
154
|
+
open().value = false
|
|
155
|
+
} catch {
|
|
156
|
+
failed(go)
|
|
157
|
+
} finally {
|
|
158
|
+
busy.value = false
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
const submit = (e: Event) => {
|
|
162
|
+
e.preventDefault()
|
|
163
|
+
void go()
|
|
164
|
+
}
|
|
165
|
+
return { go, submit }
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Type-to-confirm (09 §4.4): an AlertDialog whose field sweeps critical. Deviation from 05: focus goes to the field,
|
|
170
|
+
* not Cancel. The confirm stays disabled until the text matches exactly, and Enter submits only then.
|
|
171
|
+
*/
|
|
172
|
+
export function TypeToConfirm({
|
|
173
|
+
open,
|
|
174
|
+
title,
|
|
175
|
+
description,
|
|
176
|
+
confirmText,
|
|
177
|
+
items,
|
|
178
|
+
action,
|
|
179
|
+
glyph = TrashIcon,
|
|
180
|
+
onConfirm,
|
|
181
|
+
}: TypeToConfirmProps) {
|
|
182
|
+
const armed = latch(untrack(() => open))
|
|
183
|
+
const typed = state('')
|
|
184
|
+
const busy = state(false)
|
|
185
|
+
const ok = derived(() => confirmMatches(typed.value, confirmText))
|
|
186
|
+
watch(
|
|
187
|
+
() => open.value,
|
|
188
|
+
(on) => {
|
|
189
|
+
if (on) typed.value = ''
|
|
190
|
+
},
|
|
191
|
+
)
|
|
192
|
+
const { go, submit } = confirmActions({ open: () => open, ok, busy, confirm: () => onConfirm() })
|
|
193
|
+
return (
|
|
194
|
+
<>
|
|
195
|
+
{armed.value && (
|
|
196
|
+
<Modal
|
|
197
|
+
open={open}
|
|
198
|
+
alert
|
|
199
|
+
size="sm"
|
|
200
|
+
tone="critical"
|
|
201
|
+
title={title}
|
|
202
|
+
description={description}
|
|
203
|
+
mark={
|
|
204
|
+
<span data-part="mark" data-tone="critical">
|
|
205
|
+
{typeof glyph === 'string' ? <Glyph d={glyph} /> : glyph({})}
|
|
206
|
+
</span>
|
|
207
|
+
}
|
|
208
|
+
footer={
|
|
209
|
+
<>
|
|
210
|
+
<Button emphasis="frame" data-close="">
|
|
211
|
+
Cancel
|
|
212
|
+
</Button>
|
|
213
|
+
<Button tone="critical" disabled={!ok.value} loading={busy.value} onClick={go}>
|
|
214
|
+
{action}
|
|
215
|
+
</Button>
|
|
216
|
+
</>
|
|
217
|
+
}
|
|
218
|
+
>
|
|
219
|
+
<form data-scope="confirm" novalidate onSubmit={submit}>
|
|
220
|
+
{items && (
|
|
221
|
+
<ul>
|
|
222
|
+
{items.map((t) => (
|
|
223
|
+
<li key={t}>{t}</li>
|
|
224
|
+
))}
|
|
225
|
+
</ul>
|
|
226
|
+
)}
|
|
227
|
+
<Input
|
|
228
|
+
label={`Type ${confirmText} to confirm`}
|
|
229
|
+
autofocus
|
|
230
|
+
autocomplete="off"
|
|
231
|
+
spellcheck="false"
|
|
232
|
+
value={typed.value}
|
|
233
|
+
onInput={(e) => (typed.value = e.currentTarget.value)}
|
|
234
|
+
/>
|
|
235
|
+
</form>
|
|
236
|
+
</Modal>
|
|
237
|
+
)}
|
|
238
|
+
</>
|
|
239
|
+
)
|
|
240
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { uid } from '@kerf-js/veneer-core'
|
|
2
|
+
import { derived, untrack, watch } from '@kerf-js/core'
|
|
3
|
+
import { Badge } from '../../Badge'
|
|
4
|
+
import { Button, type Tone } from '../../Button'
|
|
5
|
+
import { Alert } from '../../Alert'
|
|
6
|
+
import { toast } from '../../Toast'
|
|
7
|
+
import { afterFlush } from '../atoms'
|
|
8
|
+
import type { IntegrationState, Integration } from '../Integrations'
|
|
9
|
+
|
|
10
|
+
const BADGE: Record<IntegrationState, [string, Tone | undefined, boolean]> = {
|
|
11
|
+
connected: ['Connected', 'positive', true],
|
|
12
|
+
error: ['Needs attention', 'critical', true],
|
|
13
|
+
off: ['Not connected', undefined, false],
|
|
14
|
+
pending: ['Connecting…', 'caution', true],
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function Card({
|
|
18
|
+
item,
|
|
19
|
+
onConnect,
|
|
20
|
+
onConfigure,
|
|
21
|
+
}: {
|
|
22
|
+
item: Integration
|
|
23
|
+
onConnect: () => void
|
|
24
|
+
onConfigure: () => void
|
|
25
|
+
}) {
|
|
26
|
+
let configure: HTMLElement | undefined
|
|
27
|
+
const id = uid('ig')
|
|
28
|
+
const badge = derived(() => BADGE[item.state])
|
|
29
|
+
watch(
|
|
30
|
+
() => item.state,
|
|
31
|
+
(now, was) => {
|
|
32
|
+
if (was !== 'pending' || now !== 'connected') return
|
|
33
|
+
toast.show({ title: `${untrack(() => item.name)} connected`, tone: 'positive' })
|
|
34
|
+
afterFlush(() => configure?.focus())
|
|
35
|
+
},
|
|
36
|
+
)
|
|
37
|
+
return (
|
|
38
|
+
<li data-scope="integration" data-state={item.state}>
|
|
39
|
+
<span data-part="logo" aria-hidden="true">
|
|
40
|
+
{item.name[0]}
|
|
41
|
+
</span>
|
|
42
|
+
<span data-part="info">
|
|
43
|
+
<b id={id}>{item.name}</b>
|
|
44
|
+
<Badge tone={badge.value[1]} dot={badge.value[2]}>
|
|
45
|
+
{badge.value[0]}
|
|
46
|
+
</Badge>
|
|
47
|
+
<span class="muted">{item.state === 'off' ? item.summary : item.detail}</span>
|
|
48
|
+
</span>
|
|
49
|
+
{item.failure && (
|
|
50
|
+
<span data-part="actions">
|
|
51
|
+
<Alert tone="critical" live>
|
|
52
|
+
{item.failure}
|
|
53
|
+
</Alert>
|
|
54
|
+
</span>
|
|
55
|
+
)}
|
|
56
|
+
<span data-part="actions">
|
|
57
|
+
{item.state === 'off' && (
|
|
58
|
+
<Button emphasis="frame" size="sm" aria-describedby={id} onClick={onConnect}>
|
|
59
|
+
Connect
|
|
60
|
+
</Button>
|
|
61
|
+
)}
|
|
62
|
+
{item.state === 'error' && (
|
|
63
|
+
<Button size="sm" tone="critical" aria-describedby={id} onClick={onConnect}>
|
|
64
|
+
Reconnect
|
|
65
|
+
</Button>
|
|
66
|
+
)}
|
|
67
|
+
{item.state === 'connected' && (
|
|
68
|
+
<Button
|
|
69
|
+
ref={(n) => (configure = n)}
|
|
70
|
+
emphasis="ghost"
|
|
71
|
+
tone="neutral"
|
|
72
|
+
size="sm"
|
|
73
|
+
aria-describedby={id}
|
|
74
|
+
onClick={onConfigure}
|
|
75
|
+
>
|
|
76
|
+
Configure
|
|
77
|
+
</Button>
|
|
78
|
+
)}
|
|
79
|
+
</span>
|
|
80
|
+
</li>
|
|
81
|
+
)
|
|
82
|
+
}
|
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
import { httpsEndpoint } from '@kerf-js/veneer-core'
|
|
2
|
+
import { derived, state, type State } from '@kerf-js/core'
|
|
3
|
+
import { Badge } from '../../Badge'
|
|
4
|
+
import { Button } from '../../Button'
|
|
5
|
+
import { Checkbox } from '../../Choice'
|
|
6
|
+
import { Input } from '../../Field'
|
|
7
|
+
import { Modal } from '../../Modal'
|
|
8
|
+
import { Table, type Column } from '../../Table'
|
|
9
|
+
import { toast } from '../../Toast'
|
|
10
|
+
import { SecretReveal, useReveal } from '../Secret'
|
|
11
|
+
import { guarded, latch, read } from '../atoms'
|
|
12
|
+
import type { Webhook, WebhooksProps } from '../Integrations'
|
|
13
|
+
import '../../styles'
|
|
14
|
+
import '@kerf-js/veneer-core/styles/flows/tokens.css'
|
|
15
|
+
import '@kerf-js/veneer-core/styles/flows/base.css'
|
|
16
|
+
import '@kerf-js/veneer-core/styles/rich/helpers.css'
|
|
17
|
+
import '@kerf-js/veneer-core/styles/layout/tokens.css'
|
|
18
|
+
import '@kerf-js/veneer-core/styles/layout/row.css'
|
|
19
|
+
import '@kerf-js/veneer-core/styles/layout/stack.css'
|
|
20
|
+
import '@kerf-js/veneer-core/styles/flows/integrations.css'
|
|
21
|
+
import '@kerf-js/veneer-core/styles/flows/integration.css'
|
|
22
|
+
import '@kerf-js/veneer-core/styles/flows/choice.css'
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* A URL that breaks where a reader would: after a slash or a query's `&` and `=`, before a dot, `?` or `#`, never inside a
|
|
26
|
+
* word, nor after a hyphen in a host name. Each piece is an inline block, so lines break only between pieces (`<wbr>`
|
|
27
|
+
* says so to anything reading the markup), and a piece longer than the line still breaks inside as a last resort.
|
|
28
|
+
*/
|
|
29
|
+
export const urlBreaks = (url: string): string[] =>
|
|
30
|
+
url.split(/(?<=[/&=])(?!\/)|(?=[.?#])/).filter(Boolean)
|
|
31
|
+
const Url = ({ href }: { href: string }) => (
|
|
32
|
+
<code data-part="url" style="white-space:normal;word-break:normal;overflow-wrap:break-word">
|
|
33
|
+
{urlBreaks(href).map((part, i) => [
|
|
34
|
+
i ? <wbr /> : null,
|
|
35
|
+
<span style="display:inline-block;max-inline-size:100%">{part}</span>,
|
|
36
|
+
])}
|
|
37
|
+
</code>
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
function webhookColumns(test: (h: Webhook) => Promise<void>): Column<Webhook>[] {
|
|
41
|
+
return [
|
|
42
|
+
{
|
|
43
|
+
id: 'url',
|
|
44
|
+
header: 'Endpoint',
|
|
45
|
+
rowHeader: true,
|
|
46
|
+
card: 'title',
|
|
47
|
+
cell: (h) => <Url href={h.url} />,
|
|
48
|
+
},
|
|
49
|
+
{ id: 'events', header: 'Events', value: (h) => h.events.join(', ') },
|
|
50
|
+
{ id: 'lastDelivery', header: 'Last delivery', value: (h) => h.lastDelivery ?? 'None yet' },
|
|
51
|
+
{
|
|
52
|
+
id: 'healthy',
|
|
53
|
+
header: 'Health',
|
|
54
|
+
card: 'badge',
|
|
55
|
+
value: (h) => (h.healthy ? 'Healthy' : 'Failing'),
|
|
56
|
+
cell: (h) => (
|
|
57
|
+
<Badge tone={h.healthy ? 'positive' : 'critical'} dot>
|
|
58
|
+
{h.healthy ? 'Healthy' : 'Failing'}
|
|
59
|
+
</Badge>
|
|
60
|
+
),
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
id: 'test',
|
|
64
|
+
header: 'Actions',
|
|
65
|
+
value: () => '',
|
|
66
|
+
cell: (h) => (
|
|
67
|
+
<Button emphasis="link" aria-label={`Send test to ${h.url}`} onClick={() => test(h)}>
|
|
68
|
+
Send test
|
|
69
|
+
</Button>
|
|
70
|
+
),
|
|
71
|
+
},
|
|
72
|
+
]
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function webhookForm({
|
|
76
|
+
events,
|
|
77
|
+
url,
|
|
78
|
+
picked,
|
|
79
|
+
urlError,
|
|
80
|
+
eventError,
|
|
81
|
+
tried,
|
|
82
|
+
check,
|
|
83
|
+
save,
|
|
84
|
+
}: {
|
|
85
|
+
events: () => string[]
|
|
86
|
+
url: State<string>
|
|
87
|
+
picked: State<string[]>
|
|
88
|
+
urlError: State<string>
|
|
89
|
+
eventError: State<string>
|
|
90
|
+
tried: State<boolean>
|
|
91
|
+
check: () => void
|
|
92
|
+
save: () => Promise<void>
|
|
93
|
+
}) {
|
|
94
|
+
const live = {
|
|
95
|
+
get events() {
|
|
96
|
+
return events()
|
|
97
|
+
},
|
|
98
|
+
}
|
|
99
|
+
return (
|
|
100
|
+
<form
|
|
101
|
+
data-scope="stack"
|
|
102
|
+
style="padding-block-start:var(--veneer-space-related)"
|
|
103
|
+
novalidate
|
|
104
|
+
onSubmit={(e: Event) => {
|
|
105
|
+
e.preventDefault()
|
|
106
|
+
void save()
|
|
107
|
+
}}
|
|
108
|
+
>
|
|
109
|
+
<Input
|
|
110
|
+
label="Endpoint URL"
|
|
111
|
+
type="url"
|
|
112
|
+
inputmode="url"
|
|
113
|
+
placeholder="https://"
|
|
114
|
+
autofocus
|
|
115
|
+
hint="Must be https."
|
|
116
|
+
value={url.value}
|
|
117
|
+
error={urlError.value}
|
|
118
|
+
onInput={(e) => {
|
|
119
|
+
url.value = e.currentTarget.value
|
|
120
|
+
if (tried.value) check()
|
|
121
|
+
}}
|
|
122
|
+
/>
|
|
123
|
+
<fieldset data-scope="choice">
|
|
124
|
+
<legend>Events</legend>
|
|
125
|
+
{live.events.map((v) => (
|
|
126
|
+
<Checkbox
|
|
127
|
+
key={v}
|
|
128
|
+
checked={picked.value.includes(v)}
|
|
129
|
+
error={v === live.events[0] && eventError.value ? eventError.value : undefined}
|
|
130
|
+
onChange={(e: Event) => {
|
|
131
|
+
picked.value = (e.currentTarget as HTMLInputElement).checked
|
|
132
|
+
? [...picked.value, v]
|
|
133
|
+
: picked.value.filter((x) => x !== v)
|
|
134
|
+
eventError.value = ''
|
|
135
|
+
}}
|
|
136
|
+
>
|
|
137
|
+
<code>{v}</code>
|
|
138
|
+
</Checkbox>
|
|
139
|
+
))}
|
|
140
|
+
</fieldset>
|
|
141
|
+
</form>
|
|
142
|
+
)
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function webhookTester(onTest: WebhooksProps['onTest']) {
|
|
146
|
+
const test = async (h: Webhook) => {
|
|
147
|
+
try {
|
|
148
|
+
const r = await onTest(h)
|
|
149
|
+
toast.show({
|
|
150
|
+
title: `Test delivered: ${r.status}`,
|
|
151
|
+
description: `${h.url} answered in ${r.ms} ms.`,
|
|
152
|
+
tone: r.status < 300 ? 'positive' : 'critical',
|
|
153
|
+
})
|
|
154
|
+
} catch {
|
|
155
|
+
toast.show({
|
|
156
|
+
title: 'The test didn’t send',
|
|
157
|
+
tone: 'critical',
|
|
158
|
+
action: { label: 'Retry', onClick: () => test(h) },
|
|
159
|
+
})
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return test
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function webhookFooter({
|
|
166
|
+
secret,
|
|
167
|
+
seen,
|
|
168
|
+
dialog,
|
|
169
|
+
busy,
|
|
170
|
+
save,
|
|
171
|
+
}: {
|
|
172
|
+
secret: State<string>
|
|
173
|
+
seen: State<boolean>
|
|
174
|
+
dialog: State<boolean>
|
|
175
|
+
busy: State<boolean>
|
|
176
|
+
save: () => Promise<void>
|
|
177
|
+
}) {
|
|
178
|
+
return derived(() =>
|
|
179
|
+
secret.value ? (
|
|
180
|
+
<Button disabled={!seen.value} onClick={() => (dialog.value = false)}>
|
|
181
|
+
Done
|
|
182
|
+
</Button>
|
|
183
|
+
) : (
|
|
184
|
+
<>
|
|
185
|
+
<Button emphasis="frame" data-close="">
|
|
186
|
+
Cancel
|
|
187
|
+
</Button>
|
|
188
|
+
<Button loading={busy.value} onClick={save}>
|
|
189
|
+
Add endpoint
|
|
190
|
+
</Button>
|
|
191
|
+
</>
|
|
192
|
+
),
|
|
193
|
+
)
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function webhookSaver({
|
|
197
|
+
onAdd,
|
|
198
|
+
busy,
|
|
199
|
+
tried,
|
|
200
|
+
check,
|
|
201
|
+
eventError,
|
|
202
|
+
picked,
|
|
203
|
+
urlError,
|
|
204
|
+
secret,
|
|
205
|
+
}: {
|
|
206
|
+
onAdd: () => Promise<string>
|
|
207
|
+
busy: State<boolean>
|
|
208
|
+
tried: State<boolean>
|
|
209
|
+
check: () => void
|
|
210
|
+
eventError: State<string>
|
|
211
|
+
picked: State<string[]>
|
|
212
|
+
urlError: State<string>
|
|
213
|
+
secret: State<string>
|
|
214
|
+
}) {
|
|
215
|
+
const save = async () => {
|
|
216
|
+
if (busy.value) return
|
|
217
|
+
tried.value = true
|
|
218
|
+
check()
|
|
219
|
+
eventError.value = picked.value.length ? '' : 'Pick at least one event.'
|
|
220
|
+
if (urlError.value || eventError.value) return
|
|
221
|
+
busy.value = true
|
|
222
|
+
try {
|
|
223
|
+
secret.value = await onAdd()
|
|
224
|
+
} catch {
|
|
225
|
+
toast.show({
|
|
226
|
+
title: 'The endpoint wasn’t added',
|
|
227
|
+
tone: 'critical',
|
|
228
|
+
action: { label: 'Retry', onClick: save },
|
|
229
|
+
})
|
|
230
|
+
} finally {
|
|
231
|
+
busy.value = false
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
return save
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
function validateUrl(url: State<string>, urlError: State<string>) {
|
|
238
|
+
urlError.value = !url.value.trim()
|
|
239
|
+
? 'Enter the URL we should call.'
|
|
240
|
+
: httpsEndpoint(url.value)
|
|
241
|
+
? ''
|
|
242
|
+
: 'Use a full https:// URL.'
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
function webhookFields() {
|
|
246
|
+
const url = state('')
|
|
247
|
+
const picked = state<string[]>([])
|
|
248
|
+
const urlError = state('')
|
|
249
|
+
const eventError = state('')
|
|
250
|
+
const tried = state(false)
|
|
251
|
+
const reset = (events: string[]) => {
|
|
252
|
+
url.value = ''
|
|
253
|
+
picked.value = events.slice(0, 2)
|
|
254
|
+
urlError.value = ''
|
|
255
|
+
eventError.value = ''
|
|
256
|
+
tried.value = false
|
|
257
|
+
}
|
|
258
|
+
return { url, picked, urlError, eventError, tried, reset }
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/** Webhooks (09 §4.6): a DataTable of endpoints. Send test reports the code and time; a new signing secret is shown once. */
|
|
262
|
+
export function Webhooks(props: WebhooksProps) {
|
|
263
|
+
const adding = state(false)
|
|
264
|
+
const armed = latch(adding)
|
|
265
|
+
const { secret, seen } = useReveal(adding)
|
|
266
|
+
const dialog = guarded(adding, () => !secret.value || seen.value)
|
|
267
|
+
const { url, picked, urlError, eventError, tried, reset } = webhookFields()
|
|
268
|
+
const busy = state(false)
|
|
269
|
+
const list = derived(() => read(props.hooks))
|
|
270
|
+
const check = () => validateUrl(url, urlError)
|
|
271
|
+
const test = webhookTester((hook) => props.onTest(hook))
|
|
272
|
+
const save = webhookSaver({
|
|
273
|
+
onAdd: () => props.onAdd(url.value.trim(), picked.value),
|
|
274
|
+
busy,
|
|
275
|
+
tried,
|
|
276
|
+
check,
|
|
277
|
+
eventError,
|
|
278
|
+
picked,
|
|
279
|
+
urlError,
|
|
280
|
+
secret,
|
|
281
|
+
})
|
|
282
|
+
const open = () => {
|
|
283
|
+
reset(props.events)
|
|
284
|
+
adding.value = true
|
|
285
|
+
}
|
|
286
|
+
const columns = webhookColumns(test)
|
|
287
|
+
const tools = derived(() => (
|
|
288
|
+
<Button emphasis="frame" onClick={open}>
|
|
289
|
+
Add endpoint
|
|
290
|
+
</Button>
|
|
291
|
+
)) // one build: Table reads the prop twice
|
|
292
|
+
const footer = webhookFooter({ secret, seen, dialog, busy, save })
|
|
293
|
+
return (
|
|
294
|
+
<div data-scope="stack">
|
|
295
|
+
<Table
|
|
296
|
+
caption="Webhook endpoints"
|
|
297
|
+
captionHidden
|
|
298
|
+
rows={list}
|
|
299
|
+
columns={columns}
|
|
300
|
+
picker={false}
|
|
301
|
+
heading={3}
|
|
302
|
+
actions={tools.value}
|
|
303
|
+
empty={{ title: 'No webhooks yet', text: 'Add an endpoint to get events.' }}
|
|
304
|
+
/>
|
|
305
|
+
{armed.value && (
|
|
306
|
+
<Modal
|
|
307
|
+
open={dialog}
|
|
308
|
+
alert={!!secret.value}
|
|
309
|
+
size="sm"
|
|
310
|
+
title={secret.value ? 'Copy your signing secret' : 'Add a webhook endpoint'}
|
|
311
|
+
description={
|
|
312
|
+
secret.value
|
|
313
|
+
? 'You won’t see it again. Use it to verify our signature.'
|
|
314
|
+
: 'We POST JSON to this URL for each event you pick.'
|
|
315
|
+
}
|
|
316
|
+
footer={<>{footer.value}</>}
|
|
317
|
+
>
|
|
318
|
+
{secret.value ? (
|
|
319
|
+
<SecretReveal
|
|
320
|
+
label="Signing secret"
|
|
321
|
+
secret={secret.value}
|
|
322
|
+
done={seen}
|
|
323
|
+
ack="I’ve saved this secret somewhere safe"
|
|
324
|
+
/>
|
|
325
|
+
) : (
|
|
326
|
+
webhookForm({
|
|
327
|
+
events: () => props.events,
|
|
328
|
+
url,
|
|
329
|
+
picked,
|
|
330
|
+
urlError,
|
|
331
|
+
eventError,
|
|
332
|
+
tried,
|
|
333
|
+
check,
|
|
334
|
+
save,
|
|
335
|
+
})
|
|
336
|
+
)}
|
|
337
|
+
</Modal>
|
|
338
|
+
)}
|
|
339
|
+
</div>
|
|
340
|
+
)
|
|
341
|
+
}
|