@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
package/src/Shell.tsx
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import './styles'
|
|
2
|
+
import '@kerf-js/veneer-core/styles/components/avatar.css'
|
|
3
|
+
import '@kerf-js/veneer-core/styles/components/button.css'
|
|
4
|
+
import '@kerf-js/veneer-core/styles/components/menu.css'
|
|
5
|
+
import '@kerf-js/veneer-core/styles/layout/tokens.css'
|
|
6
|
+
import '@kerf-js/veneer-core/styles/layout/base.css'
|
|
7
|
+
import '@kerf-js/veneer-core/styles/layout/shell.css'
|
|
8
|
+
import '@kerf-js/veneer-core/styles/layout/breadcrumb.css'
|
|
9
|
+
|
|
10
|
+
export { Shell } from './Shell/shell'
|
|
11
|
+
export type { NavIcon } from './Shell/shared'
|
|
12
|
+
export type { NavItem } from './Shell/shared'
|
|
13
|
+
export type { NavGroup } from './Shell/shared'
|
|
14
|
+
export type { Crumb } from './Shell/shared'
|
|
15
|
+
export type { MenuEntry } from './Shell/shared'
|
|
16
|
+
export type { Workspace } from './Shell/shared'
|
|
17
|
+
export type { ShellProps } from './Shell/shared'
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { RightIcon } from '@kerf-js/veneer-icons'
|
|
2
|
+
import type { SideNavProps } from '../SideNav'
|
|
3
|
+
import type { SideNavState } from './state'
|
|
4
|
+
|
|
5
|
+
type Props = Pick<SideNavState, 'id' | 'refs' | 'shown' | 'holds' | 'unfolded' | 'toggle'> & {
|
|
6
|
+
props: SideNavProps
|
|
7
|
+
}
|
|
8
|
+
export function SideNavSections({ props, id, refs, shown, holds, unfolded, toggle }: Props) {
|
|
9
|
+
return (
|
|
10
|
+
<nav ref={(n) => (refs.list = n)} data-scope="navlist" data-bar="" aria-label={props.label}>
|
|
11
|
+
<ul data-part="sections">
|
|
12
|
+
{shown.value.map((x) => (
|
|
13
|
+
<li key={x.section.title} data-current={holds(x.section) ? '' : undefined}>
|
|
14
|
+
{x.section.pinned ? (
|
|
15
|
+
<p data-part="group-label">{x.section.title}</p>
|
|
16
|
+
) : (
|
|
17
|
+
<button
|
|
18
|
+
type="button"
|
|
19
|
+
data-part="item"
|
|
20
|
+
data-fold=""
|
|
21
|
+
aria-expanded={unfolded(x.section) ? 'true' : 'false'}
|
|
22
|
+
aria-controls={`${id}-${x.n}`}
|
|
23
|
+
onClick={() => toggle(x.section)}
|
|
24
|
+
>
|
|
25
|
+
<span data-part="fold-label">{x.section.title}</span>
|
|
26
|
+
<span data-part="chevron" aria-hidden="true">
|
|
27
|
+
<RightIcon />
|
|
28
|
+
</span>
|
|
29
|
+
</button>
|
|
30
|
+
)}
|
|
31
|
+
<ul id={`${id}-${x.n}`} data-collapse="" hidden={!unfolded(x.section)}>
|
|
32
|
+
{x.items.map((i) => (
|
|
33
|
+
<li key={i.href}>
|
|
34
|
+
<a
|
|
35
|
+
data-part="item"
|
|
36
|
+
href={i.href}
|
|
37
|
+
aria-current={i.href === props.current ? 'page' : undefined}
|
|
38
|
+
>
|
|
39
|
+
{i.label}
|
|
40
|
+
</a>
|
|
41
|
+
</li>
|
|
42
|
+
))}
|
|
43
|
+
</ul>
|
|
44
|
+
</li>
|
|
45
|
+
))}
|
|
46
|
+
</ul>
|
|
47
|
+
<span data-part="indicator" aria-hidden="true"></span>
|
|
48
|
+
</nav>
|
|
49
|
+
)
|
|
50
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import {
|
|
2
|
+
navIndicator,
|
|
3
|
+
readCollapsed,
|
|
4
|
+
readFolds,
|
|
5
|
+
sideNav,
|
|
6
|
+
uid,
|
|
7
|
+
writeCollapsed,
|
|
8
|
+
writeFolds,
|
|
9
|
+
type Folds,
|
|
10
|
+
} from '@kerf-js/veneer-core'
|
|
11
|
+
import { derived, onMount, state, untrack, watch } from '@kerf-js/core'
|
|
12
|
+
import { use } from '@kerf-js/veneer-core/kerf'
|
|
13
|
+
import type { SideNavProps, SideNavSection } from '../SideNav'
|
|
14
|
+
|
|
15
|
+
export function sideNavState(props: SideNavProps) {
|
|
16
|
+
const id = untrack(() => props.id) ?? uid('sidenav')
|
|
17
|
+
const chosen = state<Folds>({})
|
|
18
|
+
const query = state('')
|
|
19
|
+
const open = state(false)
|
|
20
|
+
const collapsible = untrack(() => props.collapsible) !== false
|
|
21
|
+
const collapsed = state(false)
|
|
22
|
+
const refs: { root?: HTMLElement | undefined; list?: HTMLElement | undefined } = {}
|
|
23
|
+
|
|
24
|
+
const key = () =>
|
|
25
|
+
props.remember === false ? undefined : (props.remember ?? `veneer:sidenav:${props.label}`)
|
|
26
|
+
const holds = (s: SideNavSection) => s.items.some((i) => i.href === props.current)
|
|
27
|
+
const words = derived(() => query.value.trim().toLowerCase())
|
|
28
|
+
const shown = derived(() =>
|
|
29
|
+
props.sections
|
|
30
|
+
.map((section, n) => ({
|
|
31
|
+
section,
|
|
32
|
+
n,
|
|
33
|
+
items: words.value
|
|
34
|
+
? section.items.filter((i) => i.label.toLowerCase().includes(words.value))
|
|
35
|
+
: section.items,
|
|
36
|
+
}))
|
|
37
|
+
.filter((x) => x.items.length > 0),
|
|
38
|
+
)
|
|
39
|
+
const unfolded = (s: SideNavSection) =>
|
|
40
|
+
words.value !== '' || !!s.pinned || (chosen.value[s.title] ?? holds(s))
|
|
41
|
+
const toggle = (s: SideNavSection) => {
|
|
42
|
+
const next = !unfolded(s)
|
|
43
|
+
// one open at a time unless `multiple`: opening a section folds the others
|
|
44
|
+
chosen.value =
|
|
45
|
+
next && !props.multiple
|
|
46
|
+
? { ...only(props.sections, s.title), [s.title]: true }
|
|
47
|
+
: { ...chosen.value, [s.title]: next }
|
|
48
|
+
const k = key()
|
|
49
|
+
if (k) writeFolds(k, chosen.value)
|
|
50
|
+
}
|
|
51
|
+
bindSideNav(props, { key, holds, chosen, collapsible, collapsed, open, refs })
|
|
52
|
+
|
|
53
|
+
const filterText = () =>
|
|
54
|
+
typeof props.filter === 'string' ? props.filter : `Filter ${props.label.toLowerCase()}`
|
|
55
|
+
return {
|
|
56
|
+
id,
|
|
57
|
+
query,
|
|
58
|
+
open,
|
|
59
|
+
collapsible,
|
|
60
|
+
collapsed,
|
|
61
|
+
refs,
|
|
62
|
+
words,
|
|
63
|
+
shown,
|
|
64
|
+
holds,
|
|
65
|
+
unfolded,
|
|
66
|
+
toggle,
|
|
67
|
+
filterText,
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
export type SideNavState = ReturnType<typeof sideNavState>
|
|
71
|
+
|
|
72
|
+
/** Folds with `title` open and every other foldable section closed. */
|
|
73
|
+
function only(sections: SideNavSection[], title: string): Folds {
|
|
74
|
+
return Object.fromEntries(
|
|
75
|
+
sections.filter((x) => !x.pinned).map((x) => [x.title, x.title === title]),
|
|
76
|
+
)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function bindSideNav(
|
|
80
|
+
props: SideNavProps,
|
|
81
|
+
d: {
|
|
82
|
+
key: () => string | undefined
|
|
83
|
+
holds: (s: SideNavSection) => boolean
|
|
84
|
+
chosen: ReturnType<typeof state<Folds>>
|
|
85
|
+
collapsible: boolean
|
|
86
|
+
collapsed: ReturnType<typeof state<boolean>>
|
|
87
|
+
open: ReturnType<typeof state<boolean>>
|
|
88
|
+
refs: { root?: HTMLElement | undefined; list?: HTMLElement | undefined }
|
|
89
|
+
},
|
|
90
|
+
) {
|
|
91
|
+
const { key, holds, chosen, collapsible, collapsed, open, refs } = d
|
|
92
|
+
// Arriving on a page opens its section, whatever was remembered, so the current link is never folded away.
|
|
93
|
+
const reveal = () => {
|
|
94
|
+
const s = props.sections.find(holds)
|
|
95
|
+
if (!s) return
|
|
96
|
+
if (!props.multiple) chosen.value = only(props.sections, s.title)
|
|
97
|
+
else if (chosen.value[s.title] === false) chosen.value = { ...chosen.value, [s.title]: true }
|
|
98
|
+
}
|
|
99
|
+
const fold = (v: boolean) => {
|
|
100
|
+
collapsed.value = v
|
|
101
|
+
const k = key()
|
|
102
|
+
if (k) writeCollapsed(`${k}:collapsed`, v)
|
|
103
|
+
}
|
|
104
|
+
onMount(() => {
|
|
105
|
+
const k = key()
|
|
106
|
+
if (k) chosen.value = readFolds(k)
|
|
107
|
+
if (k && collapsible) collapsed.value = readCollapsed(`${k}:collapsed`)
|
|
108
|
+
reveal()
|
|
109
|
+
})
|
|
110
|
+
// A sidebar kept across sections can change its key with them: each section's folds are its own.
|
|
111
|
+
watch(key, (k, was) => {
|
|
112
|
+
if (was === undefined || k === was) return // the first run is onMount's
|
|
113
|
+
chosen.value = k ? readFolds(k) : {}
|
|
114
|
+
reveal()
|
|
115
|
+
})
|
|
116
|
+
watch(
|
|
117
|
+
() => props.current,
|
|
118
|
+
() => {
|
|
119
|
+
reveal()
|
|
120
|
+
open.value = false
|
|
121
|
+
},
|
|
122
|
+
)
|
|
123
|
+
use(
|
|
124
|
+
sideNav,
|
|
125
|
+
() => refs.root,
|
|
126
|
+
() => ({
|
|
127
|
+
current: props.current,
|
|
128
|
+
open: open.value,
|
|
129
|
+
onOpenChange: (v: boolean) => (open.value = v),
|
|
130
|
+
collapsed: collapsed.value,
|
|
131
|
+
onCollapsedChange: fold,
|
|
132
|
+
}),
|
|
133
|
+
)
|
|
134
|
+
// veneer's sliding bar, as Nav and the on-page rail have it: it follows the pointer and keyboard, and slides to a new page.
|
|
135
|
+
use(
|
|
136
|
+
navIndicator,
|
|
137
|
+
() => refs.list,
|
|
138
|
+
() => ({ axis: 'y' as const }),
|
|
139
|
+
)
|
|
140
|
+
}
|
package/src/SideNav.tsx
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { RightIcon } from '@kerf-js/veneer-icons'
|
|
2
|
+
import { CloseX } from './CloseX'
|
|
3
|
+
import { untrack } from '@kerf-js/core'
|
|
4
|
+
import { sideNavState } from './SideNav/state'
|
|
5
|
+
import { SideNavSections } from './SideNav/sections'
|
|
6
|
+
import './styles'
|
|
7
|
+
import '@kerf-js/veneer-core/styles/components/button.css' // the close button, without a bar
|
|
8
|
+
import '@kerf-js/veneer-core/styles/layout/tokens.css' // the bar height, the view's height and the safe areas, without a Shell
|
|
9
|
+
import '@kerf-js/veneer-core/styles/layout/navlist.css'
|
|
10
|
+
import '@kerf-js/veneer-core/styles/layout/sidenav.css'
|
|
11
|
+
|
|
12
|
+
/** One page in a SideNav section. */
|
|
13
|
+
export interface SideNavLink {
|
|
14
|
+
href: string
|
|
15
|
+
label: string
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** A titled run of pages. `pinned` keeps it open, with a plain heading instead of a fold. */
|
|
19
|
+
export interface SideNavSection {
|
|
20
|
+
title: string
|
|
21
|
+
items: SideNavLink[]
|
|
22
|
+
pinned?: boolean | undefined
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Props for SideNav. */
|
|
26
|
+
export interface SideNavProps {
|
|
27
|
+
/** Names the navigation landmark, and titles the panel when it is laid over the page. */
|
|
28
|
+
label: string
|
|
29
|
+
sections: SideNavSection[]
|
|
30
|
+
/** The current page's href: its link is marked, its section starts open, and the panel scrolls to it. */
|
|
31
|
+
current?: string | undefined
|
|
32
|
+
/** Let any number of sections stay open. Default false: opening one folds the others, so one is open at a time. */
|
|
33
|
+
multiple?: boolean | undefined
|
|
34
|
+
/** A filter box at the top, for a long list. A string is its placeholder. */
|
|
35
|
+
filter?: boolean | string | undefined
|
|
36
|
+
/** The localStorage key for what a viewer folded, and `<key>:collapsed` for the docked panel's fold; `false` keeps
|
|
37
|
+
* nothing. Default `veneer:sidenav:<label>`. */
|
|
38
|
+
remember?: string | false | undefined
|
|
39
|
+
/** A collapse bar at the panel's edge: on a phone it is all that shows until pressed, and it opens the panel over the
|
|
40
|
+
* page; docked, it folds the sidebar to its own width. Default true. `false` leaves the panel to an outside button. */
|
|
41
|
+
collapsible?: boolean | undefined
|
|
42
|
+
/** The panel's id. Any button with `aria-controls` naming it also opens the panel on a phone. */
|
|
43
|
+
id?: string | undefined
|
|
44
|
+
/** On a phone, where the open panel sits. `cover` (default) lays it over everything, header too. `under` opens it
|
|
45
|
+
* below the header (`--veneer-sidenav-top`), and a SideNavTitle in the header slides to the panel's title. */
|
|
46
|
+
overlay?: 'cover' | 'under' | undefined
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* A docs sidebar: one left panel whose sections fold, with a collapse bar at its edge. The section holding the current
|
|
51
|
+
* page starts open, the rest closed, and a viewer's own choices are remembered. From 900px the panel is docked: sticky,
|
|
52
|
+
* scrolling on its own, and its bar folds it to a slim strip and back, remembered too. Below that only the bar shows, a
|
|
53
|
+
* slim strip down the left edge; pressing it brings the panel over the page, full height, with focus kept inside, and
|
|
54
|
+
* the bar, Escape, the backdrop or a link closing it. Links are plain anchors, so a router that handles `<a>` clicks
|
|
55
|
+
* navigates as usual.
|
|
56
|
+
*
|
|
57
|
+
* It is chrome that outlives a page: a view transition leaves it in place (`data-vt="side"`) rather than fading it
|
|
58
|
+
* with the page. Keep it mounted across pages by rendering it in a layout above them all and
|
|
59
|
+
* passing `sections` and `current` for where the reader is (`currentPath()` in `@kerf-js/start`).
|
|
60
|
+
*/
|
|
61
|
+
export function SideNav(props: SideNavProps) {
|
|
62
|
+
const nav = sideNavState(untrack(() => props))
|
|
63
|
+
const { id, query, open, collapsible, collapsed, refs, words, shown } = nav
|
|
64
|
+
const { holds, unfolded, toggle, filterText } = nav
|
|
65
|
+
return (
|
|
66
|
+
<div
|
|
67
|
+
ref={(n) => (refs.root = n)}
|
|
68
|
+
data-scope="sidenav"
|
|
69
|
+
data-vt="side"
|
|
70
|
+
data-open={open.value ? '' : undefined}
|
|
71
|
+
data-collapsible={collapsible ? '' : undefined}
|
|
72
|
+
data-collapsed={collapsible && collapsed.value ? '' : undefined}
|
|
73
|
+
data-overlay={props.overlay === 'under' ? 'under' : undefined}
|
|
74
|
+
>
|
|
75
|
+
<div data-part="backdrop" aria-hidden="true"></div>
|
|
76
|
+
<div data-part="panel" id={id} tabindex="-1">
|
|
77
|
+
<div data-part="head">
|
|
78
|
+
<p data-part="title" id={`${id}-t`}>
|
|
79
|
+
{props.label}
|
|
80
|
+
</p>
|
|
81
|
+
{!collapsible && (
|
|
82
|
+
<button
|
|
83
|
+
type="button"
|
|
84
|
+
data-scope="button"
|
|
85
|
+
data-emphasis="ghost"
|
|
86
|
+
data-tone="neutral"
|
|
87
|
+
data-icon-only=""
|
|
88
|
+
data-size="sm"
|
|
89
|
+
aria-label="Close"
|
|
90
|
+
data-part="close"
|
|
91
|
+
>
|
|
92
|
+
<CloseX />
|
|
93
|
+
</button>
|
|
94
|
+
)}
|
|
95
|
+
</div>
|
|
96
|
+
<div data-part="scroll">
|
|
97
|
+
{props.filter && (
|
|
98
|
+
<input
|
|
99
|
+
type="search"
|
|
100
|
+
data-part="filter"
|
|
101
|
+
placeholder={filterText()}
|
|
102
|
+
aria-label={filterText()}
|
|
103
|
+
value={query.value}
|
|
104
|
+
onInput={(e: Event) => (query.value = (e.currentTarget as HTMLInputElement).value)}
|
|
105
|
+
/>
|
|
106
|
+
)}
|
|
107
|
+
<SideNavSections
|
|
108
|
+
props={props}
|
|
109
|
+
id={id}
|
|
110
|
+
refs={refs}
|
|
111
|
+
shown={shown}
|
|
112
|
+
holds={holds}
|
|
113
|
+
unfolded={unfolded}
|
|
114
|
+
toggle={toggle}
|
|
115
|
+
/>
|
|
116
|
+
{words.value !== '' && shown.value.length === 0 && (
|
|
117
|
+
<p data-part="empty">No pages match “{query.value.trim()}”.</p>
|
|
118
|
+
)}
|
|
119
|
+
</div>
|
|
120
|
+
{/* Last, as Shell's toggle is at its nav's foot. Its name is the label; aria-expanded, kept by sideNav, says the rest. */}
|
|
121
|
+
{collapsible && (
|
|
122
|
+
<button type="button" data-part="bar" aria-controls={id} aria-expanded="false">
|
|
123
|
+
<RightIcon />
|
|
124
|
+
<span data-part="bar-label">{props.label}</span>
|
|
125
|
+
</button>
|
|
126
|
+
)}
|
|
127
|
+
</div>
|
|
128
|
+
</div>
|
|
129
|
+
)
|
|
130
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import './styles'
|
|
2
|
+
import '@kerf-js/veneer-core/styles/layout/sidenav-title.css'
|
|
3
|
+
|
|
4
|
+
/** Props for SideNavTitle. */
|
|
5
|
+
export interface SideNavTitleProps {
|
|
6
|
+
/** The open SideNav's title, shown while its panel is open on a phone. */
|
|
7
|
+
title: unknown
|
|
8
|
+
/** What the header shows the rest of the time, usually the brand. */
|
|
9
|
+
children?: unknown
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The header's brand, swapped for a SideNav's title while its panel is open on a phone. Give the SideNav
|
|
14
|
+
* `overlay="under"` so the panel opens below the header and leaves this in view.
|
|
15
|
+
*/
|
|
16
|
+
export function SideNavTitle(props: SideNavTitleProps) {
|
|
17
|
+
return (
|
|
18
|
+
<span data-scope="sidenav-title">
|
|
19
|
+
<span data-part="home">{props.children}</span>
|
|
20
|
+
<span data-part="title" aria-hidden="true">
|
|
21
|
+
{props.title}
|
|
22
|
+
</span>
|
|
23
|
+
</span>
|
|
24
|
+
)
|
|
25
|
+
}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { paintStrokes, signatureSvg, strokeWidth, type Stroke } from '@kerf-js/veneer-core'
|
|
2
|
+
import { derived, flush, state, untrack } from '@kerf-js/core'
|
|
3
|
+
import { use } from '@kerf-js/veneer-core/kerf'
|
|
4
|
+
import type { bindable } from '../Picker'
|
|
5
|
+
import type { SignatureValue } from '../SignaturePad'
|
|
6
|
+
|
|
7
|
+
type Held = ReturnType<typeof bindable<SignatureValue | null>>
|
|
8
|
+
function signatureData(start: SignatureValue | null) {
|
|
9
|
+
const strokes = state<Stroke[]>(start?.strokes ?? [])
|
|
10
|
+
const typed = state(start?.text ?? '')
|
|
11
|
+
const method = state<'draw' | 'type'>(start?.method === 'typed' ? 'type' : 'draw')
|
|
12
|
+
const count = derived(() => strokes.value.length)
|
|
13
|
+
const has = derived(() =>
|
|
14
|
+
method.value === 'draw' ? count.value > 0 : typed.value.trim().length > 0,
|
|
15
|
+
)
|
|
16
|
+
const name = derived(() =>
|
|
17
|
+
method.value === 'type'
|
|
18
|
+
? 'Typed signature'
|
|
19
|
+
: count.value
|
|
20
|
+
? `Signature, ${count.value} stroke${count.value === 1 ? '' : 's'}`
|
|
21
|
+
: 'Signature, empty',
|
|
22
|
+
)
|
|
23
|
+
const status = derived(() =>
|
|
24
|
+
!has.value
|
|
25
|
+
? 'Empty'
|
|
26
|
+
: method.value === 'type'
|
|
27
|
+
? 'Typed'
|
|
28
|
+
: `${count.value} stroke${count.value === 1 ? '' : 's'} · drawn`,
|
|
29
|
+
)
|
|
30
|
+
const refs: {
|
|
31
|
+
pad?: HTMLDivElement | undefined
|
|
32
|
+
canvas?: HTMLCanvasElement | undefined
|
|
33
|
+
box?: HTMLInputElement | undefined
|
|
34
|
+
cur: Stroke | null
|
|
35
|
+
last: { x: number; y: number; t: number; w: number }
|
|
36
|
+
} = { cur: null, last: { x: 0, y: 0, t: 0, w: 2.6 } }
|
|
37
|
+
return { strokes, typed, method, count, has, name, status, refs }
|
|
38
|
+
}
|
|
39
|
+
type Data = ReturnType<typeof signatureData>
|
|
40
|
+
function signatureDraw(d: Data) {
|
|
41
|
+
const { refs, strokes } = d
|
|
42
|
+
const draw = () => {
|
|
43
|
+
const ctx = refs.canvas?.getContext?.('2d')
|
|
44
|
+
if (!ctx) return
|
|
45
|
+
const dpr = devicePixelRatio || 1,
|
|
46
|
+
r = refs.pad!.getBoundingClientRect()
|
|
47
|
+
if (
|
|
48
|
+
refs.canvas!.width !== Math.round(r.width * dpr) ||
|
|
49
|
+
refs.canvas!.height !== Math.round(r.height * dpr)
|
|
50
|
+
) {
|
|
51
|
+
refs.canvas!.width = Math.max(1, Math.round(r.width * dpr))
|
|
52
|
+
refs.canvas!.height = Math.max(1, Math.round(r.height * dpr))
|
|
53
|
+
}
|
|
54
|
+
ctx.setTransform(dpr, 0, 0, dpr, 0, 0)
|
|
55
|
+
ctx.strokeStyle = ctx.fillStyle = getComputedStyle(refs.pad!).color
|
|
56
|
+
paintStrokes(ctx, strokes.value, r.width, r.height)
|
|
57
|
+
}
|
|
58
|
+
return draw
|
|
59
|
+
}
|
|
60
|
+
function signatureEmit(d: Data, v: Held) {
|
|
61
|
+
const { has, method, strokes, typed } = d
|
|
62
|
+
const emit = () => {
|
|
63
|
+
if (!has.value) return v.set(null, 'programmatic')
|
|
64
|
+
if (method.value === 'draw')
|
|
65
|
+
v.set(
|
|
66
|
+
{ method: 'drawn', strokes: strokes.value, svg: signatureSvg(strokes.value) },
|
|
67
|
+
'pointer',
|
|
68
|
+
)
|
|
69
|
+
else {
|
|
70
|
+
const text = typed.value.trim()
|
|
71
|
+
v.set(
|
|
72
|
+
{
|
|
73
|
+
method: 'typed',
|
|
74
|
+
text,
|
|
75
|
+
svg: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 600 200"><text x="24" y="130" font-size="64" font-style="italic" fill="currentColor">${text.replace(/[&<>]/g, (c) => ({ '&': '&', '<': '<', '>': '>' })[c]!)}</text></svg>`,
|
|
76
|
+
},
|
|
77
|
+
'keyboard',
|
|
78
|
+
)
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return emit
|
|
82
|
+
}
|
|
83
|
+
function signatureEvents(d: Data, draw: () => void, emit: () => void) {
|
|
84
|
+
const { refs, strokes, typed, method } = d
|
|
85
|
+
const down = (e: PointerEvent) => {
|
|
86
|
+
if (method.value !== 'draw') return
|
|
87
|
+
refs.canvas!.setPointerCapture?.(e.pointerId)
|
|
88
|
+
const r = refs.canvas!.getBoundingClientRect()
|
|
89
|
+
refs.cur = [
|
|
90
|
+
[
|
|
91
|
+
(e.clientX - r.left) / r.width,
|
|
92
|
+
(e.clientY - r.top) / r.height,
|
|
93
|
+
e.pointerType === 'pen' && e.pressure ? 1 + e.pressure * 3 : 2.6,
|
|
94
|
+
],
|
|
95
|
+
]
|
|
96
|
+
strokes.value = [...strokes.value, refs.cur]
|
|
97
|
+
refs.last = { x: e.clientX, y: e.clientY, t: e.timeStamp, w: 2.6 }
|
|
98
|
+
draw()
|
|
99
|
+
}
|
|
100
|
+
const move = (e: PointerEvent) => {
|
|
101
|
+
if (!refs.cur) return
|
|
102
|
+
const r = refs.canvas!.getBoundingClientRect()
|
|
103
|
+
for (const ev of e.getCoalescedEvents?.().length ? e.getCoalescedEvents() : [e]) {
|
|
104
|
+
const speed =
|
|
105
|
+
Math.hypot(ev.clientX - refs.last.x, ev.clientY - refs.last.y) /
|
|
106
|
+
Math.max(1, ev.timeStamp - refs.last.t)
|
|
107
|
+
const w = strokeWidth(refs.last.w, speed, ev.pointerType === 'pen' ? ev.pressure : undefined)
|
|
108
|
+
refs.cur.push([(ev.clientX - r.left) / r.width, (ev.clientY - r.top) / r.height, w])
|
|
109
|
+
refs.last = { x: ev.clientX, y: ev.clientY, t: ev.timeStamp, w }
|
|
110
|
+
}
|
|
111
|
+
draw()
|
|
112
|
+
}
|
|
113
|
+
const up = () => {
|
|
114
|
+
if (refs.cur) {
|
|
115
|
+
refs.cur = null
|
|
116
|
+
strokes.value = [...strokes.value]
|
|
117
|
+
emit()
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
const undo = () => {
|
|
121
|
+
strokes.value = strokes.value.slice(0, -1)
|
|
122
|
+
flush()
|
|
123
|
+
draw()
|
|
124
|
+
emit()
|
|
125
|
+
}
|
|
126
|
+
const clear = () => {
|
|
127
|
+
if (method.value === 'draw') strokes.value = []
|
|
128
|
+
else typed.value = ''
|
|
129
|
+
flush()
|
|
130
|
+
draw()
|
|
131
|
+
emit()
|
|
132
|
+
}
|
|
133
|
+
const pick = (m: 'draw' | 'type') => {
|
|
134
|
+
method.value = m
|
|
135
|
+
flush()
|
|
136
|
+
if (m === 'type') refs.box?.focus()
|
|
137
|
+
else draw()
|
|
138
|
+
emit()
|
|
139
|
+
}
|
|
140
|
+
return { down, move, up, undo, clear, pick }
|
|
141
|
+
}
|
|
142
|
+
function bindSignature(d: Data, draw: () => void) {
|
|
143
|
+
const { refs } = d
|
|
144
|
+
use(
|
|
145
|
+
(el: HTMLDivElement) => {
|
|
146
|
+
const size = typeof ResizeObserver === 'undefined' ? undefined : new ResizeObserver(draw)
|
|
147
|
+
size?.observe(el)
|
|
148
|
+
const theme = new MutationObserver(() => requestAnimationFrame(draw))
|
|
149
|
+
theme.observe(el.ownerDocument.documentElement, {
|
|
150
|
+
attributes: true,
|
|
151
|
+
attributeFilter: ['data-theme', 'data-expression'],
|
|
152
|
+
})
|
|
153
|
+
return {
|
|
154
|
+
update() {},
|
|
155
|
+
destroy() {
|
|
156
|
+
size?.disconnect()
|
|
157
|
+
theme.disconnect()
|
|
158
|
+
},
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
() => refs.pad,
|
|
162
|
+
)
|
|
163
|
+
}
|
|
164
|
+
export function signatureState(v: Held) {
|
|
165
|
+
const start = untrack(() => v.value)
|
|
166
|
+
const data = signatureData(start)
|
|
167
|
+
const draw = signatureDraw(data)
|
|
168
|
+
const emit = signatureEmit(data, v)
|
|
169
|
+
const events = signatureEvents(data, draw, emit)
|
|
170
|
+
bindSignature(data, draw)
|
|
171
|
+
return { ...data, ...events, start, draw, emit }
|
|
172
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { UndoIcon, XIcon } from '@kerf-js/veneer-icons'
|
|
2
|
+
import { Button } from '../Button'
|
|
3
|
+
import type { signatureState } from './state'
|
|
4
|
+
|
|
5
|
+
type View = ReturnType<typeof signatureState>
|
|
6
|
+
export function SignatureControl({ view }: { view: View }) {
|
|
7
|
+
return (
|
|
8
|
+
<div ref={(n) => (view.refs.pad = n)} data-part="pad">
|
|
9
|
+
<canvas
|
|
10
|
+
ref={(n) => (view.refs.canvas = n)}
|
|
11
|
+
role="img"
|
|
12
|
+
aria-label={view.name.value}
|
|
13
|
+
style={view.method.value === 'type' ? 'visibility:hidden' : undefined}
|
|
14
|
+
onPointerDown={view.down}
|
|
15
|
+
onPointerMove={view.move}
|
|
16
|
+
onPointerUp={view.up}
|
|
17
|
+
onPointerCancel={view.up}
|
|
18
|
+
></canvas>
|
|
19
|
+
<span data-part="empty"></span>
|
|
20
|
+
<span data-part="baseline" aria-hidden="true">
|
|
21
|
+
×
|
|
22
|
+
</span>
|
|
23
|
+
<input
|
|
24
|
+
ref={(n) => (view.refs.box = n)}
|
|
25
|
+
data-part="typed"
|
|
26
|
+
hidden={view.method.value !== 'type'}
|
|
27
|
+
aria-label="Type your full name"
|
|
28
|
+
placeholder="Type your full name"
|
|
29
|
+
autocomplete="name"
|
|
30
|
+
value={view.typed.value}
|
|
31
|
+
onInput={(e) => {
|
|
32
|
+
view.typed.value = e.currentTarget.value
|
|
33
|
+
view.emit()
|
|
34
|
+
}}
|
|
35
|
+
/>
|
|
36
|
+
</div>
|
|
37
|
+
)
|
|
38
|
+
}
|
|
39
|
+
export function SignatureFooter({ view }: { view: View }) {
|
|
40
|
+
return (
|
|
41
|
+
<div class="row" style="justify-content:space-between">
|
|
42
|
+
<span class="muted" aria-live="polite">
|
|
43
|
+
{view.status.value}
|
|
44
|
+
</span>
|
|
45
|
+
<span class="row">
|
|
46
|
+
{view.method.value === 'draw' && (
|
|
47
|
+
<Button
|
|
48
|
+
emphasis="ghost"
|
|
49
|
+
size="sm"
|
|
50
|
+
icon={UndoIcon}
|
|
51
|
+
disabled={!view.count.value}
|
|
52
|
+
onClick={view.undo}
|
|
53
|
+
>
|
|
54
|
+
Undo
|
|
55
|
+
</Button>
|
|
56
|
+
)}
|
|
57
|
+
<Button
|
|
58
|
+
emphasis="ghost"
|
|
59
|
+
size="sm"
|
|
60
|
+
icon={XIcon}
|
|
61
|
+
disabled={!view.has.value}
|
|
62
|
+
onClick={view.clear}
|
|
63
|
+
>
|
|
64
|
+
Clear
|
|
65
|
+
</Button>
|
|
66
|
+
</span>
|
|
67
|
+
</div>
|
|
68
|
+
)
|
|
69
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { uid, type Stroke } from '@kerf-js/veneer-core'
|
|
2
|
+
import { flush } from '@kerf-js/core'
|
|
3
|
+
import { Segmented } from './Choice'
|
|
4
|
+
import { Field, type FieldShell } from './Field'
|
|
5
|
+
import { bindable, type Bindable } from './Picker'
|
|
6
|
+
import { signatureState } from './SignaturePad/state'
|
|
7
|
+
import { SignatureControl, SignatureFooter } from './SignaturePad/view'
|
|
8
|
+
import '@kerf-js/veneer-core/styles/rich/signature.css'
|
|
9
|
+
|
|
10
|
+
const METHODS = [
|
|
11
|
+
{ value: 'draw' as const, label: 'Draw' },
|
|
12
|
+
{ value: 'type' as const, label: 'Type' },
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
/** A signature, drawn or typed, with the SVG to show it. */
|
|
16
|
+
export type SignatureValue = {
|
|
17
|
+
method: 'drawn' | 'typed'
|
|
18
|
+
strokes?: Stroke[]
|
|
19
|
+
text?: string | undefined
|
|
20
|
+
svg: string
|
|
21
|
+
}
|
|
22
|
+
/** Props for SignaturePad. */
|
|
23
|
+
export type SignaturePadProps = FieldShell & Bindable<SignatureValue | null>
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* SignaturePad (04 §4): a canvas redrawn from its stored points on resize and theme change, with Undo and Clear. Typing
|
|
27
|
+
* the name is the mandatory alternative (WCAG 2.1.1, 2.5.1), so keyboard and switch users can sign.
|
|
28
|
+
*/
|
|
29
|
+
export function SignaturePad({
|
|
30
|
+
value,
|
|
31
|
+
defaultValue,
|
|
32
|
+
onValueChange,
|
|
33
|
+
label,
|
|
34
|
+
hint,
|
|
35
|
+
...rest
|
|
36
|
+
}: SignaturePadProps) {
|
|
37
|
+
const id = uid('sig')
|
|
38
|
+
const v = bindable<SignatureValue | null>(
|
|
39
|
+
() => value,
|
|
40
|
+
() => defaultValue,
|
|
41
|
+
null,
|
|
42
|
+
() => onValueChange,
|
|
43
|
+
)
|
|
44
|
+
const view = signatureState(v)
|
|
45
|
+
return (
|
|
46
|
+
<div data-scope="signature" class="stack">
|
|
47
|
+
<div class="row" style="justify-content:flex-end">
|
|
48
|
+
<Segmented
|
|
49
|
+
size="sm"
|
|
50
|
+
label="Signing method"
|
|
51
|
+
name={`${id}-m`}
|
|
52
|
+
value={view.method.value}
|
|
53
|
+
options={METHODS}
|
|
54
|
+
onChange={(m) => view.pick(m)}
|
|
55
|
+
/>
|
|
56
|
+
</div>
|
|
57
|
+
<Field
|
|
58
|
+
{...rest}
|
|
59
|
+
group
|
|
60
|
+
label={label}
|
|
61
|
+
hint={hint ?? 'Draw with a finger, a pen or a mouse, or switch to Type.'}
|
|
62
|
+
filled={view.has.value}
|
|
63
|
+
reset={() => {
|
|
64
|
+
v.reset()
|
|
65
|
+
view.strokes.value = view.start?.strokes ?? []
|
|
66
|
+
view.typed.value = view.start?.text ?? ''
|
|
67
|
+
view.method.value = view.start?.method === 'typed' ? 'type' : 'draw'
|
|
68
|
+
flush()
|
|
69
|
+
view.draw()
|
|
70
|
+
}}
|
|
71
|
+
control={() => <SignatureControl view={view} />}
|
|
72
|
+
/>
|
|
73
|
+
<SignatureFooter view={view} />
|
|
74
|
+
</div>
|
|
75
|
+
)
|
|
76
|
+
}
|