@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,76 @@
|
|
|
1
|
+
import { indicator, uid } from '@kerf-js/veneer-core'
|
|
2
|
+
import { untrack } from '@kerf-js/core'
|
|
3
|
+
import { Icon, type IconRef } from './Icon'
|
|
4
|
+
import { use } from '@kerf-js/veneer-core/kerf'
|
|
5
|
+
import './fields'
|
|
6
|
+
import '@kerf-js/veneer-core/styles/inputs/choice-segmented.css'
|
|
7
|
+
|
|
8
|
+
/** One Segmented choice. */
|
|
9
|
+
export type SegmentedOption<V extends string> = {
|
|
10
|
+
value: V
|
|
11
|
+
label: unknown
|
|
12
|
+
icon?: IconRef | undefined
|
|
13
|
+
count?: unknown
|
|
14
|
+
disabled?: boolean | undefined
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Segmented (03 §4, review 01 M8): native radios in a group that rests on its ink border; hovering or focusing an
|
|
19
|
+
* unselected option sweeps a ring round that option only; the selected face slides to it on the sweep curve.
|
|
20
|
+
*/
|
|
21
|
+
export function Segmented<V extends string>({
|
|
22
|
+
label,
|
|
23
|
+
value,
|
|
24
|
+
onChange,
|
|
25
|
+
options,
|
|
26
|
+
size,
|
|
27
|
+
name,
|
|
28
|
+
fill,
|
|
29
|
+
}: {
|
|
30
|
+
label: string
|
|
31
|
+
value: V
|
|
32
|
+
onChange: (v: V) => void
|
|
33
|
+
options: SegmentedOption<V>[]
|
|
34
|
+
size?: 'sm' | 'md' | undefined
|
|
35
|
+
name?: string | undefined
|
|
36
|
+
/** Span the container, each option an equal share. */
|
|
37
|
+
fill?: boolean | undefined
|
|
38
|
+
}) {
|
|
39
|
+
const group = untrack(() => name) ?? uid('seg')
|
|
40
|
+
let root: HTMLDivElement | undefined
|
|
41
|
+
use(
|
|
42
|
+
indicator,
|
|
43
|
+
() => root,
|
|
44
|
+
() => ({ selected: ':scope > label:has(input:checked)', at: value }),
|
|
45
|
+
)
|
|
46
|
+
return (
|
|
47
|
+
<div
|
|
48
|
+
ref={(n) => (root = n)}
|
|
49
|
+
data-scope="segmented"
|
|
50
|
+
role="radiogroup"
|
|
51
|
+
aria-label={label}
|
|
52
|
+
data-size={size === 'sm' ? 'sm' : undefined}
|
|
53
|
+
data-fill={fill ? '' : undefined}
|
|
54
|
+
>
|
|
55
|
+
<span data-part="indicator" aria-hidden="true" data-instant=""></span>
|
|
56
|
+
{options.map((o) => (
|
|
57
|
+
<label key={o.value} data-sweep="">
|
|
58
|
+
<span data-part="sweep" aria-hidden="true"></span>
|
|
59
|
+
<input
|
|
60
|
+
type="radio"
|
|
61
|
+
name={group}
|
|
62
|
+
value={o.value}
|
|
63
|
+
checked={o.value === value}
|
|
64
|
+
disabled={o.disabled}
|
|
65
|
+
onChange={() => onChange(o.value)}
|
|
66
|
+
/>
|
|
67
|
+
<span data-part="item">
|
|
68
|
+
{o.icon && <Icon name={o.icon} />}
|
|
69
|
+
{o.label}
|
|
70
|
+
{o.count !== undefined && <span data-part="count">{o.count}</span>}
|
|
71
|
+
</span>
|
|
72
|
+
</label>
|
|
73
|
+
))}
|
|
74
|
+
</div>
|
|
75
|
+
)
|
|
76
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { Interaction } from '@kerf-js/core/interaction'
|
|
2
|
+
import { useUi } from './use-ui'
|
|
3
|
+
import { sweepParts } from './Choice-parts'
|
|
4
|
+
import './fields'
|
|
5
|
+
import '@kerf-js/veneer-core/styles/inputs/choice-switch.css'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A native checkbox with role="switch" (03 §4; SIGNATURE §1c): the rail fills through the sweep as the thumb slides.
|
|
9
|
+
* The whole label is the hover target. Applies at once: never inside a form with Save (03 §8).
|
|
10
|
+
*/
|
|
11
|
+
export function Switch({
|
|
12
|
+
children,
|
|
13
|
+
hint,
|
|
14
|
+
size,
|
|
15
|
+
placement = 'end',
|
|
16
|
+
ui,
|
|
17
|
+
...rest
|
|
18
|
+
}: {
|
|
19
|
+
checked?: boolean
|
|
20
|
+
hint?: unknown
|
|
21
|
+
size?: 'sm' | 'md' | undefined
|
|
22
|
+
placement?: 'start' | 'end'
|
|
23
|
+
ui?: Interaction
|
|
24
|
+
children?: unknown
|
|
25
|
+
[attr: string]: unknown
|
|
26
|
+
}) {
|
|
27
|
+
let host: HTMLLabelElement | undefined
|
|
28
|
+
useUi(
|
|
29
|
+
() => ui,
|
|
30
|
+
() => host,
|
|
31
|
+
)
|
|
32
|
+
return (
|
|
33
|
+
<label
|
|
34
|
+
ref={(n) => (host = n)}
|
|
35
|
+
data-scope="switch"
|
|
36
|
+
data-placement={placement}
|
|
37
|
+
data-size={size === 'sm' ? 'sm' : undefined}
|
|
38
|
+
>
|
|
39
|
+
<input type="checkbox" role="switch" {...rest} />
|
|
40
|
+
<span data-part="track" data-sweep="">
|
|
41
|
+
<span data-part="rail-fill" aria-hidden="true">
|
|
42
|
+
<span data-part="rail-hover"></span>
|
|
43
|
+
</span>
|
|
44
|
+
{sweepParts()}
|
|
45
|
+
<span data-part="thumb" aria-hidden="true"></span>
|
|
46
|
+
</span>
|
|
47
|
+
<span data-part="label">{children}</span>
|
|
48
|
+
{hint !== undefined && <span data-part="hint">{hint}</span>}
|
|
49
|
+
</label>
|
|
50
|
+
)
|
|
51
|
+
}
|
package/src/Choice.tsx
ADDED
package/src/CloseX.tsx
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { XIcon } from '@kerf-js/veneer-icons'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The cross inside a close button: the glyph, and an accent copy over it that the hover wipes in (button.css). Both
|
|
5
|
+
* are the same XIcon, so a themed icon set changes them together.
|
|
6
|
+
*/
|
|
7
|
+
export function CloseX() {
|
|
8
|
+
return (
|
|
9
|
+
<>
|
|
10
|
+
<XIcon />
|
|
11
|
+
<XIcon data-part="ink" />
|
|
12
|
+
</>
|
|
13
|
+
)
|
|
14
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { CopyIcon, CheckIcon } from '@kerf-js/veneer-icons'
|
|
2
|
+
import { highlight } from '@kerf-js/veneer-core'
|
|
3
|
+
import './styles'
|
|
4
|
+
import '@kerf-js/veneer-core/styles/components/button.css'
|
|
5
|
+
import '@kerf-js/veneer-core/styles/components/copy.css'
|
|
6
|
+
import '@kerf-js/veneer-core/styles/rich/codeblock.css'
|
|
7
|
+
import '@kerf-js/veneer-core/styles/rich/code-tabs.css'
|
|
8
|
+
|
|
9
|
+
/** Props for CodeBlock. */
|
|
10
|
+
export interface CodeBlockProps {
|
|
11
|
+
/** The source to show, colour and copy. */
|
|
12
|
+
code: string
|
|
13
|
+
/** tsx by default; ts, js, json and sh are coloured too, anything else stays plain. */
|
|
14
|
+
language?: string | undefined
|
|
15
|
+
/** A file name shown in the bar above the code. */
|
|
16
|
+
filename?: string | undefined
|
|
17
|
+
/** Line numbers. */
|
|
18
|
+
lines?: boolean | undefined
|
|
19
|
+
/** Wrap long lines instead of scrolling. */
|
|
20
|
+
wrap?: boolean | undefined
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function CopyButton({ text }: { text?: string | undefined }) {
|
|
24
|
+
return (
|
|
25
|
+
<button
|
|
26
|
+
type="button"
|
|
27
|
+
data-scope="button"
|
|
28
|
+
data-emphasis="ghost"
|
|
29
|
+
data-tone="neutral"
|
|
30
|
+
data-size="sm"
|
|
31
|
+
data-act="copy"
|
|
32
|
+
data-copy=""
|
|
33
|
+
data-copy-text={text}
|
|
34
|
+
aria-label="Copy code"
|
|
35
|
+
>
|
|
36
|
+
<span data-part="indicator">
|
|
37
|
+
<CopyIcon />
|
|
38
|
+
<CheckIcon />
|
|
39
|
+
</span>
|
|
40
|
+
</button>
|
|
41
|
+
)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Code, coloured on the server (04 CodeBlock). It has no state, so it hydrates to nothing: `copyButtons()` from
|
|
46
|
+
* `@kerf-js/veneer-core`, called once anywhere in the app, runs every copy button in the document.
|
|
47
|
+
*/
|
|
48
|
+
export function CodeBlock({ code, language = 'tsx', filename, lines, wrap }: CodeBlockProps) {
|
|
49
|
+
return (
|
|
50
|
+
<figure data-scope="codeblock" data-wrap={wrap ? '' : undefined}>
|
|
51
|
+
<div data-part="head">
|
|
52
|
+
{filename && <span data-part="file">{filename}</span>}
|
|
53
|
+
<span class="sp"></span>
|
|
54
|
+
<span data-part="lang">{language}</span>
|
|
55
|
+
<CopyButton />
|
|
56
|
+
</div>
|
|
57
|
+
<pre tabindex="0" data-lines={lines ? '' : undefined}>
|
|
58
|
+
<code
|
|
59
|
+
// oxlint-disable-next-line kerf/no-html-sink -- highlight escapes the source before it wraps tokens in spans
|
|
60
|
+
innerHTML={highlight(code, language)}
|
|
61
|
+
></code>
|
|
62
|
+
</pre>
|
|
63
|
+
</figure>
|
|
64
|
+
)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** Inline code in running text. */
|
|
68
|
+
export function Code({ children }: { children: unknown }) {
|
|
69
|
+
return <code data-scope="code">{children}</code>
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** One command to copy, with its `$` (04 Snippet). */
|
|
73
|
+
export function Snippet({ code, prompt = '$' }: { code: string; prompt?: string }) {
|
|
74
|
+
return (
|
|
75
|
+
<div data-scope="snippet">
|
|
76
|
+
<span aria-hidden="true">{prompt}</span>
|
|
77
|
+
<code>{code}</code>
|
|
78
|
+
<CopyButton text={code} />
|
|
79
|
+
</div>
|
|
80
|
+
)
|
|
81
|
+
}
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
import { codeLayer, indented, jsonProblem, type ChangeReason } from '@kerf-js/veneer-core'
|
|
2
|
+
import { derived, onCleanup, state, untrack } from '@kerf-js/core'
|
|
3
|
+
import { bindable, type Bindable } from './bind'
|
|
4
|
+
import { Button } from './Button'
|
|
5
|
+
import { Field, type FieldShell } from './Field'
|
|
6
|
+
import { use } from '@kerf-js/veneer-core/kerf'
|
|
7
|
+
import '@kerf-js/veneer-core/styles/rich/body.css'
|
|
8
|
+
import '@kerf-js/veneer-core/styles/rich/code-input.css'
|
|
9
|
+
|
|
10
|
+
type CodeOwn = Bindable<string> & {
|
|
11
|
+
/** After a form's reset put the value back. */
|
|
12
|
+
onReset?: () => void
|
|
13
|
+
language?: string | undefined
|
|
14
|
+
/** Numbers each line in a gutter. Default `true`; off while `wrap` is on. */
|
|
15
|
+
lineNumbers?: boolean
|
|
16
|
+
tabSize?: 2 | 4
|
|
17
|
+
/** Soft-wraps long lines; line numbers then give way, since a number no longer means one row. */
|
|
18
|
+
wrap?: boolean
|
|
19
|
+
rows?: number
|
|
20
|
+
/** The line to mark in the gutter. */
|
|
21
|
+
errorLine?: number | undefined
|
|
22
|
+
name?: string | undefined
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Props for CodeInput: the field shell, the bound text and the editor's own options. */
|
|
26
|
+
export type CodeInputProps = FieldShell & CodeOwn
|
|
27
|
+
|
|
28
|
+
const LEAVE = 'Tab indents · Esc then Tab leaves'
|
|
29
|
+
|
|
30
|
+
function codeKeys(tabSize: () => 2 | 4, set: (area: HTMLTextAreaElement) => void) {
|
|
31
|
+
let leaving = false
|
|
32
|
+
const onKey = (e: KeyboardEvent) => {
|
|
33
|
+
const area = e.currentTarget as HTMLTextAreaElement
|
|
34
|
+
if (e.key === 'Escape') {
|
|
35
|
+
leaving = true
|
|
36
|
+
return
|
|
37
|
+
}
|
|
38
|
+
if (e.key !== 'Tab') {
|
|
39
|
+
if (e.key !== 'Shift') leaving = false
|
|
40
|
+
return
|
|
41
|
+
}
|
|
42
|
+
if (leaving) {
|
|
43
|
+
leaving = false
|
|
44
|
+
return
|
|
45
|
+
}
|
|
46
|
+
e.preventDefault()
|
|
47
|
+
const r = indented(area.value, area.selectionStart, area.selectionEnd, tabSize(), e.shiftKey)
|
|
48
|
+
area.setSelectionRange(r.from, r.to)
|
|
49
|
+
// execCommand keeps the browser's undo history, which setRangeText throws away
|
|
50
|
+
if (!document.execCommand?.('insertText', false, r.insert))
|
|
51
|
+
area.setRangeText(r.insert, r.from, r.to, 'end')
|
|
52
|
+
area.setSelectionRange(r.start, r.end)
|
|
53
|
+
set(area)
|
|
54
|
+
}
|
|
55
|
+
return onKey
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function attachCode(
|
|
59
|
+
box: () => HTMLDivElement | undefined,
|
|
60
|
+
text: () => string,
|
|
61
|
+
language: () => string | undefined,
|
|
62
|
+
) {
|
|
63
|
+
use(codeLayer, box, () => ({ text: text(), language: language() }))
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function codeValue(
|
|
67
|
+
value: () => CodeOwn['value'],
|
|
68
|
+
initial: () => string | undefined,
|
|
69
|
+
onChange: () => CodeOwn['onValueChange'],
|
|
70
|
+
) {
|
|
71
|
+
return bindable<string>(value, initial, '', onChange)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function codeEvents(held: ReturnType<typeof codeValue>, tabSize: () => 2 | 4) {
|
|
75
|
+
const set = (area: HTMLTextAreaElement) => held.set(area.value, 'keyboard')
|
|
76
|
+
return { set, onKey: codeKeys(tabSize, set) }
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function codeReset(held: ReturnType<typeof codeValue>, onReset: () => void) {
|
|
80
|
+
return () => {
|
|
81
|
+
held.reset()
|
|
82
|
+
onReset()
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* A code field (04 CodeInput; inputs-rich.html:2223-2241): a <textarea> over a layer coloured with the CSS Custom
|
|
88
|
+
* Highlight API, so a key press builds no spans; browsers without it show the textarea's own plain text. Tab indents,
|
|
89
|
+
* Shift+Tab outdents, and Esc then Tab leaves, which the hint says. No autocorrect, spellcheck or autocapitalize.
|
|
90
|
+
*/
|
|
91
|
+
export function CodeInput({
|
|
92
|
+
value,
|
|
93
|
+
defaultValue,
|
|
94
|
+
onValueChange,
|
|
95
|
+
language,
|
|
96
|
+
lineNumbers = true,
|
|
97
|
+
tabSize = 2,
|
|
98
|
+
wrap,
|
|
99
|
+
rows = 8,
|
|
100
|
+
errorLine,
|
|
101
|
+
name,
|
|
102
|
+
hint,
|
|
103
|
+
onReset,
|
|
104
|
+
...rest
|
|
105
|
+
}: CodeInputProps) {
|
|
106
|
+
const held = codeValue(
|
|
107
|
+
() => value,
|
|
108
|
+
() => defaultValue,
|
|
109
|
+
() => onValueChange,
|
|
110
|
+
)
|
|
111
|
+
const lines = derived(() => held.value.split('\n').map((_, n) => n + 1))
|
|
112
|
+
const numbered = derived(() => lineNumbers && !wrap)
|
|
113
|
+
let box: HTMLDivElement | undefined
|
|
114
|
+
const { set, onKey } = codeEvents(held, () => tabSize)
|
|
115
|
+
attachCode(
|
|
116
|
+
() => box,
|
|
117
|
+
() => held.value,
|
|
118
|
+
() => language,
|
|
119
|
+
)
|
|
120
|
+
return (
|
|
121
|
+
<Field
|
|
122
|
+
{...rest}
|
|
123
|
+
hint={hint ?? LEAVE}
|
|
124
|
+
attrs={{ 'data-multiline': '' }}
|
|
125
|
+
filled={held.value.length > 0}
|
|
126
|
+
reset={codeReset(held, () => onReset?.())}
|
|
127
|
+
control={(p) => (
|
|
128
|
+
<div data-part="body">
|
|
129
|
+
<div
|
|
130
|
+
ref={(n) => (box = n)}
|
|
131
|
+
class="code-in"
|
|
132
|
+
data-wrap={wrap ? '' : undefined}
|
|
133
|
+
style={`--_tab:${tabSize}`}
|
|
134
|
+
>
|
|
135
|
+
{numbered.value && (
|
|
136
|
+
<ol data-part="lines" class="ln" aria-hidden="true">
|
|
137
|
+
{lines.value.map((n) => (
|
|
138
|
+
<li key={n} data-error={n === errorLine ? '' : undefined}>
|
|
139
|
+
{n}
|
|
140
|
+
</li>
|
|
141
|
+
))}
|
|
142
|
+
</ol>
|
|
143
|
+
)}
|
|
144
|
+
<div data-part="surface">
|
|
145
|
+
<pre data-part="layer" aria-hidden="true">{`${held.value}\n`}</pre>
|
|
146
|
+
<textarea
|
|
147
|
+
{...p.rest}
|
|
148
|
+
data-part="input"
|
|
149
|
+
id={p.id}
|
|
150
|
+
rows={rows}
|
|
151
|
+
name={name}
|
|
152
|
+
spellcheck={false}
|
|
153
|
+
autocapitalize="off"
|
|
154
|
+
autocomplete="off"
|
|
155
|
+
wrap={wrap ? 'soft' : 'off'}
|
|
156
|
+
aria-describedby={p.describedby}
|
|
157
|
+
aria-invalid={p.invalid ? 'true' : undefined}
|
|
158
|
+
value={held.value}
|
|
159
|
+
onInput={(e) => set(e.currentTarget)}
|
|
160
|
+
onKeyDown={onKey}
|
|
161
|
+
>
|
|
162
|
+
{untrack(() => held.value)}
|
|
163
|
+
</textarea>
|
|
164
|
+
</div>
|
|
165
|
+
</div>
|
|
166
|
+
</div>
|
|
167
|
+
)}
|
|
168
|
+
/>
|
|
169
|
+
)
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/** Props for JsonEditor: CodeInput with the language fixed to JSON, and a schema check. */
|
|
173
|
+
export type JsonEditorProps = FieldShell &
|
|
174
|
+
Omit<CodeOwn, 'language' | 'errorLine'> & {
|
|
175
|
+
/** Checks parsed JSON; what it returns shows as the field's error. */
|
|
176
|
+
schema?: (value: unknown) => string | null | undefined
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* CodeInput for JSON (04 JsonEditor): parse errors, and an optional schema's, name their line in the field's error and
|
|
181
|
+
* pin the sweep; Format rewrites it with `tabSize`.
|
|
182
|
+
*/
|
|
183
|
+
export function JsonEditor({
|
|
184
|
+
value,
|
|
185
|
+
defaultValue,
|
|
186
|
+
onValueChange,
|
|
187
|
+
schema,
|
|
188
|
+
tabSize = 2,
|
|
189
|
+
...rest
|
|
190
|
+
}: JsonEditorProps) {
|
|
191
|
+
const held = bindable<string>(
|
|
192
|
+
() => value,
|
|
193
|
+
() => defaultValue,
|
|
194
|
+
'',
|
|
195
|
+
() => onValueChange,
|
|
196
|
+
)
|
|
197
|
+
const checked = state(held.value)
|
|
198
|
+
let timer: ReturnType<typeof setTimeout> | undefined
|
|
199
|
+
onCleanup(() => clearTimeout(timer))
|
|
200
|
+
const change = (v: string, reason: ChangeReason) => {
|
|
201
|
+
held.set(v, reason)
|
|
202
|
+
clearTimeout(timer)
|
|
203
|
+
timer = setTimeout(() => (checked.value = v), 250)
|
|
204
|
+
}
|
|
205
|
+
const problem = derived(() => (checked.value.trim() ? jsonProblem(checked.value) : null))
|
|
206
|
+
const failed = derived(() => {
|
|
207
|
+
const p = problem.value
|
|
208
|
+
if (p) return `Invalid JSON${p.line ? ` on line ${p.line}` : ''}: ${p.message}`
|
|
209
|
+
if (!schema || !checked.value.trim()) return undefined
|
|
210
|
+
return schema(JSON.parse(checked.value)) ?? undefined
|
|
211
|
+
})
|
|
212
|
+
const summary = derived(() => {
|
|
213
|
+
if (!checked.value.trim()) return LEAVE
|
|
214
|
+
const o = JSON.parse(checked.value)
|
|
215
|
+
return `Valid JSON · ${o && typeof o === 'object' ? `${Object.keys(o).length} ${Object.keys(o).length === 1 ? 'key' : 'keys'}` : typeof o} · ${LEAVE}`
|
|
216
|
+
})
|
|
217
|
+
const format = () => {
|
|
218
|
+
if (jsonProblem(held.value)) return
|
|
219
|
+
const next = JSON.stringify(
|
|
220
|
+
JSON.parse(held.value),
|
|
221
|
+
null,
|
|
222
|
+
untrack(() => tabSize),
|
|
223
|
+
)
|
|
224
|
+
held.set(next, 'pointer')
|
|
225
|
+
checked.value = next
|
|
226
|
+
}
|
|
227
|
+
return (
|
|
228
|
+
<CodeInput
|
|
229
|
+
{...rest}
|
|
230
|
+
tabSize={tabSize}
|
|
231
|
+
language="json"
|
|
232
|
+
value={held.value}
|
|
233
|
+
onValueChange={change}
|
|
234
|
+
onReset={() => {
|
|
235
|
+
clearTimeout(timer)
|
|
236
|
+
checked.value = held.value
|
|
237
|
+
}}
|
|
238
|
+
error={failed.value}
|
|
239
|
+
hint={problem.value ? LEAVE : summary.value}
|
|
240
|
+
errorLine={problem.value?.line}
|
|
241
|
+
end={
|
|
242
|
+
<span data-part="suffix">
|
|
243
|
+
<Button
|
|
244
|
+
emphasis="ghost"
|
|
245
|
+
tone="neutral"
|
|
246
|
+
size="sm"
|
|
247
|
+
disabled={!!problem.value}
|
|
248
|
+
onClick={format}
|
|
249
|
+
>
|
|
250
|
+
Format
|
|
251
|
+
</Button>
|
|
252
|
+
</span>
|
|
253
|
+
}
|
|
254
|
+
/>
|
|
255
|
+
)
|
|
256
|
+
}
|