portal-mojo 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 +201 -0
- package/README.md +55 -0
- package/docs/DetailView.md +173 -0
- package/docs/ModelTable.md +128 -0
- package/docs/README.md +98 -0
- package/docs/admin-assistant.md +72 -0
- package/docs/admin-bouncer.md +120 -0
- package/docs/admin-cloudwatch.md +38 -0
- package/docs/admin-credentials.md +116 -0
- package/docs/admin-dashboard.md +15 -0
- package/docs/admin-devices-geoip.md +284 -0
- package/docs/admin-dns-certificates.md +122 -0
- package/docs/admin-dns-records.md +65 -0
- package/docs/admin-dns-registrar.md +33 -0
- package/docs/admin-dns.md +80 -0
- package/docs/admin-identity-users.md +103 -0
- package/docs/admin-incidents.md +71 -0
- package/docs/admin-jobs.md +426 -0
- package/docs/admin-members.md +112 -0
- package/docs/admin-messaging.md +56 -0
- package/docs/admin-metrics-explorer.md +63 -0
- package/docs/admin-monitoring.md +99 -0
- package/docs/admin-network-security.md +393 -0
- package/docs/admin-phonehub.md +27 -0
- package/docs/admin-push.md +36 -0
- package/docs/admin-rules.md +87 -0
- package/docs/admin-security-tickets.md +40 -0
- package/docs/admin-settings.md +78 -0
- package/docs/admin-shortlinks.md +32 -0
- package/docs/admin-storage.md +141 -0
- package/docs/auth-pages.md +212 -0
- package/docs/auth.md +58 -0
- package/docs/calendar.md +122 -0
- package/docs/charts.md +303 -0
- package/docs/client.md +206 -0
- package/docs/collection-multiselect.md +117 -0
- package/docs/collection-select.md +132 -0
- package/docs/combobox.md +105 -0
- package/docs/dataview.md +226 -0
- package/docs/datepicker.md +151 -0
- package/docs/daterange.md +170 -0
- package/docs/datetimepicker.md +249 -0
- package/docs/defineModel.md +72 -0
- package/docs/detail-primitives.md +174 -0
- package/docs/feedback.md +85 -0
- package/docs/file-upload-ux.md +146 -0
- package/docs/forms.md +435 -0
- package/docs/grouping-and-fmt.md +98 -0
- package/docs/idioms.md +112 -0
- package/docs/image-editor.md +101 -0
- package/docs/loading.md +242 -0
- package/docs/location-address.md +76 -0
- package/docs/markdown.md +203 -0
- package/docs/menus-and-access.md +89 -0
- package/docs/multiselect-dropdown.md +153 -0
- package/docs/params.md +73 -0
- package/docs/popover.md +130 -0
- package/docs/realtime.md +61 -0
- package/docs/record-feed.md +238 -0
- package/docs/right-panel.md +42 -0
- package/docs/tabs-and-form-wizard.md +60 -0
- package/docs/taginput.md +120 -0
- package/docs/timepicker.md +173 -0
- package/docs/timezone-select.md +147 -0
- package/docs/worldmap.md +302 -0
- package/package.json +55 -0
- package/src/admin/assistant/AssistantFeed.tsx +29 -0
- package/src/admin/assistant/AssistantPanel.tsx +65 -0
- package/src/admin/assistant/api.ts +17 -0
- package/src/admin/assistant/data.ts +63 -0
- package/src/admin/assistant/index.ts +21 -0
- package/src/admin/assistant/launchers.tsx +33 -0
- package/src/admin/assistant/pages.tsx +78 -0
- package/src/admin/assistant/streaming.ts +238 -0
- package/src/admin/assistant/types.ts +30 -0
- package/src/admin/bouncer/devices.tsx +230 -0
- package/src/admin/bouncer/index.ts +34 -0
- package/src/admin/bouncer/models.ts +199 -0
- package/src/admin/bouncer/signals.tsx +182 -0
- package/src/admin/bouncer/signatures.tsx +220 -0
- package/src/admin/cloudwatch/CloudWatchChart.tsx +61 -0
- package/src/admin/cloudwatch/CloudWatchDashboardPage.tsx +52 -0
- package/src/admin/cloudwatch/CloudWatchResourceDetail.tsx +33 -0
- package/src/admin/cloudwatch/data.ts +163 -0
- package/src/admin/cloudwatch/index.ts +16 -0
- package/src/admin/credentials/group-api-keys.tsx +433 -0
- package/src/admin/credentials/index.ts +4 -0
- package/src/admin/credentials/models.ts +244 -0
- package/src/admin/credentials/secret-dialog.tsx +77 -0
- package/src/admin/credentials/webhook-subscriptions.tsx +423 -0
- package/src/admin/dashboard/AdminDashboardPage.tsx +101 -0
- package/src/admin/dashboard/data.ts +60 -0
- package/src/admin/dashboard/index.ts +2 -0
- package/src/admin/dns/CertificateDetail.tsx +115 -0
- package/src/admin/dns/CertificateLifecyclePoller.tsx +141 -0
- package/src/admin/dns/CertificateRequestDialog.tsx +103 -0
- package/src/admin/dns/CertificatesPage.tsx +85 -0
- package/src/admin/dns/DnsRecordEditor.tsx +110 -0
- package/src/admin/dns/DnsRecordsPage.tsx +36 -0
- package/src/admin/dns/DnsRecordsPanel.tsx +71 -0
- package/src/admin/dns/DomainCertificatesSection.tsx +40 -0
- package/src/admin/dns/DomainDetail.tsx +41 -0
- package/src/admin/dns/DomainOnboardingDialog.tsx +27 -0
- package/src/admin/dns/DomainPurchaseDetail.tsx +11 -0
- package/src/admin/dns/DomainPurchaseWizard.tsx +112 -0
- package/src/admin/dns/DomainPurchasesPage.tsx +16 -0
- package/src/admin/dns/DomainsPage.tsx +27 -0
- package/src/admin/dns/ProviderCredentialsPage.tsx +304 -0
- package/src/admin/dns/RegistrantContactPage.tsx +42 -0
- package/src/admin/dns/api.ts +515 -0
- package/src/admin/dns/certificate-data.ts +221 -0
- package/src/admin/dns/data.ts +32 -0
- package/src/admin/dns/dns-data.ts +266 -0
- package/src/admin/dns/dns-integration.ts +24 -0
- package/src/admin/dns/domain-links.ts +37 -0
- package/src/admin/dns/index.ts +86 -0
- package/src/admin/dns/models.ts +418 -0
- package/src/admin/dns/purchase-data.ts +67 -0
- package/src/admin/dns/registrant-data.ts +52 -0
- package/src/admin/identity/index.ts +5 -0
- package/src/admin/identity/members/GroupMembersPanel.tsx +146 -0
- package/src/admin/identity/members/MemberDetail.tsx +226 -0
- package/src/admin/identity/members/MembersPage.tsx +144 -0
- package/src/admin/identity/members/index.ts +24 -0
- package/src/admin/identity/members/member-flows.tsx +132 -0
- package/src/admin/identity/members/models.ts +204 -0
- package/src/admin/identity/users/UserDetail.tsx +257 -0
- package/src/admin/identity/users/UsersPage.tsx +163 -0
- package/src/admin/identity/users/index.ts +27 -0
- package/src/admin/identity/users/models.ts +232 -0
- package/src/admin/identity/users/sections/ApiKeysSection.tsx +119 -0
- package/src/admin/identity/users/sections/AuditSection.tsx +190 -0
- package/src/admin/identity/users/sections/DevicesSection.tsx +140 -0
- package/src/admin/identity/users/sections/GroupsSection.tsx +64 -0
- package/src/admin/identity/users/sections/LoginsSection.tsx +106 -0
- package/src/admin/identity/users/sections/MetadataPanel.tsx +36 -0
- package/src/admin/identity/users/sections/NotificationsSection.tsx +117 -0
- package/src/admin/identity/users/sections/OAuthSection.tsx +72 -0
- package/src/admin/identity/users/sections/OverviewSection.tsx +109 -0
- package/src/admin/identity/users/sections/PermissionsSection.tsx +35 -0
- package/src/admin/identity/users/sections/PersonalSection.tsx +73 -0
- package/src/admin/identity/users/sections/ProfileSection.tsx +175 -0
- package/src/admin/identity/users/sections/SecuritySection.tsx +123 -0
- package/src/admin/identity/users/sections/actions.tsx +752 -0
- package/src/admin/identity/users/sections/permission-catalog.ts +138 -0
- package/src/admin/identity/users/sections/queries.ts +74 -0
- package/src/admin/identity/users/sections/shared.tsx +299 -0
- package/src/admin/incidents/EventDetail.tsx +43 -0
- package/src/admin/incidents/EventsPage.tsx +52 -0
- package/src/admin/incidents/IncidentDetail.tsx +68 -0
- package/src/admin/incidents/IncidentsPage.tsx +102 -0
- package/src/admin/incidents/forensics.tsx +73 -0
- package/src/admin/incidents/index.ts +16 -0
- package/src/admin/incidents/models.ts +113 -0
- package/src/admin/incidents/sanitize.ts +71 -0
- package/src/admin/index.ts +383 -0
- package/src/admin/jobs/JobDashboardPage.tsx +111 -0
- package/src/admin/jobs/JobDetail.tsx +721 -0
- package/src/admin/jobs/JobRunnersPage.tsx +216 -0
- package/src/admin/jobs/JobsTablePage.tsx +122 -0
- package/src/admin/jobs/RunnerDetail.tsx +576 -0
- package/src/admin/jobs/ScheduledTaskDetail.tsx +421 -0
- package/src/admin/jobs/ScheduledTasksPage.tsx +167 -0
- package/src/admin/jobs/columns.tsx +297 -0
- package/src/admin/jobs/control.ts +488 -0
- package/src/admin/jobs/index.ts +85 -0
- package/src/admin/jobs/models.ts +599 -0
- package/src/admin/jobs/queries.ts +272 -0
- package/src/admin/jobs/scheduled-task-form.tsx +493 -0
- package/src/admin/jobs/sections/JobChannelsPanel.tsx +142 -0
- package/src/admin/jobs/sections/JobOperationsSection.tsx +423 -0
- package/src/admin/jobs/sections/JobRunnersStrip.tsx +82 -0
- package/src/admin/jobs/sections/JobThroughputSection.tsx +118 -0
- package/src/admin/messaging/EmailDomainWizard.tsx +24 -0
- package/src/admin/messaging/EmailDomainsPage.tsx +17 -0
- package/src/admin/messaging/EmailTemplatesPage.tsx +13 -0
- package/src/admin/messaging/MailboxesPage.tsx +15 -0
- package/src/admin/messaging/PublicMessagesPage.tsx +13 -0
- package/src/admin/messaging/SandboxedEmailPreview.tsx +23 -0
- package/src/admin/messaging/SentMessagesPage.tsx +11 -0
- package/src/admin/messaging/api.ts +17 -0
- package/src/admin/messaging/data.ts +10 -0
- package/src/admin/messaging/index.ts +23 -0
- package/src/admin/messaging/models.ts +76 -0
- package/src/admin/messaging/push/PushPage.tsx +44 -0
- package/src/admin/messaging/push/api.ts +17 -0
- package/src/admin/messaging/push/index.ts +9 -0
- package/src/admin/messaging/push/models.ts +43 -0
- package/src/admin/messaging/sanitize.ts +44 -0
- package/src/admin/monitoring/LogInspector.tsx +160 -0
- package/src/admin/monitoring/LogsPage.tsx +135 -0
- package/src/admin/monitoring/MetricsExplorerPage.tsx +360 -0
- package/src/admin/monitoring/MetricsPermissionsPage.tsx +166 -0
- package/src/admin/monitoring/MetricsSourcePicker.tsx +136 -0
- package/src/admin/monitoring/index.ts +55 -0
- package/src/admin/monitoring/metrics-explorer-client.ts +229 -0
- package/src/admin/monitoring/metrics-explorer-data.ts +158 -0
- package/src/admin/monitoring/models.ts +155 -0
- package/src/admin/network/BlockedIPsPage.tsx +194 -0
- package/src/admin/network/BlockedIpDetail.tsx +262 -0
- package/src/admin/network/FirewallLogPage.tsx +115 -0
- package/src/admin/network/IPSetDetail.tsx +280 -0
- package/src/admin/network/IPSetEditor.tsx +191 -0
- package/src/admin/network/IPSetsPage.tsx +177 -0
- package/src/admin/network/geofence/BlocksTab.tsx +289 -0
- package/src/admin/network/geofence/ExemptionsTab.tsx +349 -0
- package/src/admin/network/geofence/GeofencingPage.tsx +119 -0
- package/src/admin/network/geofence/PostureHeader.tsx +184 -0
- package/src/admin/network/geofence/RuleEditor.tsx +176 -0
- package/src/admin/network/geofence/RulesTab.tsx +254 -0
- package/src/admin/network/geofence/SimulatorTab.tsx +281 -0
- package/src/admin/network/geofence/geofence-data.ts +674 -0
- package/src/admin/network/index.ts +68 -0
- package/src/admin/network/models.ts +607 -0
- package/src/admin/phonehub/PhoneHubPage.tsx +57 -0
- package/src/admin/phonehub/api.ts +47 -0
- package/src/admin/phonehub/data.ts +6 -0
- package/src/admin/phonehub/index.ts +10 -0
- package/src/admin/phonehub/models.ts +68 -0
- package/src/admin/rules/HandlerChainBuilder.tsx +51 -0
- package/src/admin/rules/RuleSetDetailPage.tsx +33 -0
- package/src/admin/rules/RuleSetsPage.tsx +33 -0
- package/src/admin/rules/editors.tsx +54 -0
- package/src/admin/rules/handler-dsl.ts +213 -0
- package/src/admin/rules/index.ts +13 -0
- package/src/admin/rules/models.ts +112 -0
- package/src/admin/security/devices/LoginEventDetail.tsx +123 -0
- package/src/admin/security/devices/LoginLocationMap.tsx +321 -0
- package/src/admin/security/devices/LoginLocationsPage.tsx +162 -0
- package/src/admin/security/devices/UserDeviceDetail.tsx +546 -0
- package/src/admin/security/devices/UserDeviceLocationDetail.tsx +272 -0
- package/src/admin/security/devices/UserDevicesPage.tsx +84 -0
- package/src/admin/security/devices/index.ts +40 -0
- package/src/admin/security/devices/models.ts +470 -0
- package/src/admin/security/geoip/GeoIpCachePage.tsx +135 -0
- package/src/admin/security/geoip/GeoIpDossier.tsx +804 -0
- package/src/admin/security/geoip/geoip-forms.ts +102 -0
- package/src/admin/security/geoip/index.ts +27 -0
- package/src/admin/security/geoip/models.ts +397 -0
- package/src/admin/security/index.ts +31 -0
- package/src/admin/security/models.ts +137 -0
- package/src/admin/security/tickets.tsx +562 -0
- package/src/admin/security-permissions.ts +5 -0
- package/src/admin/settings/SettingDetail.tsx +57 -0
- package/src/admin/settings/SettingEditor.tsx +157 -0
- package/src/admin/settings/SettingsPage.tsx +72 -0
- package/src/admin/settings/index.ts +19 -0
- package/src/admin/settings/model.ts +143 -0
- package/src/admin/shortlinks/ShortlinkDetail.tsx +55 -0
- package/src/admin/shortlinks/ShortlinkHistoryPage.tsx +18 -0
- package/src/admin/shortlinks/ShortlinksPage.tsx +59 -0
- package/src/admin/shortlinks/index.ts +18 -0
- package/src/admin/shortlinks/models.ts +246 -0
- package/src/admin/storage/BackendsPage.tsx +43 -0
- package/src/admin/storage/BucketDetail.tsx +77 -0
- package/src/admin/storage/BucketsPage.tsx +64 -0
- package/src/admin/storage/FileManagerDetail.tsx +36 -0
- package/src/admin/storage/FilePreview.tsx +54 -0
- package/src/admin/storage/FileUploadSurface.tsx +250 -0
- package/src/admin/storage/FileView.tsx +109 -0
- package/src/admin/storage/FilesPage.tsx +53 -0
- package/src/admin/storage/file-renditions.ts +99 -0
- package/src/admin/storage/index.ts +31 -0
- package/src/admin/storage/models.ts +585 -0
- package/src/admin/storage/storage-dialogs.tsx +80 -0
- package/src/charts/CircularProgress.tsx +281 -0
- package/src/charts/KPIStrip.tsx +162 -0
- package/src/charts/KPITile.tsx +125 -0
- package/src/charts/MetricsChart.tsx +459 -0
- package/src/charts/MetricsMiniWidget.tsx +588 -0
- package/src/charts/MiniChart.tsx +283 -0
- package/src/charts/PieChart.tsx +354 -0
- package/src/charts/SeriesChart.tsx +378 -0
- package/src/charts/chart-dialogs.tsx +149 -0
- package/src/charts/exportChart.ts +144 -0
- package/src/charts/index.ts +28 -0
- package/src/charts/pie-math.ts +127 -0
- package/src/charts/stats.ts +265 -0
- package/src/charts/worldmap/WorldMap.tsx +649 -0
- package/src/charts/worldmap/countryCentroids.ts +304 -0
- package/src/charts/worldmap/geo.ts +293 -0
- package/src/charts/worldmap/use-world-land.ts +47 -0
- package/src/charts/worldmap/world-land.ts +18 -0
- package/src/charts/worldmap/worldmap-data.ts +285 -0
- package/src/client/auth.ts +737 -0
- package/src/client/client.ts +268 -0
- package/src/client/duid.ts +31 -0
- package/src/client/errors.ts +33 -0
- package/src/client/group-context.ts +28 -0
- package/src/client/group.tsx +126 -0
- package/src/client/hooks.ts +50 -0
- package/src/client/index.ts +37 -0
- package/src/client/jwt.ts +75 -0
- package/src/client/location.ts +285 -0
- package/src/client/lookups.ts +41 -0
- package/src/client/markdown-fallback.tsx +115 -0
- package/src/client/markdown-parse.ts +386 -0
- package/src/client/markdown-sanitize.ts +217 -0
- package/src/client/markdown.ts +122 -0
- package/src/client/me.ts +188 -0
- package/src/client/mock.ts +9984 -0
- package/src/client/model.ts +227 -0
- package/src/client/params.ts +292 -0
- package/src/client/realtime-mock.ts +221 -0
- package/src/client/realtime.ts +561 -0
- package/src/client/record-feed.ts +329 -0
- package/src/client/safe-export.ts +71 -0
- package/src/client/types.ts +278 -0
- package/src/client/upload.ts +421 -0
- package/src/ui/AddressField.tsx +273 -0
- package/src/ui/AttachmentQueue.tsx +92 -0
- package/src/ui/CollectionMultiSelect.tsx +622 -0
- package/src/ui/CollectionSelect.tsx +517 -0
- package/src/ui/ComboBox.tsx +336 -0
- package/src/ui/DetailView.tsx +438 -0
- package/src/ui/FileDrop.tsx +194 -0
- package/src/ui/FileField.tsx +369 -0
- package/src/ui/FilterBar.tsx +269 -0
- package/src/ui/FormFields.tsx +77 -0
- package/src/ui/FormView.tsx +360 -0
- package/src/ui/FormWizard.tsx +336 -0
- package/src/ui/GroupSwitcher.tsx +202 -0
- package/src/ui/Guarded.tsx +16 -0
- package/src/ui/MarkdownView.tsx +89 -0
- package/src/ui/ModelTable.tsx +848 -0
- package/src/ui/MultiSelectDropdown.tsx +390 -0
- package/src/ui/Popover.tsx +204 -0
- package/src/ui/RecordFeed.tsx +627 -0
- package/src/ui/RequiresGroup.tsx +32 -0
- package/src/ui/RightPanel.tsx +107 -0
- package/src/ui/SidebarNav.tsx +330 -0
- package/src/ui/Tabs.tsx +161 -0
- package/src/ui/TagInput.tsx +381 -0
- package/src/ui/ThemeProvider.tsx +52 -0
- package/src/ui/UploadQueue.tsx +603 -0
- package/src/ui/armed-button.tsx +91 -0
- package/src/ui/date/Calendar.tsx +498 -0
- package/src/ui/date/DatePicker.tsx +289 -0
- package/src/ui/date/DateRangePicker.tsx +280 -0
- package/src/ui/date/DateTimePicker.tsx +587 -0
- package/src/ui/date/PresetRail.tsx +165 -0
- package/src/ui/date/TimePicker.tsx +624 -0
- package/src/ui/date/TimezoneSelect.tsx +267 -0
- package/src/ui/date/fns.ts +679 -0
- package/src/ui/detail/DataView.tsx +692 -0
- package/src/ui/detail/FlowStrip.tsx +80 -0
- package/src/ui/detail/KnownFieldsCard.tsx +121 -0
- package/src/ui/detail/MetadataSection.tsx +219 -0
- package/src/ui/detail/StackTraceView.tsx +150 -0
- package/src/ui/detail/StatusPanel.tsx +73 -0
- package/src/ui/detail/Timeline.tsx +52 -0
- package/src/ui/detail/index.ts +12 -0
- package/src/ui/field-registry.tsx +428 -0
- package/src/ui/field-wire.ts +322 -0
- package/src/ui/form-autosave.ts +583 -0
- package/src/ui/format.ts +444 -0
- package/src/ui/grouping.ts +150 -0
- package/src/ui/image-editor/ImageEditor.tsx +484 -0
- package/src/ui/image-editor/canvas.ts +254 -0
- package/src/ui/image-editor/index.ts +3 -0
- package/src/ui/image-editor/math.ts +416 -0
- package/src/ui/index.ts +58 -0
- package/src/ui/loading.tsx +604 -0
- package/src/ui/menu-registry.ts +213 -0
- package/src/ui/modal.tsx +297 -0
- package/src/ui/password.tsx +302 -0
- package/src/ui/schema-form-core.tsx +315 -0
- package/src/ui/toast.tsx +219 -0
- package/src/ui/ui.tsx +45 -0
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
import { useEffect, useId, useMemo, useRef, useState } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
LocationClient,
|
|
4
|
+
isStaleLocationRequest,
|
|
5
|
+
type AddressDetails,
|
|
6
|
+
type AddressSuggestion,
|
|
7
|
+
} from '../client/location';
|
|
8
|
+
import type { FieldValue, FieldValues } from '../client/types';
|
|
9
|
+
import { Popover } from './Popover';
|
|
10
|
+
|
|
11
|
+
export type AddressPart = keyof Pick<AddressDetails,
|
|
12
|
+
'address1' | 'address2' | 'city' | 'state' | 'state_code' |
|
|
13
|
+
'postal_code' | 'country' | 'country_code' | 'latitude' |
|
|
14
|
+
'longitude' | 'formatted_address' | 'place_id'>;
|
|
15
|
+
|
|
16
|
+
export interface AddressFieldProps {
|
|
17
|
+
value: string;
|
|
18
|
+
onCommit: (value: string) => void;
|
|
19
|
+
/** When supplied, selection is one atomic multi-field form commit. */
|
|
20
|
+
onPatch?: (patch: FieldValues) => void;
|
|
21
|
+
/** address detail part → declared form field name. */
|
|
22
|
+
fields?: Partial<Record<AddressPart, string>>;
|
|
23
|
+
/** Default destination for address1 when fields.address1 is absent. */
|
|
24
|
+
fieldName?: string;
|
|
25
|
+
client?: LocationClient;
|
|
26
|
+
country?: string;
|
|
27
|
+
minChars?: number;
|
|
28
|
+
debounceMs?: number;
|
|
29
|
+
maxSuggestions?: number;
|
|
30
|
+
placeholder?: string;
|
|
31
|
+
disabled?: boolean;
|
|
32
|
+
required?: boolean;
|
|
33
|
+
invalid?: boolean;
|
|
34
|
+
id?: string;
|
|
35
|
+
ariaDescribedBy?: string;
|
|
36
|
+
focusTarget?: (node: HTMLElement | null) => void;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function detailsPatch(
|
|
40
|
+
details: AddressDetails,
|
|
41
|
+
destinations: Partial<Record<AddressPart, string>>,
|
|
42
|
+
): FieldValues {
|
|
43
|
+
const patch: FieldValues = {};
|
|
44
|
+
for (const [part, name] of Object.entries(destinations) as Array<[AddressPart, string]>) {
|
|
45
|
+
const value = details[part];
|
|
46
|
+
if (value !== undefined && value !== null) patch[name] = value as FieldValue;
|
|
47
|
+
}
|
|
48
|
+
return patch;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function AddressField({
|
|
52
|
+
value,
|
|
53
|
+
onCommit,
|
|
54
|
+
onPatch,
|
|
55
|
+
fields,
|
|
56
|
+
fieldName,
|
|
57
|
+
client,
|
|
58
|
+
country = 'US',
|
|
59
|
+
minChars = 3,
|
|
60
|
+
debounceMs = 220,
|
|
61
|
+
maxSuggestions = 8,
|
|
62
|
+
placeholder = 'Start typing an address…',
|
|
63
|
+
disabled = false,
|
|
64
|
+
required = false,
|
|
65
|
+
invalid = false,
|
|
66
|
+
id,
|
|
67
|
+
ariaDescribedBy,
|
|
68
|
+
focusTarget,
|
|
69
|
+
}: AddressFieldProps) {
|
|
70
|
+
const ownedClientRef = useRef<LocationClient | null>(null);
|
|
71
|
+
if (!client && !ownedClientRef.current) ownedClientRef.current = new LocationClient();
|
|
72
|
+
const location = client ?? ownedClientRef.current!;
|
|
73
|
+
const previousClientRef = useRef(location);
|
|
74
|
+
const mountedRef = useRef(true);
|
|
75
|
+
const selectionRef = useRef(0);
|
|
76
|
+
const [draft, setDraft] = useState<string | null>(null);
|
|
77
|
+
const draftRef = useRef<string | null>(null);
|
|
78
|
+
const [suggestions, setSuggestions] = useState<AddressSuggestion[]>([]);
|
|
79
|
+
const [open, setOpen] = useState(false);
|
|
80
|
+
const [highlight, setHighlight] = useState(-1);
|
|
81
|
+
const [busy, setBusy] = useState(false);
|
|
82
|
+
const [error, setError] = useState('');
|
|
83
|
+
const anchorRef = useRef<HTMLDivElement>(null);
|
|
84
|
+
const uid = useId();
|
|
85
|
+
const listId = `address-list-${uid}`;
|
|
86
|
+
const destinations = useMemo(() => ({
|
|
87
|
+
...(fieldName ? { address1: fieldName } : {}),
|
|
88
|
+
...(fields ?? {}),
|
|
89
|
+
}), [fieldName, fields]);
|
|
90
|
+
|
|
91
|
+
useEffect(() => {
|
|
92
|
+
if (previousClientRef.current !== location) previousClientRef.current.cancelPending();
|
|
93
|
+
previousClientRef.current = location;
|
|
94
|
+
return () => location.cancelPending();
|
|
95
|
+
}, [location]);
|
|
96
|
+
|
|
97
|
+
useEffect(() => {
|
|
98
|
+
mountedRef.current = true;
|
|
99
|
+
return () => {
|
|
100
|
+
mountedRef.current = false;
|
|
101
|
+
selectionRef.current += 1;
|
|
102
|
+
ownedClientRef.current?.cancelPending();
|
|
103
|
+
};
|
|
104
|
+
}, []);
|
|
105
|
+
|
|
106
|
+
const setDraftBoth = (next: string | null) => {
|
|
107
|
+
draftRef.current = next;
|
|
108
|
+
setDraft(next);
|
|
109
|
+
};
|
|
110
|
+
const close = () => {
|
|
111
|
+
setOpen(false);
|
|
112
|
+
setHighlight(-1);
|
|
113
|
+
setSuggestions([]);
|
|
114
|
+
};
|
|
115
|
+
const revert = () => {
|
|
116
|
+
selectionRef.current += 1;
|
|
117
|
+
location.reset();
|
|
118
|
+
setDraftBoth(null);
|
|
119
|
+
setBusy(false);
|
|
120
|
+
setError('');
|
|
121
|
+
close();
|
|
122
|
+
};
|
|
123
|
+
const commitRaw = () => {
|
|
124
|
+
const next = draftRef.current;
|
|
125
|
+
if (next === null) { close(); return; }
|
|
126
|
+
location.reset();
|
|
127
|
+
setDraftBoth(null);
|
|
128
|
+
close();
|
|
129
|
+
if (next !== value) onCommit(next);
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
useEffect(() => {
|
|
133
|
+
const query = draft?.trim() ?? '';
|
|
134
|
+
setSuggestions([]);
|
|
135
|
+
setHighlight(-1);
|
|
136
|
+
// Selection details started before this render; its own busy-state
|
|
137
|
+
// update must not invalidate that request.
|
|
138
|
+
if (busy) {
|
|
139
|
+
setOpen(false);
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
location.cancelPending();
|
|
143
|
+
if (disabled || query.length < minChars) {
|
|
144
|
+
setOpen(false);
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
const timer = window.setTimeout(() => {
|
|
148
|
+
location.autocomplete(query, { country }).then(
|
|
149
|
+
(result) => {
|
|
150
|
+
if (!mountedRef.current || draftRef.current?.trim() !== query) return;
|
|
151
|
+
setSuggestions(result.data.slice(0, maxSuggestions));
|
|
152
|
+
setOpen(true);
|
|
153
|
+
setError('');
|
|
154
|
+
},
|
|
155
|
+
(reason: unknown) => {
|
|
156
|
+
if (!mountedRef.current || isStaleLocationRequest(reason)) return;
|
|
157
|
+
setSuggestions([]);
|
|
158
|
+
setOpen(false);
|
|
159
|
+
setError(reason instanceof Error ? reason.message : 'Address lookup failed');
|
|
160
|
+
},
|
|
161
|
+
);
|
|
162
|
+
}, debounceMs);
|
|
163
|
+
return () => window.clearTimeout(timer);
|
|
164
|
+
}, [draft, country, debounceMs, disabled, busy, location, maxSuggestions, minChars]);
|
|
165
|
+
|
|
166
|
+
const select = async (suggestion: AddressSuggestion) => {
|
|
167
|
+
const selection = ++selectionRef.current;
|
|
168
|
+
setDraftBoth(suggestion.description);
|
|
169
|
+
close();
|
|
170
|
+
setBusy(true);
|
|
171
|
+
setError('');
|
|
172
|
+
try {
|
|
173
|
+
const details = await location.placeDetails(suggestion.place_id);
|
|
174
|
+
if (!mountedRef.current || selection !== selectionRef.current) return;
|
|
175
|
+
const patch = detailsPatch(details, destinations);
|
|
176
|
+
const primary = details.address1 ?? details.formatted_address ?? suggestion.description;
|
|
177
|
+
setDraftBoth(null);
|
|
178
|
+
if (onPatch && Object.keys(patch).length > 0) onPatch(patch);
|
|
179
|
+
else if (primary !== value) onCommit(primary);
|
|
180
|
+
} catch (reason) {
|
|
181
|
+
if (!mountedRef.current || selection !== selectionRef.current || isStaleLocationRequest(reason)) return;
|
|
182
|
+
// The provider description was never committed, so dropping the
|
|
183
|
+
// draft atomically restores the prior controlled value.
|
|
184
|
+
setDraftBoth(null);
|
|
185
|
+
setError(reason instanceof Error ? reason.message : 'Address details failed');
|
|
186
|
+
} finally {
|
|
187
|
+
if (mountedRef.current && selection === selectionRef.current) setBusy(false);
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
const shown = draft ?? value;
|
|
192
|
+
const activeId = open && highlight >= 0 ? `${listId}-${highlight}` : undefined;
|
|
193
|
+
|
|
194
|
+
return (
|
|
195
|
+
<div className="address-field" ref={anchorRef}>
|
|
196
|
+
<div className="address-input-wrap">
|
|
197
|
+
<i className="bi bi-geo-alt address-icon" aria-hidden="true" />
|
|
198
|
+
<input
|
|
199
|
+
ref={(node) => focusTarget?.(node)}
|
|
200
|
+
id={id}
|
|
201
|
+
className={`input address-input${invalid ? ' input-invalid' : ''}`}
|
|
202
|
+
role="combobox"
|
|
203
|
+
aria-autocomplete="list"
|
|
204
|
+
aria-expanded={open}
|
|
205
|
+
aria-controls={listId}
|
|
206
|
+
aria-activedescendant={activeId}
|
|
207
|
+
aria-describedby={ariaDescribedBy}
|
|
208
|
+
aria-invalid={invalid || undefined}
|
|
209
|
+
autoComplete="street-address"
|
|
210
|
+
value={shown}
|
|
211
|
+
placeholder={placeholder}
|
|
212
|
+
disabled={disabled}
|
|
213
|
+
readOnly={busy}
|
|
214
|
+
aria-busy={busy || undefined}
|
|
215
|
+
required={required}
|
|
216
|
+
onChange={(event) => {
|
|
217
|
+
setDraftBoth(event.target.value);
|
|
218
|
+
setError('');
|
|
219
|
+
}}
|
|
220
|
+
onBlur={() => { if (!busy) commitRaw(); }}
|
|
221
|
+
onKeyDown={(event) => {
|
|
222
|
+
if (event.key === 'ArrowDown' && suggestions.length > 0) {
|
|
223
|
+
event.preventDefault();
|
|
224
|
+
setOpen(true);
|
|
225
|
+
setHighlight((current) => (current + 1) % suggestions.length);
|
|
226
|
+
} else if (event.key === 'ArrowUp' && open && suggestions.length > 0) {
|
|
227
|
+
event.preventDefault();
|
|
228
|
+
setHighlight((current) => current <= 0 ? suggestions.length - 1 : current - 1);
|
|
229
|
+
} else if (event.key === 'Enter') {
|
|
230
|
+
event.preventDefault();
|
|
231
|
+
if (open && highlight >= 0 && suggestions[highlight]) void select(suggestions[highlight]);
|
|
232
|
+
else commitRaw();
|
|
233
|
+
} else if (event.key === 'Tab' && draftRef.current !== null) {
|
|
234
|
+
commitRaw();
|
|
235
|
+
} else if (event.key === 'Escape' && !open && draftRef.current !== null) {
|
|
236
|
+
event.preventDefault();
|
|
237
|
+
revert();
|
|
238
|
+
}
|
|
239
|
+
}}
|
|
240
|
+
/>
|
|
241
|
+
{busy && <span className="address-spinner" role="status" aria-label="Loading address details" />}
|
|
242
|
+
</div>
|
|
243
|
+
{error && <span className="address-error" role="alert">{error}</span>}
|
|
244
|
+
<Popover
|
|
245
|
+
anchorRef={anchorRef}
|
|
246
|
+
open={open}
|
|
247
|
+
onClose={(reason) => reason === 'escape' ? revert() : commitRaw()}
|
|
248
|
+
id={listId}
|
|
249
|
+
className="address-pop"
|
|
250
|
+
role="listbox"
|
|
251
|
+
>
|
|
252
|
+
{suggestions.map((suggestion, index) => (
|
|
253
|
+
<div
|
|
254
|
+
key={suggestion.place_id}
|
|
255
|
+
id={`${listId}-${index}`}
|
|
256
|
+
className={`address-option${highlight === index ? ' address-option-hot' : ''}`}
|
|
257
|
+
role="option"
|
|
258
|
+
aria-selected={highlight === index}
|
|
259
|
+
onMouseDown={(event) => event.preventDefault()}
|
|
260
|
+
onMouseEnter={() => setHighlight(index)}
|
|
261
|
+
onClick={() => void select(suggestion)}
|
|
262
|
+
>
|
|
263
|
+
<i className="bi bi-geo-alt" aria-hidden="true" />
|
|
264
|
+
<span>
|
|
265
|
+
<strong>{suggestion.main_text || suggestion.description}</strong>
|
|
266
|
+
{suggestion.secondary_text && <small>{suggestion.secondary_text}</small>}
|
|
267
|
+
</span>
|
|
268
|
+
</div>
|
|
269
|
+
))}
|
|
270
|
+
</Popover>
|
|
271
|
+
</div>
|
|
272
|
+
);
|
|
273
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { useEffect, useMemo, useRef } from 'react';
|
|
2
|
+
import type { StartFileUploadOptions, UploadedFileRef } from '../client/upload';
|
|
3
|
+
import type { FileReference } from '../client/record-feed';
|
|
4
|
+
import { FileDropZone, type FileSelectionResult } from './FileDrop';
|
|
5
|
+
import { UploadQueue, useUploadQueue } from './UploadQueue';
|
|
6
|
+
import { toast } from './toast';
|
|
7
|
+
|
|
8
|
+
export interface AttachmentQueueState {
|
|
9
|
+
files: readonly FileReference[];
|
|
10
|
+
busy: boolean;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface AttachmentQueueProps {
|
|
14
|
+
consumerKey: string;
|
|
15
|
+
capacity: number;
|
|
16
|
+
destination: StartFileUploadOptions;
|
|
17
|
+
expectedGroupId: number | null;
|
|
18
|
+
disabled?: boolean;
|
|
19
|
+
resetKey?: number;
|
|
20
|
+
onChange(state: AttachmentQueueState): void;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function completedReference(file: UploadedFileRef, expectedGroupId: number | null): FileReference {
|
|
24
|
+
if (!Number.isSafeInteger(file.id) || file.id <= 0
|
|
25
|
+
|| !Number.isSafeInteger(file.fileManagerId) || Number(file.fileManagerId) <= 0
|
|
26
|
+
|| file.groupId !== expectedGroupId
|
|
27
|
+
|| typeof file.filename !== 'string' || !file.filename
|
|
28
|
+
|| typeof file.contentType !== 'string' || !file.contentType
|
|
29
|
+
|| (file.category !== null && typeof file.category !== 'string')) {
|
|
30
|
+
throw new Error('The completed upload did not match this attachment destination.');
|
|
31
|
+
}
|
|
32
|
+
return {
|
|
33
|
+
id: file.id,
|
|
34
|
+
filename: file.filename,
|
|
35
|
+
content_type: file.contentType,
|
|
36
|
+
category: file.category,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Shared reference-only attachment queue. Browser File values and transfer
|
|
42
|
+
* capabilities remain inside UploadQueue; consumers receive only completed,
|
|
43
|
+
* capability-free metadata rebuilt from the authoritative lifecycle response.
|
|
44
|
+
*/
|
|
45
|
+
export function AttachmentQueue({
|
|
46
|
+
consumerKey, capacity, destination, expectedGroupId, disabled = false,
|
|
47
|
+
resetKey = 0, onChange,
|
|
48
|
+
}: AttachmentQueueProps) {
|
|
49
|
+
const queue = useUploadQueue({
|
|
50
|
+
concurrency: Math.min(3, capacity), capacity, consumerKey, destination,
|
|
51
|
+
onComplete: (file) => { completedReference(file, expectedGroupId); },
|
|
52
|
+
});
|
|
53
|
+
const busy = queue.snapshot.activeCount > 0 || queue.snapshot.queuedCount > 0;
|
|
54
|
+
const files = useMemo(() => queue.snapshot.items.flatMap((item) => {
|
|
55
|
+
if (item.status !== 'completed' || !item.file) return [];
|
|
56
|
+
try { return [completedReference(item.file, expectedGroupId)]; } catch { return []; }
|
|
57
|
+
}), [expectedGroupId, queue.snapshot.items]);
|
|
58
|
+
|
|
59
|
+
const latestChange = useRef(onChange);
|
|
60
|
+
latestChange.current = onChange;
|
|
61
|
+
const fileSignature = files.map((file) => `${file.id}:${file.filename}:${file.content_type}:${file.category ?? ''}`).join('|');
|
|
62
|
+
useEffect(() => { latestChange.current({ files, busy }); }, [busy, fileSignature]);
|
|
63
|
+
useEffect(() => {
|
|
64
|
+
for (const item of queue.snapshot.items) {
|
|
65
|
+
if (item.canCancel) queue.cancel(item.id);
|
|
66
|
+
queue.remove(item.id);
|
|
67
|
+
}
|
|
68
|
+
}, [queue, resetKey]);
|
|
69
|
+
useEffect(() => { if (disabled) queue.cancelAll(); }, [disabled, queue]);
|
|
70
|
+
|
|
71
|
+
const select = (selection: FileSelectionResult) => {
|
|
72
|
+
selection.rejected.forEach((item) => toast.warning(item.message));
|
|
73
|
+
const result = queue.add(selection.accepted);
|
|
74
|
+
result.rejected.forEach((item) => toast.warning(item.message));
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
return (
|
|
78
|
+
<div className="attachment-queue">
|
|
79
|
+
<FileDropZone
|
|
80
|
+
className="attachment-drop"
|
|
81
|
+
label={capacity === 1 ? 'Attach a file or drop it here' : 'Attach files or drop them here'}
|
|
82
|
+
multiple={capacity > 1}
|
|
83
|
+
maxFiles={Math.max(1, capacity - queue.snapshot.items.length)}
|
|
84
|
+
disabled={disabled || queue.snapshot.items.length >= capacity}
|
|
85
|
+
onSelection={select}
|
|
86
|
+
>
|
|
87
|
+
<span><i className="bi bi-paperclip" aria-hidden="true" /> Attach {capacity === 1 ? 'file' : 'files'}</span>
|
|
88
|
+
</FileDropZone>
|
|
89
|
+
<UploadQueue queue={queue} />
|
|
90
|
+
</div>
|
|
91
|
+
);
|
|
92
|
+
}
|