@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,316 @@
|
|
|
1
|
+
// `veneer({ colors, system, parts, themes })`: names colours once, restyles any part in any state, and ships named
|
|
2
|
+
// themes that switch at runtime (`data-palette`, `setDial('palette', name)`). Everything here is emitted only when the
|
|
3
|
+
// app configures it, so an app that sets nothing gets exactly veneer's own CSS. No Node here: a browser can run it too
|
|
4
|
+
// (`@kerf-js/veneer/theme`), given the stylesheet facts theme-context.mjs reads.
|
|
5
|
+
import { contrast, fromHex, toLinear } from '../../tokens/color.mjs'
|
|
6
|
+
import { themeCss } from './theme-css.mjs'
|
|
7
|
+
import { PARTS, STATES, allParts, propsOf, statesOf } from './theme-parts.mjs'
|
|
8
|
+
import { motionNames, motionRef, motionToken, motionValue } from './theme-motion.mjs'
|
|
9
|
+
import { textTokens } from './theme-text.mjs'
|
|
10
|
+
import { NAME, bad, fontValue, plain, px, safe } from './theme-values.mjs'
|
|
11
|
+
|
|
12
|
+
const BUILTIN = new Set(['white', 'black', 'transparent', 'currentColor', 'inherit'])
|
|
13
|
+
const VENEER_COLORS = [
|
|
14
|
+
'page',
|
|
15
|
+
'surface',
|
|
16
|
+
'surface-raised',
|
|
17
|
+
'surface-sunken',
|
|
18
|
+
'text',
|
|
19
|
+
'text-subtle',
|
|
20
|
+
'text-faint',
|
|
21
|
+
'border',
|
|
22
|
+
'border-strong',
|
|
23
|
+
'accent-solid',
|
|
24
|
+
'accent-soft',
|
|
25
|
+
'accent-text',
|
|
26
|
+
'accent-border',
|
|
27
|
+
'focus',
|
|
28
|
+
'sweep',
|
|
29
|
+
]
|
|
30
|
+
const SPACE = ['hair', 'tight', 'related', 'group', 'section', 'page']
|
|
31
|
+
const RADIUS = {
|
|
32
|
+
control: 'control',
|
|
33
|
+
surface: 'surface',
|
|
34
|
+
mark: 'mark',
|
|
35
|
+
round: 'round',
|
|
36
|
+
pill: null,
|
|
37
|
+
none: null,
|
|
38
|
+
}
|
|
39
|
+
const SHADOW = { none: 'none', 0: 0, 1: 1, 2: 2, 3: 3, sm: 1, md: 2, lg: 3 }
|
|
40
|
+
const SYSTEM = {
|
|
41
|
+
radius: (k) => RADIUS[k] !== undefined && RADIUS[k] !== null && `--veneer-radius-${k}`,
|
|
42
|
+
space: (k) => SPACE.includes(k) && `--veneer-space-${k}`,
|
|
43
|
+
pad: (k) => ['control', 'surface'].includes(k) && `--veneer-pad-${k}`,
|
|
44
|
+
control: (k) => ['sm', 'md', 'lg'].includes(k) && `--veneer-control-${k}`,
|
|
45
|
+
font: (k) => ['sans', 'display', 'mono'].includes(k) && `--veneer-font-${k}`,
|
|
46
|
+
shadow: (k) =>
|
|
47
|
+
SHADOW[k] !== undefined && typeof SHADOW[k] === 'number' && `--veneer-elevation-${SHADOW[k]}`,
|
|
48
|
+
border: (k) => ['hairline', 'emphasis'].includes(k) && `--veneer-border-${k}`,
|
|
49
|
+
icon: (k) => ['sm', 'md', 'stroke'].includes(k) && `--veneer-icon-${k}`,
|
|
50
|
+
}
|
|
51
|
+
const UNITLESS = new Set(['weight', 'leading', 'stroke'])
|
|
52
|
+
|
|
53
|
+
export { bad }
|
|
54
|
+
|
|
55
|
+
// -- reading values ------------------------------------------------------------------------------------------------
|
|
56
|
+
|
|
57
|
+
/** A colour value as CSS: a configured name reads its variable, so a theme that renames it repaints every use. */
|
|
58
|
+
function colorValue(value, colors, path) {
|
|
59
|
+
if (typeof value !== 'string' || !safe(value))
|
|
60
|
+
throw bad(path, 'must be a colour name or a CSS colour')
|
|
61
|
+
if (colors.has(value)) return `var(--veneer-color-${value})`
|
|
62
|
+
if (VENEER_COLORS.includes(value)) return `var(--veneer-color-${value})`
|
|
63
|
+
if (
|
|
64
|
+
BUILTIN.has(value) ||
|
|
65
|
+
/^(#[0-9a-f]{3,8}|(rgb|hsl|oklch|oklab|lab|lch|color|color-mix|light-dark|var)\()/i.test(value)
|
|
66
|
+
)
|
|
67
|
+
return value
|
|
68
|
+
throw bad(path, `unknown colour \`${value}\`; name it in \`colors\`, or use #rrggbb`)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const KINDS = {
|
|
72
|
+
color: colorValue,
|
|
73
|
+
length: (v) => px(v),
|
|
74
|
+
space: (v) => (SPACE.includes(v) ? `var(--veneer-space-${v})` : px(v)),
|
|
75
|
+
radius: (v) =>
|
|
76
|
+
v === 'pill'
|
|
77
|
+
? '9999px'
|
|
78
|
+
: v === 'none'
|
|
79
|
+
? '0px'
|
|
80
|
+
: RADIUS[v]
|
|
81
|
+
? `var(--veneer-radius-${v})`
|
|
82
|
+
: px(v),
|
|
83
|
+
shadow: (v) =>
|
|
84
|
+
SHADOW[v] === 'none'
|
|
85
|
+
? 'none'
|
|
86
|
+
: SHADOW[v] !== undefined
|
|
87
|
+
? `var(--veneer-elevation-${SHADOW[v]})`
|
|
88
|
+
: v,
|
|
89
|
+
font: fontValue,
|
|
90
|
+
plain: (v) => String(v),
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** A part's value as CSS. `names` holds the configured colour and motion names. */
|
|
94
|
+
function read(kind, value, names, path) {
|
|
95
|
+
if (kind === 'time' || kind === 'ease') return motionRef(kind, value, { names, at: path })
|
|
96
|
+
if (!safe(value)) throw bad(path, 'must be a CSS value or a number')
|
|
97
|
+
return kind === 'color' ? colorValue(value, names.colors, path) : KINDS[kind](value)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// -- options -------------------------------------------------------------------------------------------------------
|
|
101
|
+
|
|
102
|
+
function checkColors(colors = {}, path) {
|
|
103
|
+
if (!plain(colors)) throw bad(path, 'must be an object of names to colours')
|
|
104
|
+
const out = {}
|
|
105
|
+
for (const [name, value] of Object.entries(colors)) {
|
|
106
|
+
if (!NAME.test(name) || VENEER_COLORS.includes(name) || BUILTIN.has(name))
|
|
107
|
+
throw bad(`${path}.${name}`, 'must be a lowercase name that veneer does not already use')
|
|
108
|
+
if (typeof value !== 'string' || !/^#[0-9a-f]{6}$/i.test(value))
|
|
109
|
+
throw bad(
|
|
110
|
+
`${path}.${name}`,
|
|
111
|
+
'must be #rrggbb (a tone is solved from it, and contrast is checked)',
|
|
112
|
+
)
|
|
113
|
+
out[name] = value.toLowerCase()
|
|
114
|
+
}
|
|
115
|
+
return out
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** `system` as `--veneer-*` declarations, checked against the stylesheet's own token names (`ctx.tokenNames`). */
|
|
119
|
+
function systemTokens(system = {}, ctx, path) {
|
|
120
|
+
if (!plain(system)) throw bad(path, 'must be an object')
|
|
121
|
+
const out = {}
|
|
122
|
+
for (const [group, entries] of Object.entries(system)) {
|
|
123
|
+
if (!plain(entries)) throw bad(`${path}.${group}`, 'must be an object')
|
|
124
|
+
for (const [key, value] of Object.entries(entries)) {
|
|
125
|
+
const at = `${path}.${group}.${key}`
|
|
126
|
+
if (group === 'text') {
|
|
127
|
+
textTokens(key, value, { ...ctx, out, at })
|
|
128
|
+
continue
|
|
129
|
+
}
|
|
130
|
+
if (group === 'duration' || group === 'ease') {
|
|
131
|
+
out[motionToken(group, key, { ...ctx, at })] = motionValue(group, value, at)
|
|
132
|
+
continue
|
|
133
|
+
}
|
|
134
|
+
const token = SYSTEM[group]?.(key)
|
|
135
|
+
if (!token)
|
|
136
|
+
throw bad(
|
|
137
|
+
at,
|
|
138
|
+
SYSTEM[group]
|
|
139
|
+
? 'unknown step'
|
|
140
|
+
: `unknown group; use text, duration, ease, ${Object.keys(SYSTEM).join(', ')}`,
|
|
141
|
+
)
|
|
142
|
+
if (!safe(value)) throw bad(at, 'must be a CSS value or a number')
|
|
143
|
+
out[token] =
|
|
144
|
+
group === 'font' ? KINDS.font(value) : UNITLESS.has(key) ? String(value) : px(value)
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return out
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** Flattens a part's config to `{ key, part, prop, state, target, value }` rows, validating each. */
|
|
151
|
+
function partRows(parts = {}, names, path) {
|
|
152
|
+
if (!plain(parts)) throw bad(path, 'must be an object of parts')
|
|
153
|
+
const specs = new Map(allParts())
|
|
154
|
+
const rows = []
|
|
155
|
+
const walk = (name, config, at) => {
|
|
156
|
+
const spec = specs.get(name)
|
|
157
|
+
if (!spec) throw bad(at, `unknown part; use ${[...specs.keys()].join(', ')}`)
|
|
158
|
+
if (!plain(config)) throw bad(at, 'must be an object')
|
|
159
|
+
const props = propsOf(spec)
|
|
160
|
+
const add = (state, entries, where) => {
|
|
161
|
+
for (const [prop, value] of Object.entries(entries)) {
|
|
162
|
+
const target = props[prop]
|
|
163
|
+
if (!target)
|
|
164
|
+
throw bad(`${where}.${prop}`, `unknown property; use ${Object.keys(props).join(', ')}`)
|
|
165
|
+
rows.push({
|
|
166
|
+
part: name,
|
|
167
|
+
spec,
|
|
168
|
+
prop,
|
|
169
|
+
state,
|
|
170
|
+
target,
|
|
171
|
+
value: read(target.kind, value, names, `${where}.${prop}`),
|
|
172
|
+
})
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
const rest = {}
|
|
176
|
+
for (const [key, value] of Object.entries(config)) {
|
|
177
|
+
if (spec.sub?.[key]) walk(`${name}.${key}`, value, `${at}.${key}`)
|
|
178
|
+
else if (STATES[key]) {
|
|
179
|
+
if (!statesOf(spec).includes(key)) throw bad(`${at}.${key}`, `${name} has no ${key} state`)
|
|
180
|
+
if (!plain(value)) throw bad(`${at}.${key}`, 'must be an object of properties')
|
|
181
|
+
add(key, value, `${at}.${key}`)
|
|
182
|
+
} else rest[key] = value
|
|
183
|
+
}
|
|
184
|
+
add(null, rest, at)
|
|
185
|
+
}
|
|
186
|
+
for (const [name, config] of Object.entries(parts)) walk(name, config, `${path}.${name}`)
|
|
187
|
+
return rows
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/** Validates `colors`, `system`, `parts` and `themes`. `tokenNames` is every `--veneer-*` the stylesheet declares. */
|
|
191
|
+
export function themeOptions(input, tokenNames, checkTheme) {
|
|
192
|
+
const out = {}
|
|
193
|
+
const colors = checkColors(input.colors, 'colors')
|
|
194
|
+
if (Object.keys(colors).length) out.colors = colors
|
|
195
|
+
const names = (c, ...systems) => ({ colors: new Set(Object.keys(c)), ...motionNames(...systems) })
|
|
196
|
+
// the app's own text roles, from the page's system and every theme's: each gets one rule. `media` holds the
|
|
197
|
+
// tokens a breakpoint sets, per scope.
|
|
198
|
+
out.roles = {}
|
|
199
|
+
out.media = {}
|
|
200
|
+
const ctx = { tokenNames, roles: out.roles }
|
|
201
|
+
out.system = systemTokens(input.system, { ...ctx, media: out.media }, 'system')
|
|
202
|
+
out.rows = partRows(input.parts, names(colors, input.system), 'parts')
|
|
203
|
+
out.themes = {}
|
|
204
|
+
if (input.themes !== undefined && !plain(input.themes))
|
|
205
|
+
throw bad('themes', 'must be an object of named themes')
|
|
206
|
+
for (const [name, theme] of Object.entries(input.themes ?? {})) {
|
|
207
|
+
const at = `themes.${name}`
|
|
208
|
+
if (!NAME.test(name) || name === 'auto') throw bad(at, 'must be a lowercase name, not auto')
|
|
209
|
+
if (!plain(theme)) throw bad(at, 'must be an object')
|
|
210
|
+
for (const key of Object.keys(theme))
|
|
211
|
+
if (!['seed', 'colors', 'system', 'parts', 'tokens'].includes(key))
|
|
212
|
+
throw bad(`${at}.${key}`, 'unknown option')
|
|
213
|
+
const own = checkColors(theme.colors, `${at}.colors`)
|
|
214
|
+
const seed =
|
|
215
|
+
theme.seed && checkTheme.seed(theme.seed, `${at}.seed`, { ...input.colors, ...theme.colors })
|
|
216
|
+
const neutral = seed?.neutral
|
|
217
|
+
? {
|
|
218
|
+
'--veneer-ref-neutral-h': seed.neutral.hue,
|
|
219
|
+
'--veneer-ref-neutral-c': seed.neutral.chroma,
|
|
220
|
+
}
|
|
221
|
+
: {}
|
|
222
|
+
const media = {}
|
|
223
|
+
out.themes[name] = {
|
|
224
|
+
seed,
|
|
225
|
+
colors: own,
|
|
226
|
+
system: {
|
|
227
|
+
...neutral,
|
|
228
|
+
...systemTokens(theme.system, { ...ctx, media }, `${at}.system`),
|
|
229
|
+
...checkTheme.tokens(theme.tokens, `${at}.tokens`),
|
|
230
|
+
},
|
|
231
|
+
media,
|
|
232
|
+
rows: partRows(
|
|
233
|
+
theme.parts,
|
|
234
|
+
names({ ...colors, ...own }, input.system, theme.system),
|
|
235
|
+
`${at}.parts`,
|
|
236
|
+
),
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
if (input.default !== undefined && !out.themes[input.default])
|
|
240
|
+
throw bad('dials.palette', 'must name one of `themes`')
|
|
241
|
+
return out
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
// -- contrast ------------------------------------------------------------------------------------------------------
|
|
245
|
+
|
|
246
|
+
const linear = (hex) => {
|
|
247
|
+
const { L, C, H } = fromHex(hex)
|
|
248
|
+
return toLinear({ L, C, H })
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/** D010 for parts: a configured text colour on a configured fill, both known, below 4.5:1 (3:1 for large type). */
|
|
252
|
+
export function partContrast(rows, colors, scope) {
|
|
253
|
+
const hexOf = (v) => {
|
|
254
|
+
const name = /^var\(--veneer-color-([a-z0-9-]+)\)$/.exec(v)?.[1]
|
|
255
|
+
if (v === 'white' || v === 'black') return v === 'white' ? '#ffffff' : '#000000'
|
|
256
|
+
return name ? colors[name] : /^#[0-9a-f]{6}$/i.test(v) ? v : undefined
|
|
257
|
+
}
|
|
258
|
+
const failures = []
|
|
259
|
+
const key = (r) => `${r.part}|${r.state ?? ''}`
|
|
260
|
+
const fills = new Map(rows.filter((r) => r.prop === 'bg').map((r) => [key(r), r]))
|
|
261
|
+
for (const text of rows.filter((r) => r.prop === 'text')) {
|
|
262
|
+
const fill = fills.get(key(text)) ?? fills.get(`${text.part}|`)
|
|
263
|
+
const [fg, bg] = [hexOf(text.value), fill && hexOf(fill.value)]
|
|
264
|
+
if (!fg || !bg) continue
|
|
265
|
+
const ratio = contrast(linear(fg), linear(bg))
|
|
266
|
+
if (ratio < 4.5)
|
|
267
|
+
failures.push(
|
|
268
|
+
`${scope}parts.${text.part}${text.state ? `.${text.state}` : ''}: text ${fg} on ${bg} is ${ratio.toFixed(2)}:1, needs 4.5:1`,
|
|
269
|
+
)
|
|
270
|
+
}
|
|
271
|
+
return failures
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
const safeText = (v) => typeof v === 'string' && v !== '' && !/[;{}<]/.test(v)
|
|
275
|
+
|
|
276
|
+
/** `tokens` (top level or a theme's): `--veneer-*` names with CSS values; colours stay readable by the contrast check. */
|
|
277
|
+
export function checkTokens(tokens, path) {
|
|
278
|
+
for (const [token, value] of Object.entries(tokens ?? {})) {
|
|
279
|
+
if (!/^--veneer-[a-z0-9-]+$/.test(token))
|
|
280
|
+
throw bad(`${path}.${token}`, 'must be a veneer token, like --veneer-color-page')
|
|
281
|
+
if (!safeText(value)) throw bad(`${path}.${token}`, 'must be a CSS value')
|
|
282
|
+
if (
|
|
283
|
+
token.startsWith('--veneer-color-') &&
|
|
284
|
+
!/^(#[0-9a-f]{6}|(oklch|color-mix|light-dark)\(.+\))$/i.test(value)
|
|
285
|
+
)
|
|
286
|
+
throw bad(`${path}.${token}`, 'must be #rrggbb or oklch(), so the contrast check can read it')
|
|
287
|
+
}
|
|
288
|
+
return tokens
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/** The theming CSS, after D010: each named theme's seed and tokens, and every configured text-on-fill pair. */
|
|
292
|
+
export function themed(theme, { context, seed, dials, checkSeed, declare: declareOf }) {
|
|
293
|
+
const failures = partContrast(theme.rows, theme.colors ?? {}, '')
|
|
294
|
+
for (const [name, t] of Object.entries(theme.themes)) {
|
|
295
|
+
failures.push(...partContrast(t.rows, { ...theme.colors, ...t.colors }, `themes.${name}.`))
|
|
296
|
+
if (t.seed || Object.keys(t.system).length) {
|
|
297
|
+
// the same fit a custom page seed gets: the two tightest tokens relit to the default's contrast
|
|
298
|
+
const fit = checkSeed(t.seed ?? seed, declareOf({ seed: t.seed, tokens: t.system }), dials)
|
|
299
|
+
for (const d of fit ? fit.split(';') : []) {
|
|
300
|
+
const at = d.indexOf(':')
|
|
301
|
+
t.system[d.slice(0, at)] = d.slice(at + 1)
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
if (failures.length)
|
|
306
|
+
throw Object.assign(new Error(`veneer part colours fail contrast: ${failures.join('; ')}`), {
|
|
307
|
+
code: 'D010',
|
|
308
|
+
failures,
|
|
309
|
+
help: 'Pick a text colour with more contrast against the fill, or set only one of them.',
|
|
310
|
+
})
|
|
311
|
+
return themeCss(theme, context)
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
export { PARTS }
|
|
315
|
+
export { tailwindTheme, themeCss, toneChannels } from './theme-css.mjs'
|
|
316
|
+
export { normalizeSeed, seedByName } from './seed.mjs'
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { PlusIcon } from '@kerf-js/veneer-icons'
|
|
2
|
+
import type { CalEvent } from '@kerf-js/veneer-core'
|
|
3
|
+
import type { State } from '@kerf-js/core'
|
|
4
|
+
import { Button } from '../Button'
|
|
5
|
+
import { AgendaPage } from './AgendaPage'
|
|
6
|
+
import { AgendaStrip } from './AgendaStrip'
|
|
7
|
+
import { agendaModel } from './AgendaModel'
|
|
8
|
+
import { EventEditor, type CalendarSource } from './EventEditor'
|
|
9
|
+
import { MoveSheet } from './MoveSheet'
|
|
10
|
+
import '@kerf-js/veneer-core/styles/app/agenda.css'
|
|
11
|
+
import '@kerf-js/veneer-core/styles/components/fab.css'
|
|
12
|
+
export * from './AgendaDay'
|
|
13
|
+
|
|
14
|
+
/** Props for Agenda. */
|
|
15
|
+
export type AgendaProps = {
|
|
16
|
+
events: CalEvent[]
|
|
17
|
+
/** The day it opens on: a state it writes as you page, or a plain value. */
|
|
18
|
+
date?: State<string> | string | undefined
|
|
19
|
+
defaultDate?: string | undefined
|
|
20
|
+
/** Called with the new day when you page or jump to today. */
|
|
21
|
+
onDateChange?: ((d: string) => void) | undefined
|
|
22
|
+
title?: unknown
|
|
23
|
+
/** The calendars the events belong to, for their colours and names. */
|
|
24
|
+
calendars?: CalendarSource[] | undefined
|
|
25
|
+
/** The IANA zone times are shown in, such as `Europe/Berlin`. The browser's otherwise. */
|
|
26
|
+
timeZone?: string | undefined
|
|
27
|
+
/** Pins today's date, for server rendering and tests. The browser's clock otherwise. */
|
|
28
|
+
today?: string | undefined
|
|
29
|
+
/** Pins the current time, for server rendering and tests. The browser's clock otherwise. */
|
|
30
|
+
now?: string | undefined
|
|
31
|
+
locale?: string | undefined
|
|
32
|
+
/** `h12` for AM and PM, `h23` for a 24-hour clock. The locale's otherwise. */
|
|
33
|
+
hourCycle?: string | undefined
|
|
34
|
+
firstDayOfWeek?: number | undefined
|
|
35
|
+
/** Long press: open your own sheet. Without it the built-in MoveSheet opens and calls `onMove`. */
|
|
36
|
+
onLongPress?: ((e: CalEvent) => void) | undefined
|
|
37
|
+
onMove?: (e: CalEvent, to: { start: string; end: string; resource?: string | undefined }) => void
|
|
38
|
+
onOpen?: ((e: CalEvent) => void) | undefined
|
|
39
|
+
/** The FAB opens the editor; Save calls this. */
|
|
40
|
+
onCreate?: ((e: CalEvent) => void) | undefined
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* The phone agenda (07 §2.3, `#cal-phone`): a week strip of APG tabs with dots per source, three day pages that swipe, a
|
|
45
|
+
* now marker, "1 h free" gaps and the FAB. A long press (or Shift+F10) opens the MoveSheet.
|
|
46
|
+
*/
|
|
47
|
+
export function Agenda(p: AgendaProps) {
|
|
48
|
+
const model = agendaModel(() => p)
|
|
49
|
+
|
|
50
|
+
return (
|
|
51
|
+
<div ref={model.setRoot} data-scope="agenda" data-part="root">
|
|
52
|
+
<div data-part="app-bar">
|
|
53
|
+
<h3 data-part="app-title">{p.title ?? model.month.value}</h3>
|
|
54
|
+
<span data-part="spacer"></span>
|
|
55
|
+
<Button
|
|
56
|
+
emphasis="outline"
|
|
57
|
+
tone="neutral"
|
|
58
|
+
size="sm"
|
|
59
|
+
onClick={() => model.go(model.env.today.value)}
|
|
60
|
+
>
|
|
61
|
+
Today
|
|
62
|
+
</Button>
|
|
63
|
+
</div>
|
|
64
|
+
<AgendaStrip
|
|
65
|
+
id={model.id}
|
|
66
|
+
week={model.week.value}
|
|
67
|
+
date={model.date.value}
|
|
68
|
+
today={model.env.today.value}
|
|
69
|
+
locale={model.env.locale.value}
|
|
70
|
+
events={p.events}
|
|
71
|
+
onTabs={model.onTabs}
|
|
72
|
+
go={model.go}
|
|
73
|
+
/>
|
|
74
|
+
<div
|
|
75
|
+
ref={model.setView}
|
|
76
|
+
data-part="viewport"
|
|
77
|
+
id={`${model.id}-panel`}
|
|
78
|
+
role="tabpanel"
|
|
79
|
+
aria-labelledby={`${model.id}-${model.date.value}`}
|
|
80
|
+
onKeyDown={model.onKey}
|
|
81
|
+
onClick={model.onClick}
|
|
82
|
+
>
|
|
83
|
+
<div ref={model.setTrack} data-part="track">
|
|
84
|
+
{model.pages.value.map((g) => (
|
|
85
|
+
<AgendaPage
|
|
86
|
+
key={g.day}
|
|
87
|
+
day={g.day}
|
|
88
|
+
offset={g.at}
|
|
89
|
+
locale={model.env.locale.value}
|
|
90
|
+
events={p.events}
|
|
91
|
+
now={model.now.value}
|
|
92
|
+
hourCycle={p.hourCycle}
|
|
93
|
+
/>
|
|
94
|
+
))}
|
|
95
|
+
</div>
|
|
96
|
+
</div>
|
|
97
|
+
{p.onCreate && (
|
|
98
|
+
<button data-scope="fab" type="button" aria-label="New event" onClick={model.create}>
|
|
99
|
+
<PlusIcon />
|
|
100
|
+
</button>
|
|
101
|
+
)}
|
|
102
|
+
<MoveSheet
|
|
103
|
+
open={model.sheet}
|
|
104
|
+
event={model.moving.value}
|
|
105
|
+
events={p.events}
|
|
106
|
+
firstDayOfWeek={model.first.value}
|
|
107
|
+
locale={model.env.locale.value}
|
|
108
|
+
hourCycle={p.hourCycle}
|
|
109
|
+
onMove={model.moved}
|
|
110
|
+
onClose={() => (model.lifted.value = null)}
|
|
111
|
+
/>
|
|
112
|
+
<EventEditor
|
|
113
|
+
open={model.editing}
|
|
114
|
+
event={model.draft.value}
|
|
115
|
+
isNew
|
|
116
|
+
calendars={p.calendars}
|
|
117
|
+
timeZone={p.timeZone}
|
|
118
|
+
locale={model.env.locale.value}
|
|
119
|
+
today={model.env.today.value}
|
|
120
|
+
onSave={(e) => p.onCreate?.(e)}
|
|
121
|
+
/>
|
|
122
|
+
</div>
|
|
123
|
+
)
|
|
124
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { at, clock, fmt, uid, type CalEvent, type Slot } from '@kerf-js/veneer-core'
|
|
2
|
+
import type { State } from '@kerf-js/core'
|
|
3
|
+
import type { usePickerEnv } from '../Picker'
|
|
4
|
+
import type { AgendaProps } from './Agenda'
|
|
5
|
+
|
|
6
|
+
export function agendaCreate(
|
|
7
|
+
date: { readonly value: string },
|
|
8
|
+
draft: State<CalEvent | null>,
|
|
9
|
+
editing: State<boolean>,
|
|
10
|
+
) {
|
|
11
|
+
return () => {
|
|
12
|
+
const d = date.value
|
|
13
|
+
draft.value = { id: uid('new'), title: '', start: `${d}T13:00`, end: `${d}T14:00`, cal: 1 }
|
|
14
|
+
editing.value = true
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function agendaMoved(
|
|
19
|
+
p: () => AgendaProps,
|
|
20
|
+
env: ReturnType<typeof usePickerEnv>,
|
|
21
|
+
go: (d: string) => void,
|
|
22
|
+
say: (t: string) => unknown,
|
|
23
|
+
) {
|
|
24
|
+
return (e: CalEvent, to: Slot) => {
|
|
25
|
+
p().onMove?.(e, { start: at(to.date, to.s), end: at(to.date, to.e), resource: to.resource })
|
|
26
|
+
go(to.date)
|
|
27
|
+
say(
|
|
28
|
+
`Moved ${e.title} to ${fmt(to.date, { weekday: 'long' }, env.locale.value)} ${clock(to.s, env.locale.value, p().hourCycle)}`,
|
|
29
|
+
)
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import {
|
|
2
|
+
agendaItems,
|
|
3
|
+
clock,
|
|
4
|
+
longDuration,
|
|
5
|
+
type AgendaItem,
|
|
6
|
+
type CalEvent,
|
|
7
|
+
} from '@kerf-js/veneer-core'
|
|
8
|
+
import { derived } from '@kerf-js/core'
|
|
9
|
+
import { RepeatGlyph, tint } from './bits'
|
|
10
|
+
|
|
11
|
+
const summary = (e: CalEvent) =>
|
|
12
|
+
[
|
|
13
|
+
e.location,
|
|
14
|
+
e.video ? 'Video call' : '',
|
|
15
|
+
e.attendees?.length ? `${e.attendees.length} people` : '',
|
|
16
|
+
]
|
|
17
|
+
.filter(Boolean)
|
|
18
|
+
.join(' · ')
|
|
19
|
+
|
|
20
|
+
function Row({
|
|
21
|
+
item,
|
|
22
|
+
hourCycle,
|
|
23
|
+
locale,
|
|
24
|
+
}: {
|
|
25
|
+
item: AgendaItem
|
|
26
|
+
hourCycle?: string | undefined
|
|
27
|
+
locale: string
|
|
28
|
+
}) {
|
|
29
|
+
const time = (m: number) => clock(m, locale, hourCycle)
|
|
30
|
+
return (
|
|
31
|
+
<>
|
|
32
|
+
{item.kind === 'now' ? (
|
|
33
|
+
<div
|
|
34
|
+
data-part="now"
|
|
35
|
+
role="listitem"
|
|
36
|
+
aria-label={`Now, ${time(item.at)}`}
|
|
37
|
+
aria-current="time"
|
|
38
|
+
>
|
|
39
|
+
<span aria-hidden="true">{time(item.at)}</span>
|
|
40
|
+
<i></i>
|
|
41
|
+
</div>
|
|
42
|
+
) : item.kind === 'free' ? (
|
|
43
|
+
<div data-part="free" role="listitem">
|
|
44
|
+
<span></span>
|
|
45
|
+
<span>{longDuration(item.minutes)} free</span>
|
|
46
|
+
</div>
|
|
47
|
+
) : item.kind === 'allday' ? (
|
|
48
|
+
<div
|
|
49
|
+
data-part="row"
|
|
50
|
+
data-allday=""
|
|
51
|
+
data-cal={item.event.cal ?? 1}
|
|
52
|
+
style={tint(item.event.cal)}
|
|
53
|
+
role="listitem"
|
|
54
|
+
data-id={item.event.id}
|
|
55
|
+
tabindex="0"
|
|
56
|
+
>
|
|
57
|
+
<time>All day</time>
|
|
58
|
+
<i></i>
|
|
59
|
+
<div>
|
|
60
|
+
<b>{item.event.title}</b>
|
|
61
|
+
</div>
|
|
62
|
+
</div>
|
|
63
|
+
) : (
|
|
64
|
+
<div
|
|
65
|
+
data-part="row"
|
|
66
|
+
data-cal={item.event.cal ?? 1}
|
|
67
|
+
style={tint(item.event.cal)}
|
|
68
|
+
data-id={item.event.id}
|
|
69
|
+
role="listitem"
|
|
70
|
+
tabindex="0"
|
|
71
|
+
aria-label={`${item.event.title}, ${time(item.s)} to ${time(item.e)}`}
|
|
72
|
+
>
|
|
73
|
+
<time>
|
|
74
|
+
{time(item.s)}
|
|
75
|
+
<small>{time(item.e)}</small>
|
|
76
|
+
</time>
|
|
77
|
+
<i></i>
|
|
78
|
+
<div>
|
|
79
|
+
<b>
|
|
80
|
+
{item.event.recurrence && <RepeatGlyph />}
|
|
81
|
+
{item.event.recurrence ? ' ' : ''}
|
|
82
|
+
{item.event.title}
|
|
83
|
+
</b>
|
|
84
|
+
<span>{summary(item.event) || longDuration(item.e - item.s)}</span>
|
|
85
|
+
</div>
|
|
86
|
+
</div>
|
|
87
|
+
)}
|
|
88
|
+
</>
|
|
89
|
+
)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** One day's list of rows; the Agenda pages and the Calendar's Agenda view both draw it. */
|
|
93
|
+
export function AgendaDay({
|
|
94
|
+
events,
|
|
95
|
+
day,
|
|
96
|
+
now,
|
|
97
|
+
locale,
|
|
98
|
+
hourCycle,
|
|
99
|
+
label,
|
|
100
|
+
}: {
|
|
101
|
+
events: CalEvent[]
|
|
102
|
+
day: string
|
|
103
|
+
now?: string | null | undefined
|
|
104
|
+
locale: string
|
|
105
|
+
hourCycle?: string | undefined
|
|
106
|
+
label: string
|
|
107
|
+
}) {
|
|
108
|
+
const items = derived(() => agendaItems(events, day, now))
|
|
109
|
+
return (
|
|
110
|
+
<>
|
|
111
|
+
{items.value.length ? (
|
|
112
|
+
<div role="list" aria-label={label}>
|
|
113
|
+
{items.value.map((i) => (
|
|
114
|
+
<Row key={i.key} item={i} locale={locale} hourCycle={hourCycle} />
|
|
115
|
+
))}
|
|
116
|
+
</div>
|
|
117
|
+
) : (
|
|
118
|
+
<div data-scope="empty-state">
|
|
119
|
+
<p data-part="description">Nothing scheduled. Enjoy it.</p>
|
|
120
|
+
</div>
|
|
121
|
+
)}
|
|
122
|
+
</>
|
|
123
|
+
)
|
|
124
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { addDays, longPress, swipePages, type CalEvent } from '@kerf-js/veneer-core'
|
|
2
|
+
import { use } from '@kerf-js/veneer-core/kerf'
|
|
3
|
+
|
|
4
|
+
export function agendaGestures({
|
|
5
|
+
view,
|
|
6
|
+
track,
|
|
7
|
+
date,
|
|
8
|
+
go,
|
|
9
|
+
byId,
|
|
10
|
+
open,
|
|
11
|
+
}: {
|
|
12
|
+
view: () => HTMLDivElement | undefined
|
|
13
|
+
track: () => HTMLDivElement | undefined
|
|
14
|
+
date: { readonly value: string }
|
|
15
|
+
go: (d: string) => void
|
|
16
|
+
byId: (id: string | undefined) => CalEvent | undefined
|
|
17
|
+
open: (e: CalEvent) => unknown
|
|
18
|
+
}) {
|
|
19
|
+
use(swipePages, view, () => ({ track, onStep: (d: 1 | -1) => go(addDays(date.value, d)) }))
|
|
20
|
+
use(longPress, view, () => ({
|
|
21
|
+
selector: '[data-part="row"][data-id]',
|
|
22
|
+
onPress: (r: HTMLElement) => {
|
|
23
|
+
const e = byId(r.dataset.id)
|
|
24
|
+
if (e) open(e)
|
|
25
|
+
},
|
|
26
|
+
}))
|
|
27
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { CalEvent, IsoDate } from '@kerf-js/veneer-core'
|
|
2
|
+
import type { AgendaProps } from './Agenda'
|
|
3
|
+
|
|
4
|
+
export function agendaKeys({
|
|
5
|
+
p,
|
|
6
|
+
week,
|
|
7
|
+
date,
|
|
8
|
+
settle,
|
|
9
|
+
byId,
|
|
10
|
+
open,
|
|
11
|
+
}: {
|
|
12
|
+
p: () => AgendaProps
|
|
13
|
+
week: { readonly value: readonly IsoDate[] }
|
|
14
|
+
date: { readonly value: string }
|
|
15
|
+
settle: (d: string, focus?: boolean) => void
|
|
16
|
+
byId: (id: string | undefined) => CalEvent | undefined
|
|
17
|
+
open: (e: CalEvent) => unknown
|
|
18
|
+
}) {
|
|
19
|
+
const onKey = (e: KeyboardEvent) => {
|
|
20
|
+
const r = (e.target as Element).closest?.<HTMLElement>('[data-part="row"][data-id]')
|
|
21
|
+
if (!r) return
|
|
22
|
+
const hit = byId(r.dataset.id)
|
|
23
|
+
if (!hit) return
|
|
24
|
+
if (e.key === 'F10' && e.shiftKey) {
|
|
25
|
+
e.preventDefault()
|
|
26
|
+
open(hit)
|
|
27
|
+
} else if (e.key === 'Enter') {
|
|
28
|
+
e.preventDefault()
|
|
29
|
+
p().onOpen ? p().onOpen!(hit) : open(hit)
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
const onClick = (e: MouseEvent) => {
|
|
33
|
+
const hit = byId(
|
|
34
|
+
(e.target as Element).closest?.<HTMLElement>('[data-part="row"][data-id]')?.dataset.id,
|
|
35
|
+
)
|
|
36
|
+
if (hit) p().onOpen?.(hit)
|
|
37
|
+
}
|
|
38
|
+
const onTabs = (e: KeyboardEvent) => {
|
|
39
|
+
const to = ({ ArrowRight: 1, ArrowLeft: -1 } as Record<string, number>)[e.key]
|
|
40
|
+
const days = week.value
|
|
41
|
+
const i = days.indexOf(date.value as IsoDate)
|
|
42
|
+
if (e.key === 'Home' || e.key === 'End') {
|
|
43
|
+
e.preventDefault()
|
|
44
|
+
return settle(days[e.key === 'Home' ? 0 : 6]!, true)
|
|
45
|
+
}
|
|
46
|
+
if (!to) return
|
|
47
|
+
e.preventDefault()
|
|
48
|
+
const rtl = getComputedStyle(e.currentTarget as Element).direction === 'rtl'
|
|
49
|
+
settle(days[(i + (rtl ? -to : to) + 7) % 7]!, true)
|
|
50
|
+
}
|
|
51
|
+
return { onKey, onClick, onTabs }
|
|
52
|
+
}
|