@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,308 @@
|
|
|
1
|
+
// Table rows, editable cells and the detail sheet.
|
|
2
|
+
import { pushLayer } from '@kerf-js/veneer-core'
|
|
3
|
+
import { derived, onCleanup, onMount, state, untrack, watch, type State } from '@kerf-js/core'
|
|
4
|
+
import { Button } from './Button'
|
|
5
|
+
import { tableEditor } from './Table-editor'
|
|
6
|
+
|
|
7
|
+
import { For } from '@kerf-js/core/dom'
|
|
8
|
+
import type { Column, Ctx } from './Table-types'
|
|
9
|
+
|
|
10
|
+
/** The input used to edit a cell. */
|
|
11
|
+
export { Editor } from './Table-editor'
|
|
12
|
+
|
|
13
|
+
/** The details disclosure icon. */
|
|
14
|
+
export const chevron = () => (
|
|
15
|
+
<svg
|
|
16
|
+
aria-hidden="true"
|
|
17
|
+
focusable="false"
|
|
18
|
+
viewBox="0 0 16 16"
|
|
19
|
+
fill="none"
|
|
20
|
+
stroke="currentColor"
|
|
21
|
+
stroke-width="1.5"
|
|
22
|
+
>
|
|
23
|
+
<path d="M6 3.5 10.5 8 6 12.5" />
|
|
24
|
+
</svg>
|
|
25
|
+
)
|
|
26
|
+
/** Every column as a list: what a sheet and a detail row show by default. */
|
|
27
|
+
export function Fields<T>(props: { row: T; ctx: Ctx<T> }) {
|
|
28
|
+
return untrack(() =>
|
|
29
|
+
tableFields(
|
|
30
|
+
() => props.row,
|
|
31
|
+
() => props.ctx,
|
|
32
|
+
),
|
|
33
|
+
)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Render row fields under the detail owner. */
|
|
37
|
+
export function tableFields<T>(row: () => T, ctx: () => Ctx<T>) {
|
|
38
|
+
const columns = derived(() => ctx().cols())
|
|
39
|
+
return (
|
|
40
|
+
<dl data-scope="desc">
|
|
41
|
+
<For each={columns.value} by={(column) => column.id}>
|
|
42
|
+
{(column) => (
|
|
43
|
+
<div>
|
|
44
|
+
<dt>{column().header}</dt>
|
|
45
|
+
<dd>{(column().cell ?? ((value: T) => ctx().read(column(), value)))(row())}</dd>
|
|
46
|
+
</div>
|
|
47
|
+
)}
|
|
48
|
+
</For>
|
|
49
|
+
</dl>
|
|
50
|
+
)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// The conditional owner holds the shown value; only editing replaces its nodes.
|
|
54
|
+
function shown<T>(row: () => T, c: Column<T>, value: () => unknown) {
|
|
55
|
+
if (c.live)
|
|
56
|
+
return (
|
|
57
|
+
<>
|
|
58
|
+
<span data-part="dir" aria-hidden="true"></span>
|
|
59
|
+
{c.cell ? c.cell(row()) : value()}
|
|
60
|
+
</>
|
|
61
|
+
)
|
|
62
|
+
return <>{c.cell ? c.cell(row()) : value()}</>
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function cell<T>(row: () => T, col: () => Column<T>, ctx: () => Ctx<T>) {
|
|
66
|
+
const c = untrack(col)
|
|
67
|
+
const editing = state(false)
|
|
68
|
+
const problem = state('')
|
|
69
|
+
const delta = state<string | undefined>(undefined)
|
|
70
|
+
const message = () => `${ctx().id}-${ctx().keyOf(row())}-${c.id}-e`
|
|
71
|
+
const value = () => ctx().read(c, row())
|
|
72
|
+
let td: HTMLElement | undefined
|
|
73
|
+
if (c.live)
|
|
74
|
+
watch(value, (now, was) => {
|
|
75
|
+
if (was === undefined || now === was) return
|
|
76
|
+
const dir = (now as number) > (was as number) ? 'up' : 'down'
|
|
77
|
+
delta.value = delta.value === dir ? `${dir}2` : dir // two names per direction, so the flash replays
|
|
78
|
+
})
|
|
79
|
+
let seed = ''
|
|
80
|
+
const begin = () => {
|
|
81
|
+
if (c.edit && !editing.value) {
|
|
82
|
+
seed = String((untrack(value) as string | number | null | undefined) ?? '')
|
|
83
|
+
problem.value = ''
|
|
84
|
+
editing.value = true
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
const done = (save: boolean, text: string) => {
|
|
88
|
+
if (!editing.value) return
|
|
89
|
+
if (save) {
|
|
90
|
+
const next = typeof c.edit === 'function' ? c.edit(text) : text
|
|
91
|
+
const ok = c.validate?.(next) ?? true
|
|
92
|
+
if (ok !== true) {
|
|
93
|
+
problem.value = typeof ok === 'string' ? ok : 'That value is not valid'
|
|
94
|
+
return
|
|
95
|
+
}
|
|
96
|
+
ctx().edit?.(row(), c.id, next)
|
|
97
|
+
}
|
|
98
|
+
problem.value = ''
|
|
99
|
+
editing.value = false
|
|
100
|
+
td?.focus()
|
|
101
|
+
}
|
|
102
|
+
return (
|
|
103
|
+
<td
|
|
104
|
+
ref={(n) => (td = n)}
|
|
105
|
+
role={c.rowHeader ? 'rowheader' : 'cell'}
|
|
106
|
+
data-col={c.id}
|
|
107
|
+
data-label={c.header}
|
|
108
|
+
data-numeric={c.numeric ? '' : undefined}
|
|
109
|
+
data-priority={c.priority}
|
|
110
|
+
data-card={c.card}
|
|
111
|
+
data-pinned={c.pin ? 'last' : undefined}
|
|
112
|
+
data-live={c.live ? '' : undefined}
|
|
113
|
+
data-delta={delta.value}
|
|
114
|
+
data-editable={c.edit ? '' : undefined}
|
|
115
|
+
data-invalid={problem.value ? '' : undefined}
|
|
116
|
+
tabindex={c.edit ? '0' : undefined}
|
|
117
|
+
aria-description={c.edit ? 'Press Enter to edit' : undefined}
|
|
118
|
+
onDblClick={c.edit ? begin : undefined}
|
|
119
|
+
onKeyDown={(c.edit ? cellKey(begin) : undefined)!}
|
|
120
|
+
>
|
|
121
|
+
{editing.value ? (
|
|
122
|
+
<>
|
|
123
|
+
{untrack(() =>
|
|
124
|
+
tableEditor({
|
|
125
|
+
label: () => `${c.header} for ${ctx().title(row())}`,
|
|
126
|
+
start: () => seed,
|
|
127
|
+
callbacks: { onDone: done },
|
|
128
|
+
}),
|
|
129
|
+
)}
|
|
130
|
+
{problem.value && (
|
|
131
|
+
<span data-part="sr-only" id={message()} role="alert">
|
|
132
|
+
{problem.value}
|
|
133
|
+
</span>
|
|
134
|
+
)}
|
|
135
|
+
</>
|
|
136
|
+
) : (
|
|
137
|
+
untrack(() => shown(row, c, value))
|
|
138
|
+
)}
|
|
139
|
+
</td>
|
|
140
|
+
)
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function cellKey(begin: () => void) {
|
|
144
|
+
return (e: KeyboardEvent) => {
|
|
145
|
+
if (e.target === e.currentTarget && (e.key === 'Enter' || e.key === 'F2')) {
|
|
146
|
+
e.preventDefault()
|
|
147
|
+
begin()
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/** A keyed row with its optional detail row. */
|
|
153
|
+
export function Row<T>(props: { row: T; ctx: Ctx<T> }) {
|
|
154
|
+
return untrack(() =>
|
|
155
|
+
tableRow(
|
|
156
|
+
() => props.row,
|
|
157
|
+
() => props.ctx,
|
|
158
|
+
),
|
|
159
|
+
)
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/** Render a row under the keyed row owner. */
|
|
163
|
+
export function tableRow<T>(row: () => T, ctx: () => Ctx<T>) {
|
|
164
|
+
const key = () => ctx().keyOf(row())
|
|
165
|
+
const on = () => !!ctx().sel?.get(key())
|
|
166
|
+
const opened = () => !!(ctx().open.get(key()) as boolean | undefined)
|
|
167
|
+
const detail = () => `${ctx().id}-d-${key()}`
|
|
168
|
+
// a closing row stays until it has slid shut. A timer, because transitionend never comes
|
|
169
|
+
// when the transition is skipped, and that would strand an empty row
|
|
170
|
+
const mounted = state(untrack(opened))
|
|
171
|
+
let tr: HTMLElement | undefined
|
|
172
|
+
const settle = () => settleRow(opened, mounted)
|
|
173
|
+
watch(opened, (now) => {
|
|
174
|
+
if (now) return void (mounted.value = true)
|
|
175
|
+
if (!mounted.value) return
|
|
176
|
+
queueMicrotask(() => {
|
|
177
|
+
const slide = tr?.nextElementSibling?.querySelector('[data-part="slide"]')
|
|
178
|
+
setTimeout(settle, slide ? parseFloat(getComputedStyle(slide).transitionDuration) * 1000 : 0)
|
|
179
|
+
})
|
|
180
|
+
})
|
|
181
|
+
const click = rowClick(row, ctx)
|
|
182
|
+
const renderCell = (column: () => Column<T>) => untrack(() => cell(row, column, ctx))
|
|
183
|
+
const columns = derived(() => ctx().cols())
|
|
184
|
+
return (
|
|
185
|
+
<>
|
|
186
|
+
<tr
|
|
187
|
+
ref={(n) => (tr = n)}
|
|
188
|
+
role="row"
|
|
189
|
+
data-id={key()}
|
|
190
|
+
data-selected={on() ? '' : undefined}
|
|
191
|
+
data-clickable={ctx().details ? '' : undefined}
|
|
192
|
+
onClick={(ctx().details ? click : undefined)!}
|
|
193
|
+
>
|
|
194
|
+
{ctx().sel && (
|
|
195
|
+
<td role="cell" data-part="select" data-pinned="first">
|
|
196
|
+
<label data-scope="checkbox">
|
|
197
|
+
<input
|
|
198
|
+
type="checkbox"
|
|
199
|
+
checked={ctx().sel!.get(key())}
|
|
200
|
+
aria-label={`Select ${ctx().title(row())}`}
|
|
201
|
+
onClick={(e: MouseEvent) => ctx().pick(key(), e)}
|
|
202
|
+
/>
|
|
203
|
+
<span data-part="control">
|
|
204
|
+
<span data-part="mark" aria-hidden="true"></span>
|
|
205
|
+
</span>
|
|
206
|
+
</label>
|
|
207
|
+
</td>
|
|
208
|
+
)}
|
|
209
|
+
{ctx().details && (
|
|
210
|
+
<td role="cell" style="padding-inline:4px">
|
|
211
|
+
<button
|
|
212
|
+
type="button"
|
|
213
|
+
data-part="expand"
|
|
214
|
+
aria-expanded={opened() ? 'true' : 'false'}
|
|
215
|
+
aria-controls={mounted.value ? detail() : undefined}
|
|
216
|
+
aria-label={`Details for ${ctx().title(row())}`}
|
|
217
|
+
onClick={(e: MouseEvent) => ctx().toggle(row(), e.currentTarget as HTMLElement)}
|
|
218
|
+
>
|
|
219
|
+
{chevron()}
|
|
220
|
+
</button>
|
|
221
|
+
</td>
|
|
222
|
+
)}
|
|
223
|
+
<For each={columns.value} by={(column) => column.id}>
|
|
224
|
+
{renderCell}
|
|
225
|
+
</For>
|
|
226
|
+
</tr>
|
|
227
|
+
{mounted.value && (
|
|
228
|
+
<tr data-part="detail" role="row" id={detail()}>
|
|
229
|
+
<td role="cell" colspan={ctx().span()}>
|
|
230
|
+
<div data-part="slide" data-closing={opened() ? undefined : ''}>
|
|
231
|
+
<div>
|
|
232
|
+
<div>{ctx().body(row())}</div>
|
|
233
|
+
</div>
|
|
234
|
+
</div>
|
|
235
|
+
</td>
|
|
236
|
+
</tr>
|
|
237
|
+
)}
|
|
238
|
+
</>
|
|
239
|
+
)
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
function settleRow(opened: () => boolean, mounted: State<boolean>) {
|
|
243
|
+
if (!untrack(opened)) mounted.value = false
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
function rowClick<T>(row: () => T, ctx: () => Ctx<T>) {
|
|
247
|
+
return (e: MouseEvent) => {
|
|
248
|
+
if ((e.target as Element).closest?.('button, input, select, a, label, [data-editable]')) return
|
|
249
|
+
ctx().toggle(
|
|
250
|
+
row(),
|
|
251
|
+
(e.currentTarget as HTMLElement).querySelector<HTMLElement>('[data-part="expand"]')!,
|
|
252
|
+
)
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
type SheetProps<T> = { row: T; ctx: Ctx<T>; onClose: (restore?: boolean) => void }
|
|
257
|
+
|
|
258
|
+
/** The tablet detail sheet (06 §5): non-modal, Escape closes it from anywhere, focus moves to Close and back to the row. */
|
|
259
|
+
export function Sheet<T>(props: SheetProps<T>) {
|
|
260
|
+
return untrack(() =>
|
|
261
|
+
tableSheet(
|
|
262
|
+
() => props.row,
|
|
263
|
+
() => props.ctx,
|
|
264
|
+
props,
|
|
265
|
+
),
|
|
266
|
+
)
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/** Render the sheet under its conditional owner. */
|
|
270
|
+
export function tableSheet<T>(
|
|
271
|
+
row: () => T,
|
|
272
|
+
ctx: () => Ctx<T>,
|
|
273
|
+
callbacks: Pick<SheetProps<T>, 'onClose'>,
|
|
274
|
+
) {
|
|
275
|
+
let close: HTMLElement | undefined
|
|
276
|
+
let el: HTMLElement | undefined
|
|
277
|
+
onMount(() => {
|
|
278
|
+
close?.focus()
|
|
279
|
+
onCleanup(pushLayer({ el: el!, close: (reason) => callbacks.onClose(reason === 'escape') }))
|
|
280
|
+
})
|
|
281
|
+
const id = () => `${ctx().id}-sh`
|
|
282
|
+
return (
|
|
283
|
+
<div
|
|
284
|
+
ref={(n) => (el = n)}
|
|
285
|
+
data-part="sheet"
|
|
286
|
+
role="dialog"
|
|
287
|
+
aria-modal="false"
|
|
288
|
+
aria-labelledby={id()}
|
|
289
|
+
>
|
|
290
|
+
<header>
|
|
291
|
+
<h4 id={id()} aria-level={ctx().level} style="margin:0">
|
|
292
|
+
{ctx().title(row())}
|
|
293
|
+
</h4>
|
|
294
|
+
<Button
|
|
295
|
+
emphasis="ghost"
|
|
296
|
+
tone="neutral"
|
|
297
|
+
ref={(n) => (close = n)}
|
|
298
|
+
onClick={() => callbacks.onClose(true)}
|
|
299
|
+
>
|
|
300
|
+
Close
|
|
301
|
+
</Button>
|
|
302
|
+
</header>
|
|
303
|
+
<div tabindex="0" role="group" aria-labelledby={id()}>
|
|
304
|
+
{ctx().body(row())}
|
|
305
|
+
</div>
|
|
306
|
+
</div>
|
|
307
|
+
)
|
|
308
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// Selection and sorting state for a table.
|
|
2
|
+
import { derived, type State } from '@kerf-js/core'
|
|
3
|
+
import { checkState, rangeOf, type SortDir } from '@kerf-js/veneer-core'
|
|
4
|
+
import type { Column, TableProps, TableSort } from './Table-types'
|
|
5
|
+
|
|
6
|
+
/** Create selection and sort callbacks under the table's owner. */
|
|
7
|
+
export function tableSelection<T>({
|
|
8
|
+
sel,
|
|
9
|
+
visible,
|
|
10
|
+
keyOf,
|
|
11
|
+
cols,
|
|
12
|
+
order,
|
|
13
|
+
props,
|
|
14
|
+
}: {
|
|
15
|
+
sel: State<Record<string, boolean>> | undefined
|
|
16
|
+
visible: { readonly value: readonly T[] }
|
|
17
|
+
keyOf: (row: T) => string
|
|
18
|
+
cols: { readonly value: Column<T>[] }
|
|
19
|
+
order: State<TableSort | undefined>
|
|
20
|
+
props: TableProps<T>
|
|
21
|
+
}) {
|
|
22
|
+
let anchor: string | undefined
|
|
23
|
+
const keys = derived(() => visible.value.map(keyOf))
|
|
24
|
+
const chosen = () => Object.keys(sel!.value).filter((k) => sel!.value[k])
|
|
25
|
+
const write = (next: Record<string, boolean>) => {
|
|
26
|
+
sel!.value = next
|
|
27
|
+
props.onSelectionChange?.(Object.keys(next).filter((k) => next[k]))
|
|
28
|
+
}
|
|
29
|
+
const pick = (key: string, e: MouseEvent) => {
|
|
30
|
+
const next = { ...sel!.value }
|
|
31
|
+
if (e.shiftKey && anchor !== undefined)
|
|
32
|
+
for (const k of rangeOf(keys.value, anchor, key)) next[k] = true
|
|
33
|
+
else if (next[key]) delete next[key]
|
|
34
|
+
else next[key] = true
|
|
35
|
+
anchor = key
|
|
36
|
+
write(next)
|
|
37
|
+
}
|
|
38
|
+
const headerCheck = derived(() =>
|
|
39
|
+
sel ? checkState(keys.value, (k) => !!(sel.get(k) as boolean | undefined)) : 'none',
|
|
40
|
+
)
|
|
41
|
+
const pickAll = () => {
|
|
42
|
+
const next = { ...sel!.value }
|
|
43
|
+
const off = headerCheck.value === 'all'
|
|
44
|
+
for (const k of keys.value) {
|
|
45
|
+
if (off) delete next[k]
|
|
46
|
+
else next[k] = true
|
|
47
|
+
}
|
|
48
|
+
write(next)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const askSort = (c: Column<T>, dir?: SortDir) => {
|
|
52
|
+
const now = order.value
|
|
53
|
+
const next = {
|
|
54
|
+
id: c.id,
|
|
55
|
+
dir: dir ?? (now?.id === c.id && now.dir === 'ascending' ? 'descending' : 'ascending'),
|
|
56
|
+
}
|
|
57
|
+
order.value = next
|
|
58
|
+
props.onSortChange?.(next)
|
|
59
|
+
}
|
|
60
|
+
const sortable = derived(() => cols.value.filter((c) => c.sort))
|
|
61
|
+
|
|
62
|
+
return [keys, chosen, write, pick, headerCheck, pickAll, askSort, sortable] as const
|
|
63
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// The phone card sorting controls.
|
|
2
|
+
import { Button } from './Button'
|
|
3
|
+
import { Select } from './Select'
|
|
4
|
+
import type { TableModel } from './Table-model'
|
|
5
|
+
|
|
6
|
+
/** Render the sort controls under the table's owner. */
|
|
7
|
+
export function tableSortbar<T>(
|
|
8
|
+
base: TableModel<T>['base'],
|
|
9
|
+
selection: TableModel<T>['selection'],
|
|
10
|
+
) {
|
|
11
|
+
const [, , cols, , , , , order] = base
|
|
12
|
+
const [, , , , , , askSort, sortChoices] = selection
|
|
13
|
+
return (
|
|
14
|
+
<div data-part="sortbar">
|
|
15
|
+
<Select
|
|
16
|
+
label="Sort by"
|
|
17
|
+
size="sm"
|
|
18
|
+
value={order.value?.id ?? ''}
|
|
19
|
+
placeholder="None"
|
|
20
|
+
options={sortChoices.value.map((c) => ({ value: c.id, label: c.header }))}
|
|
21
|
+
onChange={(e: Event) => {
|
|
22
|
+
const c = cols.value.find((x) => x.id === (e.currentTarget as HTMLInputElement).value)
|
|
23
|
+
if (c) askSort(c, order.value?.dir ?? 'ascending')
|
|
24
|
+
}}
|
|
25
|
+
/>
|
|
26
|
+
<Button
|
|
27
|
+
emphasis="outline"
|
|
28
|
+
tone="neutral"
|
|
29
|
+
size="sm"
|
|
30
|
+
aria-label="Toggle sort direction"
|
|
31
|
+
disabled={!order.value}
|
|
32
|
+
onClick={() => {
|
|
33
|
+
const c = cols.value.find((x) => x.id === order.value?.id)
|
|
34
|
+
if (c) askSort(c, order.value!.dir === 'ascending' ? 'descending' : 'ascending')
|
|
35
|
+
}}
|
|
36
|
+
>
|
|
37
|
+
{order.value?.dir === 'ascending' ? '↑' : '↓'}
|
|
38
|
+
</Button>
|
|
39
|
+
</div>
|
|
40
|
+
)
|
|
41
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// Filtering, ordering and paging of table rows.
|
|
2
|
+
import { derived, type Resource, type State } from '@kerf-js/core'
|
|
3
|
+
import { filterRows, pageSlice, sortRows } from '@kerf-js/veneer-core'
|
|
4
|
+
import type { Column, ListPage, TableProps, TableSort, TableStatus } from './Table-types'
|
|
5
|
+
|
|
6
|
+
const isResource = (r: unknown): r is Resource<unknown> =>
|
|
7
|
+
typeof (r as Resource<unknown> | null | undefined)?.refresh === 'function'
|
|
8
|
+
const isState = (r: object | null | undefined): r is State<unknown> =>
|
|
9
|
+
r != null && !Array.isArray(r) && 'value' in r
|
|
10
|
+
|
|
11
|
+
/** Create the table's derived row and status views. */
|
|
12
|
+
export function tableSource<T>({
|
|
13
|
+
props,
|
|
14
|
+
cols,
|
|
15
|
+
typed,
|
|
16
|
+
order,
|
|
17
|
+
at,
|
|
18
|
+
read,
|
|
19
|
+
}: {
|
|
20
|
+
props: TableProps<T>
|
|
21
|
+
cols: { readonly value: Column<T>[] }
|
|
22
|
+
typed: State<string>
|
|
23
|
+
order: State<TableSort | undefined>
|
|
24
|
+
at: State<number>
|
|
25
|
+
read: (column: Column<T>, row: T) => unknown
|
|
26
|
+
}) {
|
|
27
|
+
const source = () =>
|
|
28
|
+
(isResource(props.rows)
|
|
29
|
+
? (props.rows as Resource<unknown>).value
|
|
30
|
+
: isState(props.rows)
|
|
31
|
+
? (props.rows as State<unknown>).value
|
|
32
|
+
: props.rows) as readonly T[] | ListPage<T> | undefined
|
|
33
|
+
const remote = derived(() => !!props.server || isResource(props.rows))
|
|
34
|
+
const list = derived<readonly T[]>(() => {
|
|
35
|
+
const v = source()
|
|
36
|
+
return Array.isArray(v) ? (v as readonly T[]) : ((v as ListPage<T> | undefined)?.items ?? [])
|
|
37
|
+
})
|
|
38
|
+
const envelope = derived<ListPage<T> | undefined>(() => {
|
|
39
|
+
const v = source()
|
|
40
|
+
return v && !Array.isArray(v) ? (v as ListPage<T>) : undefined
|
|
41
|
+
})
|
|
42
|
+
const shown = derived(() => {
|
|
43
|
+
if (remote.value) return list.value
|
|
44
|
+
const c = cols.value
|
|
45
|
+
const found = filterRows(list.value, typed.value, (r) => c.map((x) => read(x, r)))
|
|
46
|
+
const s = order.value
|
|
47
|
+
const by = s && c.find((x) => x.id === s.id)
|
|
48
|
+
if (!s || !by) return found
|
|
49
|
+
return sortRows(found, typeof by.sort === 'function' ? by.sort : (r) => read(by, r), s.dir)
|
|
50
|
+
})
|
|
51
|
+
const paged = derived(() => {
|
|
52
|
+
const size = props.page?.size
|
|
53
|
+
return size && !remote.value ? pageSlice(shown.value, at.value, size) : undefined
|
|
54
|
+
})
|
|
55
|
+
const visible = derived(() => paged.value?.rows ?? shown.value)
|
|
56
|
+
const phase = derived<TableStatus>(() => {
|
|
57
|
+
if (props.status) return props.status
|
|
58
|
+
const r = props.rows
|
|
59
|
+
if (isResource(r)) {
|
|
60
|
+
if (r.error) return 'error'
|
|
61
|
+
if (r.value === undefined) return 'loading'
|
|
62
|
+
}
|
|
63
|
+
return visible.value.length ? 'ready' : 'empty'
|
|
64
|
+
})
|
|
65
|
+
return [remote, list, envelope, shown, paged, visible, phase] as const
|
|
66
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// The table's filter and column chooser toolbar.
|
|
2
|
+
import { ColumnsIcon } from '@kerf-js/veneer-icons'
|
|
3
|
+
import { Button } from './Button'
|
|
4
|
+
import { Search } from './Field'
|
|
5
|
+
import { ColumnsPanel } from './Table-columns'
|
|
6
|
+
import type { TableModel } from './Table-model'
|
|
7
|
+
|
|
8
|
+
/** The column chooser icon. */
|
|
9
|
+
export const columnsIcon = () => <ColumnsIcon />
|
|
10
|
+
/** Render the toolbar in the table's existing owner. */
|
|
11
|
+
export function tableToolbar<T>({
|
|
12
|
+
input,
|
|
13
|
+
refs,
|
|
14
|
+
base,
|
|
15
|
+
paging,
|
|
16
|
+
hideable,
|
|
17
|
+
flip,
|
|
18
|
+
}: {
|
|
19
|
+
input: TableModel<T>['input']
|
|
20
|
+
refs: TableModel<T>['refs']
|
|
21
|
+
base: TableModel<T>['base']
|
|
22
|
+
paging: TableModel<T>['paging']
|
|
23
|
+
hideable: TableModel<T>['hideable']
|
|
24
|
+
flip: TableModel<T>['flip']
|
|
25
|
+
}) {
|
|
26
|
+
const [id, , , , , , typed, , , , hidden, , , picking, picked] = base
|
|
27
|
+
const [, , , , count] = paging
|
|
28
|
+
return (
|
|
29
|
+
<div data-part="toolbar">
|
|
30
|
+
{input.filter !== undefined && (
|
|
31
|
+
<Search
|
|
32
|
+
label={input.filter}
|
|
33
|
+
value={typed.value}
|
|
34
|
+
onInput={(e: Event) => (typed.value = (e.currentTarget as HTMLInputElement).value)}
|
|
35
|
+
/>
|
|
36
|
+
)}
|
|
37
|
+
<span data-part="count" aria-live="polite">
|
|
38
|
+
{count.value}
|
|
39
|
+
</span>
|
|
40
|
+
<span data-part="spacer"></span>
|
|
41
|
+
{input.actions}
|
|
42
|
+
{(input.picker === undefined ? true : input.picker) && (
|
|
43
|
+
<div>
|
|
44
|
+
<Button
|
|
45
|
+
emphasis="outline"
|
|
46
|
+
tone="neutral"
|
|
47
|
+
ref={(n) => (refs.columnsButton = n)}
|
|
48
|
+
aria-expanded={picking.value ? 'true' : 'false'}
|
|
49
|
+
aria-controls={picked.value ? `${id}-cols` : undefined}
|
|
50
|
+
onClick={() => {
|
|
51
|
+
picked.value = true
|
|
52
|
+
picking.value = !picking.value
|
|
53
|
+
}}
|
|
54
|
+
>
|
|
55
|
+
{columnsIcon()}Columns
|
|
56
|
+
</Button>
|
|
57
|
+
{picked.value && (
|
|
58
|
+
<ColumnsPanel
|
|
59
|
+
id={`${id}-cols`}
|
|
60
|
+
open={picking}
|
|
61
|
+
trigger={() => refs.columnsButton!}
|
|
62
|
+
items={hideable.value}
|
|
63
|
+
shown={(c) => !hidden.value.includes(c.id)}
|
|
64
|
+
flip={flip}
|
|
65
|
+
/>
|
|
66
|
+
)}
|
|
67
|
+
</div>
|
|
68
|
+
)}
|
|
69
|
+
</div>
|
|
70
|
+
)
|
|
71
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import type { Derived, Resource, State } from '@kerf-js/core'
|
|
2
|
+
import type { SortDir } from '@kerf-js/veneer-core'
|
|
3
|
+
|
|
4
|
+
/** One Table column. */
|
|
5
|
+
export interface Column<T> {
|
|
6
|
+
id: string
|
|
7
|
+
/** Text: it also labels the cell on a phone card and the Columns checkbox. */
|
|
8
|
+
header: string
|
|
9
|
+
/** What the cell holds, sorts by and filters on. Default `row[id]`. */
|
|
10
|
+
value?: ((row: T) => unknown) | undefined
|
|
11
|
+
/** How the cell draws it. Default the value as text. */
|
|
12
|
+
cell?: ((row: T) => unknown) | undefined
|
|
13
|
+
/** `true` sorts by `value`; a function sorts by what it returns. */
|
|
14
|
+
sort?: (boolean | ((row: T) => unknown)) | undefined
|
|
15
|
+
numeric?: boolean | undefined
|
|
16
|
+
/** Sticky at the inline start. */
|
|
17
|
+
pin?: boolean | undefined
|
|
18
|
+
rowHeader?: boolean | undefined
|
|
19
|
+
/** 2 hides under 760px of table width, 3 under 1000px; a row's details still list it. */
|
|
20
|
+
priority?: 2 | 3 | undefined
|
|
21
|
+
/** Where it goes on a phone card. */
|
|
22
|
+
card?: 'title' | 'badge' | 'hide' | undefined
|
|
23
|
+
resize?: boolean | undefined
|
|
24
|
+
/** Inline edit: `true` commits the text, a function turns the text into the value. */
|
|
25
|
+
edit?: (boolean | ((text: string) => unknown)) | undefined
|
|
26
|
+
/** `true`, or the message to show: an invalid value never commits. */
|
|
27
|
+
validate?: ((value: unknown) => string | boolean) | undefined
|
|
28
|
+
/** A number that ticks: the cell flashes on change and the row is never rebuilt. */
|
|
29
|
+
live?: boolean | undefined
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** The V2 list envelope. `next`/`prev` are cursors; absent means there is no such page. */
|
|
33
|
+
export type ListPage<T> = { items: T[]; total?: number; next?: unknown; prev?: unknown }
|
|
34
|
+
/** The column a table is sorted by, and which way. */
|
|
35
|
+
export type TableSort = { id: string; dir: SortDir }
|
|
36
|
+
/** What a table is showing in place of, or along with, its rows. */
|
|
37
|
+
export type TableStatus = 'ready' | 'loading' | 'empty' | 'error'
|
|
38
|
+
|
|
39
|
+
/** Props for Table. */
|
|
40
|
+
export interface TableProps<T> {
|
|
41
|
+
rows:
|
|
42
|
+
| readonly T[]
|
|
43
|
+
| State<readonly T[]>
|
|
44
|
+
| Derived<readonly T[]>
|
|
45
|
+
| Resource<readonly T[] | ListPage<T>>
|
|
46
|
+
/** Names the table (required, 06 §5). It stays in the accessibility tree when `captionHidden`. */
|
|
47
|
+
caption: string
|
|
48
|
+
/** Hides the caption on screen. Screen readers still hear it. */
|
|
49
|
+
captionHidden?: boolean | undefined
|
|
50
|
+
columns: Column<T>[]
|
|
51
|
+
/** The field that identifies a row, or how to get it. Default `id`. */
|
|
52
|
+
rowKey?: (string | ((row: T) => string)) | undefined
|
|
53
|
+
/** `cards` stacks each row in a container under 480px wide; `columns` scrolls sideways instead. */
|
|
54
|
+
phone?: 'cards' | 'columns' | undefined
|
|
55
|
+
density?: 'compact' | 'cozy' | 'comfortable' | undefined
|
|
56
|
+
/** Show the filter field, labelled this. */
|
|
57
|
+
filter?: string | undefined
|
|
58
|
+
/** A state holding the filter text, so you can read or set it. */
|
|
59
|
+
query?: State<string> | undefined
|
|
60
|
+
/** A state holding the sorted column and direction, so you can read or set it. */
|
|
61
|
+
sort?: State<TableSort | undefined>
|
|
62
|
+
/** Called with the column and direction when someone sorts. */
|
|
63
|
+
onSortChange?: ((sort: TableSort) => void) | undefined
|
|
64
|
+
/** The rows arrive sorted, filtered and paged (a Resource's are): the table only reports what's asked. */
|
|
65
|
+
server?: boolean | undefined
|
|
66
|
+
/** Checkboxes, Shift-click ranges and the bulk bar. */
|
|
67
|
+
selection?: boolean | State<Record<string, boolean>> | undefined
|
|
68
|
+
/** Called with the keys of every selected row after each change. */
|
|
69
|
+
onSelectionChange?: ((keys: string[]) => void) | undefined
|
|
70
|
+
/** The bulk bar's actions. */
|
|
71
|
+
bulk?: ((keys: string[]) => unknown) | undefined
|
|
72
|
+
page?: { size: number } | undefined
|
|
73
|
+
/** Called on Next or Previous, with the page or server cursor to load. */
|
|
74
|
+
onPageChange?: ((to: unknown, reason: 'next' | 'prev') => void) | undefined
|
|
75
|
+
/** A row's details. Default a list of every column. */
|
|
76
|
+
expand?: ((row: T) => unknown) | undefined
|
|
77
|
+
/** inline (default): they slide open in place at every width. sheet: a panel over the table below 1000px. */
|
|
78
|
+
details?: 'inline' | 'sheet' | undefined
|
|
79
|
+
/** Called with the row, the column's id and the new value when a cell edit is committed. */
|
|
80
|
+
onEdit?: ((row: T, column: string, value: unknown) => void) | undefined
|
|
81
|
+
/** The toolbar's own actions. */
|
|
82
|
+
actions?: unknown
|
|
83
|
+
/** The Columns disclosure. */
|
|
84
|
+
picker?: boolean | undefined
|
|
85
|
+
/** Columns hidden from the start, in the server's HTML too. Bind a State to keep what people choose. */
|
|
86
|
+
hiddenColumns?: readonly string[] | State<readonly string[]> | undefined
|
|
87
|
+
/** Forces a state; a Resource's own is used otherwise. */
|
|
88
|
+
status?: TableStatus | undefined
|
|
89
|
+
/** What to show when there are no rows: a title, a line of text and an action. */
|
|
90
|
+
empty?: { title?: unknown; text?: unknown; action?: unknown } | undefined
|
|
91
|
+
error?: { title?: unknown; text?: unknown } | undefined
|
|
92
|
+
/** Called by the error state's Retry. A Resource refreshes itself as well. */
|
|
93
|
+
onRetry?: (() => void) | undefined
|
|
94
|
+
/** A CSS height past which the body scrolls under a sticky header, such as `480px`. */
|
|
95
|
+
maxHeight?: string | undefined
|
|
96
|
+
/** The outline level of the table's state and sheet headings, under the page's h1. */
|
|
97
|
+
heading?: number | undefined
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export type Ctx<T> = {
|
|
101
|
+
id: string
|
|
102
|
+
level: number
|
|
103
|
+
cols: () => Column<T>[]
|
|
104
|
+
keyOf: (row: T) => string
|
|
105
|
+
read: (c: Column<T>, row: T) => unknown
|
|
106
|
+
sel: State<Record<string, boolean>> | undefined
|
|
107
|
+
open: State<Record<string, boolean>>
|
|
108
|
+
details: boolean
|
|
109
|
+
span: () => number
|
|
110
|
+
title: (row: T) => string
|
|
111
|
+
pick: (key: string, e: MouseEvent) => void
|
|
112
|
+
toggle: (row: T, from: HTMLElement) => void
|
|
113
|
+
body: (row: T) => unknown
|
|
114
|
+
edit?: ((row: T, column: string, value: unknown) => void) | undefined
|
|
115
|
+
}
|