@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,60 @@
|
|
|
1
|
+
// Public checkout data and callbacks.
|
|
2
|
+
import type { Address, CartLine, CheckoutError } from '@kerf-js/veneer-core'
|
|
3
|
+
import type { State } from '@kerf-js/core'
|
|
4
|
+
import type { AddressProvider } from '../PlaceField'
|
|
5
|
+
import type { OrderStage } from './Order'
|
|
6
|
+
|
|
7
|
+
/** A way to ship an order. */
|
|
8
|
+
export type ShippingOption = {
|
|
9
|
+
id: string
|
|
10
|
+
name: string
|
|
11
|
+
/** "Arrives Thu 6 Nov" */ eta: string
|
|
12
|
+
price: number
|
|
13
|
+
}
|
|
14
|
+
/** A valid coupon and what it takes off. */
|
|
15
|
+
export type Coupon = { code: string; percentOff: number }
|
|
16
|
+
/** Where a checkout stands. */
|
|
17
|
+
export type CheckoutStep = 'cart' | 'address' | 'shipping' | 'payment' | 'review' | 'done'
|
|
18
|
+
/** Everything the buyer entered, handed over to place the order. */
|
|
19
|
+
export type OrderDraft = {
|
|
20
|
+
lines: CartLine[]
|
|
21
|
+
name: string
|
|
22
|
+
email: string
|
|
23
|
+
phone: string
|
|
24
|
+
address: Address
|
|
25
|
+
billing: Address
|
|
26
|
+
shipping: string
|
|
27
|
+
coupon?: string | undefined
|
|
28
|
+
total: number
|
|
29
|
+
idempotencyKey: string
|
|
30
|
+
}
|
|
31
|
+
/** What placing an order came back with: the order, or why not. */
|
|
32
|
+
export type PlaceOrderResult =
|
|
33
|
+
| { order: { id: string; stage?: OrderStage | undefined } }
|
|
34
|
+
| { error: CheckoutError }
|
|
35
|
+
|
|
36
|
+
/** Props for Checkout. */
|
|
37
|
+
export interface CheckoutProps {
|
|
38
|
+
cart: State<CartLine[]>
|
|
39
|
+
shipping: ShippingOption[]
|
|
40
|
+
countries?: string[] | undefined
|
|
41
|
+
defaultCountry?: string
|
|
42
|
+
addressProvider?: AddressProvider
|
|
43
|
+
taxRate?: number
|
|
44
|
+
/** The ISO 4217 code prices are shown in, such as `EUR`. */
|
|
45
|
+
currency?: string
|
|
46
|
+
locale?: string
|
|
47
|
+
/** The Payment step's body: a PayFrame, in a provider's slot. Veneer never renders card fields. */
|
|
48
|
+
payment: unknown
|
|
49
|
+
/** The saved wallet's frame button, above the divider. */
|
|
50
|
+
wallet?: { label: string; onClick: () => void }
|
|
51
|
+
/** Checks a code; resolve undefined when it isn't valid. */
|
|
52
|
+
coupon?: (code: string) => Promise<Coupon | undefined> | Coupon | undefined
|
|
53
|
+
/** The client's key for this attempt. Without one a key is made; a retry after a timeout resends it. */
|
|
54
|
+
idempotencyKey?: string | undefined
|
|
55
|
+
/** Throw on a transport failure: values stay, a Toast offers Retry with the same key. */
|
|
56
|
+
onPlaceOrder: (order: OrderDraft) => Promise<PlaceOrderResult>
|
|
57
|
+
onStepChange?: ((step: CheckoutStep) => void) | undefined
|
|
58
|
+
onContinueShopping?: () => void
|
|
59
|
+
signInHref?: string
|
|
60
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// Render checkout steps in their original order.
|
|
2
|
+
import { LeftIcon } from '@kerf-js/veneer-icons'
|
|
3
|
+
import { Button } from '../Button'
|
|
4
|
+
import { StepBar } from './StepBar'
|
|
5
|
+
import { STEPS } from './Checkout-steps'
|
|
6
|
+
import type { CheckoutStep } from './Checkout-types'
|
|
7
|
+
import type { checkoutModel } from './Checkout-model'
|
|
8
|
+
import { checkoutCart } from './Checkout-cart'
|
|
9
|
+
import { checkoutAddress } from './Checkout-address'
|
|
10
|
+
import { checkoutShipping } from './Checkout-shipping'
|
|
11
|
+
import { checkoutPayment } from './Checkout-payment-view'
|
|
12
|
+
import { checkoutReview } from './Checkout-review'
|
|
13
|
+
import { checkoutDone } from './Checkout-done'
|
|
14
|
+
import { checkoutSummary } from './Checkout-summary'
|
|
15
|
+
|
|
16
|
+
export type CheckoutModel = ReturnType<typeof checkoutModel>
|
|
17
|
+
export type CheckoutNav = (props: { back: CheckoutStep; children: unknown }) => unknown
|
|
18
|
+
|
|
19
|
+
/** Render the checkout without adding a component owner. */
|
|
20
|
+
export function checkoutView(model: CheckoutModel) {
|
|
21
|
+
const { step, dir, refs } = model.s
|
|
22
|
+
const { at, nav } = model
|
|
23
|
+
const Nav = ({ back, children }: { back: CheckoutStep; children: unknown }) => (
|
|
24
|
+
<div data-part="nav">
|
|
25
|
+
<Button emphasis="ghost" tone="neutral" icon={LeftIcon} onClick={() => nav.prev(back)}>
|
|
26
|
+
Back
|
|
27
|
+
</Button>
|
|
28
|
+
{children}
|
|
29
|
+
</div>
|
|
30
|
+
)
|
|
31
|
+
return (
|
|
32
|
+
<div ref={(n) => (refs.root = n)} data-scope="checkout">
|
|
33
|
+
<div data-part="layout">
|
|
34
|
+
<div data-scope="stack">
|
|
35
|
+
{step.value !== 'done' && (
|
|
36
|
+
<StepBar label="Checkout steps" steps={STEPS} current={at.value} />
|
|
37
|
+
)}
|
|
38
|
+
<div data-scope="flow" data-dir={dir.value}>
|
|
39
|
+
{checkoutCart(model)}
|
|
40
|
+
{checkoutAddress(model, Nav)}
|
|
41
|
+
{checkoutShipping(model, Nav)}
|
|
42
|
+
{checkoutPayment(model, Nav)}
|
|
43
|
+
{checkoutReview(model, Nav)}
|
|
44
|
+
{checkoutDone(model)}
|
|
45
|
+
</div>
|
|
46
|
+
</div>
|
|
47
|
+
{checkoutSummary(model)}
|
|
48
|
+
</div>
|
|
49
|
+
</div>
|
|
50
|
+
)
|
|
51
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { CheckoutProps } from './Checkout-types'
|
|
2
|
+
import { checkoutModel } from './Checkout-model'
|
|
3
|
+
import { checkoutView } from './Checkout-view'
|
|
4
|
+
import '../styles'
|
|
5
|
+
import '@kerf-js/veneer-core/styles/flows/tokens.css'
|
|
6
|
+
import '@kerf-js/veneer-core/styles/flows/base.css'
|
|
7
|
+
import '@kerf-js/veneer-core/styles/rich/helpers.css'
|
|
8
|
+
import '@kerf-js/veneer-core/styles/layout/tokens.css'
|
|
9
|
+
import '@kerf-js/veneer-core/styles/layout/row.css'
|
|
10
|
+
import '@kerf-js/veneer-core/styles/layout/stack.css'
|
|
11
|
+
import '@kerf-js/veneer-core/styles/flows/flow.css'
|
|
12
|
+
import '@kerf-js/veneer-core/styles/flows/checkout.css'
|
|
13
|
+
import '@kerf-js/veneer-core/styles/flows/choice.css'
|
|
14
|
+
import '@kerf-js/veneer-core/styles/flows/plan-card.css'
|
|
15
|
+
import '@kerf-js/veneer-core/styles/flows/line-item.css'
|
|
16
|
+
import '@kerf-js/veneer-core/styles/flows/lines.css'
|
|
17
|
+
import '@kerf-js/veneer-core/styles/flows/auth.css' // the "or with a card" divider
|
|
18
|
+
|
|
19
|
+
export type {
|
|
20
|
+
ShippingOption,
|
|
21
|
+
Coupon,
|
|
22
|
+
CheckoutStep,
|
|
23
|
+
OrderDraft,
|
|
24
|
+
PlaceOrderResult,
|
|
25
|
+
CheckoutProps,
|
|
26
|
+
} from './Checkout-types'
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Checkout (09 §6.2): Cart → Address → Shipping → Payment → Review → Confirmation, guest first. Each step's title takes
|
|
30
|
+
* focus and the step is announced; back goes to a step without losing a value. Place order is idempotent by a client
|
|
31
|
+
* key; CARD_DECLINED returns to Payment, OUT_OF_STOCK to Cart with the line marked, PRICE_CHANGED stays on Review.
|
|
32
|
+
*/
|
|
33
|
+
export function Checkout({
|
|
34
|
+
cart,
|
|
35
|
+
shipping,
|
|
36
|
+
countries,
|
|
37
|
+
defaultCountry = 'US',
|
|
38
|
+
addressProvider,
|
|
39
|
+
taxRate = 0,
|
|
40
|
+
currency,
|
|
41
|
+
locale,
|
|
42
|
+
payment,
|
|
43
|
+
wallet,
|
|
44
|
+
coupon,
|
|
45
|
+
idempotencyKey,
|
|
46
|
+
onPlaceOrder,
|
|
47
|
+
onStepChange,
|
|
48
|
+
onContinueShopping,
|
|
49
|
+
signInHref,
|
|
50
|
+
}: CheckoutProps) {
|
|
51
|
+
return checkoutView(
|
|
52
|
+
checkoutModel({
|
|
53
|
+
cart: () => cart,
|
|
54
|
+
shipping: () => shipping,
|
|
55
|
+
countries: () => countries,
|
|
56
|
+
defaultCountry: () => defaultCountry,
|
|
57
|
+
addressProvider: () => addressProvider,
|
|
58
|
+
taxRate: () => taxRate,
|
|
59
|
+
currency: () => currency,
|
|
60
|
+
locale: () => locale,
|
|
61
|
+
payment: () => payment,
|
|
62
|
+
wallet: () => wallet,
|
|
63
|
+
coupon: () => coupon,
|
|
64
|
+
applyCoupon: (code) => coupon?.(code),
|
|
65
|
+
idempotencyKey: () => idempotencyKey,
|
|
66
|
+
onPlaceOrder: (order) => onPlaceOrder(order()),
|
|
67
|
+
onStepChange: (step) => onStepChange?.(step),
|
|
68
|
+
onContinueShopping: () => onContinueShopping,
|
|
69
|
+
signInHref: () => signInHref,
|
|
70
|
+
}),
|
|
71
|
+
)
|
|
72
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
// CSV loading and import actions.
|
|
2
|
+
import {
|
|
3
|
+
autoMap,
|
|
4
|
+
importRecords,
|
|
5
|
+
isCsvFile,
|
|
6
|
+
parseCsv,
|
|
7
|
+
SKIP_COLUMN,
|
|
8
|
+
type CsvTable,
|
|
9
|
+
type ImportIssue,
|
|
10
|
+
} from '@kerf-js/veneer-core'
|
|
11
|
+
import { derived, type State } from '@kerf-js/core'
|
|
12
|
+
import { toast } from '../Toast'
|
|
13
|
+
import type { CsvImportProps } from './CsvImport'
|
|
14
|
+
|
|
15
|
+
export type Stage = 'upload' | 'map' | 'review' | 'done'
|
|
16
|
+
|
|
17
|
+
const PREVIEW_ROWS = 50
|
|
18
|
+
|
|
19
|
+
export function csvPreview({
|
|
20
|
+
props,
|
|
21
|
+
table,
|
|
22
|
+
map,
|
|
23
|
+
issues,
|
|
24
|
+
}: {
|
|
25
|
+
props: CsvImportProps
|
|
26
|
+
table: State<CsvTable>
|
|
27
|
+
map: State<string[]>
|
|
28
|
+
issues: { readonly value: ImportIssue[] }
|
|
29
|
+
}) {
|
|
30
|
+
const cellIssue = (row: number, target: string) =>
|
|
31
|
+
issues.value.find((x) => x.row === row && x.path === target)
|
|
32
|
+
const preview = derived(() =>
|
|
33
|
+
table.value.rows.slice(0, PREVIEW_ROWS).map((cells, row) => ({ row, cells })),
|
|
34
|
+
)
|
|
35
|
+
const columns = derived(() =>
|
|
36
|
+
table.value.headers.map((h, col) => ({ h, col, target: map.value[col] })),
|
|
37
|
+
)
|
|
38
|
+
const kept = derived(() => columns.value.filter((c) => c.target !== SKIP_COLUMN))
|
|
39
|
+
const titleOf = (target: string) => props.targets.find((t) => t.id === target)?.label ?? target
|
|
40
|
+
|
|
41
|
+
return { cellIssue, preview, columns, kept, titleOf }
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function csvLoading({
|
|
45
|
+
props,
|
|
46
|
+
table,
|
|
47
|
+
map,
|
|
48
|
+
file,
|
|
49
|
+
issue,
|
|
50
|
+
go,
|
|
51
|
+
}: {
|
|
52
|
+
props: CsvImportProps
|
|
53
|
+
table: State<CsvTable>
|
|
54
|
+
map: State<string[]>
|
|
55
|
+
file: State<string>
|
|
56
|
+
issue: State<string>
|
|
57
|
+
go: (next: Stage) => void
|
|
58
|
+
}) {
|
|
59
|
+
const load = (name: string, text: string) => {
|
|
60
|
+
const t = parseCsv(text)
|
|
61
|
+
if (t.problem) {
|
|
62
|
+
issue.value = t.problem
|
|
63
|
+
return
|
|
64
|
+
}
|
|
65
|
+
if (t.rows.length > (props.rowLimit === undefined ? 5000 : props.rowLimit)) {
|
|
66
|
+
issue.value = `This file has ${t.rows.length.toLocaleString('en-US')} rows. The limit is ${(props.rowLimit === undefined ? 5000 : props.rowLimit).toLocaleString('en-US')}.`
|
|
67
|
+
return
|
|
68
|
+
}
|
|
69
|
+
issue.value = ''
|
|
70
|
+
file.value = name
|
|
71
|
+
table.value = t
|
|
72
|
+
map.value = autoMap(t.headers, props.targets)
|
|
73
|
+
go('map')
|
|
74
|
+
}
|
|
75
|
+
const take = async (f?: File | null) => {
|
|
76
|
+
if (!f) return
|
|
77
|
+
if (!isCsvFile(f.name, f.type))
|
|
78
|
+
return void toast.show({
|
|
79
|
+
title: 'That isn’t a CSV file',
|
|
80
|
+
description: `${f.name} wasn’t uploaded. Export it as .csv and try again.`,
|
|
81
|
+
tone: 'critical',
|
|
82
|
+
})
|
|
83
|
+
load(f.name, await f.text())
|
|
84
|
+
}
|
|
85
|
+
return { load, take }
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export function csvRun({
|
|
89
|
+
props,
|
|
90
|
+
table,
|
|
91
|
+
map,
|
|
92
|
+
issues,
|
|
93
|
+
percent,
|
|
94
|
+
finished,
|
|
95
|
+
count,
|
|
96
|
+
go,
|
|
97
|
+
}: {
|
|
98
|
+
props: CsvImportProps
|
|
99
|
+
table: State<CsvTable>
|
|
100
|
+
map: State<string[]>
|
|
101
|
+
issues: { readonly value: ImportIssue[] }
|
|
102
|
+
percent: State<number>
|
|
103
|
+
finished: State<boolean>
|
|
104
|
+
count: (n: number) => string
|
|
105
|
+
go: (next: Stage) => void
|
|
106
|
+
}) {
|
|
107
|
+
const run = async () => {
|
|
108
|
+
const records = importRecords(table.value.rows, map.value, issues.value)
|
|
109
|
+
go('done')
|
|
110
|
+
percent.value = 0
|
|
111
|
+
finished.value = false
|
|
112
|
+
try {
|
|
113
|
+
await props.onImport(records, (p) => (percent.value = p))
|
|
114
|
+
percent.value = 100
|
|
115
|
+
finished.value = true
|
|
116
|
+
toast.show({
|
|
117
|
+
title: `${count(records.length)} imported`,
|
|
118
|
+
description: 'They’ll get an invite email.',
|
|
119
|
+
tone: 'positive',
|
|
120
|
+
})
|
|
121
|
+
} catch {
|
|
122
|
+
toast.show({
|
|
123
|
+
title: 'The import stopped',
|
|
124
|
+
description: 'Nothing was lost. Try again.',
|
|
125
|
+
tone: 'critical',
|
|
126
|
+
action: { label: 'Retry', onClick: run },
|
|
127
|
+
})
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return run
|
|
131
|
+
}
|
|
@@ -0,0 +1,379 @@
|
|
|
1
|
+
import { AlertCircleIcon, UploadIcon } from '@kerf-js/veneer-icons'
|
|
2
|
+
import {
|
|
3
|
+
announce,
|
|
4
|
+
badRows,
|
|
5
|
+
checkImport,
|
|
6
|
+
missingTargets,
|
|
7
|
+
plural,
|
|
8
|
+
SKIP_COLUMN,
|
|
9
|
+
uid,
|
|
10
|
+
type CsvTable,
|
|
11
|
+
type ImportIssue,
|
|
12
|
+
type ImportTarget,
|
|
13
|
+
} from '@kerf-js/veneer-core'
|
|
14
|
+
import { derived, state, untrack } from '@kerf-js/core'
|
|
15
|
+
import { Alert } from '../Alert'
|
|
16
|
+
import { Button } from '../Button'
|
|
17
|
+
import { Progress } from '../Progress'
|
|
18
|
+
import { PlainTable } from './PlainTable'
|
|
19
|
+
import { csvLoading, csvPreview, csvRun, type Stage } from './CsvImport-actions'
|
|
20
|
+
import { StepBar } from './StepBar'
|
|
21
|
+
import { InlineSelect, Sweep, afterFlush } from './atoms'
|
|
22
|
+
import '../styles'
|
|
23
|
+
import '@kerf-js/veneer-core/styles/flows/tokens.css'
|
|
24
|
+
import '@kerf-js/veneer-core/styles/flows/base.css'
|
|
25
|
+
import '@kerf-js/veneer-core/styles/rich/helpers.css'
|
|
26
|
+
import '@kerf-js/veneer-core/styles/layout/tokens.css'
|
|
27
|
+
import '@kerf-js/veneer-core/styles/layout/row.css'
|
|
28
|
+
import '@kerf-js/veneer-core/styles/layout/stack.css'
|
|
29
|
+
import '@kerf-js/veneer-core/styles/inputs/field.css'
|
|
30
|
+
import '@kerf-js/veneer-core/styles/inputs/file.css'
|
|
31
|
+
import '@kerf-js/veneer-core/styles/flows/import-map.css'
|
|
32
|
+
import '@kerf-js/veneer-core/styles/flows/import-preview.css'
|
|
33
|
+
|
|
34
|
+
/** Props for CsvImport. */
|
|
35
|
+
export interface CsvImportProps {
|
|
36
|
+
targets: ImportTarget[]
|
|
37
|
+
noun?: [one: string, many: string]
|
|
38
|
+
rowLimit?: number
|
|
39
|
+
/** "Use the sample": a name and its text. */
|
|
40
|
+
sample?: { name: string; text: string }
|
|
41
|
+
/** Runs the import; report progress from 0 to 100. The job is the server's: leaving the page is fine. */
|
|
42
|
+
onImport: (
|
|
43
|
+
records: Record<string, string>[],
|
|
44
|
+
progress: (percent: number) => void,
|
|
45
|
+
) => Promise<void>
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const STEPS = [
|
|
49
|
+
{ id: 'upload', title: 'Upload' },
|
|
50
|
+
{ id: 'map', title: 'Map' },
|
|
51
|
+
{ id: 'review', title: 'Review' },
|
|
52
|
+
{ id: 'done', title: 'Import' },
|
|
53
|
+
]
|
|
54
|
+
const SAY: Record<Stage, string> = {
|
|
55
|
+
upload: 'upload',
|
|
56
|
+
map: 'map columns',
|
|
57
|
+
review: 'review',
|
|
58
|
+
done: 'importing',
|
|
59
|
+
}
|
|
60
|
+
const ORDER: Stage[] = ['upload', 'map', 'review', 'done']
|
|
61
|
+
|
|
62
|
+
type CsvRefs = { headingElement?: HTMLElement | undefined }
|
|
63
|
+
|
|
64
|
+
function announceCsvStep(refs: CsvRefs, s: Stage) {
|
|
65
|
+
if (refs.headingElement)
|
|
66
|
+
announce(
|
|
67
|
+
refs.headingElement.ownerDocument,
|
|
68
|
+
`Import, step ${ORDER.indexOf(s) + 1} of 4, ${SAY[s]}`,
|
|
69
|
+
)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function csvModel(props: CsvImportProps) {
|
|
73
|
+
const refs: CsvRefs = {}
|
|
74
|
+
const id = uid('csv')
|
|
75
|
+
const stage = state<Stage>('upload')
|
|
76
|
+
const file = state('')
|
|
77
|
+
const table = state<CsvTable>({ headers: [], rows: [] })
|
|
78
|
+
const map = state<string[]>([])
|
|
79
|
+
const percent = state(0)
|
|
80
|
+
const finished = state(false)
|
|
81
|
+
const dragging = state(false)
|
|
82
|
+
const issue = state('')
|
|
83
|
+
|
|
84
|
+
const at = derived(() => ORDER.indexOf(stage.value))
|
|
85
|
+
const options = derived(() => [
|
|
86
|
+
...props.targets.map((t) => ({ value: t.id, label: t.label })),
|
|
87
|
+
{ value: SKIP_COLUMN, label: 'Don’t import' },
|
|
88
|
+
])
|
|
89
|
+
const missing = derived(() => missingTargets(map.value, props.targets))
|
|
90
|
+
const issues = derived<ImportIssue[]>(() =>
|
|
91
|
+
checkImport(table.value.rows, map.value, props.targets),
|
|
92
|
+
)
|
|
93
|
+
const bad = derived(() => badRows(issues.value))
|
|
94
|
+
const good = derived(() => (missing.value.length ? 0 : table.value.rows.length - bad.value))
|
|
95
|
+
const count = (n: number) =>
|
|
96
|
+
plural(
|
|
97
|
+
n,
|
|
98
|
+
(props.noun === undefined ? (['person', 'people'] as const) : props.noun)[0],
|
|
99
|
+
(props.noun === undefined ? (['person', 'people'] as const) : props.noun)[1],
|
|
100
|
+
)
|
|
101
|
+
const go = (next: Stage) => {
|
|
102
|
+
stage.value = next
|
|
103
|
+
announceCsvStep(refs, next)
|
|
104
|
+
afterFlush(() => refs.headingElement?.focus())
|
|
105
|
+
}
|
|
106
|
+
const { load, take } = csvLoading({ props, table, map, file, issue, go })
|
|
107
|
+
const run = csvRun({ props, table, map, issues, percent, finished, count, go })
|
|
108
|
+
const again = () => {
|
|
109
|
+
table.value = { headers: [], rows: [] }
|
|
110
|
+
map.value = []
|
|
111
|
+
file.value = ''
|
|
112
|
+
go('upload')
|
|
113
|
+
}
|
|
114
|
+
const { cellIssue, preview, columns, kept, titleOf } = csvPreview({ props, table, map, issues })
|
|
115
|
+
|
|
116
|
+
return {
|
|
117
|
+
refs,
|
|
118
|
+
id,
|
|
119
|
+
stage,
|
|
120
|
+
file,
|
|
121
|
+
table,
|
|
122
|
+
map,
|
|
123
|
+
percent,
|
|
124
|
+
finished,
|
|
125
|
+
dragState: dragging,
|
|
126
|
+
issue,
|
|
127
|
+
at,
|
|
128
|
+
options,
|
|
129
|
+
missing,
|
|
130
|
+
issues,
|
|
131
|
+
bad,
|
|
132
|
+
good,
|
|
133
|
+
countText: count,
|
|
134
|
+
go,
|
|
135
|
+
load,
|
|
136
|
+
take,
|
|
137
|
+
run,
|
|
138
|
+
again,
|
|
139
|
+
cellIssue,
|
|
140
|
+
preview,
|
|
141
|
+
columns,
|
|
142
|
+
kept,
|
|
143
|
+
titleOf,
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function csvUpload(props: CsvImportProps, model: ReturnType<typeof csvModel>) {
|
|
148
|
+
const { id, dragState: dragging, take, issue, load } = model
|
|
149
|
+
const rowLimit = () => (props.rowLimit === undefined ? 5000 : props.rowLimit)
|
|
150
|
+
return (
|
|
151
|
+
<>
|
|
152
|
+
<div
|
|
153
|
+
data-scope="dropzone"
|
|
154
|
+
data-sweep=""
|
|
155
|
+
data-pin={dragging.value ? '' : undefined}
|
|
156
|
+
onDragOver={(e: DragEvent) => {
|
|
157
|
+
e.preventDefault()
|
|
158
|
+
dragging.value = true
|
|
159
|
+
}}
|
|
160
|
+
onDragLeave={() => (dragging.value = false)}
|
|
161
|
+
onDrop={(e: DragEvent) => {
|
|
162
|
+
e.preventDefault()
|
|
163
|
+
dragging.value = false
|
|
164
|
+
void take(e.dataTransfer?.files[0])
|
|
165
|
+
}}
|
|
166
|
+
>
|
|
167
|
+
<Sweep />
|
|
168
|
+
<input
|
|
169
|
+
type="file"
|
|
170
|
+
accept=".csv,text/csv"
|
|
171
|
+
aria-labelledby={`${id}-t`}
|
|
172
|
+
aria-describedby={`${id}-h`}
|
|
173
|
+
onChange={(e: Event) => {
|
|
174
|
+
void take((e.currentTarget as HTMLInputElement).files?.[0])
|
|
175
|
+
;(e.currentTarget as HTMLInputElement).value = ''
|
|
176
|
+
}}
|
|
177
|
+
/>
|
|
178
|
+
<span data-part="icon" aria-hidden="true">
|
|
179
|
+
<UploadIcon />
|
|
180
|
+
</span>
|
|
181
|
+
<span data-part="drop-copy">
|
|
182
|
+
<span data-part="title" id={`${id}-t`}>
|
|
183
|
+
Drop a CSV here or <u>browse</u>
|
|
184
|
+
</span>
|
|
185
|
+
</span>
|
|
186
|
+
<span data-part="hint" id={`${id}-h`}>
|
|
187
|
+
Up to {rowLimit().toLocaleString('en-US')} rows · first row is the header
|
|
188
|
+
</span>
|
|
189
|
+
</div>
|
|
190
|
+
{issue.value && (
|
|
191
|
+
<Alert tone="critical" live title="That file can’t be read">
|
|
192
|
+
{issue.value}
|
|
193
|
+
</Alert>
|
|
194
|
+
)}
|
|
195
|
+
{props.sample && (
|
|
196
|
+
<div>
|
|
197
|
+
<Button emphasis="link" onClick={() => load(props.sample!.name, props.sample!.text)}>
|
|
198
|
+
Use the sample
|
|
199
|
+
</Button>
|
|
200
|
+
</div>
|
|
201
|
+
)}
|
|
202
|
+
</>
|
|
203
|
+
)
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function csvMapping(model: ReturnType<typeof csvModel>) {
|
|
207
|
+
const { file, table, columns, map, options } = model
|
|
208
|
+
return (
|
|
209
|
+
<>
|
|
210
|
+
<span class="muted">
|
|
211
|
+
<b>{file.value}</b> · {plural(table.value.rows.length, 'row')} ·{' '}
|
|
212
|
+
{plural(table.value.headers.length, 'column')}
|
|
213
|
+
</span>
|
|
214
|
+
<PlainTable
|
|
215
|
+
label="Column mapping"
|
|
216
|
+
scope="import-map"
|
|
217
|
+
caption="Map each CSV column to a field"
|
|
218
|
+
head={
|
|
219
|
+
<tr>
|
|
220
|
+
<th scope="col">CSV column</th>
|
|
221
|
+
<th scope="col">Sample</th>
|
|
222
|
+
<th scope="col">Imports as</th>
|
|
223
|
+
</tr>
|
|
224
|
+
}
|
|
225
|
+
>
|
|
226
|
+
{columns.value.map((c) => (
|
|
227
|
+
<tr key={c.h}>
|
|
228
|
+
<th scope="row">
|
|
229
|
+
<code>{c.h}</code>
|
|
230
|
+
</th>
|
|
231
|
+
<td class="muted">{table.value.rows[0]?.[c.col]}</td>
|
|
232
|
+
<td>
|
|
233
|
+
<InlineSelect
|
|
234
|
+
label={`${c.h} imports as`}
|
|
235
|
+
value={c.target!}
|
|
236
|
+
options={options.value}
|
|
237
|
+
onValueChange={(v) => {
|
|
238
|
+
const next = [...map.value]
|
|
239
|
+
next[c.col] = v
|
|
240
|
+
map.value = next
|
|
241
|
+
}}
|
|
242
|
+
/>
|
|
243
|
+
</td>
|
|
244
|
+
</tr>
|
|
245
|
+
))}
|
|
246
|
+
</PlainTable>
|
|
247
|
+
</>
|
|
248
|
+
)
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
function csvReview(model: ReturnType<typeof csvModel>) {
|
|
252
|
+
const { missing, bad, table, good, kept, titleOf, preview, issues, cellIssue } = model
|
|
253
|
+
return (
|
|
254
|
+
<>
|
|
255
|
+
{missing.value.length > 0 ? (
|
|
256
|
+
<Alert
|
|
257
|
+
tone="critical"
|
|
258
|
+
title={`No column is mapped to ${missing.value.map((t) => t.label).join(', ')}`}
|
|
259
|
+
>
|
|
260
|
+
Go back and map one to continue.
|
|
261
|
+
</Alert>
|
|
262
|
+
) : bad.value > 0 ? (
|
|
263
|
+
<Alert
|
|
264
|
+
tone="caution"
|
|
265
|
+
title={`${bad.value} of ${plural(table.value.rows.length, 'row')} need a fix`}
|
|
266
|
+
>
|
|
267
|
+
Fix them in the file and upload again, or import the {good.value} good rows now and skip
|
|
268
|
+
the rest.
|
|
269
|
+
</Alert>
|
|
270
|
+
) : (
|
|
271
|
+
<Alert tone="positive" title={`All ${plural(table.value.rows.length, 'row')} look good`} />
|
|
272
|
+
)}
|
|
273
|
+
<PlainTable
|
|
274
|
+
label="Import preview"
|
|
275
|
+
scope="import-preview"
|
|
276
|
+
caption="Preview of the first rows"
|
|
277
|
+
head={
|
|
278
|
+
<tr>
|
|
279
|
+
{kept.value.map((c) => (
|
|
280
|
+
<th key={c.h} scope="col">
|
|
281
|
+
{titleOf(c.target!)}
|
|
282
|
+
</th>
|
|
283
|
+
))}
|
|
284
|
+
</tr>
|
|
285
|
+
}
|
|
286
|
+
>
|
|
287
|
+
{preview.value.map((r) => (
|
|
288
|
+
<tr key={r.row} data-invalid={issues.value.some((x) => x.row === r.row) ? '' : undefined}>
|
|
289
|
+
{kept.value.map((c) => (
|
|
290
|
+
<Cell key={c.h} value={r.cells[c.col]!} issue={cellIssue(r.row, c.target!)} />
|
|
291
|
+
))}
|
|
292
|
+
</tr>
|
|
293
|
+
))}
|
|
294
|
+
</PlainTable>
|
|
295
|
+
</>
|
|
296
|
+
)
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
function csvDone(model: ReturnType<typeof csvModel>) {
|
|
300
|
+
const { finished, percent, countText: count, good, again } = model
|
|
301
|
+
return (
|
|
302
|
+
<>
|
|
303
|
+
<Progress label={finished.value ? 'Imported' : 'Importing'} value={percent.value} />
|
|
304
|
+
{finished.value ? (
|
|
305
|
+
<div data-scope="row">
|
|
306
|
+
<span>{count(good.value)} imported.</span>
|
|
307
|
+
<Button emphasis="link" onClick={again}>
|
|
308
|
+
Import another file
|
|
309
|
+
</Button>
|
|
310
|
+
</div>
|
|
311
|
+
) : (
|
|
312
|
+
<span class="muted">You can leave this page; we’ll email you when it finishes.</span>
|
|
313
|
+
)}
|
|
314
|
+
</>
|
|
315
|
+
)
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
function csvNavigation(model: ReturnType<typeof csvModel>) {
|
|
319
|
+
const { stage, go, good, run } = model
|
|
320
|
+
return (
|
|
321
|
+
<div data-scope="row" data-justify="between">
|
|
322
|
+
<Button
|
|
323
|
+
emphasis="ghost"
|
|
324
|
+
tone="neutral"
|
|
325
|
+
onClick={() => go(stage.value === 'map' ? 'upload' : 'map')}
|
|
326
|
+
>
|
|
327
|
+
Back
|
|
328
|
+
</Button>
|
|
329
|
+
{stage.value === 'map' ? (
|
|
330
|
+
<Button onClick={() => go('review')}>Preview</Button>
|
|
331
|
+
) : (
|
|
332
|
+
<Button
|
|
333
|
+
disabled={good.value === 0}
|
|
334
|
+
onClick={run}
|
|
335
|
+
>{`Import ${plural(good.value, 'row')}`}</Button>
|
|
336
|
+
)}
|
|
337
|
+
</div>
|
|
338
|
+
)
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
function csvView(props: CsvImportProps, model: ReturnType<typeof csvModel>) {
|
|
342
|
+
const { refs, stage, at } = model
|
|
343
|
+
return (
|
|
344
|
+
<div data-scope="stack">
|
|
345
|
+
<StepBar label="Import progress" steps={STEPS} current={at.value} />
|
|
346
|
+
<h3 ref={(n) => (refs.headingElement = n)} data-part="step-title" tabindex="-1">
|
|
347
|
+
{STEPS[at.value]!.title} {(props.noun === undefined ? ['person', 'people'] : props.noun)[1]}
|
|
348
|
+
</h3>
|
|
349
|
+
{stage.value === 'upload' && csvUpload(props, model)}
|
|
350
|
+
{stage.value === 'map' && csvMapping(model)}
|
|
351
|
+
{stage.value === 'review' && csvReview(model)}
|
|
352
|
+
{stage.value === 'done' && csvDone(model)}
|
|
353
|
+
{(stage.value === 'map' || stage.value === 'review') && csvNavigation(model)}
|
|
354
|
+
</div>
|
|
355
|
+
)
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* The CSV import wizard (09 §4.7), Upload → Map → Review → Import: parsing, mapping and validation are veneer-core's. Each
|
|
360
|
+
* step's heading takes focus. Bad cells say why inline; a required target with no column is reported once.
|
|
361
|
+
*/
|
|
362
|
+
export function CsvImport(props: CsvImportProps) {
|
|
363
|
+
const live = untrack(() => props)
|
|
364
|
+
return csvView(live, csvModel(live))
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
function Cell({ value, issue }: { value: string; issue?: ImportIssue | undefined }) {
|
|
368
|
+
return (
|
|
369
|
+
<td data-invalid={issue ? '' : undefined}>
|
|
370
|
+
{value}
|
|
371
|
+
{issue && (
|
|
372
|
+
<span data-part="error">
|
|
373
|
+
<AlertCircleIcon />
|
|
374
|
+
{issue.message}
|
|
375
|
+
</span>
|
|
376
|
+
)}
|
|
377
|
+
</td>
|
|
378
|
+
)
|
|
379
|
+
}
|