@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,137 @@
|
|
|
1
|
+
// The palette's row pool and match highlights.
|
|
2
|
+
import { derived, effect, untrack } from '@kerf-js/core'
|
|
3
|
+
import { Icon } from './Icon'
|
|
4
|
+
import type { Command } from './CommandPalette'
|
|
5
|
+
|
|
6
|
+
export type Row =
|
|
7
|
+
| { head: string; item?: undefined; at?: undefined }
|
|
8
|
+
| { head?: undefined; item: Command; at: number }
|
|
9
|
+
|
|
10
|
+
const HIT = 'veneer-palette-hit'
|
|
11
|
+
|
|
12
|
+
/** Rows for groups in `order`, numbered in the order the arrows walk them. */
|
|
13
|
+
export function arrange(commands: Command[], order: readonly string[] = []) {
|
|
14
|
+
const groups = new Map<string, Command[]>()
|
|
15
|
+
for (const c of commands) {
|
|
16
|
+
const name = c.group ?? ''
|
|
17
|
+
if (!groups.has(name)) groups.set(name, [])
|
|
18
|
+
groups.get(name)!.push(c)
|
|
19
|
+
}
|
|
20
|
+
const rank = (n: string) => {
|
|
21
|
+
const i = order.indexOf(n)
|
|
22
|
+
return i < 0 ? order.length : i
|
|
23
|
+
}
|
|
24
|
+
const rows: Row[] = []
|
|
25
|
+
let at = 0
|
|
26
|
+
for (const [name, list] of [...groups].sort((a, b) => rank(a[0]) - rank(b[0]))) {
|
|
27
|
+
if (name) rows.push({ head: name })
|
|
28
|
+
for (const item of list) rows.push({ item, at: at++ })
|
|
29
|
+
}
|
|
30
|
+
return rows
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Marks where `words` start in the rows' text, through the CSS Custom Highlight API: no markup, no row is rebuilt. */
|
|
34
|
+
export function paint(list: HTMLElement | undefined, query: string, rows: readonly Row[]) {
|
|
35
|
+
const win = list?.ownerDocument.defaultView
|
|
36
|
+
if (!win?.CSS?.highlights || typeof win.Highlight !== 'function') return
|
|
37
|
+
const ranges: Range[] = []
|
|
38
|
+
const words = query.trim().toLowerCase().split(/\s+/).filter(Boolean)
|
|
39
|
+
const mark = (node: Text | null | undefined, indices: number[]) => {
|
|
40
|
+
for (const i of indices) {
|
|
41
|
+
if (!node || i >= node.length) continue
|
|
42
|
+
const r = new win.Range()
|
|
43
|
+
r.setStart(node, i)
|
|
44
|
+
r.setEnd(node, i + 1)
|
|
45
|
+
ranges.push(r)
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
rows.forEach((row, n) => {
|
|
49
|
+
if (!row.item) return
|
|
50
|
+
const el = list!.querySelectorAll(':scope > [data-part="row"]')[n]
|
|
51
|
+
const label = el?.querySelector('[data-part="text"]')?.firstChild as Text | null
|
|
52
|
+
const hint = el?.querySelector('[data-part="hint"]')?.firstChild as Text | null
|
|
53
|
+
if (row.item.hits) return mark(label, row.item.hits)
|
|
54
|
+
for (const node of [label, hint]) {
|
|
55
|
+
const text = node?.data.toLowerCase() ?? ''
|
|
56
|
+
for (const w of words) {
|
|
57
|
+
const i = text.indexOf(w)
|
|
58
|
+
if (i >= 0)
|
|
59
|
+
mark(
|
|
60
|
+
node,
|
|
61
|
+
Array.from({ length: w.length }, (_, k) => i + k),
|
|
62
|
+
)
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
})
|
|
66
|
+
win.CSS.highlights.set(HIT, new win.Highlight(...ranges))
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** Writes `value` only if it differs, and hides the node when there is nothing to show. */
|
|
70
|
+
const put = (el: HTMLElement, value: string | undefined) => {
|
|
71
|
+
el.hidden = !value
|
|
72
|
+
if (value && el.textContent !== value) el.textContent = value
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** One row of the pool. Everything but the active mark is one write pass per change of row, so a list costs little to open. */
|
|
76
|
+
export function Slot({
|
|
77
|
+
row,
|
|
78
|
+
id,
|
|
79
|
+
active,
|
|
80
|
+
onPick,
|
|
81
|
+
onHover,
|
|
82
|
+
}: {
|
|
83
|
+
row: () => Row | undefined
|
|
84
|
+
id: string
|
|
85
|
+
active: () => number
|
|
86
|
+
onPick: (at: number) => void
|
|
87
|
+
onHover: (at: number) => void
|
|
88
|
+
}) {
|
|
89
|
+
const r = derived(() => row())
|
|
90
|
+
const at = () => untrack(() => r.value?.at ?? -1)
|
|
91
|
+
let box!: HTMLElement,
|
|
92
|
+
head!: HTMLElement,
|
|
93
|
+
option!: HTMLElement,
|
|
94
|
+
text!: HTMLElement,
|
|
95
|
+
hint!: HTMLElement,
|
|
96
|
+
keys!: HTMLElement
|
|
97
|
+
const view = (
|
|
98
|
+
<div ref={(n) => (box = n)} data-part="row" role="presentation" hidden="">
|
|
99
|
+
<div ref={(n) => (head = n)} data-part="group-label" role="presentation" hidden=""></div>
|
|
100
|
+
<div
|
|
101
|
+
ref={(n) => (option = n)}
|
|
102
|
+
data-part="item"
|
|
103
|
+
hidden=""
|
|
104
|
+
aria-selected={r.value?.item ? (r.value.at === active() ? 'true' : 'false') : undefined}
|
|
105
|
+
onPointerMove={() => {
|
|
106
|
+
if (at() !== active()) onHover(at())
|
|
107
|
+
}}
|
|
108
|
+
onClick={() => onPick(at())}
|
|
109
|
+
>
|
|
110
|
+
{r.value?.item?.icon && <Icon name={r.value?.item?.icon} />}
|
|
111
|
+
<span ref={(n) => (text = n)} data-part="text"></span>
|
|
112
|
+
<span ref={(n) => (hint = n)} data-part="hint" hidden=""></span>
|
|
113
|
+
<span ref={(n) => (keys = n)} data-part="shortcut" hidden=""></span>
|
|
114
|
+
</div>
|
|
115
|
+
</div>
|
|
116
|
+
)
|
|
117
|
+
effect(
|
|
118
|
+
() => r.value,
|
|
119
|
+
(v) => {
|
|
120
|
+
const item = v?.item
|
|
121
|
+
box.hidden = !v
|
|
122
|
+
put(head, v?.head)
|
|
123
|
+
option.hidden = !item
|
|
124
|
+
if (item) {
|
|
125
|
+
option.setAttribute('role', 'option')
|
|
126
|
+
option.id = `${id}-${v.at}`
|
|
127
|
+
} else {
|
|
128
|
+
option.removeAttribute('role')
|
|
129
|
+
option.removeAttribute('id')
|
|
130
|
+
}
|
|
131
|
+
text.textContent = item?.label ?? ''
|
|
132
|
+
put(hint, item?.hint)
|
|
133
|
+
put(keys, item?.shortcut)
|
|
134
|
+
},
|
|
135
|
+
)
|
|
136
|
+
return view
|
|
137
|
+
}
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import { SearchIcon } from '@kerf-js/veneer-icons'
|
|
2
|
+
import { untrack } from '@kerf-js/core'
|
|
3
|
+
import type { Openable } from './bind'
|
|
4
|
+
import type { IconRef } from './Icon'
|
|
5
|
+
import { Slot } from './CommandPalette-rows'
|
|
6
|
+
import { paletteController } from './CommandPalette-controller'
|
|
7
|
+
import { Kbd } from './Kbd'
|
|
8
|
+
import './styles'
|
|
9
|
+
import '@kerf-js/veneer-core/styles/components/dialog.css'
|
|
10
|
+
import '@kerf-js/veneer-core/styles/components/menu.css'
|
|
11
|
+
import '@kerf-js/veneer-core/styles/components/command-palette.css'
|
|
12
|
+
import '@kerf-js/veneer-core/styles/components/palette-motion.css'
|
|
13
|
+
|
|
14
|
+
/** One entry the palette can run or drill into. */
|
|
15
|
+
export interface Command {
|
|
16
|
+
/** Stable key for the row; the label is used when it is left out. */
|
|
17
|
+
id?: string
|
|
18
|
+
/** The row's words, searched by fuzzy letters. */
|
|
19
|
+
label: string
|
|
20
|
+
/** Rows gather under their group's heading. */
|
|
21
|
+
group?: string
|
|
22
|
+
/** A glyph before the label. */
|
|
23
|
+
icon?: IconRef
|
|
24
|
+
/** Keys shown at the row's end, like "⌘N". Shown only: binding the key is the app's. */
|
|
25
|
+
shortcut?: string
|
|
26
|
+
/** Quiet text at the row's end: where it lives, or the words that matched. */
|
|
27
|
+
hint?: string
|
|
28
|
+
/** More words it answers to. */
|
|
29
|
+
keywords?: string[]
|
|
30
|
+
/** Letters of `label` to mark, from `rankCommands`. A source's rows mark what the query matched without it. */
|
|
31
|
+
hits?: number[]
|
|
32
|
+
/** Where it goes. ⌘Enter opens this in a new tab. */
|
|
33
|
+
href?: string
|
|
34
|
+
/** → on the row, or picking a row with no `run`, shows these in the same list. */
|
|
35
|
+
children?: () => Command[]
|
|
36
|
+
/** The name of the list `children` opens ("Region"), shown before the query while you're in it. The label without it. */
|
|
37
|
+
title?: string
|
|
38
|
+
/** What picking the row does. It runs after the palette has closed, so what it opens takes focus. */
|
|
39
|
+
run?: () => void
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Results for a query. Return an array to answer in the same frame; return a promise and its rows land below what's
|
|
44
|
+
* showing, without moving the active row. The signal aborts when the query has changed.
|
|
45
|
+
*/
|
|
46
|
+
export type CommandSource = (query: string, signal: AbortSignal) => Command[] | Promise<Command[]>
|
|
47
|
+
|
|
48
|
+
/** What a first character changes to: `>` for commands, `@` for one kind of thing. */
|
|
49
|
+
export interface CommandMode {
|
|
50
|
+
/** The first characters that switch to this mode, like ">" or "@". */
|
|
51
|
+
prefix: string
|
|
52
|
+
/** The mode's name, shown in the input row while it is on. */
|
|
53
|
+
label: string
|
|
54
|
+
/** The input's placeholder while the mode is on. */
|
|
55
|
+
placeholder?: string
|
|
56
|
+
/** The rows searched in this mode, in place of the palette's `commands`. */
|
|
57
|
+
commands?: Command[]
|
|
58
|
+
/** Searched as you type in this mode, after its `commands`. */
|
|
59
|
+
sources?: CommandSource[]
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Props for CommandPalette. */
|
|
63
|
+
export type CommandPaletteProps = Openable & {
|
|
64
|
+
/** The rows searched as you type, grouped by their `group`. */
|
|
65
|
+
commands?: Command[]
|
|
66
|
+
/** Searched as you type, after `commands`. */
|
|
67
|
+
sources?: CommandSource[]
|
|
68
|
+
/** Prefixes that switch what is searched: `>` for commands, `@` for people. */
|
|
69
|
+
modes?: CommandMode[]
|
|
70
|
+
/** The order groups show in, whatever order rows arrive. Groups not named follow. */
|
|
71
|
+
groupOrder?: string[]
|
|
72
|
+
/** Hears every command run, however it was picked. */
|
|
73
|
+
onRun?: (command: Command, reason: 'pointer' | 'keyboard') => void
|
|
74
|
+
/** The dialog's accessible name, and the input's label. */
|
|
75
|
+
label?: string
|
|
76
|
+
/** The input's placeholder when no mode is on. */
|
|
77
|
+
placeholder?: string
|
|
78
|
+
/** The key that opens it with ⌘ or Ctrl. `false` leaves opening to the app. */
|
|
79
|
+
hotkey?: string | false
|
|
80
|
+
/** `/` opens it too, outside a field. */
|
|
81
|
+
slash?: boolean | undefined
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function PaletteInput({
|
|
85
|
+
model,
|
|
86
|
+
label,
|
|
87
|
+
placeholder,
|
|
88
|
+
}: {
|
|
89
|
+
model: ReturnType<typeof paletteController>
|
|
90
|
+
label: string
|
|
91
|
+
placeholder: string
|
|
92
|
+
}) {
|
|
93
|
+
const { refs, id, crumb, mode, items, active, up, onInput, onKey } = model
|
|
94
|
+
return (
|
|
95
|
+
<div data-part="input-row" data-sweep="">
|
|
96
|
+
<span data-part="sweep-base" aria-hidden="true"></span>
|
|
97
|
+
<span data-part="sweep" aria-hidden="true"></span>
|
|
98
|
+
<SearchIcon />
|
|
99
|
+
<label for={`${id}-in`} data-part="sr-only">
|
|
100
|
+
{crumb.value ? `${label}, ${crumb.value}` : label}
|
|
101
|
+
</label>
|
|
102
|
+
{crumb.value && (
|
|
103
|
+
<button
|
|
104
|
+
type="button"
|
|
105
|
+
data-part="crumb"
|
|
106
|
+
tabindex="-1"
|
|
107
|
+
aria-label={`Back from ${crumb.value}`}
|
|
108
|
+
onClick={up}
|
|
109
|
+
>
|
|
110
|
+
{crumb.value}
|
|
111
|
+
<span aria-hidden="true">›</span>
|
|
112
|
+
</button>
|
|
113
|
+
)}
|
|
114
|
+
<input
|
|
115
|
+
ref={(n) => (refs.input = n)}
|
|
116
|
+
data-initial=""
|
|
117
|
+
data-part="input"
|
|
118
|
+
id={`${id}-in`}
|
|
119
|
+
role="combobox"
|
|
120
|
+
aria-expanded="true"
|
|
121
|
+
aria-controls={`${id}-list`}
|
|
122
|
+
aria-autocomplete="list"
|
|
123
|
+
aria-activedescendant={items.value.length ? `${id}-${active.value}` : undefined}
|
|
124
|
+
placeholder={
|
|
125
|
+
crumb.value ? `Search ${crumb.value}…` : (mode.value?.placeholder ?? placeholder)
|
|
126
|
+
}
|
|
127
|
+
autocomplete="off"
|
|
128
|
+
spellcheck={false}
|
|
129
|
+
onInput={onInput}
|
|
130
|
+
onKeyDown={onKey}
|
|
131
|
+
/>
|
|
132
|
+
{mode.value ? <span data-part="mode">{mode.value.label}</span> : <Kbd>esc</Kbd>}
|
|
133
|
+
</div>
|
|
134
|
+
)
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* The command palette (05 §3; components.html:1109-1113, 1704-1754): an APG combobox in a modal <dialog>. Focus stays in
|
|
139
|
+
* the input. ↑/↓, Home/End and PageUp/PageDown move the active row, Tab goes to the next group, → opens a row's `children`,
|
|
140
|
+
* Enter runs it, ⌘Enter opens its `href` in a new tab. Esc clears the query, then closes and returns focus. A nested level
|
|
141
|
+
* opens and closes (← at the query's start, or Esc once it is empty) with an empty query, and typing there filters its rows.
|
|
142
|
+
*
|
|
143
|
+
* Rows are a pool that only grows: a key press writes text into nodes that already exist, so a query never builds a row
|
|
144
|
+
* and nothing shifts. Matches are painted with the Custom Highlight API. Rows appear only while it's open, so a closed
|
|
145
|
+
* palette costs a page one empty dialog.
|
|
146
|
+
*/
|
|
147
|
+
export function CommandPalette(props: CommandPaletteProps) {
|
|
148
|
+
const { label = 'Command palette', placeholder = 'Search or run a command…' } = props
|
|
149
|
+
const model = paletteController(untrack(() => props))
|
|
150
|
+
const { refs, id, flag, typed, active, rows, items, pending, result, slots, run } = model
|
|
151
|
+
return (
|
|
152
|
+
<dialog ref={(n) => (refs.el = n)} data-scope="palette" aria-label={label}>
|
|
153
|
+
<PaletteInput model={model} label={label} placeholder={placeholder} />
|
|
154
|
+
<div
|
|
155
|
+
ref={(n) => (refs.list = n)}
|
|
156
|
+
data-part="list"
|
|
157
|
+
role="listbox"
|
|
158
|
+
id={`${id}-list`}
|
|
159
|
+
aria-label="Commands"
|
|
160
|
+
>
|
|
161
|
+
<span ref={(n) => (refs.face = n)} data-part="shuttle" aria-hidden="true"></span>
|
|
162
|
+
{slots.value.map((i) => (
|
|
163
|
+
<Slot
|
|
164
|
+
key={i}
|
|
165
|
+
id={id}
|
|
166
|
+
row={() => rows.value[i]}
|
|
167
|
+
active={() => active.value}
|
|
168
|
+
onPick={(at) => run(at, 'pointer')}
|
|
169
|
+
onHover={(at) => (active.value = at)}
|
|
170
|
+
/>
|
|
171
|
+
))}
|
|
172
|
+
</div>
|
|
173
|
+
{flag.value && !items.value.length && !pending.value && (
|
|
174
|
+
<div data-part="empty">{`Nothing matches “${typed.value}”.`}</div>
|
|
175
|
+
)}
|
|
176
|
+
<span data-part="sr-only" role="status">
|
|
177
|
+
{result.value}
|
|
178
|
+
</span>
|
|
179
|
+
<div data-part="footer" aria-hidden="true">
|
|
180
|
+
<span>
|
|
181
|
+
<Kbd>↑</Kbd>
|
|
182
|
+
<Kbd>↓</Kbd> move
|
|
183
|
+
</span>
|
|
184
|
+
<span>
|
|
185
|
+
<Kbd>tab</Kbd> group
|
|
186
|
+
</span>
|
|
187
|
+
<span>
|
|
188
|
+
<Kbd>↵</Kbd> open
|
|
189
|
+
</span>
|
|
190
|
+
<span>
|
|
191
|
+
<Kbd>esc</Kbd> close
|
|
192
|
+
</span>
|
|
193
|
+
</div>
|
|
194
|
+
</dialog>
|
|
195
|
+
)
|
|
196
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
// Editing, filters and saved view actions for a grid.
|
|
2
|
+
import { moved, toCSV } from '@kerf-js/veneer-core'
|
|
3
|
+
import { derived } from '@kerf-js/core'
|
|
4
|
+
import type { DataGridProps, GridColumn, GridPaste } from './DataGrid'
|
|
5
|
+
import { shownText } from './DataGrid-rows'
|
|
6
|
+
import type { GridState, GridLines } from './DataGrid-model'
|
|
7
|
+
|
|
8
|
+
export function gridEditing<T>(
|
|
9
|
+
props: DataGridProps<T>,
|
|
10
|
+
st: GridState<T>,
|
|
11
|
+
ln: GridLines<T>,
|
|
12
|
+
say: (s: string) => void,
|
|
13
|
+
) {
|
|
14
|
+
const { current, change, all, refs, cols } = st
|
|
15
|
+
const { lines } = ln
|
|
16
|
+
const reorder = (col: string, to: number) => {
|
|
17
|
+
const order = current.value.order.filter((k) => !current.value.hidden.includes(k))
|
|
18
|
+
const placed = moved(order, col, to)
|
|
19
|
+
change({
|
|
20
|
+
order: [...placed, ...current.value.order.filter((k) => current.value.hidden.includes(k))],
|
|
21
|
+
})
|
|
22
|
+
const c = all.value.find((x) => x.id === col)
|
|
23
|
+
say(`${c?.header} moved to column ${placed.indexOf(col) + 1} of ${placed.length}`)
|
|
24
|
+
queueMicrotask(() =>
|
|
25
|
+
refs.el?.querySelector<HTMLElement>(`thead th[data-col="${col}"] button`)?.focus(),
|
|
26
|
+
)
|
|
27
|
+
}
|
|
28
|
+
const paste = (cell: HTMLElement, matrix: string[][]) => {
|
|
29
|
+
const flat = lines.value.filter((l) => l.kind === 'row')
|
|
30
|
+
const startRow = flat.findIndex((l) => l.id === cell.parentElement!.dataset.row)
|
|
31
|
+
const startCol = cols.value.findIndex((c) => c.id === cell.dataset.col)
|
|
32
|
+
const changes: GridPaste<T>[] = []
|
|
33
|
+
let refused = 0
|
|
34
|
+
matrix.forEach((line, r) =>
|
|
35
|
+
line.forEach((text, c) => {
|
|
36
|
+
const row = flat[startRow + r],
|
|
37
|
+
col = cols.value[startCol + c]
|
|
38
|
+
if (!row || !col?.edit) return void refused++
|
|
39
|
+
const value = typeof col.edit === 'function' ? col.edit(text) : text
|
|
40
|
+
if ((col.validate?.(value) ?? true) !== true) return void refused++
|
|
41
|
+
changes.push({ row: row.row, column: col.id, value })
|
|
42
|
+
}),
|
|
43
|
+
)
|
|
44
|
+
if (changes.length) {
|
|
45
|
+
if (props.onPaste) props.onPaste(changes)
|
|
46
|
+
else for (const x of changes) props.onEdit?.(x.row, x.column, x.value)
|
|
47
|
+
}
|
|
48
|
+
say(
|
|
49
|
+
`Pasted ${changes.length} ${changes.length === 1 ? 'cell' : 'cells'}${refused ? `, ${refused} refused` : ''}`,
|
|
50
|
+
)
|
|
51
|
+
}
|
|
52
|
+
return { reorder, paste }
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function gridViewActions<T>(
|
|
56
|
+
props: DataGridProps<T>,
|
|
57
|
+
st: GridState<T>,
|
|
58
|
+
ln: GridLines<T>,
|
|
59
|
+
say: (s: string) => void,
|
|
60
|
+
) {
|
|
61
|
+
const { current, change, all, at, saved, named, closed, cols, read } = st
|
|
62
|
+
const { visible } = ln
|
|
63
|
+
const toggleHidden = (c: GridColumn<T>, on: boolean) =>
|
|
64
|
+
change({
|
|
65
|
+
hidden: on ? current.value.hidden.filter((x) => x !== c.id) : [...current.value.hidden, c.id],
|
|
66
|
+
})
|
|
67
|
+
const askSort = (c: GridColumn<T>) => {
|
|
68
|
+
const s = current.value.sort
|
|
69
|
+
change({
|
|
70
|
+
sort: { id: c.id, dir: s?.id === c.id && s.dir === 'ascending' ? 'descending' : 'ascending' },
|
|
71
|
+
})
|
|
72
|
+
}
|
|
73
|
+
const setFilter = (k: string, v: string) => {
|
|
74
|
+
at.value = 1
|
|
75
|
+
const f = { ...current.value.filters }
|
|
76
|
+
if (v) f[k] = v
|
|
77
|
+
else delete f[k]
|
|
78
|
+
change({ filters: f })
|
|
79
|
+
}
|
|
80
|
+
const applied = derived(() =>
|
|
81
|
+
Object.entries(current.value.filters).map(([k, v]) => ({
|
|
82
|
+
k,
|
|
83
|
+
v,
|
|
84
|
+
c: all.value.find((x) => x.id === k),
|
|
85
|
+
})),
|
|
86
|
+
)
|
|
87
|
+
const opOf = (c?: GridColumn<T>) => (c?.filter === 'min' ? '≥' : c?.filter === 'text' ? '~' : '=')
|
|
88
|
+
|
|
89
|
+
const save = () => {
|
|
90
|
+
const name = `My view ${Object.keys(saved.value).filter((k) => k.startsWith('My view')).length + 1}`
|
|
91
|
+
saved.value = { ...saved.value, [name]: structuredClone(current.value) }
|
|
92
|
+
named.value = name
|
|
93
|
+
props.onSaveView?.(name, current.value)
|
|
94
|
+
say(`Saved “${name}”`)
|
|
95
|
+
}
|
|
96
|
+
const useView = (name: string) => {
|
|
97
|
+
const v = saved.value[name]
|
|
98
|
+
if (!v) return
|
|
99
|
+
named.value = name
|
|
100
|
+
closed.value = {}
|
|
101
|
+
at.value = 1
|
|
102
|
+
current.value = structuredClone(v)
|
|
103
|
+
}
|
|
104
|
+
const download = () => {
|
|
105
|
+
const shown = cols.value
|
|
106
|
+
const csv = toCSV(
|
|
107
|
+
shown.map((c) => c.header),
|
|
108
|
+
visible.value.map((r) => shown.map((c) => shownText(c, read(c, r)))),
|
|
109
|
+
)
|
|
110
|
+
const a = document.createElement('a')
|
|
111
|
+
a.href = URL.createObjectURL(new Blob([csv], { type: 'text/csv' }))
|
|
112
|
+
a.download = `${props.exportName === undefined ? 'export' : props.exportName}.csv`
|
|
113
|
+
a.click()
|
|
114
|
+
setTimeout(() => URL.revokeObjectURL(a.href), 1000)
|
|
115
|
+
say(`Exported ${visible.value.length} rows`)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return { toggleHidden, askSort, setFilter, applied, opOf, save, useView, download }
|
|
119
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// Keyed body rows and aggregate footer.
|
|
2
|
+
import { GridRow, GroupRow, total } from './DataGrid-rows'
|
|
3
|
+
import { chevron } from './Table'
|
|
4
|
+
import type { GridModel } from './DataGrid-controller'
|
|
5
|
+
|
|
6
|
+
export function GridBody<T>({ model }: { model: GridModel<T> }) {
|
|
7
|
+
return (
|
|
8
|
+
<tbody>
|
|
9
|
+
{model.lines.value.map((l) =>
|
|
10
|
+
l.kind === 'row' ? (
|
|
11
|
+
<GridRow key={l.id} line={l} ctx={model.ctx} />
|
|
12
|
+
) : l.kind === 'group' ? (
|
|
13
|
+
<GroupRow key={l.id} line={l} ctx={model.ctx} />
|
|
14
|
+
) : (
|
|
15
|
+
<tr
|
|
16
|
+
key={l.id}
|
|
17
|
+
role="row"
|
|
18
|
+
data-part="loading"
|
|
19
|
+
aria-level={l.level}
|
|
20
|
+
style={`--_lvl:${l.level}${l.tint ? `;--_bc:var(--veneer-color-data-${l.tint})` : ''}`}
|
|
21
|
+
>
|
|
22
|
+
<td role="gridcell" data-part="tree-cell" colspan={model.ctx.span()}>
|
|
23
|
+
<span data-part="tree-label">
|
|
24
|
+
<span data-part="toggle" data-leaf="" aria-hidden="true">
|
|
25
|
+
{chevron()}
|
|
26
|
+
</span>
|
|
27
|
+
{`Loading ${l.label}…`}
|
|
28
|
+
<span data-part="skeleton" aria-hidden="true"></span>
|
|
29
|
+
</span>
|
|
30
|
+
</td>
|
|
31
|
+
</tr>
|
|
32
|
+
),
|
|
33
|
+
)}
|
|
34
|
+
</tbody>
|
|
35
|
+
)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function GridAggregate<T>({ model }: { model: GridModel<T> }) {
|
|
39
|
+
return (
|
|
40
|
+
<tfoot>
|
|
41
|
+
<tr role="row" data-part="aggregate">
|
|
42
|
+
{model.hasDetails && <td role="gridcell"></td>}
|
|
43
|
+
{model.cols.value.map((c, n) => (
|
|
44
|
+
<td
|
|
45
|
+
key={c.id}
|
|
46
|
+
role="gridcell"
|
|
47
|
+
data-numeric={c.numeric ? '' : undefined}
|
|
48
|
+
data-pinned={c.pin ? 'last' : undefined}
|
|
49
|
+
>
|
|
50
|
+
{n === 0 && !c.aggregate
|
|
51
|
+
? `${model.footed.value.length} ${model.footed.value.length === 1 ? 'row' : 'rows'}`
|
|
52
|
+
: total(c, model.footed.value, model.read)}
|
|
53
|
+
</td>
|
|
54
|
+
))}
|
|
55
|
+
</tr>
|
|
56
|
+
</tfoot>
|
|
57
|
+
)
|
|
58
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
// Connect the grid model to its DOM behaviours.
|
|
2
|
+
import { grid, table, type GridOptions } from '@kerf-js/veneer-core'
|
|
3
|
+
import { derived, untrack } from '@kerf-js/core'
|
|
4
|
+
import { use } from '@kerf-js/veneer-core/kerf'
|
|
5
|
+
import type { DataGridProps } from './DataGrid'
|
|
6
|
+
import type { Ctx } from './DataGrid-rows'
|
|
7
|
+
import {
|
|
8
|
+
gridState,
|
|
9
|
+
gridSource,
|
|
10
|
+
gridLines,
|
|
11
|
+
type GridState,
|
|
12
|
+
type GridSource,
|
|
13
|
+
type GridLines,
|
|
14
|
+
} from './DataGrid-model'
|
|
15
|
+
import { gridTreeActions } from './DataGrid-tree'
|
|
16
|
+
import { gridEditing, gridViewActions } from './DataGrid-actions'
|
|
17
|
+
|
|
18
|
+
function gridContext<T>({
|
|
19
|
+
props,
|
|
20
|
+
st,
|
|
21
|
+
src,
|
|
22
|
+
isOpen,
|
|
23
|
+
toggle,
|
|
24
|
+
hasDetails,
|
|
25
|
+
say,
|
|
26
|
+
}: {
|
|
27
|
+
props: DataGridProps<T>
|
|
28
|
+
st: GridState<T>
|
|
29
|
+
src: GridSource<T>
|
|
30
|
+
isOpen: (key: string) => boolean
|
|
31
|
+
toggle: (key: string, on?: boolean) => void
|
|
32
|
+
hasDetails: boolean
|
|
33
|
+
say: (s: string) => void
|
|
34
|
+
}) {
|
|
35
|
+
const { id, all, cols, keyOf, read, query, expanded, refs, busy } = st
|
|
36
|
+
const { treed, kidsOf, rolled } = src
|
|
37
|
+
const namedCol = derived(() => all.value.find((c) => c.rowHeader) ?? all.value[0])
|
|
38
|
+
const ctx: Ctx<T> = {
|
|
39
|
+
id,
|
|
40
|
+
cols: () => cols.value,
|
|
41
|
+
keyOf,
|
|
42
|
+
read,
|
|
43
|
+
treed: () => treed.value,
|
|
44
|
+
get tree() {
|
|
45
|
+
return props.tree
|
|
46
|
+
},
|
|
47
|
+
kidsOf,
|
|
48
|
+
title: (r) => String((read(namedCol.value!, r) as string | number | null | undefined) ?? ''),
|
|
49
|
+
query: () => query.value.trim(),
|
|
50
|
+
rolled,
|
|
51
|
+
commit: (r, c, v) => props.onEdit?.(r, c, v),
|
|
52
|
+
toggle,
|
|
53
|
+
editors: new Map(),
|
|
54
|
+
status: say,
|
|
55
|
+
expanded,
|
|
56
|
+
hasDetails,
|
|
57
|
+
body: (r) => props.expand?.(r),
|
|
58
|
+
flip: (k) => {
|
|
59
|
+
const { [k]: was, ...rest } = expanded.value
|
|
60
|
+
expanded.value = was ? rest : { ...rest, [k]: true }
|
|
61
|
+
},
|
|
62
|
+
refocus: () => refs.behaviour?.refocus(),
|
|
63
|
+
span: () => cols.value.length + (hasDetails ? 1 : 0),
|
|
64
|
+
expandedTree: isOpen,
|
|
65
|
+
busy: (k) => !!(busy.get(k) as boolean | undefined),
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return ctx
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function gridConnect<T>({
|
|
72
|
+
st,
|
|
73
|
+
src,
|
|
74
|
+
ln,
|
|
75
|
+
ctx,
|
|
76
|
+
toggle,
|
|
77
|
+
editing,
|
|
78
|
+
say,
|
|
79
|
+
}: {
|
|
80
|
+
st: GridState<T>
|
|
81
|
+
src: GridSource<T>
|
|
82
|
+
ln: GridLines<T>
|
|
83
|
+
ctx: Ctx<T>
|
|
84
|
+
toggle: (key: string, on?: boolean) => void
|
|
85
|
+
editing: ReturnType<typeof gridEditing<T>>
|
|
86
|
+
say: (s: string) => void
|
|
87
|
+
}) {
|
|
88
|
+
const { refs, cols, picked } = st
|
|
89
|
+
const { treed } = src
|
|
90
|
+
const { lines } = ln
|
|
91
|
+
const { reorder, paste } = editing
|
|
92
|
+
use(
|
|
93
|
+
table,
|
|
94
|
+
() => refs.el,
|
|
95
|
+
() => ({ hidden: [], rows: lines.value }),
|
|
96
|
+
)
|
|
97
|
+
use(
|
|
98
|
+
(node: HTMLDivElement, o: GridOptions) => {
|
|
99
|
+
const g = grid(node, o)
|
|
100
|
+
refs.behaviour = g
|
|
101
|
+
return g
|
|
102
|
+
},
|
|
103
|
+
() => refs.el,
|
|
104
|
+
() => ({
|
|
105
|
+
tree: treed.value,
|
|
106
|
+
rows: [lines.value, cols.value],
|
|
107
|
+
onEdit: (c: HTMLElement) => ctx.editors.get(c)?.(),
|
|
108
|
+
onToggle: (r: HTMLElement, on: boolean) => toggle(r.dataset.row!, on),
|
|
109
|
+
onReorder: reorder,
|
|
110
|
+
onSelect: (r: string[]) => (picked.value = r),
|
|
111
|
+
onStatus: say,
|
|
112
|
+
onPaste: paste,
|
|
113
|
+
}),
|
|
114
|
+
)
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export function gridController<T>(props: DataGridProps<T>) {
|
|
118
|
+
const st = gridState(props)
|
|
119
|
+
const src = gridSource(props, st)
|
|
120
|
+
const ln = gridLines(props, st, src)
|
|
121
|
+
const hasDetails = untrack(() => props.expand !== undefined)
|
|
122
|
+
const say = (s: string) => (st.status.value = s)
|
|
123
|
+
const tree = gridTreeActions({ props, st, src, ln, say, getCtx: () => ctx })
|
|
124
|
+
const ctx: Ctx<T> = gridContext({
|
|
125
|
+
props,
|
|
126
|
+
st,
|
|
127
|
+
src,
|
|
128
|
+
isOpen: tree.isOpen,
|
|
129
|
+
toggle: tree.toggle,
|
|
130
|
+
hasDetails,
|
|
131
|
+
say,
|
|
132
|
+
})
|
|
133
|
+
const editing = gridEditing(props, st, ln, say)
|
|
134
|
+
const views = gridViewActions(props, st, ln, say)
|
|
135
|
+
|
|
136
|
+
gridConnect({ st, src, ln, ctx, toggle: tree.toggle, editing, say })
|
|
137
|
+
const hint = () =>
|
|
138
|
+
`Arrows move · Shift extends · ${st.all.value.some((c) => c.edit) ? 'Enter edits · ' : ''}⌘/Ctrl C copies`
|
|
139
|
+
const hasAggregate = derived(() => st.all.value.some((c) => c.aggregate))
|
|
140
|
+
const chosen = () => st.picked.value.filter((k) => !k.startsWith('g:'))
|
|
141
|
+
return { ...st, ...src, ...ln, ...tree, ...views, ctx, hasDetails, hint, hasAggregate, chosen }
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** The per-instance grid model used by its views. */
|
|
145
|
+
export type GridModel<T> = ReturnType<typeof gridController<T>>
|