@kelpie/ui 0.16.0 → 0.18.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/dist/api/client.d.ts +1 -1
- package/dist/api/resources/ai.d.ts +21 -0
- package/dist/api/resources/ai.d.ts.map +1 -0
- package/dist/api/resources/ai.js +101 -0
- package/dist/api/resources/ai.js.map +1 -0
- package/dist/api/resources/conversions.js +1 -1
- package/dist/api/resources/conversions.js.map +1 -1
- package/dist/api/resources/forms.d.ts +8 -0
- package/dist/api/resources/forms.d.ts.map +1 -1
- package/dist/api/resources/forms.js +39 -0
- package/dist/api/resources/forms.js.map +1 -1
- package/dist/api/resources/personIntake.d.ts +12 -0
- package/dist/api/resources/personIntake.d.ts.map +1 -0
- package/dist/api/resources/personIntake.js +54 -0
- package/dist/api/resources/personIntake.js.map +1 -0
- package/dist/api/resources/session.d.ts.map +1 -1
- package/dist/api/resources/session.js +3 -1
- package/dist/api/resources/session.js.map +1 -1
- package/dist/api/resources/workspace.d.ts +2 -2
- package/dist/api/resources/workspace.js +2 -2
- package/dist/app/KelpieApp.js +2 -2
- package/dist/app/KelpieApp.js.map +1 -1
- package/dist/components/ActivitiesPanel.d.ts +7 -4
- package/dist/components/ActivitiesPanel.d.ts.map +1 -1
- package/dist/components/ActivitiesPanel.js +12 -2
- package/dist/components/ActivitiesPanel.js.map +1 -1
- package/dist/components/ActivityAction.d.ts +15 -0
- package/dist/components/ActivityAction.d.ts.map +1 -0
- package/dist/components/ActivityAction.js +20 -0
- package/dist/components/ActivityAction.js.map +1 -0
- package/dist/components/AgentTasks.d.ts +5 -0
- package/dist/components/AgentTasks.d.ts.map +1 -1
- package/dist/components/AgentTasks.js +88 -10
- package/dist/components/AgentTasks.js.map +1 -1
- package/dist/components/DecisionsPanel.d.ts.map +1 -1
- package/dist/components/DecisionsPanel.js +3 -1
- package/dist/components/DecisionsPanel.js.map +1 -1
- package/dist/components/LinkedText.d.ts +12 -0
- package/dist/components/LinkedText.d.ts.map +1 -0
- package/dist/components/LinkedText.js +25 -0
- package/dist/components/LinkedText.js.map +1 -0
- package/dist/components/MarkdownView.d.ts +3 -1
- package/dist/components/MarkdownView.d.ts.map +1 -1
- package/dist/components/MarkdownView.js +17 -3
- package/dist/components/MarkdownView.js.map +1 -1
- package/dist/components/NotesPanel.d.ts +2 -1
- package/dist/components/NotesPanel.d.ts.map +1 -1
- package/dist/components/NotesPanel.js +6 -7
- package/dist/components/NotesPanel.js.map +1 -1
- package/dist/components/PersonIntakeDialog.d.ts +19 -0
- package/dist/components/PersonIntakeDialog.d.ts.map +1 -0
- package/dist/components/PersonIntakeDialog.js +87 -0
- package/dist/components/PersonIntakeDialog.js.map +1 -0
- package/dist/components/PlanPanel.d.ts.map +1 -1
- package/dist/components/PlanPanel.js +3 -1
- package/dist/components/PlanPanel.js.map +1 -1
- package/dist/components/RecordLinkTextarea.d.ts +12 -0
- package/dist/components/RecordLinkTextarea.d.ts.map +1 -0
- package/dist/components/RecordLinkTextarea.js +142 -0
- package/dist/components/RecordLinkTextarea.js.map +1 -0
- package/dist/components/Shell.js +1 -1
- package/dist/components/Shell.js.map +1 -1
- package/dist/components/WorkspaceSwitcher.d.ts +2 -1
- package/dist/components/WorkspaceSwitcher.d.ts.map +1 -1
- package/dist/components/WorkspaceSwitcher.js +7 -2
- package/dist/components/WorkspaceSwitcher.js.map +1 -1
- package/dist/index.d.ts +5 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -1
- package/dist/index.js.map +1 -1
- package/dist/lib/fragmentTarget.d.ts +18 -0
- package/dist/lib/fragmentTarget.d.ts.map +1 -0
- package/dist/lib/fragmentTarget.js +73 -0
- package/dist/lib/fragmentTarget.js.map +1 -0
- package/dist/lib/recordLinks.d.ts +17 -0
- package/dist/lib/recordLinks.d.ts.map +1 -0
- package/dist/lib/recordLinks.js +48 -0
- package/dist/lib/recordLinks.js.map +1 -0
- package/dist/lib/recordReferences.d.ts +41 -0
- package/dist/lib/recordReferences.d.ts.map +1 -0
- package/dist/lib/recordReferences.js +92 -0
- package/dist/lib/recordReferences.js.map +1 -0
- package/dist/modules/PersonIntakeWizard.d.ts +3 -0
- package/dist/modules/PersonIntakeWizard.d.ts.map +1 -0
- package/dist/modules/PersonIntakeWizard.js +223 -0
- package/dist/modules/PersonIntakeWizard.js.map +1 -0
- package/dist/modules/ai.d.ts +14 -0
- package/dist/modules/ai.d.ts.map +1 -0
- package/dist/modules/ai.js +26 -0
- package/dist/modules/ai.js.map +1 -0
- package/dist/modules/aiRunner.d.ts +3 -0
- package/dist/modules/aiRunner.d.ts.map +1 -0
- package/dist/modules/aiRunner.js +68 -0
- package/dist/modules/aiRunner.js.map +1 -0
- package/dist/modules/personIntakeSelection.d.ts +7 -0
- package/dist/modules/personIntakeSelection.d.ts.map +1 -0
- package/dist/modules/personIntakeSelection.js +21 -0
- package/dist/modules/personIntakeSelection.js.map +1 -0
- package/dist/pages/CompanyDetail.d.ts.map +1 -1
- package/dist/pages/CompanyDetail.js +2 -1
- package/dist/pages/CompanyDetail.js.map +1 -1
- package/dist/pages/DealDetail.d.ts.map +1 -1
- package/dist/pages/DealDetail.js +2 -1
- package/dist/pages/DealDetail.js.map +1 -1
- package/dist/pages/EnquiryDetail.d.ts.map +1 -1
- package/dist/pages/EnquiryDetail.js +2 -1
- package/dist/pages/EnquiryDetail.js.map +1 -1
- package/dist/pages/EventDetail.d.ts.map +1 -1
- package/dist/pages/EventDetail.js +2 -1
- package/dist/pages/EventDetail.js.map +1 -1
- package/dist/pages/FormsPage.js +4 -4
- package/dist/pages/FormsPage.js.map +1 -1
- package/dist/pages/OpportunityDetail.d.ts.map +1 -1
- package/dist/pages/OpportunityDetail.js +2 -1
- package/dist/pages/OpportunityDetail.js.map +1 -1
- package/dist/pages/PartnershipDetail.d.ts.map +1 -1
- package/dist/pages/PartnershipDetail.js +2 -1
- package/dist/pages/PartnershipDetail.js.map +1 -1
- package/dist/pages/PeoplePage.d.ts.map +1 -1
- package/dist/pages/PeoplePage.js +7 -1
- package/dist/pages/PeoplePage.js.map +1 -1
- package/dist/pages/PersonDetail.d.ts.map +1 -1
- package/dist/pages/PersonDetail.js +2 -1
- package/dist/pages/PersonDetail.js.map +1 -1
- package/dist/pages/RaiseDetail.d.ts.map +1 -1
- package/dist/pages/RaiseDetail.js +2 -1
- package/dist/pages/RaiseDetail.js.map +1 -1
- package/dist/pages/SearchPage.d.ts.map +1 -1
- package/dist/pages/SearchPage.js +26 -14
- package/dist/pages/SearchPage.js.map +1 -1
- package/dist/pages/admin/AiAdminPage.d.ts +2 -0
- package/dist/pages/admin/AiAdminPage.d.ts.map +1 -0
- package/dist/pages/admin/AiAdminPage.js +19 -0
- package/dist/pages/admin/AiAdminPage.js.map +1 -0
- package/dist/pages/admin/AiPage.d.ts +5 -0
- package/dist/pages/admin/AiPage.d.ts.map +1 -0
- package/dist/pages/admin/AiPage.js +196 -0
- package/dist/pages/admin/AiPage.js.map +1 -0
- package/dist/pages/admin/McpPage.js +2 -2
- package/dist/pages/admin/McpPage.js.map +1 -1
- package/dist/pages/admin/McpPanel.d.ts +3 -0
- package/dist/pages/admin/McpPanel.d.ts.map +1 -0
- package/dist/pages/admin/McpPanel.js +123 -0
- package/dist/pages/admin/McpPanel.js.map +1 -0
- package/dist/pages/admin/PrivacyPage.js +19 -3
- package/dist/pages/admin/PrivacyPage.js.map +1 -1
- package/dist/pages/admin/WorkspaceSettingsPage.d.ts +5 -6
- package/dist/pages/admin/WorkspaceSettingsPage.d.ts.map +1 -1
- package/dist/pages/admin/WorkspaceSettingsPage.js +12 -17
- package/dist/pages/admin/WorkspaceSettingsPage.js.map +1 -1
- package/dist/pages/dashboard/attention.d.ts +0 -5
- package/dist/pages/dashboard/attention.d.ts.map +1 -1
- package/dist/pages/dashboard/attention.js +1 -21
- package/dist/pages/dashboard/attention.js.map +1 -1
- package/dist/pages/dashboard/sections.d.ts.map +1 -1
- package/dist/pages/dashboard/sections.js +6 -3
- package/dist/pages/dashboard/sections.js.map +1 -1
- package/dist/pages/forms/EmbedPanel.js +5 -2
- package/dist/pages/forms/EmbedPanel.js.map +1 -1
- package/dist/pages/forms/FieldsEditor.d.ts.map +1 -1
- package/dist/pages/forms/FieldsEditor.js +90 -8
- package/dist/pages/forms/FieldsEditor.js.map +1 -1
- package/dist/pages/forms/FormSettings.d.ts.map +1 -1
- package/dist/pages/forms/FormSettings.js +73 -6
- package/dist/pages/forms/FormSettings.js.map +1 -1
- package/dist/pages/forms/SubmissionDetail.d.ts.map +1 -1
- package/dist/pages/forms/SubmissionDetail.js +2 -1
- package/dist/pages/forms/SubmissionDetail.js.map +1 -1
- package/dist/pages/forms/SubmissionsTable.d.ts.map +1 -1
- package/dist/pages/forms/SubmissionsTable.js +2 -1
- package/dist/pages/forms/SubmissionsTable.js.map +1 -1
- package/dist/pages/forms/fieldList.d.ts +2 -2
- package/dist/pages/forms/fieldList.d.ts.map +1 -1
- package/dist/pages/forms/fieldList.js +38 -10
- package/dist/pages/forms/fieldList.js.map +1 -1
- package/dist/pages/forms/template.d.ts.map +1 -1
- package/dist/pages/forms/template.js +13 -0
- package/dist/pages/forms/template.js.map +1 -1
- package/dist/pages/handbook/HandbookPage.d.ts.map +1 -1
- package/dist/pages/handbook/HandbookPage.js +2 -3
- package/dist/pages/handbook/HandbookPage.js.map +1 -1
- package/dist/pages/onboarding/WorkspaceStepPage.d.ts.map +1 -1
- package/dist/pages/onboarding/WorkspaceStepPage.js +9 -27
- package/dist/pages/onboarding/WorkspaceStepPage.js.map +1 -1
- package/dist/pages/onboarding/onboardingRerun.d.ts +9 -0
- package/dist/pages/onboarding/onboardingRerun.d.ts.map +1 -1
- package/dist/pages/onboarding/onboardingRerun.js +11 -0
- package/dist/pages/onboarding/onboardingRerun.js.map +1 -1
- package/dist/registry/context.d.ts +7 -1
- package/dist/registry/context.d.ts.map +1 -1
- package/dist/registry/context.js +12 -0
- package/dist/registry/context.js.map +1 -1
- package/dist/registry/contributions.d.ts +70 -1
- package/dist/registry/contributions.d.ts.map +1 -1
- package/dist/registry/registry.d.ts +12 -1
- package/dist/registry/registry.d.ts.map +1 -1
- package/dist/registry/registry.js +21 -0
- package/dist/registry/registry.js.map +1 -1
- package/package.json +2 -2
- package/src/api/client.ts +1 -1
- package/src/api/resources/ai.ts +120 -0
- package/src/api/resources/conversions.ts +1 -1
- package/src/api/resources/forms.ts +56 -0
- package/src/api/resources/personIntake.ts +95 -0
- package/src/api/resources/session.ts +3 -1
- package/src/api/resources/workspace.ts +4 -4
- package/src/app/KelpieApp.tsx +4 -2
- package/src/components/ActivitiesPanel.tsx +39 -10
- package/src/components/ActivityAction.tsx +33 -0
- package/src/components/AgentTasks.tsx +138 -10
- package/src/components/DecisionsPanel.tsx +9 -1
- package/src/components/LinkedText.tsx +51 -0
- package/src/components/MarkdownView.tsx +37 -7
- package/src/components/NotesPanel.tsx +18 -12
- package/src/components/PersonIntakeDialog.tsx +226 -0
- package/src/components/PlanPanel.tsx +9 -1
- package/src/components/RecordLinkTextarea.tsx +257 -0
- package/src/components/Shell.tsx +1 -1
- package/src/components/WorkspaceSwitcher.tsx +15 -1
- package/src/index.ts +16 -0
- package/src/lib/fragmentTarget.ts +96 -0
- package/src/lib/recordLinks.ts +57 -0
- package/src/lib/recordReferences.ts +139 -0
- package/src/modules/PersonIntakeWizard.tsx +633 -0
- package/src/modules/ai.tsx +27 -0
- package/src/modules/aiRunner.ts +83 -0
- package/src/modules/personIntakeSelection.ts +24 -0
- package/src/pages/CompanyDetail.tsx +2 -1
- package/src/pages/DealDetail.tsx +2 -1
- package/src/pages/EnquiryDetail.tsx +2 -1
- package/src/pages/EventDetail.tsx +2 -1
- package/src/pages/FormsPage.tsx +4 -4
- package/src/pages/OpportunityDetail.tsx +2 -1
- package/src/pages/PartnershipDetail.tsx +2 -1
- package/src/pages/PeoplePage.tsx +21 -5
- package/src/pages/PersonDetail.tsx +2 -1
- package/src/pages/RaiseDetail.tsx +2 -1
- package/src/pages/SearchPage.tsx +30 -15
- package/src/pages/admin/AiAdminPage.tsx +52 -0
- package/src/pages/admin/AiPage.tsx +457 -0
- package/src/pages/admin/{McpPage.tsx → McpPanel.tsx} +15 -11
- package/src/pages/admin/PrivacyPage.tsx +42 -0
- package/src/pages/admin/WorkspaceSettingsPage.tsx +13 -28
- package/src/pages/dashboard/attention.ts +1 -24
- package/src/pages/dashboard/sections.tsx +9 -4
- package/src/pages/forms/EmbedPanel.tsx +5 -1
- package/src/pages/forms/FieldsEditor.tsx +204 -15
- package/src/pages/forms/FormSettings.tsx +156 -9
- package/src/pages/forms/SubmissionDetail.tsx +2 -1
- package/src/pages/forms/SubmissionsTable.tsx +2 -1
- package/src/pages/forms/fieldList.ts +39 -10
- package/src/pages/forms/template.ts +13 -0
- package/src/pages/handbook/HandbookPage.tsx +5 -6
- package/src/pages/onboarding/WorkspaceStepPage.tsx +19 -43
- package/src/pages/onboarding/onboardingRerun.ts +14 -0
- package/src/registry/context.ts +19 -0
- package/src/registry/contributions.ts +64 -1
- package/src/registry/registry.ts +48 -0
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import { PERSON_INTAKE_MAX_TEXT } from '@kelpie/schemas'
|
|
2
|
+
import { useEffect, useState } from 'react'
|
|
3
|
+
import type { ReactNode } from 'react'
|
|
4
|
+
|
|
5
|
+
import { useResolveAgentTask } from '../api/resources/agentTasks.ts'
|
|
6
|
+
import { useWorkspace } from '../api/resources/workspace.ts'
|
|
7
|
+
import type { AgentRunnerAvailability, PersonIntakeProvider } from '../registry/contributions.ts'
|
|
8
|
+
import { usePersonIntakeProvider } from '../registry/context.ts'
|
|
9
|
+
import { ErrorPanel, LoadingPanel } from './QueryState.tsx'
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* People's **Add from notes**: a second way to add a person, from what the
|
|
13
|
+
* user already knows.
|
|
14
|
+
*
|
|
15
|
+
* Core owns the button and this dialog. When a module provides a wizard and
|
|
16
|
+
* it is ready (Kelpie AI enabled, with a key), the dialog renders it. Without
|
|
17
|
+
* one, the dialog still works: it builds the `workspace.add_person` prompt
|
|
18
|
+
* with the user's notes appended, for the user to paste into their own agent.
|
|
19
|
+
* That is the same pattern as the Log transcript task.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
const ADD_PERSON_TASK = 'workspace.add_person'
|
|
23
|
+
|
|
24
|
+
export function AddFromNotesButton({ onClick }: { readonly onClick: () => void }): React.JSX.Element {
|
|
25
|
+
return (
|
|
26
|
+
<button
|
|
27
|
+
type="button"
|
|
28
|
+
onClick={onClick}
|
|
29
|
+
title="Add a person from notes"
|
|
30
|
+
className="inline-flex h-7 shrink-0 items-center gap-1.5 rounded-md border border-border px-2.5 text-[12px] font-medium text-ink transition hover:border-border-strong hover:bg-surface-sunken"
|
|
31
|
+
>
|
|
32
|
+
<span aria-hidden="true" className="text-accent">
|
|
33
|
+
✦
|
|
34
|
+
</span>
|
|
35
|
+
Add from notes
|
|
36
|
+
</button>
|
|
37
|
+
)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface PersonIntakeDialogProps {
|
|
41
|
+
readonly onClose: () => void
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function PersonIntakeDialog({ onClose }: PersonIntakeDialogProps): React.JSX.Element {
|
|
45
|
+
const provider = usePersonIntakeProvider()
|
|
46
|
+
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
function onKey(event: KeyboardEvent): void {
|
|
49
|
+
if (event.key === 'Escape') onClose()
|
|
50
|
+
}
|
|
51
|
+
window.addEventListener('keydown', onKey)
|
|
52
|
+
return () => {
|
|
53
|
+
window.removeEventListener('keydown', onKey)
|
|
54
|
+
}
|
|
55
|
+
}, [onClose])
|
|
56
|
+
|
|
57
|
+
return (
|
|
58
|
+
<div
|
|
59
|
+
className="fixed inset-0 z-40 flex items-end justify-center bg-ink/30 p-4 sm:items-center"
|
|
60
|
+
role="dialog"
|
|
61
|
+
aria-modal="true"
|
|
62
|
+
aria-label="Add a person from notes"
|
|
63
|
+
onClick={onClose}
|
|
64
|
+
>
|
|
65
|
+
<div
|
|
66
|
+
className="flex max-h-[90vh] w-full max-w-2xl flex-col overflow-hidden rounded-lg border border-border bg-surface"
|
|
67
|
+
onClick={(event) => {
|
|
68
|
+
event.stopPropagation()
|
|
69
|
+
}}
|
|
70
|
+
>
|
|
71
|
+
<div className="flex items-start justify-between gap-3 border-b border-border px-4 py-3">
|
|
72
|
+
<div>
|
|
73
|
+
<div className="text-[14px] font-semibold text-ink">Add a person from notes</div>
|
|
74
|
+
<div className="mt-0.5 text-[12px] text-ink-muted">
|
|
75
|
+
Paste what you know. Kelpie builds the record from it.
|
|
76
|
+
</div>
|
|
77
|
+
</div>
|
|
78
|
+
<button type="button" className="text-[12px] font-medium text-ink-muted hover:text-ink" onClick={onClose}>
|
|
79
|
+
Close
|
|
80
|
+
</button>
|
|
81
|
+
</div>
|
|
82
|
+
{provider === undefined ? (
|
|
83
|
+
<CopyPromptIntake reason="The AI module is not part of this install." />
|
|
84
|
+
) : (
|
|
85
|
+
<ProvidedIntake provider={provider} onClose={onClose} />
|
|
86
|
+
)}
|
|
87
|
+
</div>
|
|
88
|
+
</div>
|
|
89
|
+
)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** Split out so `useAvailability` is only called when a provider exists. */
|
|
93
|
+
function ProvidedIntake({
|
|
94
|
+
provider,
|
|
95
|
+
onClose,
|
|
96
|
+
}: {
|
|
97
|
+
readonly provider: PersonIntakeProvider
|
|
98
|
+
readonly onClose: () => void
|
|
99
|
+
}): React.JSX.Element {
|
|
100
|
+
const availability: AgentRunnerAvailability = provider.useAvailability({ enabled: true })
|
|
101
|
+
|
|
102
|
+
if (availability.status === 'loading') {
|
|
103
|
+
return <LoadingPanel label="Checking AI…" />
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (availability.status === 'unavailable') {
|
|
107
|
+
return <CopyPromptIntake reason={availability.reason} />
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const Wizard = provider.Wizard
|
|
111
|
+
|
|
112
|
+
return <Wizard onClose={onClose} />
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** The dialog body and footer, the same frame the wizard's steps use. */
|
|
116
|
+
export function IntakeFrame({
|
|
117
|
+
children,
|
|
118
|
+
footer,
|
|
119
|
+
}: {
|
|
120
|
+
readonly children: ReactNode
|
|
121
|
+
readonly footer: ReactNode
|
|
122
|
+
}): React.JSX.Element {
|
|
123
|
+
return (
|
|
124
|
+
<>
|
|
125
|
+
<div className="min-h-0 flex-1 overflow-y-auto px-4 py-3">{children}</div>
|
|
126
|
+
<div className="flex flex-wrap items-center justify-end gap-2 border-t border-border px-4 py-3">{footer}</div>
|
|
127
|
+
</>
|
|
128
|
+
)
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export function NotesField({
|
|
132
|
+
value,
|
|
133
|
+
onChange,
|
|
134
|
+
disabled = false,
|
|
135
|
+
}: {
|
|
136
|
+
readonly value: string
|
|
137
|
+
readonly onChange: (value: string) => void
|
|
138
|
+
readonly disabled?: boolean
|
|
139
|
+
}): React.JSX.Element {
|
|
140
|
+
return (
|
|
141
|
+
<label className="block text-[12px] font-medium text-ink-muted">
|
|
142
|
+
What do you know about this person?
|
|
143
|
+
<textarea
|
|
144
|
+
value={value}
|
|
145
|
+
onChange={(event) => {
|
|
146
|
+
onChange(event.target.value)
|
|
147
|
+
}}
|
|
148
|
+
disabled={disabled}
|
|
149
|
+
rows={9}
|
|
150
|
+
maxLength={PERSON_INTAKE_MAX_TEXT}
|
|
151
|
+
autoFocus
|
|
152
|
+
placeholder={'Names, emails, a LinkedIn URL, an email signature, meeting notes…\n\nDana Reyes, dana@brightline.health. Met at HLTH; asked about a pilot.'}
|
|
153
|
+
className="mt-1 block w-full resize-y rounded-md border border-border bg-surface px-2.5 py-2 text-[13px] font-normal text-ink outline-none placeholder:text-ink-faint focus:border-accent disabled:opacity-60"
|
|
154
|
+
/>
|
|
155
|
+
<span className="mt-1 block font-normal text-ink-faint">
|
|
156
|
+
LinkedIn pages cannot be read without signing in. For the full profile, open it in your own browser, select
|
|
157
|
+
all, copy, and paste it here.
|
|
158
|
+
</span>
|
|
159
|
+
</label>
|
|
160
|
+
)
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/** The fallback: the add-person agent task's prompt with the notes appended. */
|
|
164
|
+
function CopyPromptIntake({ reason }: { readonly reason: string }): React.JSX.Element {
|
|
165
|
+
const { workspace } = useWorkspace()
|
|
166
|
+
const resolve = useResolveAgentTask()
|
|
167
|
+
const [text, setText] = useState('')
|
|
168
|
+
const [copied, setCopied] = useState(false)
|
|
169
|
+
const [clipboardFailed, setClipboardFailed] = useState(false)
|
|
170
|
+
|
|
171
|
+
async function copy(): Promise<void> {
|
|
172
|
+
if (workspace === undefined) return
|
|
173
|
+
|
|
174
|
+
setClipboardFailed(false)
|
|
175
|
+
const resolved = await resolve.runAsync({ taskId: ADD_PERSON_TASK, targetType: 'workspace', targetId: workspace.id })
|
|
176
|
+
const prompt = `${resolved.prompt}\n\n## Notes about the person\n\n${text.trim()}\n`
|
|
177
|
+
|
|
178
|
+
try {
|
|
179
|
+
await navigator.clipboard.writeText(prompt)
|
|
180
|
+
setCopied(true)
|
|
181
|
+
} catch {
|
|
182
|
+
setClipboardFailed(true)
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return (
|
|
187
|
+
<IntakeFrame
|
|
188
|
+
footer={
|
|
189
|
+
<button
|
|
190
|
+
type="button"
|
|
191
|
+
disabled={text.trim().length === 0 || resolve.isPending || workspace === undefined}
|
|
192
|
+
onClick={() => {
|
|
193
|
+
void copy().catch(() => undefined)
|
|
194
|
+
}}
|
|
195
|
+
className="rounded-md bg-accent px-3 py-1.5 text-[12px] font-semibold text-accent-fg hover:bg-accent-hover disabled:opacity-50"
|
|
196
|
+
>
|
|
197
|
+
{resolve.isPending ? 'Preparing…' : copied ? 'Copied' : 'Copy prompt for your agent'}
|
|
198
|
+
</button>
|
|
199
|
+
}
|
|
200
|
+
>
|
|
201
|
+
<div className="mb-3 rounded-md border border-border bg-surface-sunken px-3 py-2 text-[12px] text-ink-muted">
|
|
202
|
+
<p className="font-medium text-ink">AI cannot run this for you now.</p>
|
|
203
|
+
<p className="mt-0.5">{reason}</p>
|
|
204
|
+
<p className="mt-1">
|
|
205
|
+
You can still copy a prompt with your notes in it. Paste it into an agent connected to Kelpie over MCP
|
|
206
|
+
(Claude, Cursor, …), and the agent creates the records.
|
|
207
|
+
</p>
|
|
208
|
+
</div>
|
|
209
|
+
<NotesField
|
|
210
|
+
value={text}
|
|
211
|
+
onChange={(value) => {
|
|
212
|
+
setText(value)
|
|
213
|
+
setCopied(false)
|
|
214
|
+
}}
|
|
215
|
+
/>
|
|
216
|
+
{resolve.error !== null && (
|
|
217
|
+
<div className="mt-3">
|
|
218
|
+
<ErrorPanel error={resolve.error} />
|
|
219
|
+
</div>
|
|
220
|
+
)}
|
|
221
|
+
{clipboardFailed && (
|
|
222
|
+
<p className="mt-2 text-[12px] text-danger">The browser did not allow Kelpie to copy to the clipboard.</p>
|
|
223
|
+
)}
|
|
224
|
+
</IntakeFrame>
|
|
225
|
+
)
|
|
226
|
+
}
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
useUpdatePlanItem,
|
|
12
12
|
} from '../api/resources/planItems.ts'
|
|
13
13
|
import { formatDay } from '../lib/dates.ts'
|
|
14
|
+
import { FRAGMENT_HIGHLIGHT, useFragmentTarget } from '../lib/fragmentTarget.ts'
|
|
14
15
|
import { planStatusTone } from '../lib/plan.ts'
|
|
15
16
|
import { Chip } from './Chip.tsx'
|
|
16
17
|
import { Paginator } from './Paginator.tsx'
|
|
@@ -113,6 +114,7 @@ function PlanItemRow({ item }: { readonly item: PlanItem }): React.JSX.Element {
|
|
|
113
114
|
const updateItem = useUpdatePlanItem()
|
|
114
115
|
const deleteItem = useDeletePlanItem()
|
|
115
116
|
const [editing, setEditing] = useState(false)
|
|
117
|
+
const target = useFragmentTarget<HTMLLIElement>(item.id)
|
|
116
118
|
|
|
117
119
|
function save(fields: PlanFields): void {
|
|
118
120
|
updateItem.run({
|
|
@@ -148,7 +150,13 @@ function PlanItemRow({ item }: { readonly item: PlanItem }): React.JSX.Element {
|
|
|
148
150
|
}
|
|
149
151
|
|
|
150
152
|
return (
|
|
151
|
-
<li
|
|
153
|
+
<li
|
|
154
|
+
id={item.id}
|
|
155
|
+
ref={target.ref}
|
|
156
|
+
className={`group flex flex-wrap items-baseline gap-x-3 gap-y-1 border-b border-border px-4 py-2.5 transition-colors last:border-0 ${
|
|
157
|
+
target.highlighted ? FRAGMENT_HIGHLIGHT : ''
|
|
158
|
+
}`}
|
|
159
|
+
>
|
|
152
160
|
<time dateTime={item.date} className="shrink-0 text-[12px] font-medium text-ink tabular-nums">
|
|
153
161
|
{formatDay(item.date)}
|
|
154
162
|
</time>
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
import { formatRecordLinkToken, isRecordReferenceType } from '@kelpie/schemas'
|
|
2
|
+
import type { RecordReferenceType } from '@kelpie/schemas'
|
|
3
|
+
import { useEffect, useId, useRef, useState } from 'react'
|
|
4
|
+
import type { KeyboardEvent } from 'react'
|
|
5
|
+
|
|
6
|
+
import { useSearch } from '../api/resources/search.ts'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A textarea that links records: type `[[` and a few letters, pick a record, and
|
|
10
|
+
* a `[[type:id|Label]]` token goes in where the brackets were.
|
|
11
|
+
*
|
|
12
|
+
* The choices come from `GET /v1/search`, the same public endpoint the search
|
|
13
|
+
* page uses, so anything search finds can be linked. `@` is not a trigger. It is
|
|
14
|
+
* kept for naming workspace members.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/** How many choices the list shows. Search ranks them, so the best come first. */
|
|
18
|
+
const MAX_CHOICES = 8
|
|
19
|
+
|
|
20
|
+
const TYPE_LABELS: Readonly<Partial<Record<RecordReferenceType, string>>> = {
|
|
21
|
+
handbook_page: 'Handbook',
|
|
22
|
+
person: 'Person',
|
|
23
|
+
role: 'Role',
|
|
24
|
+
company: 'Company',
|
|
25
|
+
enquiry: 'Enquiry',
|
|
26
|
+
deal: 'Deal',
|
|
27
|
+
opportunity: 'Opportunity',
|
|
28
|
+
raise: 'Raise',
|
|
29
|
+
partnership: 'Partnership',
|
|
30
|
+
event: 'Event',
|
|
31
|
+
decision: 'Decision',
|
|
32
|
+
note: 'Note',
|
|
33
|
+
plan_item: 'Plan item',
|
|
34
|
+
list: 'List',
|
|
35
|
+
form: 'Form',
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
interface Choice {
|
|
39
|
+
readonly targetType: RecordReferenceType
|
|
40
|
+
readonly targetId: string
|
|
41
|
+
readonly title: string
|
|
42
|
+
readonly subtitle: string | null
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** An open `[[`: where it starts, and what has been typed after it. */
|
|
46
|
+
interface Trigger {
|
|
47
|
+
readonly start: number
|
|
48
|
+
readonly query: string
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* The `[[` the caret is in, if any. A `]` or a line break after the brackets
|
|
53
|
+
* closes it, so finished tokens and ordinary brackets never reopen the list.
|
|
54
|
+
*/
|
|
55
|
+
function openTrigger(value: string, caret: number): Trigger | null {
|
|
56
|
+
const before = value.slice(0, caret)
|
|
57
|
+
const start = before.lastIndexOf('[[')
|
|
58
|
+
|
|
59
|
+
if (start === -1) {
|
|
60
|
+
return null
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const query = before.slice(start + 2)
|
|
64
|
+
|
|
65
|
+
return /[\]\n]/u.test(query) ? null : { start, query }
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export interface RecordLinkTextareaProps {
|
|
69
|
+
readonly value: string
|
|
70
|
+
readonly onChange: (value: string) => void
|
|
71
|
+
readonly rows?: number
|
|
72
|
+
readonly placeholder?: string
|
|
73
|
+
readonly autoFocus?: boolean
|
|
74
|
+
readonly className?: string
|
|
75
|
+
readonly ariaLabel?: string
|
|
76
|
+
readonly spellCheck?: boolean
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function RecordLinkTextarea({
|
|
80
|
+
value,
|
|
81
|
+
onChange,
|
|
82
|
+
rows,
|
|
83
|
+
placeholder,
|
|
84
|
+
autoFocus,
|
|
85
|
+
className,
|
|
86
|
+
ariaLabel,
|
|
87
|
+
spellCheck,
|
|
88
|
+
}: RecordLinkTextareaProps): React.JSX.Element {
|
|
89
|
+
const textarea = useRef<HTMLTextAreaElement>(null)
|
|
90
|
+
const listId = useId()
|
|
91
|
+
const [caret, setCaret] = useState(0)
|
|
92
|
+
const [active, setActive] = useState(0)
|
|
93
|
+
// The `[[` the user closed with Escape. It stays closed until they type
|
|
94
|
+
// somewhere else, so Escape is not undone by the next keystroke.
|
|
95
|
+
const [dismissedAt, setDismissedAt] = useState<number | null>(null)
|
|
96
|
+
const [pendingCaret, setPendingCaret] = useState<number | null>(null)
|
|
97
|
+
|
|
98
|
+
const trigger = openTrigger(value, caret)
|
|
99
|
+
const open = trigger !== null && trigger.start !== dismissedAt
|
|
100
|
+
const search = useSearch(open ? trigger.query : '')
|
|
101
|
+
|
|
102
|
+
const choices: Choice[] = open
|
|
103
|
+
? (search.results?.groups ?? [])
|
|
104
|
+
.flatMap((group): Choice[] => {
|
|
105
|
+
const targetType = group.collection
|
|
106
|
+
|
|
107
|
+
return isRecordReferenceType(targetType)
|
|
108
|
+
? group.items.map((item) => ({
|
|
109
|
+
targetType,
|
|
110
|
+
targetId: item.id,
|
|
111
|
+
title: item.title,
|
|
112
|
+
subtitle: item.subtitle,
|
|
113
|
+
}))
|
|
114
|
+
: []
|
|
115
|
+
})
|
|
116
|
+
.slice(0, MAX_CHOICES)
|
|
117
|
+
: []
|
|
118
|
+
|
|
119
|
+
// Put the caret after an inserted token once React has written the new value.
|
|
120
|
+
useEffect(() => {
|
|
121
|
+
if (pendingCaret !== null && textarea.current !== null) {
|
|
122
|
+
textarea.current.setSelectionRange(pendingCaret, pendingCaret)
|
|
123
|
+
setCaret(pendingCaret)
|
|
124
|
+
setPendingCaret(null)
|
|
125
|
+
}
|
|
126
|
+
}, [pendingCaret, value])
|
|
127
|
+
|
|
128
|
+
function readCaret(): void {
|
|
129
|
+
const element = textarea.current
|
|
130
|
+
|
|
131
|
+
if (element !== null) {
|
|
132
|
+
setCaret(element.selectionStart)
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function choose(choice: Choice): void {
|
|
137
|
+
if (trigger === null) {
|
|
138
|
+
return
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const token = formatRecordLinkToken({
|
|
142
|
+
targetType: choice.targetType,
|
|
143
|
+
targetId: choice.targetId,
|
|
144
|
+
label: choice.title,
|
|
145
|
+
})
|
|
146
|
+
const next = value.slice(0, trigger.start) + token + value.slice(caret)
|
|
147
|
+
|
|
148
|
+
onChange(next)
|
|
149
|
+
setPendingCaret(trigger.start + token.length)
|
|
150
|
+
setActive(0)
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function onKeyDown(event: KeyboardEvent<HTMLTextAreaElement>): void {
|
|
154
|
+
if (!open) {
|
|
155
|
+
return
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (event.key === 'Escape') {
|
|
159
|
+
event.preventDefault()
|
|
160
|
+
setDismissedAt(trigger.start)
|
|
161
|
+
|
|
162
|
+
return
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
if (choices.length === 0) {
|
|
166
|
+
return
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
if (event.key === 'ArrowDown') {
|
|
170
|
+
event.preventDefault()
|
|
171
|
+
setActive((current) => (current + 1) % choices.length)
|
|
172
|
+
} else if (event.key === 'ArrowUp') {
|
|
173
|
+
event.preventDefault()
|
|
174
|
+
setActive((current) => (current - 1 + choices.length) % choices.length)
|
|
175
|
+
} else if (event.key === 'Enter' || event.key === 'Tab') {
|
|
176
|
+
const choice = choices[Math.min(active, choices.length - 1)]
|
|
177
|
+
|
|
178
|
+
if (choice !== undefined) {
|
|
179
|
+
event.preventDefault()
|
|
180
|
+
choose(choice)
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
const activeChoice = open && choices.length > 0 ? Math.min(active, choices.length - 1) : null
|
|
186
|
+
|
|
187
|
+
return (
|
|
188
|
+
<div className="relative">
|
|
189
|
+
<textarea
|
|
190
|
+
ref={textarea}
|
|
191
|
+
value={value}
|
|
192
|
+
onChange={(event) => {
|
|
193
|
+
onChange(event.target.value)
|
|
194
|
+
setCaret(event.target.selectionStart)
|
|
195
|
+
setActive(0)
|
|
196
|
+
}}
|
|
197
|
+
onKeyDown={onKeyDown}
|
|
198
|
+
onKeyUp={readCaret}
|
|
199
|
+
onClick={readCaret}
|
|
200
|
+
onSelect={readCaret}
|
|
201
|
+
rows={rows}
|
|
202
|
+
placeholder={placeholder}
|
|
203
|
+
autoFocus={autoFocus}
|
|
204
|
+
className={className}
|
|
205
|
+
aria-label={ariaLabel}
|
|
206
|
+
spellCheck={spellCheck}
|
|
207
|
+
role="combobox"
|
|
208
|
+
aria-autocomplete="list"
|
|
209
|
+
aria-expanded={open}
|
|
210
|
+
aria-controls={listId}
|
|
211
|
+
aria-activedescendant={activeChoice === null ? undefined : `${listId}-${String(activeChoice)}`}
|
|
212
|
+
/>
|
|
213
|
+
{open && (
|
|
214
|
+
<div
|
|
215
|
+
id={listId}
|
|
216
|
+
role="listbox"
|
|
217
|
+
aria-label="Link a record"
|
|
218
|
+
className="absolute right-0 left-0 z-20 mt-1 max-h-64 overflow-y-auto rounded-md border border-border bg-surface-raised py-1 shadow-lg"
|
|
219
|
+
>
|
|
220
|
+
{trigger.query.trim().length === 0 ? (
|
|
221
|
+
<p className="px-3 py-1.5 text-[12px] text-ink-faint">Type to find a record to link</p>
|
|
222
|
+
) : search.isLoading ? (
|
|
223
|
+
<p className="px-3 py-1.5 text-[12px] text-ink-faint">Searching…</p>
|
|
224
|
+
) : choices.length === 0 ? (
|
|
225
|
+
<p className="px-3 py-1.5 text-[12px] text-ink-faint">No records match</p>
|
|
226
|
+
) : (
|
|
227
|
+
choices.map((choice, index) => (
|
|
228
|
+
<div
|
|
229
|
+
key={`${choice.targetType}:${choice.targetId}`}
|
|
230
|
+
id={`${listId}-${String(index)}`}
|
|
231
|
+
role="option"
|
|
232
|
+
aria-selected={index === activeChoice}
|
|
233
|
+
// mousedown, not click: a click would blur the textarea first.
|
|
234
|
+
onMouseDown={(event) => {
|
|
235
|
+
event.preventDefault()
|
|
236
|
+
choose(choice)
|
|
237
|
+
}}
|
|
238
|
+
onMouseEnter={() => {
|
|
239
|
+
setActive(index)
|
|
240
|
+
}}
|
|
241
|
+
className={`flex cursor-pointer items-baseline gap-2 px-3 py-1.5 text-[13px] ${
|
|
242
|
+
index === activeChoice ? 'bg-surface-sunken' : ''
|
|
243
|
+
}`}
|
|
244
|
+
>
|
|
245
|
+
<span className="truncate text-ink">{choice.title}</span>
|
|
246
|
+
<span className="shrink-0 text-[11px] text-ink-faint">
|
|
247
|
+
{TYPE_LABELS[choice.targetType] ?? choice.targetType}
|
|
248
|
+
{choice.subtitle === null ? '' : ` · ${choice.subtitle}`}
|
|
249
|
+
</span>
|
|
250
|
+
</div>
|
|
251
|
+
))
|
|
252
|
+
)}
|
|
253
|
+
</div>
|
|
254
|
+
)}
|
|
255
|
+
</div>
|
|
256
|
+
)
|
|
257
|
+
}
|
package/src/components/Shell.tsx
CHANGED
|
@@ -29,7 +29,7 @@ const CORE_ADMIN_NAV: readonly NavItem[] = [
|
|
|
29
29
|
{ id: 'data', label: 'Data', to: '/admin/data', order: 300 },
|
|
30
30
|
{ id: 'api-keys', label: 'API keys', to: '/admin/api-keys', order: 350 },
|
|
31
31
|
{ id: 'webhooks', label: 'Webhooks', to: '/admin/webhooks', order: 400 },
|
|
32
|
-
{ id: '
|
|
32
|
+
{ id: 'ai', label: 'AI', to: '/admin/ai', order: 500 },
|
|
33
33
|
{ id: 'modules', label: 'Modules', to: '/admin/modules', order: 600 },
|
|
34
34
|
]
|
|
35
35
|
|
|
@@ -2,12 +2,14 @@ import { useEffect, useRef, useState } from 'react'
|
|
|
2
2
|
import { useNavigate } from 'react-router'
|
|
3
3
|
|
|
4
4
|
import { useAccountWorkspaces, useSession, useSwitchWorkspace } from '../api/resources/session.ts'
|
|
5
|
+
import { ONBOARDING_NEW_WORKSPACE_ENTRY } from '../pages/onboarding/onboardingRerun.ts'
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* Header control: the workspace this session is in, and a menu to move it.
|
|
8
9
|
*
|
|
9
10
|
* The list and the switch both live under `/v1/auth`, so a suspended current
|
|
10
|
-
* workspace still lets the reader see the other memberships and leave.
|
|
11
|
+
* workspace still lets the reader see the other memberships and leave. The
|
|
12
|
+
* last item opens the create form for another workspace.
|
|
11
13
|
*/
|
|
12
14
|
|
|
13
15
|
export function WorkspaceSwitcher(): React.JSX.Element | null {
|
|
@@ -124,6 +126,18 @@ export function WorkspaceSwitcher(): React.JSX.Element | null {
|
|
|
124
126
|
</button>
|
|
125
127
|
)
|
|
126
128
|
})}
|
|
129
|
+
<button
|
|
130
|
+
type="button"
|
|
131
|
+
role="menuitem"
|
|
132
|
+
disabled={switchWorkspace.isPending}
|
|
133
|
+
onClick={() => {
|
|
134
|
+
setOpen(false)
|
|
135
|
+
void navigate(ONBOARDING_NEW_WORKSPACE_ENTRY)
|
|
136
|
+
}}
|
|
137
|
+
className="mt-1 block w-full border-t border-border px-3 py-1.5 pt-2 text-left text-[13px] text-ink hover:bg-surface-sunken disabled:opacity-60"
|
|
138
|
+
>
|
|
139
|
+
New workspace
|
|
140
|
+
</button>
|
|
127
141
|
{switchWorkspace.error !== null && (
|
|
128
142
|
<p className="border-t border-border px-3 py-1.5 text-[12px] text-danger">
|
|
129
143
|
{switchWorkspace.error.message}
|
package/src/index.ts
CHANGED
|
@@ -208,12 +208,19 @@ export type { ThemePreference } from './lib/theme.ts'
|
|
|
208
208
|
|
|
209
209
|
export { EXTENSIBLE_RECORD_TYPES, NAV_SLOTS } from './registry/contributions.ts'
|
|
210
210
|
export type {
|
|
211
|
+
AdminTab,
|
|
212
|
+
AgentRunner,
|
|
213
|
+
AgentRunnerAvailability,
|
|
214
|
+
AgentRunnerProgress,
|
|
211
215
|
AuthMethod,
|
|
212
216
|
AuthMethodContext,
|
|
213
217
|
DashboardCard,
|
|
218
|
+
ExtensibleAdminPage,
|
|
214
219
|
ExtensibleRecordType,
|
|
215
220
|
NavItem,
|
|
216
221
|
NavSlot,
|
|
222
|
+
PersonIntakeProvider,
|
|
223
|
+
PersonIntakeWizardProps,
|
|
217
224
|
RecordContext,
|
|
218
225
|
RecordSidebarCard,
|
|
219
226
|
RecordTab,
|
|
@@ -227,11 +234,14 @@ export { NO_UI_MODULES, UiModuleError, inSlotOrder, registerUiModules } from './
|
|
|
227
234
|
export type { UiExtensions, UiModule, UiModuleContext } from './registry/registry.ts'
|
|
228
235
|
|
|
229
236
|
export {
|
|
237
|
+
useAdminTabs,
|
|
238
|
+
useAgentRunner,
|
|
230
239
|
useAuthMethods,
|
|
231
240
|
useDashboardCards,
|
|
232
241
|
useModuleRoutes,
|
|
233
242
|
useNavItems,
|
|
234
243
|
useOverridable,
|
|
244
|
+
usePersonIntakeProvider,
|
|
235
245
|
useRecordSidebarCards,
|
|
236
246
|
useRecordTabs,
|
|
237
247
|
useUiExtensions,
|
|
@@ -239,3 +249,9 @@ export {
|
|
|
239
249
|
|
|
240
250
|
export { UiExtensionProvider } from './registry/UiExtensionProvider.tsx'
|
|
241
251
|
export type { UiExtensionProviderProps } from './registry/UiExtensionProvider.tsx'
|
|
252
|
+
|
|
253
|
+
// The optional `ai` module's UI. An assembly that lists `createAiModule()` on
|
|
254
|
+
// the server lists `aiUi` in its `uiModules`.
|
|
255
|
+
export { aiUi } from './modules/ai.tsx'
|
|
256
|
+
export { AiRunLogTab, AiSettingsTab } from './pages/admin/AiPage.tsx'
|
|
257
|
+
export { useAiRuns, useAiSettings, useDisableAi, useSaveAiSettings } from './api/resources/ai.ts'
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { useEffect, useRef, useState } from 'react'
|
|
2
|
+
import type { RefObject } from 'react'
|
|
3
|
+
import { useLocation } from 'react-router'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A row a link can point at: `/companies/com_1#note_1` opens the company and
|
|
7
|
+
* brings note `note_1` into view.
|
|
8
|
+
*
|
|
9
|
+
* Notes, Decisions and Plan items have no page of their own, so a link to one
|
|
10
|
+
* opens the record it is on with the item's id as the fragment. The row whose id
|
|
11
|
+
* matches scrolls to the middle of the screen and is highlighted for a moment, so
|
|
12
|
+
* the reader sees which one was meant. A row on a later page of its panel is not
|
|
13
|
+
* on screen, and nothing happens.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/** How long the highlight stays, in milliseconds. */
|
|
17
|
+
const HIGHLIGHT_MS = 2000
|
|
18
|
+
|
|
19
|
+
export interface FragmentTarget<T extends HTMLElement> {
|
|
20
|
+
readonly ref: RefObject<T | null>
|
|
21
|
+
readonly highlighted: boolean
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function useFragmentTarget<T extends HTMLElement>(id: string): FragmentTarget<T> {
|
|
25
|
+
const { hash } = useLocation()
|
|
26
|
+
const ref = useRef<T>(null)
|
|
27
|
+
const [highlighted, setHighlighted] = useState(false)
|
|
28
|
+
const targeted = hash === `#${id}`
|
|
29
|
+
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
if (!targeted) {
|
|
32
|
+
return undefined
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const element = ref.current
|
|
36
|
+
|
|
37
|
+
// jsdom has no layout, and so no `scrollIntoView`.
|
|
38
|
+
if (element !== null && typeof element.scrollIntoView === 'function') {
|
|
39
|
+
element.scrollIntoView({ block: 'center', behavior: 'smooth' })
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
setHighlighted(true)
|
|
43
|
+
|
|
44
|
+
const timer = window.setTimeout(() => {
|
|
45
|
+
setHighlighted(false)
|
|
46
|
+
}, HIGHLIGHT_MS)
|
|
47
|
+
|
|
48
|
+
return () => {
|
|
49
|
+
window.clearTimeout(timer)
|
|
50
|
+
}
|
|
51
|
+
}, [targeted])
|
|
52
|
+
|
|
53
|
+
return { ref, highlighted }
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* The detail-page tab that holds a row with this id prefix. Every record page
|
|
58
|
+
* names these three tabs the same.
|
|
59
|
+
*/
|
|
60
|
+
const TAB_BY_PREFIX: readonly (readonly [string, string])[] = [
|
|
61
|
+
['note_', 'notes'],
|
|
62
|
+
['dec_', 'decisions'],
|
|
63
|
+
['plan_', 'plan'],
|
|
64
|
+
]
|
|
65
|
+
|
|
66
|
+
function tabForHash(hash: string): string | undefined {
|
|
67
|
+
const id = hash.startsWith('#') ? hash.slice(1) : hash
|
|
68
|
+
|
|
69
|
+
return TAB_BY_PREFIX.find(([prefix]) => id.startsWith(prefix))?.[1]
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* A detail page's active tab, opened on the tab a fragment points into.
|
|
74
|
+
*
|
|
75
|
+
* `/companies/com_1#note_1` must land on Notes, or the row it names is not on
|
|
76
|
+
* screen to scroll to. The fragment picks the tab on the first render and again
|
|
77
|
+
* whenever it changes, so a link to another note on the same page switches too.
|
|
78
|
+
* Anything else starts on Overview, and a click on a tab still wins.
|
|
79
|
+
*/
|
|
80
|
+
export function useRecordTab(): readonly [string, (tab: string) => void] {
|
|
81
|
+
const { hash } = useLocation()
|
|
82
|
+
const [tab, setTab] = useState(() => tabForHash(hash) ?? 'overview')
|
|
83
|
+
|
|
84
|
+
useEffect(() => {
|
|
85
|
+
const fromHash = tabForHash(hash)
|
|
86
|
+
|
|
87
|
+
if (fromHash !== undefined) {
|
|
88
|
+
setTab(fromHash)
|
|
89
|
+
}
|
|
90
|
+
}, [hash])
|
|
91
|
+
|
|
92
|
+
return [tab, setTab]
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** The classes a highlighted row adds. */
|
|
96
|
+
export const FRAGMENT_HIGHLIGHT = 'bg-accent-soft/40 ring-2 ring-accent/40'
|