@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,206 @@
|
|
|
1
|
+
// The shapes a scene stage and its scenes agree on. A renderer's bridge (keel's `defineScene`) fills them;
|
|
2
|
+
// the stage needs nothing else from it, so veneer imports no renderer.
|
|
3
|
+
import type { SurfaceBase } from '@kerf-js/core/surface'
|
|
4
|
+
import type { MediaAsset } from '@kerf-js/core/media'
|
|
5
|
+
import type { Handover, Levers } from '@kerf-js/veneer-core/scenes'
|
|
6
|
+
|
|
7
|
+
export type { Handover, Levers }
|
|
8
|
+
|
|
9
|
+
/** A point on the stage, each axis in -1..1 with y up. */
|
|
10
|
+
export interface StagePointer {
|
|
11
|
+
readonly x: number
|
|
12
|
+
readonly y: number
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** What a scene is told each frame besides its position. */
|
|
16
|
+
export interface SceneFrame {
|
|
17
|
+
/** Null while the pointer is off the page. */
|
|
18
|
+
readonly pointer: StagePointer | null
|
|
19
|
+
/** How fast the active scene's position moves, in viewports per second. */
|
|
20
|
+
readonly velocity: number
|
|
21
|
+
/** The shared clock in seconds; it stands still under reduced motion. */
|
|
22
|
+
readonly time: number
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* A section's pass over its scene, each value a plain number: a paper panel that sweeps up over the frame and off its
|
|
27
|
+
* top with a straight or torn edge, and the darkening and blur of the frame under it.
|
|
28
|
+
*/
|
|
29
|
+
export interface StagePost {
|
|
30
|
+
/** The sweep: 0 → 1 the panel's top edge rises over the frame, 1 → 2 its bottom edge follows; 0 and 2 nothing. */
|
|
31
|
+
readonly progress?: number
|
|
32
|
+
/** Moves both edges, in frame heights with y up, -1..1. */
|
|
33
|
+
readonly position?: number
|
|
34
|
+
/** 0 a straight edge, 1 a torn one. */
|
|
35
|
+
readonly tear?: number
|
|
36
|
+
/** The paper: `#rrggbb`, or display values 0..1. */
|
|
37
|
+
readonly colour?: string | readonly [number, number, number]
|
|
38
|
+
/** Darkens the frame under the panel, 0..1. */
|
|
39
|
+
readonly darken?: number
|
|
40
|
+
/** Blurs the frame under the panel, 0..1. */
|
|
41
|
+
readonly blur?: number
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** How a `<Scene>` arrives and what lies over it while it is active. */
|
|
45
|
+
export interface SceneLook {
|
|
46
|
+
/** How the hand-over into this scene looks. Default `noise`. */
|
|
47
|
+
mode?: 'noise' | 'radial'
|
|
48
|
+
/** Where a radial hand-over into this scene starts, -1..1 each way with y up. Default the frame's centre. */
|
|
49
|
+
centre?: StagePointer
|
|
50
|
+
/** False: the scene fills in without line work. */
|
|
51
|
+
lines?: boolean
|
|
52
|
+
/**
|
|
53
|
+
* Under reduced motion, and where the governor holds (a low tier): the position the scene stands at, whatever the
|
|
54
|
+
* scroll. Its scene's own `hold` otherwise.
|
|
55
|
+
*/
|
|
56
|
+
hold?: number
|
|
57
|
+
/** The section's pass while it is active: values, or values for its position. Its scene's tracks override them. */
|
|
58
|
+
post?: StagePost | ((position: number) => StagePost)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** A built scene. */
|
|
62
|
+
export interface StageScene {
|
|
63
|
+
/** Where the scene stands when the page holds it still, unless its `<Scene hold>` says. */
|
|
64
|
+
readonly hold?: number | undefined
|
|
65
|
+
/** The section pass its own tracks gave at the last `at`, over the `<Scene post>` values; null without one. */
|
|
66
|
+
readonly post?: StagePost | null
|
|
67
|
+
at(position: number, frame: SceneFrame): void
|
|
68
|
+
setQuality(levers: Levers): void
|
|
69
|
+
render(): void
|
|
70
|
+
dispose(): void
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** What a scene is built on: the stage's surface, the scene's seed and the levers in force. */
|
|
74
|
+
export interface SceneHost {
|
|
75
|
+
readonly surface: SurfaceBase
|
|
76
|
+
readonly seed: number
|
|
77
|
+
readonly quality: Levers
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** A scene the stage can build: `defineScene(...)` from @kerf-js/keel. */
|
|
81
|
+
export interface StageSceneDef {
|
|
82
|
+
/** Fetches what `build` needs, ahead of time. */
|
|
83
|
+
load?(): Promise<void>
|
|
84
|
+
build(host: SceneHost): Promise<StageScene>
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** How a frame looks: the hand-over into the incoming scene, as its `<Scene>` asks, and the active section's pass. */
|
|
88
|
+
export interface BlendOptions {
|
|
89
|
+
/** `fade` under reduced motion: a plain dissolve the stage times, 300 ms. */
|
|
90
|
+
readonly mode: 'noise' | 'radial' | 'fade'
|
|
91
|
+
readonly pointer: StagePointer | null
|
|
92
|
+
/** A radial reveal's centre, -1..1 each way with y up; null for the frame's centre. */
|
|
93
|
+
readonly centre: StagePointer | null
|
|
94
|
+
/** False under reduced motion or when the scene asks: the incoming fills in without line work. */
|
|
95
|
+
readonly lines: boolean
|
|
96
|
+
/** The levers in force: the less visible scene is drawn at `blendScale`. */
|
|
97
|
+
readonly levers: Levers
|
|
98
|
+
/** The active section's pass, or null. */
|
|
99
|
+
readonly post: StagePost | null
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Draws every frame once it is made: a hand-over from `a` to `b` at `t`, or one scene alone with `a` = `b` and `t` = 1,
|
|
104
|
+
* with the active section's pass over it. Without one the stage draws each scene plainly and cuts at `t` = 0.5.
|
|
105
|
+
*/
|
|
106
|
+
export interface StageBlend {
|
|
107
|
+
draw(a: StageScene, b: StageScene, t: number, options: BlendOptions): void
|
|
108
|
+
dispose?(): void
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** The page's frame governor: device tier to levers, frame times to render scale, a pixel ratio and an fps cap. */
|
|
112
|
+
export interface StageGovernor {
|
|
113
|
+
/** Reads the device. Until it resolves the stage draws at full levers, 60 fps and the device's ratio up to 2. */
|
|
114
|
+
start(): Promise<void>
|
|
115
|
+
/** Hands over the time between two drawn frames, in ms. */
|
|
116
|
+
frame(ms: number): void
|
|
117
|
+
/** The same object until a lever changes: the stage passes a new one to every scene. */
|
|
118
|
+
readonly levers: Levers
|
|
119
|
+
readonly fps: number
|
|
120
|
+
/** True where scenes should stand still rather than move with the scroll: those with a `hold` stand there. */
|
|
121
|
+
readonly hold?: boolean
|
|
122
|
+
/** The highest pixel ratio for a canvas `width` CSS px wide, before the render scale. */
|
|
123
|
+
pixelRatio(width: number): number
|
|
124
|
+
/** The device's tier once `start` resolved. A stage with `tier="auto"` shows posters on `low`. */
|
|
125
|
+
readonly tier?: 'high' | 'mid' | 'low'
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** Where the page stands, written once per frame when it moves. */
|
|
129
|
+
export interface ActiveScene extends Handover {
|
|
130
|
+
/** The active scene's position, in viewports. */
|
|
131
|
+
readonly position: number
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** `<Stage>`'s props. */
|
|
135
|
+
export interface StageProps {
|
|
136
|
+
/** What the scenes show, for assistive tech. */
|
|
137
|
+
label: string
|
|
138
|
+
/** The surface kind the scenes draw on. Default `keel-lit`. */
|
|
139
|
+
kind?: string
|
|
140
|
+
/** Device tier, render scale, pixel ratio and fps cap. Without one: full levers, 60 fps, ratio up to 2. */
|
|
141
|
+
governor?: StageGovernor
|
|
142
|
+
/** The hand-over blend, made once the surface is up. Without one the stage cuts at the switch. */
|
|
143
|
+
blend?: (surface: SurfaceBase) => StageBlend | Promise<StageBlend>
|
|
144
|
+
/** Called when the active scene, its position or the hand-over moves. */
|
|
145
|
+
onActive?: (active: ActiveScene) => void
|
|
146
|
+
/** Called when the scroll has settled and the scenes it wants have drawn: the frame a capture may take. */
|
|
147
|
+
onReady?: (active: ActiveScene) => void
|
|
148
|
+
/**
|
|
149
|
+
* `live` draws the scenes. `poster` shows only their posters and never loads a renderer. `auto` shows posters
|
|
150
|
+
* on a phone or tablet and where the governor rates the device `low`, decided before any renderer loads.
|
|
151
|
+
* Default `live`.
|
|
152
|
+
*/
|
|
153
|
+
tier?: 'live' | 'poster' | 'auto'
|
|
154
|
+
class?: string
|
|
155
|
+
children?: unknown
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/** `<Scene>`'s props. */
|
|
159
|
+
export interface SceneProps extends SceneLook {
|
|
160
|
+
use: StageSceneDef
|
|
161
|
+
/**
|
|
162
|
+
* Shown until the scene draws, and where it can't: a colour, an image URL, a baked poster, or `bake` for the
|
|
163
|
+
* one `bakedPosters` holds under this scene's `id`.
|
|
164
|
+
*/
|
|
165
|
+
poster?: string | ScenePoster
|
|
166
|
+
/** How many viewports the blend into this scene lasts. Default 1. */
|
|
167
|
+
hero?: number
|
|
168
|
+
/** How many viewports before the section enters its position starts. Default 0.2. */
|
|
169
|
+
early?: number
|
|
170
|
+
seed?: number
|
|
171
|
+
id?: string
|
|
172
|
+
class?: string
|
|
173
|
+
label?: string
|
|
174
|
+
children?: unknown
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** A still of a scene for wide screens, and one for tall ones: what a poster bake writes, as media records. */
|
|
178
|
+
export interface ScenePoster {
|
|
179
|
+
readonly desktop: MediaAsset
|
|
180
|
+
readonly mobile?: MediaAsset
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/** A scene as a driver outside the page sees it. */
|
|
184
|
+
export interface StageSceneInfo {
|
|
185
|
+
readonly index: number
|
|
186
|
+
readonly id: string | null
|
|
187
|
+
/** Its poster is `bake`. */
|
|
188
|
+
readonly bake: boolean
|
|
189
|
+
/** Its position when its section's top meets the viewport's top: where a baked poster is drawn without a hold. */
|
|
190
|
+
readonly rest: number
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/** What a stage offers a driver outside the page, such as a capture harness or a poster bake: `root[STAGE]`. */
|
|
194
|
+
export interface StageHandle {
|
|
195
|
+
/** `live` draws scenes, `poster` shows only posters; null until `tier="auto"` decides. */
|
|
196
|
+
readonly tier: 'live' | 'poster' | null
|
|
197
|
+
/** Every scene, in page order. */
|
|
198
|
+
scenes(): StageSceneInfo[]
|
|
199
|
+
/** Stops the shared clock at `seconds` and turns TAA off, so the same scroll draws the same frame. */
|
|
200
|
+
freeze(seconds: number): void
|
|
201
|
+
/**
|
|
202
|
+
* Draws scene `index` alone at `position` with the clock at `seconds`; resolves with a PNG data URL. Without a
|
|
203
|
+
* position it stands where its poster is drawn: its `hold`, else its `rest`.
|
|
204
|
+
*/
|
|
205
|
+
still(index: number, position?: number, seconds?: number): Promise<string>
|
|
206
|
+
}
|
package/src/Stage.tsx
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
// @kerf-js/veneer/scenes: one WebGL canvas pinned behind the whole page, and a scene per section drawn on it. The
|
|
2
|
+
// stage reads each section's scroll position, keeps the active scene and its neighbours built, hands over from one
|
|
3
|
+
// scene to the next, and owns the pixel ratio and frame rate. Scenes come from a renderer's bridge.
|
|
4
|
+
import { onCleanup, onMount, state, untrack, type State } from '@kerf-js/core'
|
|
5
|
+
import { defineSurface, Surface } from '@kerf-js/core/surface'
|
|
6
|
+
import { progress } from '@kerf-js/scroll/timeline'
|
|
7
|
+
import { isMobileDevice } from '@kerf-js/veneer-core'
|
|
8
|
+
import { attach, director, handleOf, type Director, type Entry } from './Stage-director'
|
|
9
|
+
import { PINNED, posterLayer, posterOf } from './Stage-poster'
|
|
10
|
+
import type { SceneProps, StageProps } from './Stage-types'
|
|
11
|
+
|
|
12
|
+
export type * from './Stage-types'
|
|
13
|
+
export { bakedPosters } from './Stage-poster'
|
|
14
|
+
|
|
15
|
+
/** The key of a stage's `StageHandle` on its root element, `[data-stage]`: `root[Symbol.for('kerf.stage')]`. */
|
|
16
|
+
export const STAGE = Symbol.for('kerf.stage')
|
|
17
|
+
|
|
18
|
+
const STAGES = new WeakMap<Element, Director>()
|
|
19
|
+
|
|
20
|
+
/** `auto`'s answer: posters on a phone or tablet, or where the governor rates the device `low`. */
|
|
21
|
+
async function tierOf(d: Director) {
|
|
22
|
+
const asked = d.props.tier ?? 'live'
|
|
23
|
+
if (asked !== 'auto') return asked
|
|
24
|
+
if (isMobileDevice()) return 'poster'
|
|
25
|
+
await (d.started ??= d.props.governor?.start())
|
|
26
|
+
return d.props.governor?.tier === 'low' ? 'poster' : 'live'
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async function decide(d: Director, live: State<boolean>) {
|
|
30
|
+
const tier = await tierOf(d)
|
|
31
|
+
d.tier = tier
|
|
32
|
+
d.root?.setAttribute('data-stage-tier', tier)
|
|
33
|
+
live.value = tier === 'live'
|
|
34
|
+
if (tier === 'poster') return d.root?.setAttribute('data-stage-ready', 'poster')
|
|
35
|
+
void (d.started ??= d.props.governor?.start())?.then(() => d.s?.invalidate())
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function follow(d: Director) {
|
|
39
|
+
const move = (e: PointerEvent) => {
|
|
40
|
+
d.pointer = { x: (e.clientX / innerWidth) * 2 - 1, y: 1 - (e.clientY / innerHeight) * 2 }
|
|
41
|
+
}
|
|
42
|
+
const away = () => (d.pointer = null)
|
|
43
|
+
addEventListener('pointermove', move, { passive: true })
|
|
44
|
+
document.documentElement.addEventListener('pointerleave', away)
|
|
45
|
+
onCleanup(() => {
|
|
46
|
+
removeEventListener('pointermove', move)
|
|
47
|
+
document.documentElement.removeEventListener('pointerleave', away)
|
|
48
|
+
})
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** The stage's one surface. Its kind is read once: a stage keeps its surface for life. */
|
|
52
|
+
function surfaceOf(d: Director) {
|
|
53
|
+
return defineSurface({
|
|
54
|
+
name: 'stage',
|
|
55
|
+
kind: d.props.kind ?? 'keel-lit',
|
|
56
|
+
maxDpr: d.dpr,
|
|
57
|
+
setup: (s) => attach(d, s),
|
|
58
|
+
})
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function root(d: Director, el: HTMLElement) {
|
|
62
|
+
STAGES.set((d.root = el), d)
|
|
63
|
+
Object.defineProperty(el, STAGE, { value: handleOf(d), configurable: true })
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* One canvas pinned behind the page for every `<Scene>` inside it. Sections scroll over it at full speed; the
|
|
68
|
+
* active section's scene draws, and the next one blends in as its section arrives.
|
|
69
|
+
*/
|
|
70
|
+
export function Stage(props: StageProps) {
|
|
71
|
+
const d = untrack(() => director(props))
|
|
72
|
+
const def = surfaceOf(d)
|
|
73
|
+
// Only a stage told `live` renders its surface before it mounts: `auto` waits for the device.
|
|
74
|
+
const live = state(d.tier === 'live')
|
|
75
|
+
onMount(() => {
|
|
76
|
+
follow(d)
|
|
77
|
+
void decide(d, live)
|
|
78
|
+
})
|
|
79
|
+
return (
|
|
80
|
+
<div ref={(el: HTMLElement) => root(d, el)} data-stage class={props.class}>
|
|
81
|
+
<div data-stage-viewport style={`${PINNED};overflow:hidden;z-index:0`}>
|
|
82
|
+
{live.value ? (
|
|
83
|
+
<Surface
|
|
84
|
+
use={def}
|
|
85
|
+
label={props.label}
|
|
86
|
+
style="position:absolute;inset:0;aspect-ratio:auto;transition:opacity .3s"
|
|
87
|
+
/>
|
|
88
|
+
) : null}
|
|
89
|
+
</div>
|
|
90
|
+
<div style="position:relative">{props.children}</div>
|
|
91
|
+
</div>
|
|
92
|
+
)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** Adds a scene to its stage, keeping the stage's scenes in document order. */
|
|
96
|
+
function enter(d: Director, entry: Entry) {
|
|
97
|
+
d.entries.push(entry)
|
|
98
|
+
d.entries.sort((a, b) => (a.el.compareDocumentPosition(b.el) & 4 ? -1 : 1))
|
|
99
|
+
d.entries.forEach((each, i) => {
|
|
100
|
+
each.index = i
|
|
101
|
+
each.el.dataset.scene = String(i)
|
|
102
|
+
})
|
|
103
|
+
d.s?.invalidate()
|
|
104
|
+
onCleanup(() => {
|
|
105
|
+
d.entries.splice(d.entries.indexOf(entry), 1)
|
|
106
|
+
entry.live?.dispose()
|
|
107
|
+
entry.scroll.destroy()
|
|
108
|
+
})
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* A section with a scene, inside a `<Stage>`. Its poster is pinned behind it while on screen: the page's first paint,
|
|
113
|
+
* and what shows before the scene is built or without WebGL2. Its `--scene-position` is its scene's position.
|
|
114
|
+
*/
|
|
115
|
+
export function Scene(props: SceneProps) {
|
|
116
|
+
let el!: HTMLElement
|
|
117
|
+
onMount(() => {
|
|
118
|
+
const d = STAGES.get(el.closest('[data-stage]')!)
|
|
119
|
+
if (!d) throw new Error('kerf: <Scene> must be inside a <Stage>.')
|
|
120
|
+
const scroll = progress(el, {
|
|
121
|
+
range: 'scene',
|
|
122
|
+
early: props.early ?? 0.2,
|
|
123
|
+
damp: 0.5,
|
|
124
|
+
touch: 'raw',
|
|
125
|
+
onChange: (value) => {
|
|
126
|
+
el.style.setProperty('--scene-position', String(Math.round(value * 1e4) / 1e4))
|
|
127
|
+
d.s?.invalidate()
|
|
128
|
+
},
|
|
129
|
+
})
|
|
130
|
+
// The entry keeps the live props: the stage reads `use`, `hero` and `mode` where it needs them.
|
|
131
|
+
enter(
|
|
132
|
+
d,
|
|
133
|
+
untrack(() => ({ index: 0, props, el, scroll, live: null, building: false })),
|
|
134
|
+
)
|
|
135
|
+
})
|
|
136
|
+
return (
|
|
137
|
+
<section
|
|
138
|
+
ref={(e: HTMLElement) => (el = e)}
|
|
139
|
+
id={props.id}
|
|
140
|
+
class={props.class}
|
|
141
|
+
aria-label={props.label}
|
|
142
|
+
>
|
|
143
|
+
{posterLayer(posterOf(props.poster, props.id))}
|
|
144
|
+
{props.children}
|
|
145
|
+
</section>
|
|
146
|
+
)
|
|
147
|
+
}
|
package/src/TabBar.tsx
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { onCleanup, onMount } from '@kerf-js/core'
|
|
2
|
+
import { Icon, type IconRef } from './Icon'
|
|
3
|
+
import './styles'
|
|
4
|
+
import '@kerf-js/veneer-core/styles/layout/tokens.css'
|
|
5
|
+
import '@kerf-js/veneer-core/styles/layout/tab-bar.css'
|
|
6
|
+
|
|
7
|
+
/** One destination in a TabBar. */
|
|
8
|
+
export interface TabBarItem {
|
|
9
|
+
href: string
|
|
10
|
+
label: string
|
|
11
|
+
icon: IconRef
|
|
12
|
+
/** The main action (a bag, a new post): raised in the accent. One at most. */
|
|
13
|
+
primary?: boolean | undefined
|
|
14
|
+
/** A badge count; 0 or undefined shows none. */
|
|
15
|
+
count?: number | undefined
|
|
16
|
+
/** Which paths mark it current. Default: the href itself, and anything under it (exact for "/"). */
|
|
17
|
+
match?: ((path: string) => boolean) | undefined
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** Tucks the bar away while the page scrolls down and brings it back on any scroll up, once per frame. */
|
|
21
|
+
function tucker(bar: HTMLElement, allowed: () => boolean) {
|
|
22
|
+
let last = scrollY
|
|
23
|
+
let frame = 0
|
|
24
|
+
return () => {
|
|
25
|
+
if (frame) return
|
|
26
|
+
frame = requestAnimationFrame(() => {
|
|
27
|
+
frame = 0
|
|
28
|
+
const y = scrollY
|
|
29
|
+
const dy = y - last
|
|
30
|
+
if (Math.abs(dy) < 6) return
|
|
31
|
+
// tuck only past the first screen's top and away from the bottom edge, where it must stay reachable
|
|
32
|
+
const end = document.documentElement.scrollHeight - innerHeight - 24
|
|
33
|
+
bar.toggleAttribute('data-tucked', allowed() && dy > 0 && y > 80 && y < end)
|
|
34
|
+
last = y
|
|
35
|
+
})
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* A site's bottom navigation on a phone (under 760px; wider, nothing is drawn): four or five destinations under the thumb.
|
|
41
|
+
* It slips away while the page scrolls down and comes back on any scroll up, steps aside while the keyboard is up, and
|
|
42
|
+
* pads the page's end by its own height while it shows. `current` names the current path; by default it reads
|
|
43
|
+
* location.pathname and follows client navigation.
|
|
44
|
+
*/
|
|
45
|
+
export function TabBar(props: {
|
|
46
|
+
items: TabBarItem[]
|
|
47
|
+
label?: string
|
|
48
|
+
current?: () => string
|
|
49
|
+
hideOnScroll?: boolean
|
|
50
|
+
}) {
|
|
51
|
+
let bar!: HTMLElement
|
|
52
|
+
const on = (it: TabBarItem, path: string) =>
|
|
53
|
+
it.match
|
|
54
|
+
? it.match(path)
|
|
55
|
+
: it.href === '/'
|
|
56
|
+
? path === '/'
|
|
57
|
+
: path === it.href || path.startsWith(`${it.href}/`)
|
|
58
|
+
onMount(() => {
|
|
59
|
+
const path = () => props.current?.() ?? location.pathname
|
|
60
|
+
const mark = () => {
|
|
61
|
+
const p = path()
|
|
62
|
+
bar.querySelectorAll<HTMLAnchorElement>('[data-part="item"]').forEach((a, i) => {
|
|
63
|
+
const it = props.items[i]
|
|
64
|
+
if (it && on(it, p)) a.setAttribute('aria-current', 'page')
|
|
65
|
+
else a.removeAttribute('aria-current')
|
|
66
|
+
})
|
|
67
|
+
bar.removeAttribute('data-tucked')
|
|
68
|
+
}
|
|
69
|
+
const scroll = tucker(bar, () => props.hideOnScroll !== false)
|
|
70
|
+
const vv = window.visualViewport
|
|
71
|
+
const keyboard = () => {
|
|
72
|
+
if (!vv) return
|
|
73
|
+
bar.toggleAttribute('data-off', innerHeight - vv.height > 150)
|
|
74
|
+
}
|
|
75
|
+
mark()
|
|
76
|
+
addEventListener('scroll', scroll, { passive: true })
|
|
77
|
+
addEventListener('popstate', mark)
|
|
78
|
+
// client navigation: the Navigation API hears every route change; a click on our own links marks at once
|
|
79
|
+
const clicked = () => queueMicrotask(mark)
|
|
80
|
+
bar.addEventListener('click', clicked)
|
|
81
|
+
const nav = (window as { navigation?: EventTarget }).navigation
|
|
82
|
+
nav?.addEventListener('navigatesuccess', mark)
|
|
83
|
+
vv?.addEventListener('resize', keyboard)
|
|
84
|
+
onCleanup(() => {
|
|
85
|
+
removeEventListener('scroll', scroll)
|
|
86
|
+
removeEventListener('popstate', mark)
|
|
87
|
+
bar.removeEventListener('click', clicked)
|
|
88
|
+
nav?.removeEventListener('navigatesuccess', mark)
|
|
89
|
+
vv?.removeEventListener('resize', keyboard)
|
|
90
|
+
})
|
|
91
|
+
})
|
|
92
|
+
return (
|
|
93
|
+
<nav data-scope="tab-bar" aria-label={props.label ?? 'Main'} ref={(n) => (bar = n)}>
|
|
94
|
+
<ul>
|
|
95
|
+
{props.items.map((it) => (
|
|
96
|
+
<li key={it.href}>
|
|
97
|
+
<a href={it.href} data-part="item" data-primary={it.primary ? '' : undefined}>
|
|
98
|
+
<span data-part="icon">
|
|
99
|
+
<Icon name={it.icon} />
|
|
100
|
+
{!!it.count && (
|
|
101
|
+
<span data-part="count" aria-hidden="true">
|
|
102
|
+
{it.count > 99 ? '99+' : it.count}
|
|
103
|
+
</span>
|
|
104
|
+
)}
|
|
105
|
+
</span>
|
|
106
|
+
<span data-part="label">{it.label}</span>
|
|
107
|
+
{!!it.count && <span data-part="count-label">, {it.count} items</span>}
|
|
108
|
+
</a>
|
|
109
|
+
</li>
|
|
110
|
+
))}
|
|
111
|
+
</ul>
|
|
112
|
+
</nav>
|
|
113
|
+
)
|
|
114
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// Bulk actions and page navigation in a table.
|
|
2
|
+
import type { TableProps } from './Table-types'
|
|
3
|
+
import type { tablePaging } from './Table-paging'
|
|
4
|
+
import { Button } from './Button'
|
|
5
|
+
|
|
6
|
+
/** Render actions for the current selection. */
|
|
7
|
+
export function tableBulk(
|
|
8
|
+
chosen: () => string[],
|
|
9
|
+
write: (next: Record<string, boolean>) => void,
|
|
10
|
+
props: Pick<TableProps<unknown>, 'bulk'>,
|
|
11
|
+
) {
|
|
12
|
+
return (
|
|
13
|
+
<div data-part="bulk" hidden={chosen().length === 0} role="region" aria-label="Bulk actions">
|
|
14
|
+
<b>{chosen().length} selected</b>
|
|
15
|
+
{props.bulk?.(chosen())}
|
|
16
|
+
<Button emphasis="ghost" onClick={() => write({})}>
|
|
17
|
+
Clear
|
|
18
|
+
</Button>
|
|
19
|
+
</div>
|
|
20
|
+
)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Render the table's page navigation. */
|
|
24
|
+
export function tableFooter(paging: ReturnType<typeof tablePaging>) {
|
|
25
|
+
const [go, hasPrev, hasNext, range] = paging
|
|
26
|
+
return (
|
|
27
|
+
<div data-part="footer">
|
|
28
|
+
<span>{range.value}</span>
|
|
29
|
+
<div style="display:flex;gap:8px">
|
|
30
|
+
<Button
|
|
31
|
+
emphasis="outline"
|
|
32
|
+
tone="neutral"
|
|
33
|
+
size="sm"
|
|
34
|
+
disabled={!hasPrev.value}
|
|
35
|
+
onClick={() => go('prev')}
|
|
36
|
+
>
|
|
37
|
+
Previous
|
|
38
|
+
</Button>
|
|
39
|
+
<Button
|
|
40
|
+
emphasis="outline"
|
|
41
|
+
tone="neutral"
|
|
42
|
+
size="sm"
|
|
43
|
+
disabled={!hasNext.value}
|
|
44
|
+
onClick={() => go('next')}
|
|
45
|
+
>
|
|
46
|
+
Next
|
|
47
|
+
</Button>
|
|
48
|
+
</div>
|
|
49
|
+
</div>
|
|
50
|
+
)
|
|
51
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// Per-instance table state and column access.
|
|
2
|
+
import { derived, state, untrack, type State } from '@kerf-js/core'
|
|
3
|
+
import { uid } from '@kerf-js/veneer-core'
|
|
4
|
+
import type { Column, TableProps, TableSort } from './Table-types'
|
|
5
|
+
|
|
6
|
+
const CARDS_BELOW = 480
|
|
7
|
+
const isState = (r: object | null | undefined): r is State<unknown> =>
|
|
8
|
+
r != null && !Array.isArray(r) && 'value' in r
|
|
9
|
+
|
|
10
|
+
/** Initialize the table's per-instance state. */
|
|
11
|
+
export function tableBase<T>(input: TableProps<T>) {
|
|
12
|
+
const rowKey = () => (input.rowKey === undefined ? 'id' : input.rowKey)
|
|
13
|
+
const id = uid('tbl')
|
|
14
|
+
const level = untrack(() => (input.heading === undefined ? 2 : input.heading))
|
|
15
|
+
const cols = derived(() => input.columns)
|
|
16
|
+
const keyOf = (r: T) =>
|
|
17
|
+
String(
|
|
18
|
+
typeof rowKey() === 'function'
|
|
19
|
+
? (rowKey() as (row: T) => string)(r)
|
|
20
|
+
: (r as Record<string, unknown>)[rowKey() as string],
|
|
21
|
+
)
|
|
22
|
+
const read = (c: Column<T>, r: T) => (c.value ? c.value(r) : (r as Record<string, unknown>)[c.id])
|
|
23
|
+
const named = derived(() => cols.value.find((c) => c.rowHeader) ?? cols.value[0])
|
|
24
|
+
const title = (r: T) =>
|
|
25
|
+
String((read(named.value!, r) as string | number | null | undefined) ?? '')
|
|
26
|
+
|
|
27
|
+
const typed = untrack(() => input.query) ?? state('')
|
|
28
|
+
const order = untrack(() => input.sort) ?? state<TableSort | undefined>(undefined)
|
|
29
|
+
const given = untrack(() => input.selection)
|
|
30
|
+
const sel = given ? (given === true ? state<Record<string, boolean>>({}) : given) : undefined
|
|
31
|
+
const open = state<Record<string, boolean>>({})
|
|
32
|
+
const startHidden = untrack(() => input.hiddenColumns)
|
|
33
|
+
const hidden: State<readonly string[]> = isState(startHidden)
|
|
34
|
+
? startHidden
|
|
35
|
+
: state<readonly string[]>(startHidden ?? [])
|
|
36
|
+
const at = state(0)
|
|
37
|
+
const sheet = state<{ row: T; from: HTMLElement } | undefined>(undefined)
|
|
38
|
+
const picking = state(false)
|
|
39
|
+
// the panel is built on first open and kept, so a closed table carries none of its checkboxes
|
|
40
|
+
const picked = state(false)
|
|
41
|
+
const width = state<number | undefined>(undefined)
|
|
42
|
+
const shape = derived(() =>
|
|
43
|
+
(input.phone === undefined ? 'cards' : input.phone) === 'cards' &&
|
|
44
|
+
(width.value ?? 0) >= CARDS_BELOW
|
|
45
|
+
? 'columns'
|
|
46
|
+
: input.phone === undefined
|
|
47
|
+
? 'cards'
|
|
48
|
+
: input.phone,
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
return [
|
|
52
|
+
id,
|
|
53
|
+
level,
|
|
54
|
+
cols,
|
|
55
|
+
keyOf,
|
|
56
|
+
read,
|
|
57
|
+
title,
|
|
58
|
+
typed,
|
|
59
|
+
order,
|
|
60
|
+
sel,
|
|
61
|
+
open,
|
|
62
|
+
hidden,
|
|
63
|
+
at,
|
|
64
|
+
sheet,
|
|
65
|
+
picking,
|
|
66
|
+
picked,
|
|
67
|
+
width,
|
|
68
|
+
shape,
|
|
69
|
+
] as const
|
|
70
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// The table's loading, row and empty-state body.
|
|
2
|
+
import { Button } from './Button'
|
|
3
|
+
import { untrack } from '@kerf-js/core'
|
|
4
|
+
import { For } from '@kerf-js/core/dom'
|
|
5
|
+
import { tableRow } from './Table-rows'
|
|
6
|
+
import type { TableModel } from './Table-model'
|
|
7
|
+
|
|
8
|
+
const SKELETON_ROWS = 6
|
|
9
|
+
|
|
10
|
+
/** Render the current table body under the table's owner. */
|
|
11
|
+
export function tableBody<T>({
|
|
12
|
+
input,
|
|
13
|
+
base,
|
|
14
|
+
source,
|
|
15
|
+
details,
|
|
16
|
+
notice,
|
|
17
|
+
}: {
|
|
18
|
+
input: TableModel<T>['input']
|
|
19
|
+
base: TableModel<T>['base']
|
|
20
|
+
source: TableModel<T>['source']
|
|
21
|
+
details: TableModel<T>['details']
|
|
22
|
+
notice: TableModel<T>['notice']
|
|
23
|
+
}) {
|
|
24
|
+
const [, level, cols, keyOf, , , typed, , sel] = base
|
|
25
|
+
const [, , , , , visible, phase] = source
|
|
26
|
+
const [ctx, hasDetails] = details
|
|
27
|
+
const [retry, clear, noticeTitle, noticeText] = notice
|
|
28
|
+
return (
|
|
29
|
+
<>
|
|
30
|
+
{phase.value === 'loading' ? (
|
|
31
|
+
Array.from({ length: SKELETON_ROWS }, (_, n) => n).map((n) => (
|
|
32
|
+
<tr key={n} role="row">
|
|
33
|
+
{sel && <td role="cell" data-part="select"></td>}
|
|
34
|
+
{hasDetails && <td role="cell"></td>}
|
|
35
|
+
{cols.value.map((col) => (
|
|
36
|
+
<td key={col.id} role="cell" data-col={col.id} data-priority={col.priority}>
|
|
37
|
+
<span
|
|
38
|
+
data-part="skeleton"
|
|
39
|
+
style={`--w:${30 + ((n * 17 + col.id.length * 9) % 55)}%`}
|
|
40
|
+
></span>
|
|
41
|
+
</td>
|
|
42
|
+
))}
|
|
43
|
+
</tr>
|
|
44
|
+
))
|
|
45
|
+
) : phase.value === 'ready' ? (
|
|
46
|
+
<For each={visible.value} by={keyOf}>
|
|
47
|
+
{(row) => untrack(() => tableRow(row, () => ctx))}
|
|
48
|
+
</For>
|
|
49
|
+
) : (
|
|
50
|
+
<tr role="row">
|
|
51
|
+
<td role="cell" colspan={ctx.span()} style="white-space:normal;block-size:auto">
|
|
52
|
+
<div
|
|
53
|
+
data-part="state"
|
|
54
|
+
data-kind={phase.value}
|
|
55
|
+
role={phase.value === 'error' ? 'alert' : 'status'}
|
|
56
|
+
>
|
|
57
|
+
<svg viewBox="0 0 72 40" aria-hidden="true">
|
|
58
|
+
<line x1="8" y1="0" x2="8" y2="40" />
|
|
59
|
+
<line x1="22" y1="0" x2="22" y2="40" />
|
|
60
|
+
<line x1="36" y1="0" x2="36" y2="40" />
|
|
61
|
+
<line x1="50" y1="0" x2="50" y2="40" />
|
|
62
|
+
<line x1="64" y1="0" x2="64" y2="40" />
|
|
63
|
+
<path d={phase.value === 'error' ? 'M0 20H30' : 'M0 14H72M0 26H72'} />
|
|
64
|
+
</svg>
|
|
65
|
+
<h4 aria-level={level}>{noticeTitle.value}</h4>
|
|
66
|
+
<p>{noticeText.value}</p>
|
|
67
|
+
{phase.value === 'error' ? (
|
|
68
|
+
<Button emphasis="outline" tone="neutral" onClick={retry}>
|
|
69
|
+
Retry
|
|
70
|
+
</Button>
|
|
71
|
+
) : typed.value ? (
|
|
72
|
+
<Button emphasis="outline" tone="neutral" onClick={clear}>
|
|
73
|
+
Clear filter
|
|
74
|
+
</Button>
|
|
75
|
+
) : (
|
|
76
|
+
input.empty?.action
|
|
77
|
+
)}
|
|
78
|
+
</div>
|
|
79
|
+
</td>
|
|
80
|
+
</tr>
|
|
81
|
+
)}
|
|
82
|
+
</>
|
|
83
|
+
)
|
|
84
|
+
}
|