@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,305 @@
|
|
|
1
|
+
import '@kerf-js/veneer-core/styles/rich/listbox.css'
|
|
2
|
+
import '@kerf-js/veneer-core/styles/rich/timezone.css'
|
|
3
|
+
import '@kerf-js/veneer-core/styles/rich/phone.css'
|
|
4
|
+
import type { RichFieldProps, Bindable } from '../Picker'
|
|
5
|
+
import type { E164, CountryCode, PhoneCountry } from '@kerf-js/veneer-core'
|
|
6
|
+
import { usePickerEnv, bindable, useOpen } from '../Picker'
|
|
7
|
+
import { untrack, state, derived } from '@kerf-js/core'
|
|
8
|
+
import {
|
|
9
|
+
PHONE_COUNTRIES,
|
|
10
|
+
regionOf,
|
|
11
|
+
inferCountry,
|
|
12
|
+
formatPhone,
|
|
13
|
+
displayName,
|
|
14
|
+
digitsOf,
|
|
15
|
+
caretAfter,
|
|
16
|
+
nationalLength,
|
|
17
|
+
} from '@kerf-js/veneer-core'
|
|
18
|
+
import { use } from '@kerf-js/veneer-core/kerf'
|
|
19
|
+
import { Field } from '../Field'
|
|
20
|
+
import { PhoneControl, PhonePanel, type PhoneView } from './phone-view'
|
|
21
|
+
|
|
22
|
+
/** A prefix moves where the label rests: onto the input, past the country button (specimen, `restOn`). */
|
|
23
|
+
function restOnInput(el: HTMLInputElement) {
|
|
24
|
+
const control = el.closest<HTMLElement>('[data-part="control"]')!
|
|
25
|
+
const measure = () => {
|
|
26
|
+
if (!control.style.getPropertyValue('--_inset'))
|
|
27
|
+
control.style.setProperty('--_inset', getComputedStyle(el.parentElement!).paddingInlineStart)
|
|
28
|
+
control.style.setProperty(
|
|
29
|
+
'--_lead',
|
|
30
|
+
`${Math.round(el.getBoundingClientRect().left - control.getBoundingClientRect().left)}px`,
|
|
31
|
+
)
|
|
32
|
+
}
|
|
33
|
+
measure()
|
|
34
|
+
const size = typeof ResizeObserver === 'undefined' ? undefined : new ResizeObserver(measure)
|
|
35
|
+
size?.observe(control)
|
|
36
|
+
return {
|
|
37
|
+
update() {},
|
|
38
|
+
destroy() {
|
|
39
|
+
size?.disconnect()
|
|
40
|
+
},
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Props for PhoneField. */
|
|
45
|
+
export type PhoneFieldProps = RichFieldProps &
|
|
46
|
+
Bindable<E164 | null> & {
|
|
47
|
+
country?: CountryCode
|
|
48
|
+
defaultCountry?: CountryCode
|
|
49
|
+
countries?: CountryCode[] | undefined
|
|
50
|
+
onCountryChange?: (c: CountryCode) => void
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* PhoneField (04 §3): a country button, then a native tel input (the OS keypad and SMS autofill beat anything custom).
|
|
55
|
+
* Digits format as you type and the caret stays behind the same digit; a pasted `+…` infers the country. The value is
|
|
56
|
+
* E.164, and only once the number is the country's length. The country list is a search list.
|
|
57
|
+
*/
|
|
58
|
+
export function PhoneField({
|
|
59
|
+
value,
|
|
60
|
+
defaultValue,
|
|
61
|
+
onValueChange,
|
|
62
|
+
country,
|
|
63
|
+
defaultCountry,
|
|
64
|
+
countries,
|
|
65
|
+
onCountryChange,
|
|
66
|
+
locale,
|
|
67
|
+
today,
|
|
68
|
+
name,
|
|
69
|
+
presentation,
|
|
70
|
+
label,
|
|
71
|
+
hint,
|
|
72
|
+
error,
|
|
73
|
+
disabled,
|
|
74
|
+
readonly,
|
|
75
|
+
...rest
|
|
76
|
+
}: PhoneFieldProps) {
|
|
77
|
+
const { env, v, list, find, code, text, pop, own, name_, placeholder } = phoneState({
|
|
78
|
+
value: () => value,
|
|
79
|
+
defaultValue: () => defaultValue,
|
|
80
|
+
onValueChange: () => onValueChange,
|
|
81
|
+
country: () => country,
|
|
82
|
+
defaultCountry: () => defaultCountry,
|
|
83
|
+
countries: () => countries,
|
|
84
|
+
locale: () => locale,
|
|
85
|
+
today: () => today,
|
|
86
|
+
})
|
|
87
|
+
let button: HTMLButtonElement | undefined
|
|
88
|
+
let input: HTMLInputElement | undefined
|
|
89
|
+
const actions = phoneActions({
|
|
90
|
+
code,
|
|
91
|
+
text,
|
|
92
|
+
own,
|
|
93
|
+
name_,
|
|
94
|
+
v,
|
|
95
|
+
pop,
|
|
96
|
+
list,
|
|
97
|
+
getInput: () => input,
|
|
98
|
+
onCountryChange: () => onCountryChange,
|
|
99
|
+
isReadonly: () => readonly,
|
|
100
|
+
})
|
|
101
|
+
use(restOnInput, () => input)
|
|
102
|
+
const view = phoneView({
|
|
103
|
+
data: { code, text, name: name_, placeholder, value: v, pop, env, list, find, actions },
|
|
104
|
+
readonly: () => readonly,
|
|
105
|
+
disabled: () => disabled,
|
|
106
|
+
fieldName: () => name,
|
|
107
|
+
presentation: () => presentation,
|
|
108
|
+
button: () => button!,
|
|
109
|
+
setButton: (n) => (button = n),
|
|
110
|
+
setInput: (n) => (input = n),
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
return (
|
|
114
|
+
<Field
|
|
115
|
+
{...rest}
|
|
116
|
+
label={label}
|
|
117
|
+
hint={hint}
|
|
118
|
+
error={error ?? own.value}
|
|
119
|
+
disabled={disabled}
|
|
120
|
+
readonly={readonly}
|
|
121
|
+
filled={text.value.length > 0}
|
|
122
|
+
hold={pop.value}
|
|
123
|
+
attrs={{ 'data-phone': '' }}
|
|
124
|
+
reset={actions.reset}
|
|
125
|
+
control={(p) => <PhoneControl view={view} p={p} />}
|
|
126
|
+
end={<PhonePanel view={view} />}
|
|
127
|
+
/>
|
|
128
|
+
)
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function phoneActions({
|
|
132
|
+
code,
|
|
133
|
+
text,
|
|
134
|
+
own,
|
|
135
|
+
name_,
|
|
136
|
+
v,
|
|
137
|
+
pop,
|
|
138
|
+
list,
|
|
139
|
+
getInput,
|
|
140
|
+
onCountryChange,
|
|
141
|
+
isReadonly,
|
|
142
|
+
}: {
|
|
143
|
+
code: ReturnType<typeof state<PhoneCountry>>
|
|
144
|
+
text: ReturnType<typeof state<string>>
|
|
145
|
+
own: ReturnType<typeof state<string | undefined>>
|
|
146
|
+
name_: { readonly value: string }
|
|
147
|
+
v: ReturnType<typeof bindable<E164 | null>>
|
|
148
|
+
pop: ReturnType<typeof useOpen>
|
|
149
|
+
list: PhoneCountry[]
|
|
150
|
+
getInput: () => HTMLInputElement | undefined
|
|
151
|
+
onCountryChange: () => PhoneFieldProps['onCountryChange']
|
|
152
|
+
isReadonly: () => boolean | undefined
|
|
153
|
+
}) {
|
|
154
|
+
const sync = (raw: string, caret: number | null) => {
|
|
155
|
+
const c = code.value
|
|
156
|
+
const before = digitsOf(raw.slice(0, caret ?? raw.length)).length
|
|
157
|
+
const { shown, national } = formatPhone(raw, c)
|
|
158
|
+
text.value = shown
|
|
159
|
+
const input = getInput()
|
|
160
|
+
if (input) {
|
|
161
|
+
input.value = shown
|
|
162
|
+
if (input === input.ownerDocument.activeElement) {
|
|
163
|
+
const at = caretAfter(shown, before)
|
|
164
|
+
input.setSelectionRange(at, at)
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
const need = nationalLength(c)
|
|
168
|
+
own.value =
|
|
169
|
+
national.length > need
|
|
170
|
+
? `${name_.value} numbers have ${need} digits after the country code.`
|
|
171
|
+
: undefined
|
|
172
|
+
const e = national.length === need ? (`+${c.dial}${national}` as E164) : null
|
|
173
|
+
if (e !== untrack(() => v.value)) v.set(e, 'keyboard')
|
|
174
|
+
}
|
|
175
|
+
const choose = (c: PhoneCountry) => {
|
|
176
|
+
code.value = c
|
|
177
|
+
untrack(onCountryChange)?.(c.code)
|
|
178
|
+
pop.set(false)
|
|
179
|
+
getInput()?.focus()
|
|
180
|
+
sync(text.value, null)
|
|
181
|
+
}
|
|
182
|
+
const onBlur = () => {
|
|
183
|
+
const c = code.value
|
|
184
|
+
const n = formatPhone(text.value, c).national.length,
|
|
185
|
+
need = nationalLength(c)
|
|
186
|
+
if (n && n < need) own.value = `That's ${n} digits. ${name_.value} numbers have ${need}.`
|
|
187
|
+
}
|
|
188
|
+
const onPaste = (e: ClipboardEvent) => {
|
|
189
|
+
if (isReadonly()) return
|
|
190
|
+
const t = e.clipboardData?.getData('text').trim() ?? ''
|
|
191
|
+
if (!t.startsWith('+')) return
|
|
192
|
+
const m = inferCountry(t, code.value, list)
|
|
193
|
+
if (!m) return
|
|
194
|
+
e.preventDefault()
|
|
195
|
+
code.value = m
|
|
196
|
+
sync((m.trunk ?? '') + digitsOf(t).slice(m.dial.length), null)
|
|
197
|
+
}
|
|
198
|
+
const reset = () => {
|
|
199
|
+
v.reset()
|
|
200
|
+
own.value = undefined
|
|
201
|
+
code.value = inferCountry(v.value ?? '', code.value, list) ?? code.value
|
|
202
|
+
text.value = v.value
|
|
203
|
+
? formatPhone(v.value.slice(code.value.dial.length + 1), code.value).shown
|
|
204
|
+
: ''
|
|
205
|
+
const input = getInput()
|
|
206
|
+
if (input) input.value = text.value
|
|
207
|
+
}
|
|
208
|
+
return { sync, choose, onBlur, onPaste, reset }
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
function phoneState({
|
|
212
|
+
value,
|
|
213
|
+
defaultValue,
|
|
214
|
+
onValueChange,
|
|
215
|
+
country,
|
|
216
|
+
defaultCountry,
|
|
217
|
+
countries,
|
|
218
|
+
locale,
|
|
219
|
+
today,
|
|
220
|
+
}: {
|
|
221
|
+
value: () => PhoneFieldProps['value']
|
|
222
|
+
defaultValue: () => PhoneFieldProps['defaultValue']
|
|
223
|
+
onValueChange: () => PhoneFieldProps['onValueChange']
|
|
224
|
+
country: () => PhoneFieldProps['country']
|
|
225
|
+
defaultCountry: () => PhoneFieldProps['defaultCountry']
|
|
226
|
+
countries: () => PhoneFieldProps['countries']
|
|
227
|
+
locale: () => PhoneFieldProps['locale']
|
|
228
|
+
today: () => PhoneFieldProps['today']
|
|
229
|
+
}) {
|
|
230
|
+
const env = usePickerEnv(locale, today)
|
|
231
|
+
const v = bindable<E164 | null>(value, defaultValue, null, onValueChange)
|
|
232
|
+
const list = untrack(() =>
|
|
233
|
+
countries() ? PHONE_COUNTRIES.filter((c) => countries()!.includes(c.code)) : PHONE_COUNTRIES,
|
|
234
|
+
)
|
|
235
|
+
const find = (code?: string) => list.find((c) => c.code === code)
|
|
236
|
+
const code = state<PhoneCountry>(
|
|
237
|
+
untrack(
|
|
238
|
+
() =>
|
|
239
|
+
find(country()) ?? find(defaultCountry()) ?? find(regionOf(env.locale.value)) ?? list[0]!,
|
|
240
|
+
),
|
|
241
|
+
)
|
|
242
|
+
const text = state(
|
|
243
|
+
untrack(() => {
|
|
244
|
+
const e = v.value
|
|
245
|
+
if (!e) return ''
|
|
246
|
+
const c = inferCountry(e, code.value, list) ?? code.value
|
|
247
|
+
code.value = c
|
|
248
|
+
return formatPhone(e.slice(c.dial.length + 1), c).shown
|
|
249
|
+
}),
|
|
250
|
+
)
|
|
251
|
+
const pop = useOpen(
|
|
252
|
+
() => undefined,
|
|
253
|
+
() => false,
|
|
254
|
+
() => undefined,
|
|
255
|
+
)
|
|
256
|
+
const own = state<string | undefined>(undefined)
|
|
257
|
+
const name_ = derived(() => displayName('region', code.value.code, env.locale.value))
|
|
258
|
+
const placeholder = derived(() => {
|
|
259
|
+
const c = code.value
|
|
260
|
+
return c.pattern.replace(/#/g, '0').replace(/^0/, c.trunk ? '0' : '5')
|
|
261
|
+
})
|
|
262
|
+
return { env, v, list, find, code, text, pop, own, name_, placeholder }
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
function phoneView({
|
|
266
|
+
data,
|
|
267
|
+
readonly,
|
|
268
|
+
disabled,
|
|
269
|
+
fieldName,
|
|
270
|
+
presentation,
|
|
271
|
+
button,
|
|
272
|
+
setButton,
|
|
273
|
+
setInput,
|
|
274
|
+
}: {
|
|
275
|
+
data: Omit<
|
|
276
|
+
PhoneView,
|
|
277
|
+
'readonly' | 'disabled' | 'fieldName' | 'presentation' | 'button' | 'setButton' | 'setInput'
|
|
278
|
+
>
|
|
279
|
+
readonly: () => PhoneView['readonly']
|
|
280
|
+
disabled: () => PhoneView['disabled']
|
|
281
|
+
fieldName: () => PhoneView['fieldName']
|
|
282
|
+
presentation: () => PhoneView['presentation']
|
|
283
|
+
button: PhoneView['button']
|
|
284
|
+
setButton: PhoneView['setButton']
|
|
285
|
+
setInput: PhoneView['setInput']
|
|
286
|
+
}): PhoneView {
|
|
287
|
+
return {
|
|
288
|
+
...data,
|
|
289
|
+
get readonly() {
|
|
290
|
+
return readonly()
|
|
291
|
+
},
|
|
292
|
+
get disabled() {
|
|
293
|
+
return disabled()
|
|
294
|
+
},
|
|
295
|
+
get fieldName() {
|
|
296
|
+
return fieldName()
|
|
297
|
+
},
|
|
298
|
+
get presentation() {
|
|
299
|
+
return presentation()
|
|
300
|
+
},
|
|
301
|
+
button,
|
|
302
|
+
setButton,
|
|
303
|
+
setInput,
|
|
304
|
+
}
|
|
305
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { ChangeReason } from '@kerf-js/veneer-core'
|
|
2
|
+
import { listKey } from '@kerf-js/veneer-core'
|
|
3
|
+
import { flush, type State } from '@kerf-js/core'
|
|
4
|
+
import type { Row } from './list'
|
|
5
|
+
|
|
6
|
+
export function searchKeys({
|
|
7
|
+
shown,
|
|
8
|
+
active,
|
|
9
|
+
onPick,
|
|
10
|
+
show,
|
|
11
|
+
}: {
|
|
12
|
+
shown: { readonly value: Row[] }
|
|
13
|
+
active: State<number>
|
|
14
|
+
onPick: () => (key: string, reason: ChangeReason) => void
|
|
15
|
+
show: () => void
|
|
16
|
+
}) {
|
|
17
|
+
return (e: KeyboardEvent) => {
|
|
18
|
+
const n = shown.value.length
|
|
19
|
+
if (!n) return
|
|
20
|
+
const m = listKey(e.key, active.value, n, { page: 8, wrap: true, typing: true })
|
|
21
|
+
if (!m.handled) return
|
|
22
|
+
e.preventDefault()
|
|
23
|
+
if (m.pick) return onPick()(shown.value[active.value]!.key, 'keyboard')
|
|
24
|
+
active.value = m.to
|
|
25
|
+
flush()
|
|
26
|
+
show()
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import '@kerf-js/veneer-core/styles/rich/listbox.css'
|
|
2
|
+
import '@kerf-js/veneer-core/styles/rich/timezone.css'
|
|
3
|
+
import '@kerf-js/veneer-core/styles/rich/phone.css'
|
|
4
|
+
import type { RichFieldProps, Bindable, Openable } from '../Picker'
|
|
5
|
+
import type { TimeZoneId, IsoDate } from '@kerf-js/veneer-core'
|
|
6
|
+
import { untrack } from '@kerf-js/core'
|
|
7
|
+
import { localZone, zoneRows, zoneCity, matchZone } from '@kerf-js/veneer-core'
|
|
8
|
+
import type { Row } from './list'
|
|
9
|
+
import { ListField } from './list'
|
|
10
|
+
import { GlobeIcon } from '@kerf-js/veneer-icons'
|
|
11
|
+
|
|
12
|
+
/** Props for TimeZoneSelect. */
|
|
13
|
+
export type TimeZoneSelectProps = RichFieldProps &
|
|
14
|
+
Bindable<TimeZoneId | null> &
|
|
15
|
+
Openable & { referenceDate?: string | undefined; zones?: TimeZoneId[]; showOffset?: boolean }
|
|
16
|
+
|
|
17
|
+
/** TimeZoneSelect (04 §2): every IANA zone with its offset at `referenceDate`; Local is pinned first. */
|
|
18
|
+
export function TimeZoneSelect({
|
|
19
|
+
referenceDate,
|
|
20
|
+
zones,
|
|
21
|
+
showOffset = true,
|
|
22
|
+
...props
|
|
23
|
+
}: TimeZoneSelectProps) {
|
|
24
|
+
const local = untrack(localZone)
|
|
25
|
+
const matches = new Map<string, ReturnType<typeof zoneRows>[number]>()
|
|
26
|
+
const rows = (locale: string, today: string): Row[] => {
|
|
27
|
+
const list = zoneRows(locale, (referenceDate ?? today) as IsoDate, zones)
|
|
28
|
+
for (const z of list) matches.set(z.zone, z)
|
|
29
|
+
const row = (z: (typeof list)[number]): Row => ({
|
|
30
|
+
key: z.zone,
|
|
31
|
+
main: z.city,
|
|
32
|
+
sub: z.region,
|
|
33
|
+
meta: showOffset ? z.offset : undefined,
|
|
34
|
+
pin: z.zone === local ? 'Local' : undefined,
|
|
35
|
+
search: z.search,
|
|
36
|
+
})
|
|
37
|
+
return [...list.filter((z) => z.zone === local), ...list.filter((z) => z.zone !== local)].map(
|
|
38
|
+
row,
|
|
39
|
+
)
|
|
40
|
+
}
|
|
41
|
+
return (
|
|
42
|
+
<ListField
|
|
43
|
+
icon={GlobeIcon}
|
|
44
|
+
title="Choose a time zone"
|
|
45
|
+
search="City, zone or +5:30"
|
|
46
|
+
text={(v) => zoneCity(v)}
|
|
47
|
+
rows={rows}
|
|
48
|
+
match={(r, q) => matchZone(matches.get(r.key)!, q)}
|
|
49
|
+
count={(n, q) => (q ? `${n} zone${n === 1 ? '' : 's'}` : `${n} zones · offsets for today`)}
|
|
50
|
+
{...props}
|
|
51
|
+
/>
|
|
52
|
+
)
|
|
53
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import '@kerf-js/veneer-core/styles/rich/listbox.css'
|
|
2
|
+
import '@kerf-js/veneer-core/styles/rich/timezone.css'
|
|
3
|
+
import '@kerf-js/veneer-core/styles/rich/phone.css'
|
|
4
|
+
|
|
5
|
+
export { TimeZoneSelect } from './RichSelect/timezone'
|
|
6
|
+
export { CountrySelect } from './RichSelect/codes'
|
|
7
|
+
export { LanguageSelect } from './RichSelect/codes'
|
|
8
|
+
export { CurrencySelect } from './RichSelect/codes'
|
|
9
|
+
export { PhoneField } from './RichSelect/phone'
|
|
10
|
+
export type { Row } from './RichSelect/list'
|
|
11
|
+
export type { TimeZoneSelectProps } from './RichSelect/timezone'
|
|
12
|
+
export type { CodeSelectProps } from './RichSelect/codes'
|
|
13
|
+
export type { PhoneFieldProps } from './RichSelect/phone'
|
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
import {
|
|
2
|
+
uid,
|
|
3
|
+
sanitizeHtml,
|
|
4
|
+
markdownToHtml,
|
|
5
|
+
htmlToMarkdown,
|
|
6
|
+
richText,
|
|
7
|
+
keyboardDock,
|
|
8
|
+
comboPopup,
|
|
9
|
+
nextIndex,
|
|
10
|
+
type RichTextHandle,
|
|
11
|
+
type RichTextOptions,
|
|
12
|
+
} from '@kerf-js/veneer-core'
|
|
13
|
+
import { untrack, state, derived, onCleanup, flush, watch } from '@kerf-js/core'
|
|
14
|
+
import { use } from '@kerf-js/veneer-core/kerf'
|
|
15
|
+
import { bindable } from '../bind'
|
|
16
|
+
import { TOOLS, type RichTextEditorProps, type MenuRow } from './tools'
|
|
17
|
+
import type { EditorView } from './view'
|
|
18
|
+
|
|
19
|
+
type EditorOptions = {
|
|
20
|
+
value: () => RichTextEditorProps['value']
|
|
21
|
+
defaultValue: () => RichTextEditorProps['defaultValue']
|
|
22
|
+
onValueChange: () => RichTextEditorProps['onValueChange']
|
|
23
|
+
format: () => NonNullable<RichTextEditorProps['format']>
|
|
24
|
+
toolbar: () => NonNullable<RichTextEditorProps['toolbar']>
|
|
25
|
+
marks: () => NonNullable<RichTextEditorProps['marks']>
|
|
26
|
+
blocks: () => NonNullable<RichTextEditorProps['blocks']>
|
|
27
|
+
commands: () => NonNullable<RichTextEditorProps['commands']>
|
|
28
|
+
mentions: () => RichTextEditorProps['mentions']
|
|
29
|
+
placeholder: () => string
|
|
30
|
+
minRows: () => number | undefined
|
|
31
|
+
maxRows: () => number | undefined
|
|
32
|
+
name: () => string | undefined
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function editorData(o: EditorOptions) {
|
|
36
|
+
const id = uid('rte')
|
|
37
|
+
const held = bindable<string>(o.value, o.defaultValue, '', o.onValueChange)
|
|
38
|
+
const refs = {
|
|
39
|
+
ed: undefined as HTMLDivElement | undefined,
|
|
40
|
+
handle: undefined as RichTextHandle | undefined,
|
|
41
|
+
bar: undefined as HTMLDivElement | undefined,
|
|
42
|
+
pop: undefined as HTMLDivElement | undefined,
|
|
43
|
+
mark: undefined as HTMLSpanElement | undefined,
|
|
44
|
+
link: undefined as HTMLInputElement | undefined,
|
|
45
|
+
lookup: undefined as AbortController | undefined,
|
|
46
|
+
written: '',
|
|
47
|
+
}
|
|
48
|
+
const toHtml = (v: string) =>
|
|
49
|
+
o.format() === 'markdown' ? sanitizeHtml(markdownToHtml(v)) : sanitizeHtml(v)
|
|
50
|
+
const fromEditor = (html: string) => (o.format() === 'markdown' ? htmlToMarkdown(refs.ed!) : html)
|
|
51
|
+
const start = untrack(() => toHtml(held.value))
|
|
52
|
+
refs.written = untrack(() => held.value)
|
|
53
|
+
const pressed = state<Record<string, boolean>>({})
|
|
54
|
+
const stop = state(0)
|
|
55
|
+
const linking = state(false)
|
|
56
|
+
const url = state('')
|
|
57
|
+
const items = state<MenuRow[]>([])
|
|
58
|
+
const active = state(0)
|
|
59
|
+
const menuOpen = state(false)
|
|
60
|
+
const said = state('')
|
|
61
|
+
const tools = derived(() =>
|
|
62
|
+
[
|
|
63
|
+
o
|
|
64
|
+
.blocks()
|
|
65
|
+
.filter((b) => b === 'h2' || b === 'h3')
|
|
66
|
+
.map((b) => TOOLS[b]),
|
|
67
|
+
o.marks().map((m) => TOOLS[m]),
|
|
68
|
+
o
|
|
69
|
+
.blocks()
|
|
70
|
+
.filter((b) => b !== 'h2' && b !== 'h3')
|
|
71
|
+
.map((b) => TOOLS[b]),
|
|
72
|
+
].filter((g) => g.length),
|
|
73
|
+
)
|
|
74
|
+
const flat = derived(() => tools.value.flat())
|
|
75
|
+
onCleanup(() => refs.lookup?.abort())
|
|
76
|
+
return {
|
|
77
|
+
id,
|
|
78
|
+
held,
|
|
79
|
+
refs,
|
|
80
|
+
toHtml,
|
|
81
|
+
fromEditor,
|
|
82
|
+
start,
|
|
83
|
+
pressed,
|
|
84
|
+
stop,
|
|
85
|
+
linking,
|
|
86
|
+
url,
|
|
87
|
+
items,
|
|
88
|
+
active,
|
|
89
|
+
menuOpen,
|
|
90
|
+
said,
|
|
91
|
+
tools,
|
|
92
|
+
flat,
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
type Data = ReturnType<typeof editorData>
|
|
96
|
+
|
|
97
|
+
function editorMenu(d: Data, o: EditorOptions) {
|
|
98
|
+
const close = () => {
|
|
99
|
+
d.menuOpen.value = false
|
|
100
|
+
d.refs.lookup?.abort()
|
|
101
|
+
}
|
|
102
|
+
const openMenu = (rows: MenuRow[], rect: DOMRect) => {
|
|
103
|
+
d.items.value = rows
|
|
104
|
+
d.active.value = 0
|
|
105
|
+
d.refs.mark!.style.insetBlockStart = `${rect.bottom}px`
|
|
106
|
+
d.refs.mark!.style.insetInlineStart = `${rect.left}px`
|
|
107
|
+
d.menuOpen.value = rows.length > 0
|
|
108
|
+
}
|
|
109
|
+
const onQuery = async (q: { trigger: string; query: string; rect: DOMRect } | null) => {
|
|
110
|
+
d.refs.lookup?.abort()
|
|
111
|
+
if (!q) return void (d.menuOpen.value = false)
|
|
112
|
+
const drop = () => d.refs.handle!.replaceQuery(q.query.length + 1)
|
|
113
|
+
if (q.trigger === '/') {
|
|
114
|
+
const low = q.query.toLowerCase()
|
|
115
|
+
return openMenu(
|
|
116
|
+
o
|
|
117
|
+
.commands()
|
|
118
|
+
.filter((c) => c.label.toLowerCase().includes(low))
|
|
119
|
+
.map((c) => ({
|
|
120
|
+
id: c.id,
|
|
121
|
+
main: c.label,
|
|
122
|
+
meta: c.shortcut ?? c.hint,
|
|
123
|
+
run: () => {
|
|
124
|
+
drop()
|
|
125
|
+
c.run(d.refs.handle!)
|
|
126
|
+
},
|
|
127
|
+
})),
|
|
128
|
+
q.rect,
|
|
129
|
+
)
|
|
130
|
+
}
|
|
131
|
+
if (!o.mentions()) return
|
|
132
|
+
const me = (d.refs.lookup = new AbortController())
|
|
133
|
+
try {
|
|
134
|
+
const found = await o.mentions()!.search(q.query, me.signal)
|
|
135
|
+
if (me !== d.refs.lookup) return
|
|
136
|
+
openMenu(
|
|
137
|
+
found.map((m) => ({
|
|
138
|
+
id: m.id,
|
|
139
|
+
main: m.label,
|
|
140
|
+
meta: m.meta,
|
|
141
|
+
run: () => {
|
|
142
|
+
drop()
|
|
143
|
+
d.refs.handle!.insertMention(m.label)
|
|
144
|
+
d.said.value = `Mention: ${m.label}`
|
|
145
|
+
},
|
|
146
|
+
})),
|
|
147
|
+
q.rect,
|
|
148
|
+
)
|
|
149
|
+
} catch {
|
|
150
|
+
/* superseded */
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
const choose = (at: number) => {
|
|
154
|
+
const row = d.items.value[at]
|
|
155
|
+
close()
|
|
156
|
+
row?.run()
|
|
157
|
+
}
|
|
158
|
+
return { close, onQuery, choose }
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function editorLinks(d: Data) {
|
|
162
|
+
const startLink = () => {
|
|
163
|
+
d.url.value = ''
|
|
164
|
+
d.linking.value = true
|
|
165
|
+
flush()
|
|
166
|
+
d.refs.link?.focus()
|
|
167
|
+
}
|
|
168
|
+
const endLink = (apply: boolean) => {
|
|
169
|
+
d.linking.value = false
|
|
170
|
+
if (apply && d.url.value.trim()) d.refs.handle!.run('link', d.url.value.trim())
|
|
171
|
+
else {
|
|
172
|
+
d.refs.ed!.focus()
|
|
173
|
+
d.refs.handle!.restore()
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return { startLink, endLink }
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function bindEditor({
|
|
180
|
+
d,
|
|
181
|
+
o,
|
|
182
|
+
menu,
|
|
183
|
+
links,
|
|
184
|
+
}: {
|
|
185
|
+
d: Data
|
|
186
|
+
o: EditorOptions
|
|
187
|
+
menu: ReturnType<typeof editorMenu>
|
|
188
|
+
links: ReturnType<typeof editorLinks>
|
|
189
|
+
}) {
|
|
190
|
+
use(
|
|
191
|
+
(el: HTMLDivElement, options: RichTextOptions) => (d.refs.handle = richText(el, options)),
|
|
192
|
+
() => d.refs.ed,
|
|
193
|
+
() => ({
|
|
194
|
+
onChange: (html: string) => {
|
|
195
|
+
d.refs.written = d.fromEditor(html)
|
|
196
|
+
d.held.set(d.refs.written, 'keyboard')
|
|
197
|
+
},
|
|
198
|
+
onState: (on: Record<string, boolean>) => (d.pressed.value = on),
|
|
199
|
+
onQuery: menu.onQuery,
|
|
200
|
+
onLink: links.startLink,
|
|
201
|
+
bubble: o.toolbar() === 'bubble' ? d.refs.bar : undefined,
|
|
202
|
+
}),
|
|
203
|
+
)
|
|
204
|
+
if (untrack(o.toolbar) !== 'none')
|
|
205
|
+
use(
|
|
206
|
+
keyboardDock,
|
|
207
|
+
() => d.refs.bar,
|
|
208
|
+
() => ({ editor: () => d.refs.ed }),
|
|
209
|
+
)
|
|
210
|
+
use(
|
|
211
|
+
comboPopup,
|
|
212
|
+
() => d.refs.pop,
|
|
213
|
+
() => ({ open: d.menuOpen.value, anchor: d.refs.mark!, onClose: menu.close }),
|
|
214
|
+
)
|
|
215
|
+
watch(
|
|
216
|
+
() => d.held.value,
|
|
217
|
+
(v) => {
|
|
218
|
+
if (v === d.refs.written) return
|
|
219
|
+
d.refs.written = v
|
|
220
|
+
// oxlint-disable-next-line kerf/no-html-sink -- toHtml sanitizes
|
|
221
|
+
if (d.refs.ed) d.refs.ed.innerHTML = d.toHtml(v)
|
|
222
|
+
},
|
|
223
|
+
)
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
function editorKeys(d: Data, menu: ReturnType<typeof editorMenu>) {
|
|
227
|
+
const onToolKey = (e: KeyboardEvent) => {
|
|
228
|
+
const to = nextIndex(e.key, d.stop.value, d.flat.value.length, {
|
|
229
|
+
rtl: getComputedStyle(e.currentTarget as Element).direction === 'rtl',
|
|
230
|
+
})
|
|
231
|
+
if (to < 0) return
|
|
232
|
+
e.preventDefault()
|
|
233
|
+
d.stop.value = to
|
|
234
|
+
flush()
|
|
235
|
+
;(e.currentTarget as Element).querySelector<HTMLElement>('[tabindex="0"]')?.focus()
|
|
236
|
+
}
|
|
237
|
+
const onMenuKey = (e: KeyboardEvent) => {
|
|
238
|
+
if (!d.menuOpen.value || e.isComposing) return
|
|
239
|
+
const n = d.items.value.length
|
|
240
|
+
const by = ({ ArrowDown: 1, ArrowUp: -1 } as Record<string, number>)[e.key]
|
|
241
|
+
if (by) {
|
|
242
|
+
e.preventDefault()
|
|
243
|
+
d.active.value = (d.active.value + by + n) % n
|
|
244
|
+
} else if (e.key === 'Enter' || e.key === 'Tab') {
|
|
245
|
+
e.preventDefault()
|
|
246
|
+
menu.choose(d.active.value)
|
|
247
|
+
} else if (e.key === 'Escape') {
|
|
248
|
+
e.preventDefault()
|
|
249
|
+
menu.close()
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
return { onToolKey, onMenuKey }
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
export function editorState(o: EditorOptions) {
|
|
256
|
+
const d = editorData(o)
|
|
257
|
+
const menu = editorMenu(d, o)
|
|
258
|
+
const links = editorLinks(d)
|
|
259
|
+
bindEditor({ d, o, menu, links })
|
|
260
|
+
const keys = editorKeys(d, menu)
|
|
261
|
+
const rows = () =>
|
|
262
|
+
[
|
|
263
|
+
o.minRows() && `min-block-size:${o.minRows()! * 1.6}em`,
|
|
264
|
+
o.maxRows() && `max-block-size:${o.maxRows()! * 1.6}em`,
|
|
265
|
+
]
|
|
266
|
+
.filter(Boolean)
|
|
267
|
+
.join(';') || undefined
|
|
268
|
+
const view: EditorView = {
|
|
269
|
+
id: d.id,
|
|
270
|
+
held: d.held,
|
|
271
|
+
start: d.start,
|
|
272
|
+
tools: d.tools,
|
|
273
|
+
flat: d.flat,
|
|
274
|
+
pressed: d.pressed,
|
|
275
|
+
stop: d.stop,
|
|
276
|
+
linking: d.linking,
|
|
277
|
+
url: d.url,
|
|
278
|
+
items: d.items,
|
|
279
|
+
active: d.active,
|
|
280
|
+
menuOpen: d.menuOpen,
|
|
281
|
+
said: d.said,
|
|
282
|
+
get toolbar() {
|
|
283
|
+
return o.toolbar()
|
|
284
|
+
},
|
|
285
|
+
get placeholder() {
|
|
286
|
+
return o.placeholder()
|
|
287
|
+
},
|
|
288
|
+
get name() {
|
|
289
|
+
return o.name()
|
|
290
|
+
},
|
|
291
|
+
handle: () => d.refs.handle,
|
|
292
|
+
setEditor: (n) => (d.refs.ed = n),
|
|
293
|
+
setBar: (n) => (d.refs.bar = n),
|
|
294
|
+
setPop: (n) => (d.refs.pop = n),
|
|
295
|
+
setMark: (n) => (d.refs.mark = n),
|
|
296
|
+
setLink: (n) => (d.refs.link = n),
|
|
297
|
+
rows,
|
|
298
|
+
onToolKey: keys.onToolKey,
|
|
299
|
+
onMenuKey: keys.onMenuKey,
|
|
300
|
+
startLink: links.startLink,
|
|
301
|
+
endLink: links.endLink,
|
|
302
|
+
choose: menu.choose,
|
|
303
|
+
}
|
|
304
|
+
return { held: d.held, menuOpen: d.menuOpen, view }
|
|
305
|
+
}
|