@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,375 @@
|
|
|
1
|
+
import { measureWrapped } from './ScrollGrid/measure'
|
|
2
|
+
import { CW, PAD, makeCell, makeHead, makeRow } from './ScrollGrid/parts'
|
|
3
|
+
import { derived, onCleanup, onMount, state, untrack } from '@kerf-js/core'
|
|
4
|
+
import { type MeasureHandle, type MeasureProvider } from '@kerf-js/core/text'
|
|
5
|
+
import { uid, virtualizer, type Virtualizer } from '@kerf-js/veneer-core'
|
|
6
|
+
import './styles'
|
|
7
|
+
import '@kerf-js/veneer-core/styles/data/scroll-grid.css'
|
|
8
|
+
|
|
9
|
+
/** One ScrollGrid column. */
|
|
10
|
+
export interface GridColumn {
|
|
11
|
+
id: string
|
|
12
|
+
header: string
|
|
13
|
+
/** Pixels. Default 104. */
|
|
14
|
+
width?: number | undefined
|
|
15
|
+
/** The text wraps, and rows are as tall as it needs. */
|
|
16
|
+
wrap?: boolean
|
|
17
|
+
}
|
|
18
|
+
/** Props for ScrollGrid. */
|
|
19
|
+
export interface ScrollGridProps {
|
|
20
|
+
label: string
|
|
21
|
+
rows: number
|
|
22
|
+
columns: readonly GridColumn[]
|
|
23
|
+
/** The cell at a row and column. */
|
|
24
|
+
cell: (row: number, column: GridColumn) => unknown
|
|
25
|
+
/** The first column, the row's name. */
|
|
26
|
+
rowHeader: (row: number) => string
|
|
27
|
+
/** The corner cell's text. */
|
|
28
|
+
corner?: string
|
|
29
|
+
/** Default `480px`. */
|
|
30
|
+
height?: string
|
|
31
|
+
/** Each row's height, in pixels. Default 34. */
|
|
32
|
+
rowHeight?: number
|
|
33
|
+
/** The pinned first column's width, in pixels. Default 132. */
|
|
34
|
+
headerWidth?: number
|
|
35
|
+
/** Marks a cell critical (a negative value). */
|
|
36
|
+
negative?: (row: number, column: GridColumn) => boolean
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const RH = 34,
|
|
40
|
+
HW = 132,
|
|
41
|
+
INSET = 20
|
|
42
|
+
const HELP =
|
|
43
|
+
'Arrow keys move one cell, Page Up and Page Down one screen, Home and End to the row ends, Control with Home or End to the grid ends.'
|
|
44
|
+
|
|
45
|
+
export type GridRuntime = {
|
|
46
|
+
el: HTMLElement | undefined
|
|
47
|
+
canvas: HTMLElement | undefined
|
|
48
|
+
ys: Virtualizer | undefined
|
|
49
|
+
xs: Virtualizer | undefined
|
|
50
|
+
engine: MeasureProvider | null
|
|
51
|
+
stop: (() => void) | undefined
|
|
52
|
+
font: string
|
|
53
|
+
line: number
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
type Held = { node: HTMLElement; set: (undo: () => void) => void }
|
|
57
|
+
function mountGrid({
|
|
58
|
+
runtime,
|
|
59
|
+
props,
|
|
60
|
+
rh,
|
|
61
|
+
hw,
|
|
62
|
+
size,
|
|
63
|
+
rows,
|
|
64
|
+
cols,
|
|
65
|
+
columns,
|
|
66
|
+
wrapped,
|
|
67
|
+
active,
|
|
68
|
+
held,
|
|
69
|
+
heldCols,
|
|
70
|
+
}: {
|
|
71
|
+
runtime: GridRuntime
|
|
72
|
+
props: ScrollGridProps
|
|
73
|
+
rh: number
|
|
74
|
+
hw: number
|
|
75
|
+
size: (row: number) => number
|
|
76
|
+
rows: { value: number[] }
|
|
77
|
+
cols: { value: number[] }
|
|
78
|
+
columns: { readonly value: readonly GridColumn[] }
|
|
79
|
+
wrapped: { readonly value: { c: GridColumn; i: number }[] }
|
|
80
|
+
active: { readonly value: [number, number] }
|
|
81
|
+
held: () => [Held, number][]
|
|
82
|
+
heldCols: () => [Held, number][]
|
|
83
|
+
}) {
|
|
84
|
+
onMount(() => {
|
|
85
|
+
queueMicrotask(() => {
|
|
86
|
+
if (!runtime.el) return
|
|
87
|
+
const allRows = Array.from({ length: untrack(() => props.rows) }, (_, i) => i)
|
|
88
|
+
runtime.ys = virtualizer(runtime.el, {
|
|
89
|
+
keys: allRows,
|
|
90
|
+
spacer: runtime.canvas!,
|
|
91
|
+
estimate: rh,
|
|
92
|
+
size,
|
|
93
|
+
head: rh,
|
|
94
|
+
sized: true,
|
|
95
|
+
pinned: () => [active.value[0]],
|
|
96
|
+
overscan: 200,
|
|
97
|
+
onRange: (i) => (rows.value = i),
|
|
98
|
+
})
|
|
99
|
+
runtime.xs = virtualizer(runtime.el, {
|
|
100
|
+
keys: untrack(() => columns.value.map((_, i) => i)),
|
|
101
|
+
spacer: runtime.canvas!,
|
|
102
|
+
axis: 'x',
|
|
103
|
+
estimate: (i) => untrack(() => columns.value[i]!.width ?? CW),
|
|
104
|
+
head: hw,
|
|
105
|
+
sized: true,
|
|
106
|
+
pinned: () => [active.value[1]],
|
|
107
|
+
overscan: 200,
|
|
108
|
+
onRange: (i) => (cols.value = i),
|
|
109
|
+
})
|
|
110
|
+
for (const [row, key] of held().splice(0)) row.set(runtime.ys.attach(row.node, key))
|
|
111
|
+
for (const [cell, key] of heldCols().splice(0)) cell.set(runtime.xs.attach(cell.node, key))
|
|
112
|
+
if (!untrack(() => wrapped.value.length)) return
|
|
113
|
+
measureWrapped({ runtime, rows, size, count: allRows.length })
|
|
114
|
+
})
|
|
115
|
+
onCleanup(() => {
|
|
116
|
+
runtime.stop?.()
|
|
117
|
+
runtime.ys?.destroy()
|
|
118
|
+
runtime.xs?.destroy()
|
|
119
|
+
})
|
|
120
|
+
})
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function gridSize({
|
|
124
|
+
runtime,
|
|
125
|
+
props,
|
|
126
|
+
handles,
|
|
127
|
+
wrapped,
|
|
128
|
+
rh,
|
|
129
|
+
}: {
|
|
130
|
+
runtime: GridRuntime
|
|
131
|
+
props: ScrollGridProps
|
|
132
|
+
handles: Map<string, MeasureHandle>
|
|
133
|
+
wrapped: { readonly value: { c: GridColumn; i: number }[] }
|
|
134
|
+
rh: number
|
|
135
|
+
}) {
|
|
136
|
+
const handle = (r: number, c: GridColumn) => {
|
|
137
|
+
const key = `${r}\0${c.id}`
|
|
138
|
+
let h = handles.get(key)
|
|
139
|
+
if (!h) {
|
|
140
|
+
h = runtime.engine!.prepare(
|
|
141
|
+
String((props.cell(r, c) as string | number | null | undefined) ?? ''),
|
|
142
|
+
runtime.font,
|
|
143
|
+
)
|
|
144
|
+
handles.set(key, h)
|
|
145
|
+
}
|
|
146
|
+
return h
|
|
147
|
+
}
|
|
148
|
+
const size = (r: number) => {
|
|
149
|
+
if (!runtime.engine || !wrapped.value.length) return rh
|
|
150
|
+
let most = rh
|
|
151
|
+
for (const { c } of wrapped.value)
|
|
152
|
+
most = Math.max(
|
|
153
|
+
most,
|
|
154
|
+
runtime.engine.layout(handle(r, c), (c.width ?? CW) - INSET, runtime.line).height + PAD,
|
|
155
|
+
)
|
|
156
|
+
return most
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
return size
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function gridNavigation({
|
|
163
|
+
runtime,
|
|
164
|
+
props,
|
|
165
|
+
active,
|
|
166
|
+
columns,
|
|
167
|
+
rh,
|
|
168
|
+
hw,
|
|
169
|
+
cellId,
|
|
170
|
+
}: {
|
|
171
|
+
runtime: GridRuntime
|
|
172
|
+
props: ScrollGridProps
|
|
173
|
+
active: { value: [number, number] }
|
|
174
|
+
columns: { readonly value: readonly GridColumn[] }
|
|
175
|
+
rh: number
|
|
176
|
+
hw: number
|
|
177
|
+
cellId: (row: number, column: number) => string
|
|
178
|
+
}) {
|
|
179
|
+
function focusCell([r, c]: [number, number], align = true) {
|
|
180
|
+
active.value = [r, c]
|
|
181
|
+
runtime.ys?.update({})
|
|
182
|
+
runtime.xs?.update({})
|
|
183
|
+
if (align) reveal(r, c)
|
|
184
|
+
runtime.el!.setAttribute('aria-activedescendant', cellId(r, c))
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function reveal(r: number, c: number) {
|
|
188
|
+
const top = runtime.el!.scrollTop,
|
|
189
|
+
y = runtime.ys!.sizes.offset(r),
|
|
190
|
+
h = runtime.ys!.sizes.get(r),
|
|
191
|
+
room = runtime.el!.clientHeight - rh
|
|
192
|
+
if (y < top) runtime.el!.scrollTop = y
|
|
193
|
+
else if (y + h! > top + room) runtime.el!.scrollTop = y + h! - room
|
|
194
|
+
const left = runtime.el!.scrollLeft,
|
|
195
|
+
x = runtime.xs!.sizes.offset(c),
|
|
196
|
+
w = runtime.xs!.sizes.get(c),
|
|
197
|
+
wide = runtime.el!.clientWidth - hw
|
|
198
|
+
if (x < left) runtime.el!.scrollLeft = x
|
|
199
|
+
else if (x + w! > left + wide) runtime.el!.scrollLeft = x + w! - wide
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function onKeyDown(e: KeyboardEvent) {
|
|
203
|
+
const [r, c] = active.value,
|
|
204
|
+
lastR = props.rows - 1,
|
|
205
|
+
lastC = columns.value.length - 1,
|
|
206
|
+
ctrl = e.ctrlKey || e.metaKey
|
|
207
|
+
const page = Math.max(1, Math.floor((runtime.el!.clientHeight - rh) / rh) - 1)
|
|
208
|
+
const to: Record<string, [number, number]> = {
|
|
209
|
+
ArrowDown: [r + 1, c],
|
|
210
|
+
ArrowUp: [r - 1, c],
|
|
211
|
+
ArrowRight: [r, c + 1],
|
|
212
|
+
ArrowLeft: [r, c - 1],
|
|
213
|
+
PageDown: [r + page, c],
|
|
214
|
+
PageUp: [r - page, c],
|
|
215
|
+
Home: ctrl ? [0, 0] : [r, 0],
|
|
216
|
+
End: ctrl ? [lastR, lastC] : [r, lastC],
|
|
217
|
+
}
|
|
218
|
+
const next = to[e.key]
|
|
219
|
+
if (!next) return
|
|
220
|
+
e.preventDefault()
|
|
221
|
+
focusCell([Math.max(0, Math.min(lastR, next[0])), Math.max(0, Math.min(lastC, next[1]))])
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
return { focusCell, onKeyDown }
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
function gridWindows(props: ScrollGridProps, columns: { readonly value: readonly GridColumn[] }) {
|
|
228
|
+
const rows = state<number[]>(
|
|
229
|
+
Array.from(
|
|
230
|
+
{
|
|
231
|
+
length: Math.min(
|
|
232
|
+
untrack(() => props.rows),
|
|
233
|
+
12,
|
|
234
|
+
),
|
|
235
|
+
},
|
|
236
|
+
(_, i) => i,
|
|
237
|
+
),
|
|
238
|
+
)
|
|
239
|
+
const cols = state<number[]>(
|
|
240
|
+
Array.from(
|
|
241
|
+
{
|
|
242
|
+
length: Math.min(
|
|
243
|
+
untrack(() => columns.value.length),
|
|
244
|
+
12,
|
|
245
|
+
),
|
|
246
|
+
},
|
|
247
|
+
(_, i) => i,
|
|
248
|
+
),
|
|
249
|
+
)
|
|
250
|
+
return { rows, cols }
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
function gridWatch(runtime: GridRuntime, held: [Held, number][], heldCols: [Held, number][]) {
|
|
254
|
+
return (node: () => HTMLElement, axis: 'x' | 'y', key: number) =>
|
|
255
|
+
onMount(() => {
|
|
256
|
+
let undo: (() => void) | undefined
|
|
257
|
+
const v = axis === 'y' ? runtime.ys : runtime.xs
|
|
258
|
+
if (v) undo = v.attach(node(), key)
|
|
259
|
+
else (axis === 'y' ? held : heldCols).push([{ node: node(), set: (u) => (undo = u) }, key])
|
|
260
|
+
onCleanup(() => undo?.())
|
|
261
|
+
})
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
function gridModel(props: ScrollGridProps) {
|
|
265
|
+
const runtime: GridRuntime = {
|
|
266
|
+
el: undefined,
|
|
267
|
+
canvas: undefined,
|
|
268
|
+
ys: undefined,
|
|
269
|
+
xs: undefined,
|
|
270
|
+
engine: null,
|
|
271
|
+
stop: undefined,
|
|
272
|
+
font: '',
|
|
273
|
+
line: 0,
|
|
274
|
+
}
|
|
275
|
+
const id = uid('grid')
|
|
276
|
+
const rh = untrack(() => props.rowHeight ?? RH),
|
|
277
|
+
hw = untrack(() => props.headerWidth ?? HW)
|
|
278
|
+
const columns = derived(() => props.columns)
|
|
279
|
+
const { rows, cols } = gridWindows(props, columns)
|
|
280
|
+
const active = state<[number, number]>([0, 0])
|
|
281
|
+
const shownCols = derived(() =>
|
|
282
|
+
cols.value.flatMap((c) => (columns.value[c] ? [{ c, col: columns.value[c] }] : [])),
|
|
283
|
+
)
|
|
284
|
+
const handles = new Map<string, MeasureHandle>()
|
|
285
|
+
const wrapped = derived(() => columns.value.flatMap((c, i) => (c.wrap ? [{ c, i }] : [])))
|
|
286
|
+
const cellId = (r: number, c: number) => `${id}-r${r}-c${c}`
|
|
287
|
+
|
|
288
|
+
const size = gridSize({ runtime, props: untrack(() => props), handles, wrapped, rh })
|
|
289
|
+
|
|
290
|
+
const { focusCell, onKeyDown } = gridNavigation({
|
|
291
|
+
runtime,
|
|
292
|
+
props: untrack(() => props),
|
|
293
|
+
active,
|
|
294
|
+
columns,
|
|
295
|
+
rh,
|
|
296
|
+
hw,
|
|
297
|
+
cellId,
|
|
298
|
+
})
|
|
299
|
+
|
|
300
|
+
mountGrid({
|
|
301
|
+
runtime,
|
|
302
|
+
props,
|
|
303
|
+
rh,
|
|
304
|
+
hw,
|
|
305
|
+
size,
|
|
306
|
+
rows,
|
|
307
|
+
cols,
|
|
308
|
+
columns,
|
|
309
|
+
wrapped,
|
|
310
|
+
active,
|
|
311
|
+
held: () => held,
|
|
312
|
+
heldCols: () => heldCols,
|
|
313
|
+
})
|
|
314
|
+
|
|
315
|
+
const held: [Held, number][] = [],
|
|
316
|
+
heldCols: [Held, number][] = []
|
|
317
|
+
const watch = gridWatch(runtime, held, heldCols)
|
|
318
|
+
|
|
319
|
+
const Cell = makeCell({ props, watch, active, cellId, focusCell, hw })
|
|
320
|
+
const Head = makeHead(watch, hw)
|
|
321
|
+
const Row = makeRow({ props, watch, shownCols, hw, rh, Cell })
|
|
322
|
+
|
|
323
|
+
return { runtime, id, columns, rows, shownCols, hw, cellId, onKeyDown, Head, Row }
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/** The two-axis grid (06 §6): rows and columns are each a window on one scroller, plus the active cell's row and column. */
|
|
327
|
+
export function ScrollGrid(props: ScrollGridProps) {
|
|
328
|
+
const { runtime, id, columns, rows, shownCols, hw, cellId, onKeyDown, Head, Row } = untrack(() =>
|
|
329
|
+
gridModel(props),
|
|
330
|
+
)
|
|
331
|
+
return (
|
|
332
|
+
<div
|
|
333
|
+
ref={(n) => (runtime.el = n)}
|
|
334
|
+
data-scope="scroll-grid"
|
|
335
|
+
role="grid"
|
|
336
|
+
id={id}
|
|
337
|
+
aria-label={props.label}
|
|
338
|
+
aria-describedby={`${id}-help`}
|
|
339
|
+
aria-readonly="true"
|
|
340
|
+
aria-rowcount={props.rows + 1}
|
|
341
|
+
aria-colcount={columns.value.length + 1}
|
|
342
|
+
aria-activedescendant={cellId(0, 0)}
|
|
343
|
+
tabindex="0"
|
|
344
|
+
onKeyDown={onKeyDown}
|
|
345
|
+
style={props.height ? `block-size:${props.height}` : undefined}
|
|
346
|
+
>
|
|
347
|
+
<div ref={(n) => (runtime.canvas = n)} data-part="canvas" role="presentation">
|
|
348
|
+
<div
|
|
349
|
+
data-part="head-row"
|
|
350
|
+
role="row"
|
|
351
|
+
aria-rowindex="1"
|
|
352
|
+
style="position:sticky;inset-block-start:0"
|
|
353
|
+
>
|
|
354
|
+
<div
|
|
355
|
+
data-part="corner"
|
|
356
|
+
role="columnheader"
|
|
357
|
+
aria-colindex="1"
|
|
358
|
+
style={`position:sticky;inset-inline-start:0;inline-size:${hw}px`}
|
|
359
|
+
>
|
|
360
|
+
{props.corner ?? props.label}
|
|
361
|
+
</div>
|
|
362
|
+
{shownCols.value.map((e) => (
|
|
363
|
+
<Head key={e.c} entry={e} />
|
|
364
|
+
))}
|
|
365
|
+
</div>
|
|
366
|
+
{rows.value.map((r) => (
|
|
367
|
+
<Row key={r} r={r} />
|
|
368
|
+
))}
|
|
369
|
+
</div>
|
|
370
|
+
<p id={`${id}-help`} class="vh">
|
|
371
|
+
{HELP}
|
|
372
|
+
</p>
|
|
373
|
+
</div>
|
|
374
|
+
)
|
|
375
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { onCleanup, onMount } from '@kerf-js/core'
|
|
2
|
+
import './styles'
|
|
3
|
+
import '@kerf-js/veneer-core/styles/layout/scroll-rail.css'
|
|
4
|
+
|
|
5
|
+
type Size = { track: number; total: number; h: number }
|
|
6
|
+
|
|
7
|
+
/** The thumb follows the pointer: the page scrolls as far as the thumb moves, scaled from the track to the page. */
|
|
8
|
+
function dragThumb(
|
|
9
|
+
e: PointerEvent,
|
|
10
|
+
{ rail, thumb }: { rail: HTMLElement; thumb: HTMLElement },
|
|
11
|
+
{ track, total, h }: Size,
|
|
12
|
+
) {
|
|
13
|
+
const from = e.clientY
|
|
14
|
+
const start = scrollY
|
|
15
|
+
thumb.setPointerCapture(e.pointerId)
|
|
16
|
+
rail.setAttribute('data-dragging', '')
|
|
17
|
+
const move = (m: PointerEvent) =>
|
|
18
|
+
scrollTo({
|
|
19
|
+
top: start + ((m.clientY - from) * total) / Math.max(1, track - h),
|
|
20
|
+
behavior: 'instant',
|
|
21
|
+
})
|
|
22
|
+
const up = () => {
|
|
23
|
+
rail.removeAttribute('data-dragging')
|
|
24
|
+
thumb.removeEventListener('pointermove', move)
|
|
25
|
+
thumb.removeEventListener('pointerup', up)
|
|
26
|
+
thumb.removeEventListener('pointercancel', up)
|
|
27
|
+
}
|
|
28
|
+
thumb.addEventListener('pointermove', move)
|
|
29
|
+
thumb.addEventListener('pointerup', up)
|
|
30
|
+
thumb.addEventListener('pointercancel', up)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* The page's scrollbar, drawn by veneer on every device in place of the native one, from below a sticky header
|
|
35
|
+
* (`--veneer-scroll-rail-top`) instead of over it. The document still scrolls, so keys, anchors, scroll restore and a
|
|
36
|
+
* phone's collapsing address bar work as ever. With a mouse or trackpad the thumb drags, and a press on the rail jumps
|
|
37
|
+
* the thumb to that spot and keeps dragging; on a touch screen the thumb always shows and always takes a finger, and
|
|
38
|
+
* the rest of the rail never takes a swipe. Put one in the root layout.
|
|
39
|
+
*
|
|
40
|
+
* `below` names the sticky header (a CSS selector). The rail then starts at that header's bottom edge wherever it is:
|
|
41
|
+
* under a banner that scrolls away, at a height that changes with the width, or as it shrinks on scroll. Without it,
|
|
42
|
+
* the rail starts at `--veneer-scroll-rail-top`.
|
|
43
|
+
*/
|
|
44
|
+
export function ScrollRail(props: { below?: string } = {}) {
|
|
45
|
+
let rail!: HTMLElement
|
|
46
|
+
let thumb!: HTMLElement
|
|
47
|
+
onMount(() => {
|
|
48
|
+
const doc = document.documentElement
|
|
49
|
+
let frame = 0
|
|
50
|
+
let idle: ReturnType<typeof setTimeout> | undefined
|
|
51
|
+
// the rail's top follows the header's bottom edge, measured as the page moves
|
|
52
|
+
let top = -1
|
|
53
|
+
const place = () => {
|
|
54
|
+
const header = props.below ? document.querySelector(props.below) : null
|
|
55
|
+
if (!header) return
|
|
56
|
+
const edge = Math.max(0, Math.round(header.getBoundingClientRect().bottom))
|
|
57
|
+
if (edge !== top) rail.style.insetBlockStart = `${(top = edge)}px`
|
|
58
|
+
}
|
|
59
|
+
const size = () => {
|
|
60
|
+
const track = rail.clientHeight
|
|
61
|
+
const total = doc.scrollHeight - innerHeight
|
|
62
|
+
const h = Math.max(32, (track * innerHeight) / doc.scrollHeight)
|
|
63
|
+
return { track, total, h }
|
|
64
|
+
}
|
|
65
|
+
const draw = () => {
|
|
66
|
+
frame = 0
|
|
67
|
+
place()
|
|
68
|
+
const { track, total, h } = size()
|
|
69
|
+
rail.toggleAttribute('data-none', total <= 1)
|
|
70
|
+
thumb.style.blockSize = `${h}px`
|
|
71
|
+
thumb.style.translate = `0 ${total > 0 ? ((track - h) * scrollY) / total : 0}px`
|
|
72
|
+
}
|
|
73
|
+
const moved = () => {
|
|
74
|
+
frame ||= requestAnimationFrame(draw)
|
|
75
|
+
rail.setAttribute('data-active', '')
|
|
76
|
+
clearTimeout(idle)
|
|
77
|
+
idle = setTimeout(() => rail.removeAttribute('data-active'), 900)
|
|
78
|
+
}
|
|
79
|
+
// A press on the track jumps the thumb's middle to that spot, then drags from there; a press on the thumb drags.
|
|
80
|
+
const press = (e: PointerEvent) => {
|
|
81
|
+
if (e.button !== 0) return
|
|
82
|
+
e.preventDefault()
|
|
83
|
+
const s = size()
|
|
84
|
+
if (e.target !== thumb) {
|
|
85
|
+
const span = Math.max(1, s.track - s.h)
|
|
86
|
+
const at = Math.min(
|
|
87
|
+
span,
|
|
88
|
+
Math.max(0, e.clientY - rail.getBoundingClientRect().top - s.h / 2),
|
|
89
|
+
)
|
|
90
|
+
scrollTo({ top: (at * s.total) / span, behavior: 'instant' })
|
|
91
|
+
}
|
|
92
|
+
dragThumb(e, { rail, thumb }, s)
|
|
93
|
+
}
|
|
94
|
+
const grows = new ResizeObserver(moved)
|
|
95
|
+
grows.observe(document.body)
|
|
96
|
+
addEventListener('scroll', moved, { passive: true })
|
|
97
|
+
addEventListener('resize', moved)
|
|
98
|
+
rail.addEventListener('pointerdown', press)
|
|
99
|
+
draw()
|
|
100
|
+
onCleanup(() => {
|
|
101
|
+
grows.disconnect()
|
|
102
|
+
removeEventListener('scroll', moved)
|
|
103
|
+
removeEventListener('resize', moved)
|
|
104
|
+
rail.removeEventListener('pointerdown', press)
|
|
105
|
+
cancelAnimationFrame(frame)
|
|
106
|
+
clearTimeout(idle)
|
|
107
|
+
})
|
|
108
|
+
})
|
|
109
|
+
return (
|
|
110
|
+
<div ref={(n) => (rail = n)} data-scope="scroll-rail" data-none="" aria-hidden="true">
|
|
111
|
+
<div ref={(n) => (thumb = n)} data-part="thumb"></div>
|
|
112
|
+
</div>
|
|
113
|
+
)
|
|
114
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { scroller, type ScrollOptions, type Scroller } from '@kerf-js/scroll'
|
|
2
|
+
import { use } from '@kerf-js/veneer-core/kerf'
|
|
3
|
+
import './styles'
|
|
4
|
+
import '@kerf-js/scroll/styles.css'
|
|
5
|
+
import '@kerf-js/veneer-core/styles/layout/scroll-view.css'
|
|
6
|
+
|
|
7
|
+
/** Props for ScrollView: every `@kerf-js/scroll` option, plus the box's own class and style. */
|
|
8
|
+
export interface ScrollViewProps extends ScrollOptions {
|
|
9
|
+
children?: unknown
|
|
10
|
+
class?: string | undefined
|
|
11
|
+
style?: string | undefined
|
|
12
|
+
/** Receives the scroller once it runs: `scrollTo`, `scrollIntoView`, `state` and the rest. */
|
|
13
|
+
controller?: ((s: Scroller) => void) | undefined
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* A scroll area with Veneer's bars (`@kerf-js/scroll`), drawn in the DOM or, with `renderer={canvas()}` from
|
|
18
|
+
* `@kerf-js/scroll/canvas`, on a canvas. By default the browser scrolls it and the thumb follows on the compositor;
|
|
19
|
+
* `mode="engine"` runs wheel, touch and momentum in JavaScript instead. Give it a height. Before its script runs it
|
|
20
|
+
* scrolls natively with the browser's own bar, so the server's HTML works on its own.
|
|
21
|
+
*/
|
|
22
|
+
export function ScrollView(props: ScrollViewProps) {
|
|
23
|
+
let root: HTMLDivElement | undefined
|
|
24
|
+
const make = (el: HTMLDivElement, o: ScrollOptions & Pick<ScrollViewProps, 'controller'>) => {
|
|
25
|
+
const s = scroller(el, o)
|
|
26
|
+
o.controller?.(s)
|
|
27
|
+
return s
|
|
28
|
+
}
|
|
29
|
+
use(
|
|
30
|
+
make,
|
|
31
|
+
() => root,
|
|
32
|
+
() => {
|
|
33
|
+
const { children: _children, class: _class, style: _style, ...options } = props
|
|
34
|
+
return options
|
|
35
|
+
},
|
|
36
|
+
)
|
|
37
|
+
return (
|
|
38
|
+
<div
|
|
39
|
+
ref={(n) => (root = n)}
|
|
40
|
+
data-scope="scroll-view"
|
|
41
|
+
data-scroll=""
|
|
42
|
+
data-axes={props.axes ?? 'both'}
|
|
43
|
+
class={props.class}
|
|
44
|
+
style={props.style}
|
|
45
|
+
>
|
|
46
|
+
<div data-part="viewport" aria-label={props.label} role={props.label ? 'region' : undefined}>
|
|
47
|
+
<div data-part="content">{props.children}</div>
|
|
48
|
+
</div>
|
|
49
|
+
<div data-part="scrollbar" data-orientation="vertical">
|
|
50
|
+
<div data-part="thumb"></div>
|
|
51
|
+
</div>
|
|
52
|
+
<div data-part="scrollbar" data-orientation="horizontal">
|
|
53
|
+
<div data-part="thumb"></div>
|
|
54
|
+
</div>
|
|
55
|
+
</div>
|
|
56
|
+
)
|
|
57
|
+
}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { segmentEvents } from './events'
|
|
2
|
+
import { segmentView } from './view'
|
|
3
|
+
import {
|
|
4
|
+
dayPeriods,
|
|
5
|
+
hour12,
|
|
6
|
+
isComplete,
|
|
7
|
+
isEmpty,
|
|
8
|
+
ymd,
|
|
9
|
+
segmentParts,
|
|
10
|
+
writeParts,
|
|
11
|
+
type SegmentKind,
|
|
12
|
+
type SegmentOptions,
|
|
13
|
+
type SegmentPart,
|
|
14
|
+
} from '@kerf-js/veneer-core'
|
|
15
|
+
import { derived, flush, state, untrack } from '@kerf-js/core'
|
|
16
|
+
|
|
17
|
+
import type { SegmentState } from '../Segments'
|
|
18
|
+
|
|
19
|
+
export const afterRender = (fn: () => void) => {
|
|
20
|
+
flush()
|
|
21
|
+
fn()
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function segmentModel({
|
|
25
|
+
kind,
|
|
26
|
+
locale,
|
|
27
|
+
value,
|
|
28
|
+
options,
|
|
29
|
+
today,
|
|
30
|
+
clears,
|
|
31
|
+
disabled,
|
|
32
|
+
readonly,
|
|
33
|
+
onEdit,
|
|
34
|
+
onBlurPartial,
|
|
35
|
+
}: {
|
|
36
|
+
kind: () => SegmentKind
|
|
37
|
+
locale: () => string
|
|
38
|
+
value: () => string | null
|
|
39
|
+
options: () => SegmentOptions | undefined
|
|
40
|
+
today: () => string
|
|
41
|
+
clears: () => number | undefined
|
|
42
|
+
disabled: () => boolean | undefined
|
|
43
|
+
readonly: () => boolean | undefined
|
|
44
|
+
onEdit: (state: SegmentState, parts: SegmentPart[]) => void
|
|
45
|
+
onBlurPartial: () => unknown
|
|
46
|
+
}) {
|
|
47
|
+
const make = () =>
|
|
48
|
+
writeParts(
|
|
49
|
+
segmentParts(untrack(kind), untrack(locale), untrack(options)),
|
|
50
|
+
untrack(kind),
|
|
51
|
+
untrack(value),
|
|
52
|
+
)
|
|
53
|
+
const parts = state(make())
|
|
54
|
+
const shape = derived(() => {
|
|
55
|
+
const l = locale()
|
|
56
|
+
return { periods: dayPeriods(l), h12: hour12(l, options()?.hourCycle), l }
|
|
57
|
+
})
|
|
58
|
+
let group: HTMLDivElement | undefined
|
|
59
|
+
let edited = false
|
|
60
|
+
const year = () => ymd(untrack(today))[0]
|
|
61
|
+
const spins = () => [...group!.querySelectorAll<HTMLElement>('[data-part="segment"]')]
|
|
62
|
+
const update = (next: SegmentPart[]) => {
|
|
63
|
+
if (next === parts.value) return
|
|
64
|
+
parts.value = next
|
|
65
|
+
// the value this edit makes (null for a partial or impossible date) comes back through `value`: not a new value
|
|
66
|
+
edited = true
|
|
67
|
+
queueMicrotask(() => (edited = false))
|
|
68
|
+
const st: SegmentState = isEmpty(next) ? 'empty' : isComplete(next) ? 'complete' : 'partial'
|
|
69
|
+
onEdit(st, next)
|
|
70
|
+
}
|
|
71
|
+
const { onKey, onLeave, onPaste } = segmentEvents({
|
|
72
|
+
parts,
|
|
73
|
+
spins,
|
|
74
|
+
year,
|
|
75
|
+
update,
|
|
76
|
+
group: () => group,
|
|
77
|
+
readonly,
|
|
78
|
+
disabled,
|
|
79
|
+
kind,
|
|
80
|
+
locale,
|
|
81
|
+
today,
|
|
82
|
+
onBlurPartial,
|
|
83
|
+
make,
|
|
84
|
+
value,
|
|
85
|
+
clears,
|
|
86
|
+
edited: () => edited,
|
|
87
|
+
})
|
|
88
|
+
return {
|
|
89
|
+
parts,
|
|
90
|
+
shape,
|
|
91
|
+
onKey,
|
|
92
|
+
onLeave,
|
|
93
|
+
onPaste,
|
|
94
|
+
setGroup: (node: HTMLDivElement) => (group = node),
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* A segment group (04 §1.3): each part a role=spinbutton, ordered by the locale. `onChange` hears every edit with the
|
|
100
|
+
* group's state; the group only takes `value` when that value differs from what it holds, so a half-typed date stays.
|
|
101
|
+
*/
|
|
102
|
+
export function Segments({
|
|
103
|
+
kind,
|
|
104
|
+
locale,
|
|
105
|
+
value,
|
|
106
|
+
options,
|
|
107
|
+
label,
|
|
108
|
+
today,
|
|
109
|
+
clears,
|
|
110
|
+
required,
|
|
111
|
+
disabled,
|
|
112
|
+
readonly,
|
|
113
|
+
onEdit,
|
|
114
|
+
onBlurPartial,
|
|
115
|
+
}: {
|
|
116
|
+
kind: SegmentKind
|
|
117
|
+
locale: string
|
|
118
|
+
value: string | null
|
|
119
|
+
options?: SegmentOptions | undefined
|
|
120
|
+
label?: string | undefined
|
|
121
|
+
today: string
|
|
122
|
+
clears?: number | undefined
|
|
123
|
+
required?: boolean | undefined
|
|
124
|
+
disabled?: boolean | undefined
|
|
125
|
+
readonly?: boolean | undefined
|
|
126
|
+
onEdit: (state: SegmentState, parts: SegmentPart[]) => void
|
|
127
|
+
onBlurPartial?: (() => unknown) | undefined
|
|
128
|
+
}) {
|
|
129
|
+
const model = segmentModel({
|
|
130
|
+
kind: () => kind,
|
|
131
|
+
locale: () => locale,
|
|
132
|
+
value: () => value,
|
|
133
|
+
options: () => options,
|
|
134
|
+
today: () => today,
|
|
135
|
+
clears: () => clears,
|
|
136
|
+
disabled: () => disabled,
|
|
137
|
+
readonly: () => readonly,
|
|
138
|
+
onEdit: (st, parts) => onEdit(st, parts),
|
|
139
|
+
onBlurPartial: () => onBlurPartial?.(),
|
|
140
|
+
})
|
|
141
|
+
return segmentView({
|
|
142
|
+
model,
|
|
143
|
+
label: () => label,
|
|
144
|
+
readonly: () => readonly,
|
|
145
|
+
disabled: () => disabled,
|
|
146
|
+
required: () => required,
|
|
147
|
+
})
|
|
148
|
+
}
|