@kelpie/ui 0.18.0 → 0.20.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.
Files changed (132) hide show
  1. package/dist/api/resources/forms.d.ts +21 -2
  2. package/dist/api/resources/forms.d.ts.map +1 -1
  3. package/dist/api/resources/forms.js +51 -4
  4. package/dist/api/resources/forms.js.map +1 -1
  5. package/dist/components/AiDrawer.d.ts +13 -0
  6. package/dist/components/AiDrawer.d.ts.map +1 -0
  7. package/dist/components/AiDrawer.js +165 -0
  8. package/dist/components/AiDrawer.js.map +1 -0
  9. package/dist/components/ApiKeysPanel.js +1 -1
  10. package/dist/components/DataTable.js +1 -1
  11. package/dist/components/KanbanBoard.d.ts +5 -1
  12. package/dist/components/KanbanBoard.d.ts.map +1 -1
  13. package/dist/components/KanbanBoard.js +37 -2
  14. package/dist/components/KanbanBoard.js.map +1 -1
  15. package/dist/components/NotesPanel.js +2 -2
  16. package/dist/components/NotesPanel.js.map +1 -1
  17. package/dist/components/PageHeader.js +1 -1
  18. package/dist/components/PageHeader.js.map +1 -1
  19. package/dist/components/PersonIntakePanel.d.ts +21 -0
  20. package/dist/components/PersonIntakePanel.d.ts.map +1 -0
  21. package/dist/components/PersonIntakePanel.js +76 -0
  22. package/dist/components/PersonIntakePanel.js.map +1 -0
  23. package/dist/components/SegmentedControl.js +2 -2
  24. package/dist/components/SegmentedControl.js.map +1 -1
  25. package/dist/components/Shell.d.ts.map +1 -1
  26. package/dist/components/Shell.js +39 -3
  27. package/dist/components/Shell.js.map +1 -1
  28. package/dist/components/WorkspaceSwitcher.d.ts.map +1 -1
  29. package/dist/components/WorkspaceSwitcher.js +10 -2
  30. package/dist/components/WorkspaceSwitcher.js.map +1 -1
  31. package/dist/components/aiDrawerState.d.ts +45 -0
  32. package/dist/components/aiDrawerState.d.ts.map +1 -0
  33. package/dist/components/aiDrawerState.js +14 -0
  34. package/dist/components/aiDrawerState.js.map +1 -0
  35. package/dist/components/personIntakeTask.d.ts +5 -0
  36. package/dist/components/personIntakeTask.d.ts.map +1 -0
  37. package/dist/components/personIntakeTask.js +13 -0
  38. package/dist/components/personIntakeTask.js.map +1 -0
  39. package/dist/index.d.ts +2 -0
  40. package/dist/index.d.ts.map +1 -1
  41. package/dist/index.js +3 -0
  42. package/dist/index.js.map +1 -1
  43. package/dist/lib/mediaQuery.d.ts +9 -0
  44. package/dist/lib/mediaQuery.d.ts.map +1 -0
  45. package/dist/lib/mediaQuery.js +24 -0
  46. package/dist/lib/mediaQuery.js.map +1 -0
  47. package/dist/modules/PersonIntakeWizard.d.ts +1 -1
  48. package/dist/modules/PersonIntakeWizard.d.ts.map +1 -1
  49. package/dist/modules/PersonIntakeWizard.js +9 -5
  50. package/dist/modules/PersonIntakeWizard.js.map +1 -1
  51. package/dist/pages/FormDetail.d.ts.map +1 -1
  52. package/dist/pages/FormDetail.js +9 -8
  53. package/dist/pages/FormDetail.js.map +1 -1
  54. package/dist/pages/FormsPage.d.ts.map +1 -1
  55. package/dist/pages/FormsPage.js +5 -1
  56. package/dist/pages/FormsPage.js.map +1 -1
  57. package/dist/pages/ListDetail.d.ts.map +1 -1
  58. package/dist/pages/ListDetail.js +2 -2
  59. package/dist/pages/ListDetail.js.map +1 -1
  60. package/dist/pages/PeoplePage.d.ts.map +1 -1
  61. package/dist/pages/PeoplePage.js +8 -6
  62. package/dist/pages/PeoplePage.js.map +1 -1
  63. package/dist/pages/RoleDetail.d.ts.map +1 -1
  64. package/dist/pages/RoleDetail.js +3 -3
  65. package/dist/pages/RoleDetail.js.map +1 -1
  66. package/dist/pages/account/ConnectedAppsPage.js +1 -1
  67. package/dist/pages/admin/DataPage.js +2 -2
  68. package/dist/pages/forms/AddFieldMenu.js +2 -2
  69. package/dist/pages/forms/AddFieldMenu.js.map +1 -1
  70. package/dist/pages/forms/EmbedPanel.d.ts +5 -0
  71. package/dist/pages/forms/EmbedPanel.d.ts.map +1 -1
  72. package/dist/pages/forms/EmbedPanel.js +79 -14
  73. package/dist/pages/forms/EmbedPanel.js.map +1 -1
  74. package/dist/pages/forms/FormActions.d.ts.map +1 -1
  75. package/dist/pages/forms/FormActions.js +2 -1
  76. package/dist/pages/forms/FormActions.js.map +1 -1
  77. package/dist/pages/forms/FormEmails.d.ts +6 -0
  78. package/dist/pages/forms/FormEmails.d.ts.map +1 -0
  79. package/dist/pages/forms/FormEmails.js +173 -0
  80. package/dist/pages/forms/FormEmails.js.map +1 -0
  81. package/dist/pages/forms/FormSettings.d.ts.map +1 -1
  82. package/dist/pages/forms/FormSettings.js +5 -3
  83. package/dist/pages/forms/FormSettings.js.map +1 -1
  84. package/dist/pages/forms/SubmissionDetail.d.ts.map +1 -1
  85. package/dist/pages/forms/SubmissionDetail.js +22 -3
  86. package/dist/pages/forms/SubmissionDetail.js.map +1 -1
  87. package/dist/pages/forms/SubmissionsTable.d.ts +3 -1
  88. package/dist/pages/forms/SubmissionsTable.d.ts.map +1 -1
  89. package/dist/pages/forms/SubmissionsTable.js +48 -11
  90. package/dist/pages/forms/SubmissionsTable.js.map +1 -1
  91. package/dist/pages/forms/embedPrompts.d.ts +45 -0
  92. package/dist/pages/forms/embedPrompts.d.ts.map +1 -0
  93. package/dist/pages/forms/embedPrompts.js +174 -0
  94. package/dist/pages/forms/embedPrompts.js.map +1 -0
  95. package/dist/pages/handbook/HandbookPage.js +4 -4
  96. package/dist/pages/handbook/HandbookPage.js.map +1 -1
  97. package/dist/registry/contributions.d.ts +8 -3
  98. package/dist/registry/contributions.d.ts.map +1 -1
  99. package/package.json +2 -2
  100. package/src/api/resources/forms.ts +75 -4
  101. package/src/components/AiDrawer.tsx +272 -0
  102. package/src/components/ApiKeysPanel.tsx +1 -1
  103. package/src/components/DataTable.tsx +1 -1
  104. package/src/components/KanbanBoard.tsx +119 -2
  105. package/src/components/NotesPanel.tsx +7 -4
  106. package/src/components/PageHeader.tsx +1 -1
  107. package/src/components/{PersonIntakeDialog.tsx → PersonIntakePanel.tsx} +17 -50
  108. package/src/components/SegmentedControl.tsx +2 -2
  109. package/src/components/Shell.tsx +98 -12
  110. package/src/components/WorkspaceSwitcher.tsx +13 -2
  111. package/src/components/aiDrawerState.ts +61 -0
  112. package/src/components/personIntakeTask.tsx +14 -0
  113. package/src/index.ts +5 -0
  114. package/src/lib/mediaQuery.ts +32 -0
  115. package/src/modules/PersonIntakeWizard.tsx +10 -5
  116. package/src/pages/FormDetail.tsx +22 -15
  117. package/src/pages/FormsPage.tsx +5 -1
  118. package/src/pages/ListDetail.tsx +5 -3
  119. package/src/pages/PeoplePage.tsx +7 -10
  120. package/src/pages/RoleDetail.tsx +10 -5
  121. package/src/pages/account/ConnectedAppsPage.tsx +1 -1
  122. package/src/pages/admin/DataPage.tsx +2 -2
  123. package/src/pages/forms/AddFieldMenu.tsx +2 -2
  124. package/src/pages/forms/EmbedPanel.tsx +238 -34
  125. package/src/pages/forms/FormActions.tsx +4 -1
  126. package/src/pages/forms/FormEmails.tsx +449 -0
  127. package/src/pages/forms/FormSettings.tsx +23 -4
  128. package/src/pages/forms/SubmissionDetail.tsx +64 -2
  129. package/src/pages/forms/SubmissionsTable.tsx +123 -16
  130. package/src/pages/forms/embedPrompts.ts +257 -0
  131. package/src/pages/handbook/HandbookPage.tsx +5 -5
  132. package/src/registry/contributions.ts +8 -3
@@ -65,9 +65,11 @@ export function ListDetail(): React.JSX.Element {
65
65
  ← Lists
66
66
  </Link>
67
67
 
68
- <div className="mb-6 flex flex-wrap items-start justify-between gap-3">
68
+ {/* On a phone the controls go under the heading, so a long title keeps
69
+ the full width and does not break over several lines. */}
70
+ <div className="mb-6 flex flex-col gap-3 sm:flex-row sm:flex-wrap sm:items-start sm:justify-between">
69
71
  <ListHeading list={record} />
70
- <div className="flex shrink-0 flex-wrap items-center gap-3">
72
+ <div className="flex flex-wrap items-center gap-3">
71
73
  <Chip>{RECORD_TARGET_TYPE_LABELS[record.targetType]}</Chip>
72
74
  <DeleteRecord
73
75
  recordLabel="List"
@@ -99,7 +101,7 @@ function ListHeading({ list }: { readonly list: List }): React.JSX.Element {
99
101
  const { patch, error } = useListPatch(list)
100
102
 
101
103
  return (
102
- <div className="min-w-0 flex-1">
104
+ <div className="min-w-[12rem] flex-1">
103
105
  {error !== null && (
104
106
  <div className="mb-2">
105
107
  <ErrorPanel error={error} />
@@ -5,11 +5,13 @@ import { useNavigate } from 'react-router'
5
5
 
6
6
  import { useTimezone } from '../api/resources/account.ts'
7
7
  import { useCreatePerson, usePeople } from '../api/resources/people.ts'
8
+ import { useAiDrawer } from '../components/aiDrawerState.ts'
8
9
  import { Chip } from '../components/Chip.tsx'
9
10
  import { SocialNetworkIcon } from '../components/SocialNetworkIcon.tsx'
10
11
  import { ColumnPicker } from '../components/ColumnPicker.tsx'
11
12
  import { DataTable } from '../components/DataTable.tsx'
12
- import { AddFromNotesButton, PersonIntakeDialog } from '../components/PersonIntakeDialog.tsx'
13
+ import { AddFromNotesButton } from '../components/PersonIntakePanel.tsx'
14
+ import { personIntakeTask } from '../components/personIntakeTask.tsx'
13
15
  import type { Column } from '../components/DataTable.tsx'
14
16
  import { FilterBar, PageHeader } from '../components/PageHeader.tsx'
15
17
  import { Paginator } from '../components/Paginator.tsx'
@@ -60,7 +62,7 @@ export function PeoplePage(): React.JSX.Element {
60
62
  })
61
63
  const directory = usePeopleDirectory(people.records.map((person) => person.id))
62
64
  const createPerson = useCreatePerson()
63
- const [intakeOpen, setIntakeOpen] = useState(false)
65
+ const aiDrawer = useAiDrawer()
64
66
 
65
67
  async function addPerson(): Promise<void> {
66
68
  // The same defaults the API applies, so a person created here and one
@@ -196,6 +198,8 @@ export function PeoplePage(): React.JSX.Element {
196
198
  {
197
199
  key: 'tags',
198
200
  header: 'Tags',
201
+ // On a phone the tag chips wrap one per line and make every row tall.
202
+ className: 'hidden md:table-cell',
199
203
  getSortValue: (person) => person.tags.join(', ') || null,
200
204
  render: (person) =>
201
205
  person.tags.length > 0 ? (
@@ -252,19 +256,12 @@ export function PeoplePage(): React.JSX.Element {
252
256
  />
253
257
  <AddFromNotesButton
254
258
  onClick={() => {
255
- setIntakeOpen(true)
259
+ aiDrawer.open(personIntakeTask())
256
260
  }}
257
261
  />
258
262
  </>
259
263
  }
260
264
  />
261
- {intakeOpen && (
262
- <PersonIntakeDialog
263
- onClose={() => {
264
- setIntakeOpen(false)
265
- }}
266
- />
267
- )}
268
265
  <FilterBar
269
266
  value={term}
270
267
  onChange={setTerm}
@@ -71,9 +71,11 @@ export function RoleDetail(): React.JSX.Element {
71
71
  ← Hiring
72
72
  </Link>
73
73
 
74
- <div className="mb-6 flex flex-wrap items-start justify-between gap-3">
74
+ {/* On a phone the controls go under the heading, so a long role title
75
+ keeps the full width and does not break over several lines. */}
76
+ <div className="mb-6 flex flex-col gap-3 sm:flex-row sm:flex-wrap sm:items-start sm:justify-between">
75
77
  <RoleHeading role={record} />
76
- <div className="flex shrink-0 flex-wrap items-center gap-3">
78
+ <div className="flex flex-wrap items-center gap-3">
77
79
  <RoleStatusField role={record} />
78
80
  <AgentTasks targetType="role" targetId={record.id} targetLabel={record.title} />
79
81
  <DeleteRecord
@@ -109,7 +111,7 @@ function RoleHeading({ role }: { readonly role: Role }): React.JSX.Element {
109
111
  const { patch, error } = useRolePatch(role)
110
112
 
111
113
  return (
112
- <div className="min-w-0 flex-1">
114
+ <div className="min-w-[12rem] flex-1">
113
115
  {error !== null && (
114
116
  <div className="mb-2">
115
117
  <ErrorPanel error={error} />
@@ -292,10 +294,13 @@ function CandidateRow({
292
294
 
293
295
  return (
294
296
  <li className="border-b border-border px-4 py-3.5 last:border-0">
295
- <div className="flex flex-wrap items-start justify-between gap-3">
297
+ {/* On a phone the controls always take their own line under the name.
298
+ Left to wrap, whether they fit beside it depends on the name length
299
+ and on the stage field, so rows in one list came out different. */}
300
+ <div className="flex flex-col gap-2 sm:flex-row sm:flex-wrap sm:items-start sm:justify-between sm:gap-3">
296
301
  <Link
297
302
  to={`/people/${candidate.personId}`}
298
- className="text-left text-[13px] font-medium text-ink hover:text-accent"
303
+ className="self-start text-left text-[13px] font-medium text-ink hover:text-accent"
299
304
  >
300
305
  {personName ?? candidate.personId}
301
306
  </Link>
@@ -34,7 +34,7 @@ export function ConnectedAppsPage(): React.JSX.Element {
34
34
  No connected apps. When an MCP client asks you to sign in to Kelpie, it shows up here.
35
35
  </p>
36
36
  ) : (
37
- <div className="overflow-hidden rounded-md border border-border">
37
+ <div className="overflow-x-auto rounded-md border border-border">
38
38
  <table className="w-full text-left text-[13px]">
39
39
  <thead>
40
40
  <tr className="border-b border-border bg-surface text-[11px] font-semibold tracking-wide text-ink-muted uppercase">
@@ -571,7 +571,7 @@ function MappingForm(props: MappingFormProps): ReactNode {
571
571
  : 'A company that is not here yet is left unlinked and reported as a warning.'}
572
572
  </p>
573
573
  ) : null}
574
- <div className="overflow-hidden rounded-md border border-border">
574
+ <div className="overflow-x-auto rounded-md border border-border">
575
575
  <table className="w-full text-left text-[13px]">
576
576
  <thead>
577
577
  <tr className="border-b border-border bg-surface text-[11px] font-semibold tracking-wide text-ink-muted uppercase">
@@ -810,7 +810,7 @@ function DonePanel({ job, object, onAgain }: DonePanelProps): ReactNode {
810
810
  /** The row / field / message table shared by the error and warning lists. */
811
811
  function IssueTable({ rows }: { readonly rows: readonly ImportRowError[] }): ReactNode {
812
812
  return (
813
- <div className="overflow-hidden rounded-md border border-border">
813
+ <div className="overflow-x-auto rounded-md border border-border">
814
814
  <table className="w-full text-left text-[13px]">
815
815
  <thead>
816
816
  <tr className="border-b border-border bg-surface text-[11px] font-semibold tracking-wide text-ink-muted uppercase">
@@ -57,7 +57,7 @@ export function AddFieldMenu({ fields, onAdd }: AddFieldMenuProps): React.JSX.El
57
57
  }
58
58
 
59
59
  return (
60
- <div className="relative" ref={containerRef}>
60
+ <div className="relative shrink-0" ref={containerRef}>
61
61
  <button
62
62
  type="button"
63
63
  onClick={() => {
@@ -65,7 +65,7 @@ export function AddFieldMenu({ fields, onAdd }: AddFieldMenuProps): React.JSX.El
65
65
  }}
66
66
  aria-expanded={open}
67
67
  aria-haspopup="menu"
68
- className="rounded-md bg-accent px-3 py-1.5 text-[12px] font-semibold text-accent-fg transition hover:bg-accent-hover"
68
+ className="whitespace-nowrap rounded-md bg-accent px-3 py-1.5 text-[12px] font-semibold text-accent-fg transition hover:bg-accent-hover"
69
69
  >
70
70
  + Add field
71
71
  </button>
@@ -1,10 +1,14 @@
1
- import type { Form } from '@kelpie/schemas'
2
- import { useEffect, useId, useState } from 'react'
1
+ import type { ConsentPurpose, Form } from '@kelpie/schemas'
2
+ import { useEffect, useId, useMemo, useState, type ReactNode } from 'react'
3
3
 
4
+ import { useConsentPurposes } from '../../api/resources/consentPurposes.ts'
4
5
  import { useFormEmbed } from '../../api/resources/forms.ts'
6
+ import { useLists } from '../../api/resources/lists.ts'
7
+ import { useWorkspace } from '../../api/resources/workspace.ts'
5
8
  import { CopyButton } from '../../components/CopyButton.tsx'
6
9
  import { ErrorPanel, LoadingPanel } from '../../components/QueryState.tsx'
7
10
  import { SectionHeader } from '../../components/SectionHeader.tsx'
11
+ import { buildEmbedPrompts, buildJsonSubmitPrompt } from './embedPrompts.ts'
8
12
 
9
13
  /**
10
14
  * What to paste into a website.
@@ -17,6 +21,11 @@ import { SectionHeader } from '../../components/SectionHeader.tsx'
17
21
  * Each iframe snippet has a Preview that opens the bare embed document in a
18
22
  * modal — fields only, the same document the snippet iframes — fixed height for
19
23
  * the plain iframe, auto-resize for the script variant.
24
+ *
25
+ * Each option also has an AI button that opens, in a modal, a prompt for a
26
+ * coding assistant to put that option on the person's site. The fourth option,
27
+ * Submit as JSON, is for a site that builds its own form and posts to the
28
+ * public submit endpoint; its prompt lists the fields the answers are keyed by.
20
29
  */
21
30
 
22
31
  export interface EmbedPanelProps {
@@ -25,9 +34,17 @@ export interface EmbedPanelProps {
25
34
 
26
35
  type PreviewMode = 'fixed' | 'resize'
27
36
 
37
+ interface AiPrompt {
38
+ /** Which embed option the prompt is for: "iframe". */
39
+ readonly label: string
40
+ readonly prompt: string
41
+ }
42
+
28
43
  export function EmbedPanel({ form }: EmbedPanelProps): React.JSX.Element {
29
44
  const { snippets, isLoading, error } = useFormEmbed(form.id)
30
45
  const [preview, setPreview] = useState<PreviewMode | null>(null)
46
+ const [aiPrompt, setAiPrompt] = useState<AiPrompt | null>(null)
47
+ const checkboxText = useCheckboxText()
31
48
 
32
49
  if (error !== null) {
33
50
  return <ErrorPanel error={error} />
@@ -37,6 +54,14 @@ export function EmbedPanel({ form }: EmbedPanelProps): React.JSX.Element {
37
54
  return <LoadingPanel label="Loading embed details…" />
38
55
  }
39
56
 
57
+ const formName = form.title.trim().length > 0 ? form.title : form.name
58
+ const prompts = buildEmbedPrompts({
59
+ formName,
60
+ url: snippets.url,
61
+ iframeSnippet: snippets.iframeSnippet,
62
+ scriptSnippet: snippets.scriptSnippet,
63
+ })
64
+
40
65
  return (
41
66
  <div className="max-w-2xl space-y-5">
42
67
  <SectionHeader
@@ -58,6 +83,12 @@ export function EmbedPanel({ form }: EmbedPanelProps): React.JSX.Element {
58
83
  >
59
84
  Open
60
85
  </a>
86
+ <AiPromptButton
87
+ label="hosted page"
88
+ onOpen={() => {
89
+ setAiPrompt({ label: 'Hosted page', prompt: prompts.hosted })
90
+ }}
91
+ />
61
92
  </div>
62
93
  </div>
63
94
 
@@ -68,6 +99,9 @@ export function EmbedPanel({ form }: EmbedPanelProps): React.JSX.Element {
68
99
  onPreview={() => {
69
100
  setPreview('fixed')
70
101
  }}
102
+ onAiPrompt={() => {
103
+ setAiPrompt({ label: 'iframe', prompt: prompts.iframe })
104
+ }}
71
105
  />
72
106
  <Snippet
73
107
  label="iframe with auto-resize"
@@ -76,8 +110,51 @@ export function EmbedPanel({ form }: EmbedPanelProps): React.JSX.Element {
76
110
  onPreview={() => {
77
111
  setPreview('resize')
78
112
  }}
113
+ onAiPrompt={() => {
114
+ setAiPrompt({ label: 'iframe with auto-resize', prompt: prompts.script })
115
+ }}
79
116
  />
80
117
 
118
+ <div>
119
+ <div className="mb-1.5 flex items-center justify-between gap-2">
120
+ <span className="text-[12px] font-medium text-ink">Submit as JSON</span>
121
+ <div className="flex items-center gap-2">
122
+ <AiPromptButton
123
+ label="JSON submit"
124
+ onOpen={() => {
125
+ setAiPrompt({
126
+ label: 'Submit as JSON',
127
+ prompt: buildJsonSubmitPrompt({
128
+ formName,
129
+ submitUrl: snippets.submitUrl,
130
+ tokenUrl: form.requireSpamCheck ? snippets.tokenUrl : null,
131
+ fields: form.fields,
132
+ thankYouMessage: form.thankYouMessage,
133
+ ...checkboxText,
134
+ }),
135
+ })
136
+ }}
137
+ />
138
+ <CopyButton value={snippets.submitUrl} label="Copy the JSON submit endpoint" />
139
+ </div>
140
+ </div>
141
+ <code className="block overflow-x-auto whitespace-nowrap rounded-md border border-border bg-surface-raised px-3 py-2 font-mono text-[12px] text-ink">
142
+ POST {snippets.submitUrl}
143
+ </code>
144
+ <p className="mt-1 text-[11px] text-ink-faint">
145
+ For a form you build yourself. Post {'{ "answers": { "<field id>": "…" } }'} with no
146
+ credentials. The URL holds the slug, so it changes when the slug does.
147
+ </p>
148
+ {form.requireSpamCheck && (
149
+ <p className="mt-1 text-[11px] text-warning">
150
+ This form requires the spam check. Your own form must first get a token from{' '}
151
+ <code className="font-mono">GET {snippets.tokenUrl}</code> and send it as{' '}
152
+ <code className="font-mono">token</code>, or each submission is held as spam. The AI
153
+ prompt has the full steps.
154
+ </p>
155
+ )}
156
+ </div>
157
+
81
158
  {preview !== null && (
82
159
  <EmbedPreviewModal
83
160
  formId={form.id}
@@ -90,6 +167,16 @@ export function EmbedPanel({ form }: EmbedPanelProps): React.JSX.Element {
90
167
  }}
91
168
  />
92
169
  )}
170
+
171
+ {aiPrompt !== null && (
172
+ <AiPromptModal
173
+ label={aiPrompt.label}
174
+ prompt={aiPrompt.prompt}
175
+ onClose={() => {
176
+ setAiPrompt(null)
177
+ }}
178
+ />
179
+ )}
93
180
  </div>
94
181
  )
95
182
  }
@@ -99,11 +186,13 @@ function Snippet({
99
186
  hint,
100
187
  value,
101
188
  onPreview,
189
+ onAiPrompt,
102
190
  }: {
103
191
  readonly label: string
104
192
  readonly hint: string
105
193
  readonly value: string
106
194
  readonly onPreview: () => void
195
+ readonly onAiPrompt: () => void
107
196
  }): React.JSX.Element {
108
197
  return (
109
198
  <div>
@@ -117,6 +206,7 @@ function Snippet({
117
206
  >
118
207
  Preview
119
208
  </button>
209
+ <AiPromptButton label={label} onOpen={onAiPrompt} />
120
210
  <CopyButton value={value} label={`Copy the ${label} snippet`} />
121
211
  </div>
122
212
  </div>
@@ -132,6 +222,86 @@ function Snippet({
132
222
  )
133
223
  }
134
224
 
225
+ /**
226
+ * What the JSON prompt needs to name each consent and list checkbox the way the
227
+ * embed does: the workspace's purposes, its person and company lists, and its
228
+ * name for the `{{workspace}}` token in a purpose statement.
229
+ */
230
+ function useCheckboxText(): {
231
+ readonly consentPurposes: ReadonlyMap<string, ConsentPurpose>
232
+ readonly listNames: ReadonlyMap<string, string>
233
+ readonly workspaceName: string
234
+ } {
235
+ const purposes = useConsentPurposes({ sort: 'sort_order', limit: 200 })
236
+ const personLists = useLists({ targetType: 'person' })
237
+ const companyLists = useLists({ targetType: 'company' })
238
+ const { workspace } = useWorkspace()
239
+ const consentPurposes = useMemo(
240
+ () => new Map(purposes.records.map((purpose): [string, ConsentPurpose] => [purpose.id, purpose])),
241
+ [purposes.records],
242
+ )
243
+ const listNames = useMemo(
244
+ () =>
245
+ new Map(
246
+ [...personLists.records, ...companyLists.records].map((list): [string, string] => [list.id, list.name]),
247
+ ),
248
+ [personLists.records, companyLists.records],
249
+ )
250
+
251
+ return { consentPurposes, listNames, workspaceName: workspace?.name ?? '' }
252
+ }
253
+
254
+ function AiPromptButton({
255
+ label,
256
+ onOpen,
257
+ }: {
258
+ readonly label: string
259
+ readonly onOpen: () => void
260
+ }): React.JSX.Element {
261
+ return (
262
+ <button
263
+ type="button"
264
+ onClick={onOpen}
265
+ aria-label={`Show an AI prompt to add the ${label} to your site`}
266
+ className="rounded-md border border-border px-2 py-1 text-[11px] font-medium text-ink-muted transition hover:border-border-strong hover:text-ink"
267
+ >
268
+ AI
269
+ </button>
270
+ )
271
+ }
272
+
273
+ /**
274
+ * The prompt for one embed option, read-only, with a Copy button. The person
275
+ * can read what they are about to hand an assistant before they copy it.
276
+ */
277
+ function AiPromptModal({
278
+ label,
279
+ prompt,
280
+ onClose,
281
+ }: {
282
+ readonly label: string
283
+ readonly prompt: string
284
+ readonly onClose: () => void
285
+ }): React.JSX.Element {
286
+ return (
287
+ <ModalFrame
288
+ title={`AI prompt · ${label}`}
289
+ description="Paste this into an AI coding assistant to add the form to your site."
290
+ actions={<CopyButton value={prompt} label={`Copy the ${label} AI prompt`} />}
291
+ bodyClassName="p-4"
292
+ onClose={onClose}
293
+ >
294
+ <textarea
295
+ readOnly
296
+ value={prompt}
297
+ rows={prompt.split('\n').length + 1}
298
+ aria-label={`${label} AI prompt`}
299
+ className="w-full resize-y rounded-md border border-border bg-surface px-3 py-2 font-mono text-[11px] text-ink outline-none"
300
+ />
301
+ </ModalFrame>
302
+ )
303
+ }
304
+
135
305
  /**
136
306
  * Frames the hosted embed the way each snippet would: fixed 720px for the plain
137
307
  * iframe, or listening for the height postMessage when previewing auto-resize.
@@ -151,7 +321,6 @@ function EmbedPreviewModal({
151
321
  readonly mode: PreviewMode
152
322
  readonly onClose: () => void
153
323
  }): React.JSX.Element {
154
- const titleId = useId()
155
324
  const heading = formTitle.trim().length > 0 ? formTitle : formName
156
325
  const [height, setHeight] = useState(720)
157
326
 
@@ -188,6 +357,59 @@ function EmbedPreviewModal({
188
357
  }
189
358
  }, [formId, mode, url])
190
359
 
360
+ return (
361
+ <ModalFrame
362
+ title={`Preview · ${heading}`}
363
+ description={
364
+ mode === 'resize'
365
+ ? 'Bare iframe embed with auto-resize — fields only, height follows the form.'
366
+ : 'Bare iframe embed — fields only, fixed height.'
367
+ }
368
+ bodyClassName="bg-[#f4f4f5] p-4"
369
+ onClose={onClose}
370
+ >
371
+ <div className="overflow-hidden rounded-md border border-[#d4d4d8] bg-white shadow-sm">
372
+ <iframe
373
+ src={url}
374
+ title={`${heading} preview`}
375
+ style={{
376
+ width: '100%',
377
+ border: 0,
378
+ height: mode === 'fixed' ? '720px' : `${String(height)}px`,
379
+ colorScheme: 'normal',
380
+ }}
381
+ className="block bg-transparent"
382
+ />
383
+ </div>
384
+ <p className="mt-2 text-center text-[11px] text-ink-faint">
385
+ Simulated host page — the iframe uses its own neutral styles, not Kelpie&apos;s.
386
+ </p>
387
+ </ModalFrame>
388
+ )
389
+ }
390
+
391
+ /**
392
+ * The dialog shell both modals share: backdrop and Escape close it, a header
393
+ * with a title, a description and optional actions beside Close, and a
394
+ * scrolling body.
395
+ */
396
+ function ModalFrame({
397
+ title,
398
+ description,
399
+ actions,
400
+ bodyClassName,
401
+ onClose,
402
+ children,
403
+ }: {
404
+ readonly title: string
405
+ readonly description: string
406
+ readonly actions?: ReactNode
407
+ readonly bodyClassName: string
408
+ readonly onClose: () => void
409
+ readonly children: ReactNode
410
+ }): React.JSX.Element {
411
+ const titleId = useId()
412
+
191
413
  useEffect(() => {
192
414
  function onKeyDown(event: KeyboardEvent): void {
193
415
  if (event.key === 'Escape') {
@@ -219,41 +441,23 @@ function EmbedPreviewModal({
219
441
  <div className="flex shrink-0 items-start justify-between gap-3 border-b border-border px-4 py-3">
220
442
  <div className="min-w-0">
221
443
  <h2 id={titleId} className="truncate text-[14px] font-semibold text-ink">
222
- Preview · {heading}
444
+ {title}
223
445
  </h2>
224
- <p className="mt-0.5 text-[11px] text-ink-faint">
225
- {mode === 'resize'
226
- ? 'Bare iframe embed with auto-resize — fields only, height follows the form.'
227
- : 'Bare iframe embed — fields only, fixed height.'}
228
- </p>
446
+ <p className="mt-0.5 text-[11px] text-ink-faint">{description}</p>
229
447
  </div>
230
- <button
231
- type="button"
232
- onClick={onClose}
233
- className="shrink-0 rounded-md px-2 py-1 text-[12px] font-medium text-ink-muted transition hover:text-ink"
234
- >
235
- Close
236
- </button>
237
- </div>
238
-
239
- <div className="min-h-0 flex-1 overflow-y-auto bg-[#f4f4f5] p-4">
240
- <div className="overflow-hidden rounded-md border border-[#d4d4d8] bg-white shadow-sm">
241
- <iframe
242
- src={url}
243
- title={`${heading} preview`}
244
- style={{
245
- width: '100%',
246
- border: 0,
247
- height: mode === 'fixed' ? '720px' : `${String(height)}px`,
248
- colorScheme: 'normal',
249
- }}
250
- className="block bg-transparent"
251
- />
448
+ <div className="flex shrink-0 items-center gap-2">
449
+ {actions}
450
+ <button
451
+ type="button"
452
+ onClick={onClose}
453
+ className="rounded-md px-2 py-1 text-[12px] font-medium text-ink-muted transition hover:text-ink"
454
+ >
455
+ Close
456
+ </button>
252
457
  </div>
253
- <p className="mt-2 text-center text-[11px] text-ink-faint">
254
- Simulated host page — the iframe uses its own neutral styles, not Kelpie&apos;s.
255
- </p>
256
458
  </div>
459
+
460
+ <div className={`min-h-0 flex-1 overflow-y-auto ${bodyClassName}`}>{children}</div>
257
461
  </div>
258
462
  </div>
259
463
  )
@@ -16,6 +16,7 @@ import { Chip } from '../../components/Chip.tsx'
16
16
  import { ErrorPanel } from '../../components/QueryState.tsx'
17
17
  import { SectionHeader } from '../../components/SectionHeader.tsx'
18
18
  import { toTags } from '../fields.ts'
19
+ import { FormEmails } from './FormEmails.tsx'
19
20
 
20
21
  /**
21
22
  * What the form does with a submission, once the answers are captured.
@@ -49,7 +50,7 @@ export function FormActions({ form }: FormActionsProps): React.JSX.Element {
49
50
  <div className="max-w-2xl space-y-6">
50
51
  <SectionHeader
51
52
  title="Actions"
52
- description="What the form creates, tags, lists, and links every submitter to."
53
+ description="What the form creates, tags, lists, links every submitter to, and emails."
53
54
  />
54
55
 
55
56
  {updateForm.error !== null && <ErrorPanel error={updateForm.error} />}
@@ -131,6 +132,8 @@ export function FormActions({ form }: FormActionsProps): React.JSX.Element {
131
132
  <ListsBlock form={form} onChange={(next) => patch({ listIds: next })} />
132
133
 
133
134
  <AttachTargetsBlock form={form} onChange={(next) => patch({ attachTargets: next })} />
135
+
136
+ <FormEmails form={form} />
134
137
  </div>
135
138
  )
136
139
  }