@prenta/admin 2.9.2 → 2.10.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/CHANGELOG.md +50 -0
- package/design-system/tokens.css +2 -1
- package/design-system/tokens.json +5 -1
- package/design-system/tokens.scss +1 -1
- package/dist/AdminRoot.d.ts.map +1 -1
- package/dist/AdminRoot.js +5 -3
- package/dist/AdminRoot.js.map +1 -1
- package/dist/__tests__/components/attribution-rows.test.js +1 -1
- package/dist/__tests__/components/attribution-rows.test.js.map +1 -1
- package/dist/__tests__/components/date-range-picker.test.d.ts +2 -0
- package/dist/__tests__/components/date-range-picker.test.d.ts.map +1 -0
- package/dist/__tests__/components/date-range-picker.test.js +59 -0
- package/dist/__tests__/components/date-range-picker.test.js.map +1 -0
- package/dist/__tests__/components/form-build-model.test.d.ts +2 -0
- package/dist/__tests__/components/form-build-model.test.d.ts.map +1 -0
- package/dist/__tests__/components/form-build-model.test.js +162 -0
- package/dist/__tests__/components/form-build-model.test.js.map +1 -0
- package/dist/__tests__/components/form-build.test.d.ts +2 -0
- package/dist/__tests__/components/form-build.test.d.ts.map +1 -0
- package/dist/__tests__/components/form-build.test.js +120 -0
- package/dist/__tests__/components/form-build.test.js.map +1 -0
- package/dist/__tests__/components/qa-a11y.render.test.d.ts +2 -0
- package/dist/__tests__/components/qa-a11y.render.test.d.ts.map +1 -0
- package/dist/__tests__/components/qa-a11y.render.test.js +30 -0
- package/dist/__tests__/components/qa-a11y.render.test.js.map +1 -0
- package/dist/__tests__/components/responsive-tiers.render.test.js +12 -0
- package/dist/__tests__/components/responsive-tiers.render.test.js.map +1 -1
- package/dist/__tests__/components/ui-primitives.test.js +7 -0
- package/dist/__tests__/components/ui-primitives.test.js.map +1 -1
- package/dist/__tests__/layout/shell-nav.render.test.js +5 -0
- package/dist/__tests__/layout/shell-nav.render.test.js.map +1 -1
- package/dist/__tests__/lib/batch-wizard.test.js +2 -0
- package/dist/__tests__/lib/batch-wizard.test.js.map +1 -1
- package/dist/__tests__/lib/forms-settings-normalize.test.d.ts +2 -0
- package/dist/__tests__/lib/forms-settings-normalize.test.d.ts.map +1 -0
- package/dist/__tests__/lib/forms-settings-normalize.test.js +16 -0
- package/dist/__tests__/lib/forms-settings-normalize.test.js.map +1 -0
- package/dist/__tests__/styles/qa-contrast.test.d.ts +2 -0
- package/dist/__tests__/styles/qa-contrast.test.d.ts.map +1 -0
- package/dist/__tests__/styles/qa-contrast.test.js +78 -0
- package/dist/__tests__/styles/qa-contrast.test.js.map +1 -0
- package/dist/__tests__/views/ai-settings.render.test.js +21 -0
- package/dist/__tests__/views/ai-settings.render.test.js.map +1 -1
- package/dist/__tests__/views/appearance-chrome.render.test.js +9 -0
- package/dist/__tests__/views/appearance-chrome.render.test.js.map +1 -1
- package/dist/__tests__/views/dashboard.test.js +105 -30
- package/dist/__tests__/views/dashboard.test.js.map +1 -1
- package/dist/__tests__/views/form-editor.render.test.js +17 -9
- package/dist/__tests__/views/form-editor.render.test.js.map +1 -1
- package/dist/__tests__/views/form-entries.render.test.js +23 -9
- package/dist/__tests__/views/form-entries.render.test.js.map +1 -1
- package/dist/__tests__/views/form-submissions.render.test.js +13 -14
- package/dist/__tests__/views/form-submissions.render.test.js.map +1 -1
- package/dist/__tests__/views/forms-list.render.test.js +139 -16
- package/dist/__tests__/views/forms-list.render.test.js.map +1 -1
- package/dist/__tests__/views/forms-settings.fixture.d.ts +3 -0
- package/dist/__tests__/views/forms-settings.fixture.d.ts.map +1 -0
- package/dist/__tests__/views/forms-settings.fixture.js +31 -0
- package/dist/__tests__/views/forms-settings.fixture.js.map +1 -0
- package/dist/__tests__/views/forms-settings.render.test.d.ts +2 -0
- package/dist/__tests__/views/forms-settings.render.test.d.ts.map +1 -0
- package/dist/__tests__/views/forms-settings.render.test.js +120 -0
- package/dist/__tests__/views/forms-settings.render.test.js.map +1 -0
- package/dist/__tests__/views/inbox-format.test.d.ts +2 -0
- package/dist/__tests__/views/inbox-format.test.d.ts.map +1 -0
- package/dist/__tests__/views/inbox-format.test.js +47 -0
- package/dist/__tests__/views/inbox-format.test.js.map +1 -0
- package/dist/__tests__/views/jobs-list.render.test.js +2 -0
- package/dist/__tests__/views/jobs-list.render.test.js.map +1 -1
- package/dist/__tests__/views/jobs-wizard.render.test.js +17 -3
- package/dist/__tests__/views/jobs-wizard.render.test.js.map +1 -1
- package/dist/__tests__/views/onboarding-block.render.test.js +9 -7
- package/dist/__tests__/views/onboarding-block.render.test.js.map +1 -1
- package/dist/__tests__/views/run-with-ai.render.test.js +9 -0
- package/dist/__tests__/views/run-with-ai.render.test.js.map +1 -1
- package/dist/__tests__/views/script-tags.render.test.js +8 -0
- package/dist/__tests__/views/script-tags.render.test.js.map +1 -1
- package/dist/__tests__/views/settings-tabs.render.test.js +5 -0
- package/dist/__tests__/views/settings-tabs.render.test.js.map +1 -1
- package/dist/components/SEOConfigPanel.js +2 -2
- package/dist/components/SEOConfigPanel.js.map +1 -1
- package/dist/components/forms/BlocklistDialog.d.ts +19 -0
- package/dist/components/forms/BlocklistDialog.d.ts.map +1 -0
- package/dist/components/forms/BlocklistDialog.js +225 -0
- package/dist/components/forms/BlocklistDialog.js.map +1 -0
- package/dist/components/forms/ExportMenu.d.ts +3 -1
- package/dist/components/forms/ExportMenu.d.ts.map +1 -1
- package/dist/components/forms/ExportMenu.js +2 -2
- package/dist/components/forms/ExportMenu.js.map +1 -1
- package/dist/components/forms/FieldOptions.d.ts +11 -0
- package/dist/components/forms/FieldOptions.d.ts.map +1 -0
- package/dist/components/forms/FieldOptions.js +106 -0
- package/dist/components/forms/FieldOptions.js.map +1 -0
- package/dist/components/forms/FormBuild.d.ts +11 -0
- package/dist/components/forms/FormBuild.d.ts.map +1 -0
- package/dist/components/forms/FormBuild.js +299 -0
- package/dist/components/forms/FormBuild.js.map +1 -0
- package/dist/components/forms/FormsListTable.d.ts +14 -0
- package/dist/components/forms/FormsListTable.d.ts.map +1 -0
- package/dist/components/forms/FormsListTable.js +84 -0
- package/dist/components/forms/FormsListTable.js.map +1 -0
- package/dist/components/forms/form-build-model.d.ts +74 -0
- package/dist/components/forms/form-build-model.d.ts.map +1 -0
- package/dist/components/forms/form-build-model.js +297 -0
- package/dist/components/forms/form-build-model.js.map +1 -0
- package/dist/components/forms/form-build-ui.d.ts +35 -0
- package/dist/components/forms/form-build-ui.d.ts.map +1 -0
- package/dist/components/forms/form-build-ui.js +59 -0
- package/dist/components/forms/form-build-ui.js.map +1 -0
- package/dist/components/forms/primitives.d.ts +3 -22
- package/dist/components/forms/primitives.d.ts.map +1 -1
- package/dist/components/forms/primitives.js +4 -19
- package/dist/components/forms/primitives.js.map +1 -1
- package/dist/components/seo/PageAuditPanel.js +2 -2
- package/dist/components/seo/PageAuditPanel.js.map +1 -1
- package/dist/components/seo/primitives.d.ts +1 -1
- package/dist/components/seo/primitives.d.ts.map +1 -1
- package/dist/components/seo/primitives.js +10 -1
- package/dist/components/seo/primitives.js.map +1 -1
- package/dist/components/ui/Badge.d.ts +1 -1
- package/dist/components/ui/Card.d.ts +1 -1
- package/dist/components/ui/DateRangePicker.d.ts +7 -0
- package/dist/components/ui/DateRangePicker.d.ts.map +1 -0
- package/dist/components/ui/DateRangePicker.js +112 -0
- package/dist/components/ui/DateRangePicker.js.map +1 -0
- package/dist/components/ui/FilterPill.d.ts.map +1 -1
- package/dist/components/ui/FilterPill.js +2 -2
- package/dist/components/ui/FilterPill.js.map +1 -1
- package/dist/components/ui/Input.d.ts +1 -1
- package/dist/components/ui/PageHeader.d.ts +7 -1
- package/dist/components/ui/PageHeader.d.ts.map +1 -1
- package/dist/components/ui/PageHeader.js +4 -2
- package/dist/components/ui/PageHeader.js.map +1 -1
- package/dist/components/ui/Segmented.d.ts +3 -1
- package/dist/components/ui/Segmented.d.ts.map +1 -1
- package/dist/components/ui/Segmented.js +3 -3
- package/dist/components/ui/Segmented.js.map +1 -1
- package/dist/components/ui/StatusBadge.d.ts +3 -2
- package/dist/components/ui/StatusBadge.d.ts.map +1 -1
- package/dist/components/ui/StatusBadge.js +9 -3
- package/dist/components/ui/StatusBadge.js.map +1 -1
- package/dist/components/ui/Toggle.d.ts +1 -1
- package/dist/components/ui/Toggle.d.ts.map +1 -1
- package/dist/components/ui/Toggle.js +3 -0
- package/dist/components/ui/Toggle.js.map +1 -1
- package/dist/components/ui/UnderlineTabs.d.ts +5 -1
- package/dist/components/ui/UnderlineTabs.d.ts.map +1 -1
- package/dist/components/ui/UnderlineTabs.js +14 -11
- package/dist/components/ui/UnderlineTabs.js.map +1 -1
- package/dist/layout/Sidebar.d.ts.map +1 -1
- package/dist/layout/Sidebar.js +7 -2
- package/dist/layout/Sidebar.js.map +1 -1
- package/dist/lib/batch-wizard.d.ts +1 -1
- package/dist/lib/batch-wizard.d.ts.map +1 -1
- package/dist/lib/batch-wizard.js +2 -2
- package/dist/lib/batch-wizard.js.map +1 -1
- package/dist/lib/entry-attribution.d.ts +13 -0
- package/dist/lib/entry-attribution.d.ts.map +1 -0
- package/dist/lib/entry-attribution.js +81 -0
- package/dist/lib/entry-attribution.js.map +1 -0
- package/dist/lib/forms-service.d.ts +100 -0
- package/dist/lib/forms-service.d.ts.map +1 -1
- package/dist/lib/forms-service.js +101 -0
- package/dist/lib/forms-service.js.map +1 -1
- package/dist/lib/job-drawer.d.ts +1 -0
- package/dist/lib/job-drawer.d.ts.map +1 -1
- package/dist/lib/job-drawer.js +23 -1
- package/dist/lib/job-drawer.js.map +1 -1
- package/dist/lib/job-view.d.ts +6 -0
- package/dist/lib/job-view.d.ts.map +1 -1
- package/dist/lib/job-view.js +7 -0
- package/dist/lib/job-view.js.map +1 -1
- package/dist/prenta-admin.css +1 -1
- package/dist/router/admin-routes.d.ts.map +1 -1
- package/dist/router/admin-routes.js +1 -0
- package/dist/router/admin-routes.js.map +1 -1
- package/dist/views/Dashboard.d.ts.map +1 -1
- package/dist/views/Dashboard.js +438 -309
- package/dist/views/Dashboard.js.map +1 -1
- package/dist/views/FormEditor.d.ts.map +1 -1
- package/dist/views/FormEditor.js +68 -13
- package/dist/views/FormEditor.js.map +1 -1
- package/dist/views/FormEntries.d.ts.map +1 -1
- package/dist/views/FormEntries.js +4 -190
- package/dist/views/FormEntries.js.map +1 -1
- package/dist/views/FormSubmissions.d.ts +1 -1
- package/dist/views/FormSubmissions.d.ts.map +1 -1
- package/dist/views/FormSubmissions.js +6 -195
- package/dist/views/FormSubmissions.js.map +1 -1
- package/dist/views/Forms.d.ts +11 -1
- package/dist/views/Forms.d.ts.map +1 -1
- package/dist/views/Forms.js +141 -93
- package/dist/views/Forms.js.map +1 -1
- package/dist/views/FormsSettings.d.ts +6 -1
- package/dist/views/FormsSettings.d.ts.map +1 -1
- package/dist/views/FormsSettings.js +434 -30
- package/dist/views/FormsSettings.js.map +1 -1
- package/dist/views/Jobs/DrawerReview.d.ts.map +1 -1
- package/dist/views/Jobs/DrawerReview.js +8 -7
- package/dist/views/Jobs/DrawerReview.js.map +1 -1
- package/dist/views/Jobs/NewBatchJob.d.ts.map +1 -1
- package/dist/views/Jobs/NewBatchJob.js +2 -1
- package/dist/views/Jobs/NewBatchJob.js.map +1 -1
- package/dist/views/Jobs.d.ts.map +1 -1
- package/dist/views/Jobs.js +1 -1
- package/dist/views/Jobs.js.map +1 -1
- package/dist/views/MediaBrowser.d.ts.map +1 -1
- package/dist/views/MediaBrowser.js +5 -1
- package/dist/views/MediaBrowser.js.map +1 -1
- package/dist/views/Pages/PagesListView.js +1 -1
- package/dist/views/Pages/PagesListView.js.map +1 -1
- package/dist/views/Redirects.d.ts.map +1 -1
- package/dist/views/Redirects.js +1 -3
- package/dist/views/Redirects.js.map +1 -1
- package/dist/views/ScriptTags.js +1 -1
- package/dist/views/Settings.js +1 -1
- package/dist/views/Settings.js.map +1 -1
- package/dist/views/SpamFolder.js +1 -1
- package/dist/views/SpamFolder.js.map +1 -1
- package/dist/views/dashboard/Delta.d.ts +7 -0
- package/dist/views/dashboard/Delta.d.ts.map +1 -0
- package/dist/views/dashboard/Delta.js +21 -0
- package/dist/views/dashboard/Delta.js.map +1 -0
- package/dist/views/dashboard/KpiCard.d.ts +22 -0
- package/dist/views/dashboard/KpiCard.d.ts.map +1 -0
- package/dist/views/dashboard/KpiCard.js +15 -0
- package/dist/views/dashboard/KpiCard.js.map +1 -0
- package/dist/views/dashboard/Sparkline.d.ts +11 -0
- package/dist/views/dashboard/Sparkline.d.ts.map +1 -0
- package/dist/views/dashboard/Sparkline.js +15 -0
- package/dist/views/dashboard/Sparkline.js.map +1 -0
- package/dist/views/dashboard/TrendChart.d.ts +8 -0
- package/dist/views/dashboard/TrendChart.d.ts.map +1 -0
- package/dist/views/dashboard/TrendChart.js +98 -0
- package/dist/views/dashboard/TrendChart.js.map +1 -0
- package/dist/views/dashboard/dashboard-date.d.ts +33 -0
- package/dist/views/dashboard/dashboard-date.d.ts.map +1 -0
- package/dist/views/dashboard/dashboard-date.js +136 -0
- package/dist/views/dashboard/dashboard-date.js.map +1 -0
- package/dist/views/entries/EntriesInbox.d.ts +8 -0
- package/dist/views/entries/EntriesInbox.d.ts.map +1 -0
- package/dist/views/entries/EntriesInbox.js +516 -0
- package/dist/views/entries/EntriesInbox.js.map +1 -0
- package/dist/views/entries/inbox-format.d.ts +27 -0
- package/dist/views/entries/inbox-format.d.ts.map +1 -0
- package/dist/views/entries/inbox-format.js +119 -0
- package/dist/views/entries/inbox-format.js.map +1 -0
- package/dist/views/header-footer/ChromePreview.d.ts.map +1 -1
- package/dist/views/header-footer/ChromePreview.js +12 -6
- package/dist/views/header-footer/ChromePreview.js.map +1 -1
- package/dist/views/settings/AISettingsTab.js +1 -1
- package/dist/views/settings/SecurityStatusCard.js +1 -1
- package/dist/views/settings/SecurityStatusCard.js.map +1 -1
- package/dist/views/settings/SiteIndexStatusCard.js +1 -1
- package/dist/views/settings/SiteIndexStatusCard.js.map +1 -1
- package/dist/views/settings/brand-voice/BrandVoiceAlignmentPanel.js +1 -1
- package/dist/views/settings/brand-voice/BrandVoiceRulesSections.js +3 -3
- package/dist/views/settings/components.d.ts +1 -1
- package/dist/views/settings/components.d.ts.map +1 -1
- package/dist/views/settings/components.js +1 -1
- package/package.json +4 -4
- package/src/AdminRoot.tsx +7 -3
- package/src/__tests__/components/attribution-rows.test.ts +1 -1
- package/src/__tests__/components/date-range-picker.test.tsx +69 -0
- package/src/__tests__/components/form-build-model.test.ts +200 -0
- package/src/__tests__/components/form-build.test.tsx +157 -0
- package/src/__tests__/components/qa-a11y.render.test.tsx +44 -0
- package/src/__tests__/components/responsive-tiers.render.test.tsx +13 -0
- package/src/__tests__/components/ui-primitives.test.tsx +11 -0
- package/src/__tests__/layout/shell-nav.render.test.tsx +6 -0
- package/src/__tests__/lib/batch-wizard.test.ts +2 -0
- package/src/__tests__/lib/forms-settings-normalize.test.ts +17 -0
- package/src/__tests__/styles/qa-contrast.test.ts +90 -0
- package/src/__tests__/views/ai-settings.render.test.tsx +23 -0
- package/src/__tests__/views/appearance-chrome.render.test.tsx +12 -0
- package/src/__tests__/views/dashboard.test.tsx +110 -32
- package/src/__tests__/views/form-editor.render.test.tsx +18 -10
- package/src/__tests__/views/form-entries.render.test.tsx +27 -9
- package/src/__tests__/views/form-submissions.render.test.tsx +15 -14
- package/src/__tests__/views/forms-list.render.test.tsx +157 -17
- package/src/__tests__/views/forms-settings.fixture.ts +32 -0
- package/src/__tests__/views/forms-settings.render.test.tsx +145 -0
- package/src/__tests__/views/inbox-format.test.ts +72 -0
- package/src/__tests__/views/jobs-list.render.test.tsx +2 -0
- package/src/__tests__/views/jobs-wizard.render.test.tsx +18 -3
- package/src/__tests__/views/onboarding-block.render.test.tsx +9 -7
- package/src/__tests__/views/run-with-ai.render.test.tsx +10 -0
- package/src/__tests__/views/script-tags.render.test.tsx +11 -0
- package/src/__tests__/views/settings-tabs.render.test.tsx +6 -0
- package/src/components/SEOConfigPanel.tsx +2 -2
- package/src/components/forms/BlocklistDialog.tsx +552 -0
- package/src/components/forms/ExportMenu.tsx +8 -2
- package/src/components/forms/FieldOptions.tsx +629 -0
- package/src/components/forms/FormBuild.tsx +900 -0
- package/src/components/forms/FormsListTable.tsx +300 -0
- package/src/components/forms/form-build-model.ts +365 -0
- package/src/components/forms/form-build-ui.tsx +130 -0
- package/src/components/forms/primitives.tsx +6 -55
- package/src/components/seo/PageAuditPanel.tsx +2 -2
- package/src/components/seo/primitives.tsx +15 -3
- package/src/components/ui/DateRangePicker.tsx +358 -0
- package/src/components/ui/FilterPill.tsx +4 -2
- package/src/components/ui/PageHeader.tsx +14 -1
- package/src/components/ui/Segmented.tsx +9 -2
- package/src/components/ui/StatusBadge.tsx +17 -4
- package/src/components/ui/Toggle.tsx +3 -0
- package/src/components/ui/UnderlineTabs.tsx +20 -9
- package/src/layout/Sidebar.tsx +7 -2
- package/src/lib/batch-wizard.ts +2 -2
- package/src/lib/entry-attribution.ts +94 -0
- package/src/lib/forms-service.ts +194 -0
- package/src/lib/job-drawer.ts +21 -1
- package/src/lib/job-view.ts +7 -0
- package/src/router/admin-routes.ts +1 -0
- package/src/styles/prenta-tokens.css +2 -1
- package/src/styles/theme.css +86 -0
- package/src/views/Dashboard.tsx +1183 -772
- package/src/views/FormEditor.tsx +397 -199
- package/src/views/FormEntries.tsx +3 -422
- package/src/views/FormSubmissions.tsx +5 -411
- package/src/views/Forms.tsx +333 -321
- package/src/views/FormsSettings.tsx +1381 -73
- package/src/views/Jobs/DrawerReview.tsx +14 -8
- package/src/views/Jobs/NewBatchJob.tsx +5 -1
- package/src/views/Jobs.tsx +1 -0
- package/src/views/MediaBrowser.tsx +6 -1
- package/src/views/Pages/PagesListView.tsx +1 -1
- package/src/views/Redirects.tsx +1 -3
- package/src/views/ScriptTags.tsx +1 -1
- package/src/views/Settings.tsx +1 -1
- package/src/views/SpamFolder.tsx +2 -2
- package/src/views/dashboard/Delta.tsx +44 -0
- package/src/views/dashboard/KpiCard.tsx +98 -0
- package/src/views/dashboard/Sparkline.tsx +51 -0
- package/src/views/dashboard/TrendChart.tsx +246 -0
- package/src/views/dashboard/dashboard-date.ts +168 -0
- package/src/views/entries/EntriesInbox.tsx +1277 -0
- package/src/views/entries/inbox-format.ts +128 -0
- package/src/views/header-footer/ChromePreview.tsx +18 -8
- package/src/views/settings/AISettingsTab.tsx +1 -1
- package/src/views/settings/SecurityStatusCard.tsx +1 -1
- package/src/views/settings/SiteIndexStatusCard.tsx +1 -1
- package/src/views/settings/brand-voice/BrandVoiceAlignmentPanel.tsx +1 -1
- package/src/views/settings/brand-voice/BrandVoiceRulesSections.tsx +3 -3
- package/src/views/settings/components.tsx +2 -2
- package/dist/components/forms/EntriesTable.d.ts +0 -29
- package/dist/components/forms/EntriesTable.d.ts.map +0 -1
- package/dist/components/forms/EntriesTable.js +0 -29
- package/dist/components/forms/EntriesTable.js.map +0 -1
- package/dist/components/forms/FormEntryDetailPane.d.ts +0 -23
- package/dist/components/forms/FormEntryDetailPane.d.ts.map +0 -1
- package/dist/components/forms/FormEntryDetailPane.js +0 -208
- package/dist/components/forms/FormEntryDetailPane.js.map +0 -1
- package/dist/components/ui/PanelSection.d.ts +0 -16
- package/dist/components/ui/PanelSection.d.ts.map +0 -1
- package/dist/components/ui/PanelSection.js +0 -15
- package/dist/components/ui/PanelSection.js.map +0 -1
- package/src/components/forms/EntriesTable.tsx +0 -206
- package/src/components/forms/FormEntryDetailPane.tsx +0 -402
- package/src/components/ui/PanelSection.tsx +0 -53
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Forms list rows (kit `Forms.html` `.fl` / `.fl-row`, SPEC §1). A card list
|
|
5
|
+
* rather than a `<table>` so a container query can re-flow each row: two lines
|
|
6
|
+
* at ≤860px (`form | status` / `entries | notifications`), one cell per line
|
|
7
|
+
* at ≤460px.
|
|
8
|
+
*/
|
|
9
|
+
import type { CSSProperties, KeyboardEvent, MouseEvent } from 'react'
|
|
10
|
+
import * as DropdownMenu from '@radix-ui/react-dropdown-menu'
|
|
11
|
+
import { ChevronRight, Copy, MoreHorizontal, Settings2 } from 'lucide-react'
|
|
12
|
+
import { Toggle } from '../ui/Toggle.js'
|
|
13
|
+
import { adminPortalContainer } from '../../lib/portal-container.js'
|
|
14
|
+
import type { FormListItem } from '../../lib/forms-service.js'
|
|
15
|
+
import { FieldTypeBadge, FormStatusBadge } from './primitives.js'
|
|
16
|
+
|
|
17
|
+
const TILE_TONES = ['var(--acc)', 'var(--info)', 'var(--suc)', 'var(--warn)', 'var(--orange)']
|
|
18
|
+
|
|
19
|
+
const ROW_GRID =
|
|
20
|
+
'grid grid-cols-[minmax(220px,1.5fr)_minmax(170px,1fr)_minmax(170px,1fr)_minmax(150px,.9fr)_92px_44px] [grid-template-areas:"id_fields_ent_notif_st_chev"] items-center gap-4 ' +
|
|
21
|
+
'@max-[860px]:grid-cols-[minmax(0,1fr)_auto] @max-[860px]:[grid-template-areas:"id_st"_"ent_notif"] @max-[860px]:gap-y-3 ' +
|
|
22
|
+
'@max-[460px]:[grid-template-areas:"id_st"_"ent_ent"_"notif_notif"]'
|
|
23
|
+
|
|
24
|
+
function formInitials(name: string): string {
|
|
25
|
+
return name
|
|
26
|
+
.replace(/[^A-Za-z ]/g, '')
|
|
27
|
+
.split(' ')
|
|
28
|
+
.filter(Boolean)
|
|
29
|
+
.slice(0, 2)
|
|
30
|
+
.map((word) => word[0]!.toUpperCase())
|
|
31
|
+
.join('')
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function formatLastEntry(iso: string | null | undefined, now = Date.now()): string {
|
|
35
|
+
if (!iso) return '—'
|
|
36
|
+
const then = new Date(iso).getTime()
|
|
37
|
+
if (Number.isNaN(then)) return '—'
|
|
38
|
+
const mins = Math.round((now - then) / 60000)
|
|
39
|
+
if (mins < 1) return 'just now'
|
|
40
|
+
if (mins < 60) return `${mins} min ago`
|
|
41
|
+
const hrs = Math.round(mins / 60)
|
|
42
|
+
if (hrs < 24) return `${hrs} ${hrs === 1 ? 'hour' : 'hours'} ago`
|
|
43
|
+
const days = Math.round(hrs / 24)
|
|
44
|
+
if (days < 7) return `${days} ${days === 1 ? 'day' : 'days'} ago`
|
|
45
|
+
return new Date(iso).toLocaleDateString(undefined, {
|
|
46
|
+
month: 'short',
|
|
47
|
+
day: 'numeric',
|
|
48
|
+
year: 'numeric',
|
|
49
|
+
})
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function Spark({ values }: { values: number[] }) {
|
|
53
|
+
const w = 64
|
|
54
|
+
const h = 26
|
|
55
|
+
const max = Math.max(1, ...values)
|
|
56
|
+
const bw = w / Math.max(1, values.length)
|
|
57
|
+
return (
|
|
58
|
+
<svg width={w} height={h} className="ml-auto shrink-0 @max-[860px]:ml-2" aria-hidden="true">
|
|
59
|
+
{values.map((n, i) => {
|
|
60
|
+
const bh = Math.max(2, (n / max) * h)
|
|
61
|
+
return (
|
|
62
|
+
<rect
|
|
63
|
+
key={i}
|
|
64
|
+
x={i * bw + 1}
|
|
65
|
+
y={h - bh}
|
|
66
|
+
width={bw - 2}
|
|
67
|
+
height={bh}
|
|
68
|
+
rx="1.5"
|
|
69
|
+
className="fill-[color-mix(in_srgb,var(--acc)_55%,var(--bdr))]"
|
|
70
|
+
/>
|
|
71
|
+
)
|
|
72
|
+
})}
|
|
73
|
+
</svg>
|
|
74
|
+
)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export interface FormsListTableProps {
|
|
78
|
+
forms: FormListItem[]
|
|
79
|
+
onOpenForm: (form: FormListItem) => void
|
|
80
|
+
onOpenEntries: (form: FormListItem) => void
|
|
81
|
+
onOpenDeliveries: () => void
|
|
82
|
+
onNotifyToggle: (form: FormListItem, next: boolean) => void
|
|
83
|
+
onOpenSchema: (form: FormListItem) => void
|
|
84
|
+
onDuplicate: (form: FormListItem) => void
|
|
85
|
+
/** Form whose schema pane is open (row highlight). */
|
|
86
|
+
selectedId?: string | null
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const stop = (event: MouseEvent | KeyboardEvent) => event.stopPropagation()
|
|
90
|
+
|
|
91
|
+
const menuItem =
|
|
92
|
+
'text-txt data-highlighted:bg-bg flex cursor-pointer items-center gap-2 rounded-7 px-2 py-1.5 text-body outline-none'
|
|
93
|
+
|
|
94
|
+
export function FormsListTable({
|
|
95
|
+
forms,
|
|
96
|
+
onOpenForm,
|
|
97
|
+
onOpenEntries,
|
|
98
|
+
onOpenDeliveries,
|
|
99
|
+
onNotifyToggle,
|
|
100
|
+
onOpenSchema,
|
|
101
|
+
onDuplicate,
|
|
102
|
+
selectedId,
|
|
103
|
+
}: FormsListTableProps) {
|
|
104
|
+
return (
|
|
105
|
+
<div
|
|
106
|
+
role="list"
|
|
107
|
+
aria-label="Forms"
|
|
108
|
+
className="rounded-12 border-bdr bg-card shadow-shd @container overflow-hidden border"
|
|
109
|
+
>
|
|
110
|
+
<div
|
|
111
|
+
aria-hidden="true"
|
|
112
|
+
className={`${ROW_GRID} border-bdr text-faint text-hint border-b px-[18px] py-2.5 font-semibold tracking-[0.4px] uppercase @max-[860px]:hidden`}
|
|
113
|
+
>
|
|
114
|
+
<span className="[grid-area:id]">Form</span>
|
|
115
|
+
<span className="[grid-area:fields]">Fields</span>
|
|
116
|
+
<span className="[grid-area:ent]">Entries · 14 days</span>
|
|
117
|
+
<span className="[grid-area:notif]">Notifications</span>
|
|
118
|
+
<span className="[grid-area:st]">Status</span>
|
|
119
|
+
<span className="[grid-area:chev]" />
|
|
120
|
+
</div>
|
|
121
|
+
{forms.map((form, index) => {
|
|
122
|
+
const tone = TILE_TONES[index % TILE_TONES.length]!
|
|
123
|
+
const archived = form.status === 'archived'
|
|
124
|
+
const unread = form.unreadEntries ?? 0
|
|
125
|
+
const total = form.totalEntries ?? 0
|
|
126
|
+
const failed = form.failedEmails7d ?? 0
|
|
127
|
+
const pages = form.pageCount ?? 0
|
|
128
|
+
const recipients = form.notificationSettings?.recipients?.length ?? 0
|
|
129
|
+
const notifyOn = form.notifyEnabled ?? false
|
|
130
|
+
const fieldCount = form.fieldCount ?? form.fields.length
|
|
131
|
+
const selected = form.id === selectedId
|
|
132
|
+
return (
|
|
133
|
+
<div
|
|
134
|
+
key={form.id}
|
|
135
|
+
role="listitem"
|
|
136
|
+
tabIndex={0}
|
|
137
|
+
aria-label={`Manage ${form.name}`}
|
|
138
|
+
onClick={() => onOpenForm(form)}
|
|
139
|
+
onKeyDown={(event) => {
|
|
140
|
+
if (event.target !== event.currentTarget) return
|
|
141
|
+
if (event.key === 'Enter' || event.key === ' ') {
|
|
142
|
+
event.preventDefault()
|
|
143
|
+
onOpenForm(form)
|
|
144
|
+
}
|
|
145
|
+
}}
|
|
146
|
+
className={`${ROW_GRID} group border-bdr cursor-pointer border-b px-[18px] py-[13px] transition-colors duration-[120ms] last:border-b-0 focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-[var(--acc)] ${
|
|
147
|
+
selected ? 'bg-acc-l' : 'hover:bg-bg'
|
|
148
|
+
}`}
|
|
149
|
+
>
|
|
150
|
+
<div
|
|
151
|
+
className={`flex min-w-0 items-center gap-3 [grid-area:id] ${archived ? 'opacity-60' : ''}`}
|
|
152
|
+
>
|
|
153
|
+
<span
|
|
154
|
+
style={{ '--t': tone } as CSSProperties}
|
|
155
|
+
className="rounded-10 text-sm2 flex h-[38px] w-[38px] shrink-0 items-center justify-center border border-[color-mix(in_srgb,var(--t)_22%,transparent)] bg-[color-mix(in_srgb,var(--t)_12%,var(--card))] font-bold tracking-[-0.3px] text-[var(--t)]"
|
|
156
|
+
aria-hidden="true"
|
|
157
|
+
>
|
|
158
|
+
{formInitials(form.name)}
|
|
159
|
+
</span>
|
|
160
|
+
<div className="min-w-0">
|
|
161
|
+
<div className="text-txt truncate text-[14px] font-semibold">{form.name}</div>
|
|
162
|
+
<div className="text-meta text-sub mt-0.5 flex flex-wrap items-center gap-1.5">
|
|
163
|
+
<code className="text-hint text-sub font-mono whitespace-nowrap">
|
|
164
|
+
/{form.slug}
|
|
165
|
+
</code>
|
|
166
|
+
<span className="text-faint">·</span>
|
|
167
|
+
<span className="whitespace-nowrap">
|
|
168
|
+
on {pages} {pages === 1 ? 'page' : 'pages'}
|
|
169
|
+
</span>
|
|
170
|
+
</div>
|
|
171
|
+
</div>
|
|
172
|
+
</div>
|
|
173
|
+
|
|
174
|
+
<div
|
|
175
|
+
className={`flex min-w-0 flex-wrap items-center gap-1 [grid-area:fields] @max-[860px]:hidden ${archived ? 'opacity-60' : ''}`}
|
|
176
|
+
>
|
|
177
|
+
{form.fields.slice(0, 3).map((field) => (
|
|
178
|
+
<FieldTypeBadge key={field.id} type={field.type} />
|
|
179
|
+
))}
|
|
180
|
+
<span className="text-hint text-sub ml-0.5 whitespace-nowrap">
|
|
181
|
+
{fieldCount} fields
|
|
182
|
+
</span>
|
|
183
|
+
</div>
|
|
184
|
+
|
|
185
|
+
<div className="min-w-0 [grid-area:ent]">
|
|
186
|
+
<div className="flex items-center gap-2.5">
|
|
187
|
+
<button
|
|
188
|
+
type="button"
|
|
189
|
+
onClick={(event) => {
|
|
190
|
+
stop(event)
|
|
191
|
+
onOpenEntries(form)
|
|
192
|
+
}}
|
|
193
|
+
onKeyDown={stop}
|
|
194
|
+
aria-label={`${total} entries for ${form.name}`}
|
|
195
|
+
className="text-txt hover:text-acc min-w-[22px] text-left text-[15px] font-bold tabular-nums hover:underline"
|
|
196
|
+
>
|
|
197
|
+
{total.toLocaleString()}
|
|
198
|
+
</button>
|
|
199
|
+
{unread > 0 ? (
|
|
200
|
+
<span className="text-hint text-acc bg-acc-l rounded-pill px-2 py-0.5 font-[650] whitespace-nowrap">
|
|
201
|
+
{unread} new
|
|
202
|
+
</span>
|
|
203
|
+
) : null}
|
|
204
|
+
<Spark values={form.entries14d ?? []} />
|
|
205
|
+
</div>
|
|
206
|
+
<div className="text-hint text-faint mt-[3px] whitespace-nowrap">
|
|
207
|
+
Last {formatLastEntry(form.lastEntryAt)}
|
|
208
|
+
</div>
|
|
209
|
+
</div>
|
|
210
|
+
|
|
211
|
+
<div className="flex items-center gap-2.5 [grid-area:notif]">
|
|
212
|
+
<span onClick={stop} onKeyDown={stop} className="flex">
|
|
213
|
+
<Toggle
|
|
214
|
+
size="lg"
|
|
215
|
+
variant="enabled"
|
|
216
|
+
checked={notifyOn}
|
|
217
|
+
onCheckedChange={(next) => onNotifyToggle(form, next)}
|
|
218
|
+
aria-label={`Email notifications for ${form.name}`}
|
|
219
|
+
/>
|
|
220
|
+
</span>
|
|
221
|
+
<div className="text-sm2 text-txt flex flex-col gap-0.5 whitespace-nowrap">
|
|
222
|
+
{notifyOn ? (
|
|
223
|
+
<>
|
|
224
|
+
<span>
|
|
225
|
+
{recipients} {recipients === 1 ? 'recipient' : 'recipients'}
|
|
226
|
+
</span>
|
|
227
|
+
{failed > 0 ? (
|
|
228
|
+
<button
|
|
229
|
+
type="button"
|
|
230
|
+
onClick={(event) => {
|
|
231
|
+
stop(event)
|
|
232
|
+
onOpenDeliveries()
|
|
233
|
+
}}
|
|
234
|
+
onKeyDown={stop}
|
|
235
|
+
className="text-hint text-err inline-flex items-center gap-[5px] text-left font-semibold hover:underline"
|
|
236
|
+
>
|
|
237
|
+
<span aria-hidden className="h-1.5 w-1.5 rounded-full bg-current" />
|
|
238
|
+
{failed} failed
|
|
239
|
+
</button>
|
|
240
|
+
) : (
|
|
241
|
+
<span className="text-hint text-suc inline-flex items-center gap-[5px] font-semibold">
|
|
242
|
+
<span aria-hidden className="h-1.5 w-1.5 rounded-full bg-current" />
|
|
243
|
+
Delivering
|
|
244
|
+
</span>
|
|
245
|
+
)}
|
|
246
|
+
</>
|
|
247
|
+
) : (
|
|
248
|
+
<span className="text-faint">Off</span>
|
|
249
|
+
)}
|
|
250
|
+
</div>
|
|
251
|
+
</div>
|
|
252
|
+
|
|
253
|
+
<div className="[grid-area:st]">
|
|
254
|
+
<FormStatusBadge status={form.status} pill />
|
|
255
|
+
</div>
|
|
256
|
+
|
|
257
|
+
<div className="flex items-center justify-end gap-0.5 [grid-area:chev] @max-[860px]:hidden">
|
|
258
|
+
<DropdownMenu.Root>
|
|
259
|
+
<DropdownMenu.Trigger asChild>
|
|
260
|
+
<button
|
|
261
|
+
type="button"
|
|
262
|
+
onClick={stop}
|
|
263
|
+
onKeyDown={stop}
|
|
264
|
+
aria-label={`More actions for ${form.name}`}
|
|
265
|
+
className="rounded-7 text-sub hover:bg-card hover:text-txt data-[state=open]:bg-card flex h-6 w-6 items-center justify-center opacity-0 group-focus-within:opacity-100 group-hover:opacity-100 focus-visible:opacity-100 data-[state=open]:opacity-100"
|
|
266
|
+
>
|
|
267
|
+
<MoreHorizontal size={15} strokeWidth={1.8} aria-hidden />
|
|
268
|
+
</button>
|
|
269
|
+
</DropdownMenu.Trigger>
|
|
270
|
+
<DropdownMenu.Portal container={adminPortalContainer()}>
|
|
271
|
+
<DropdownMenu.Content
|
|
272
|
+
align="end"
|
|
273
|
+
sideOffset={4}
|
|
274
|
+
onClick={stop}
|
|
275
|
+
className="border-bdr bg-card rounded-10 shadow-shd2 z-50 min-w-40 border p-1"
|
|
276
|
+
>
|
|
277
|
+
<DropdownMenu.Item className={menuItem} onSelect={() => onOpenSchema(form)}>
|
|
278
|
+
<Settings2 size={14} strokeWidth={1.8} aria-hidden />
|
|
279
|
+
Schema
|
|
280
|
+
</DropdownMenu.Item>
|
|
281
|
+
<DropdownMenu.Item className={menuItem} onSelect={() => onDuplicate(form)}>
|
|
282
|
+
<Copy size={14} strokeWidth={1.8} aria-hidden />
|
|
283
|
+
Duplicate
|
|
284
|
+
</DropdownMenu.Item>
|
|
285
|
+
</DropdownMenu.Content>
|
|
286
|
+
</DropdownMenu.Portal>
|
|
287
|
+
</DropdownMenu.Root>
|
|
288
|
+
<ChevronRight
|
|
289
|
+
size={15}
|
|
290
|
+
strokeWidth={1.8}
|
|
291
|
+
aria-hidden
|
|
292
|
+
className="text-faint group-hover:text-acc transition-[transform,color] duration-[120ms] group-hover:translate-x-0.5"
|
|
293
|
+
/>
|
|
294
|
+
</div>
|
|
295
|
+
</div>
|
|
296
|
+
)
|
|
297
|
+
})}
|
|
298
|
+
</div>
|
|
299
|
+
)
|
|
300
|
+
}
|
|
@@ -0,0 +1,365 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure model for the form editor's Build mode (SPEC §4): the field catalogue,
|
|
3
|
+
* new-field defaults, list edits, and the mapping between the kit's logic UI
|
|
4
|
+
* and the repo's `conditionalLogic` shape (CONFLICTS.md §5).
|
|
5
|
+
*/
|
|
6
|
+
import type { ConditionalOperator, ConditionalRule, FormField, FormFieldType } from '@prenta/core'
|
|
7
|
+
|
|
8
|
+
export type PaletteGroup = 'basic' | 'contact' | 'layout'
|
|
9
|
+
|
|
10
|
+
export interface PaletteType {
|
|
11
|
+
type: FormFieldType
|
|
12
|
+
label: string
|
|
13
|
+
group: PaletteGroup
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const PALETTE_GROUPS: Array<{ id: PaletteGroup; title: string }> = [
|
|
17
|
+
{ id: 'basic', title: 'Basic fields' },
|
|
18
|
+
{ id: 'contact', title: 'Contact & details' },
|
|
19
|
+
{ id: 'layout', title: 'Layout & advanced' },
|
|
20
|
+
]
|
|
21
|
+
|
|
22
|
+
export const PALETTE: PaletteType[] = [
|
|
23
|
+
{ type: 'text', label: 'Single line', group: 'basic' },
|
|
24
|
+
{ type: 'textarea', label: 'Paragraph', group: 'basic' },
|
|
25
|
+
{ type: 'email', label: 'Email', group: 'basic' },
|
|
26
|
+
{ type: 'phone', label: 'Phone', group: 'basic' },
|
|
27
|
+
{ type: 'number', label: 'Number', group: 'basic' },
|
|
28
|
+
{ type: 'select', label: 'Dropdown', group: 'basic' },
|
|
29
|
+
{ type: 'radio', label: 'Multiple choice', group: 'basic' },
|
|
30
|
+
{ type: 'checkbox', label: 'Checkboxes', group: 'basic' },
|
|
31
|
+
{ type: 'name', label: 'Name', group: 'contact' },
|
|
32
|
+
{ type: 'url', label: 'Website', group: 'contact' },
|
|
33
|
+
{ type: 'date', label: 'Date', group: 'contact' },
|
|
34
|
+
{ type: 'file', label: 'File upload', group: 'contact' },
|
|
35
|
+
{ type: 'consent', label: 'Consent', group: 'contact' },
|
|
36
|
+
{ type: 'pagebreak', label: 'Page break', group: 'layout' },
|
|
37
|
+
{ type: 'heading', label: 'Section heading', group: 'layout' },
|
|
38
|
+
{ type: 'divider', label: 'Divider', group: 'layout' },
|
|
39
|
+
{ type: 'content', label: 'Content', group: 'layout' },
|
|
40
|
+
{ type: 'hidden', label: 'Hidden field', group: 'layout' },
|
|
41
|
+
]
|
|
42
|
+
|
|
43
|
+
/** Labels for types the palette doesn't offer but stored forms may hold. */
|
|
44
|
+
const EXTRA_TYPE_LABELS: Partial<Record<FormFieldType, string>> = {
|
|
45
|
+
multiselect: 'Multi-select',
|
|
46
|
+
richtext: 'Content',
|
|
47
|
+
honeypot: 'Honeypot',
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function typeLabel(type: FormFieldType): string {
|
|
51
|
+
return PALETTE.find((item) => item.type === type)?.label ?? EXTRA_TYPE_LABELS[type] ?? type
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export const CHOICE_TYPES: ReadonlySet<FormFieldType> = new Set([
|
|
55
|
+
'select',
|
|
56
|
+
'multiselect',
|
|
57
|
+
'radio',
|
|
58
|
+
'checkbox',
|
|
59
|
+
])
|
|
60
|
+
|
|
61
|
+
/** Types with no input of their own (prototype `NO_INPUT`). */
|
|
62
|
+
const NO_INPUT_TYPES: ReadonlySet<FormFieldType> = new Set([
|
|
63
|
+
'heading',
|
|
64
|
+
'divider',
|
|
65
|
+
'content',
|
|
66
|
+
'richtext',
|
|
67
|
+
'hidden',
|
|
68
|
+
'pagebreak',
|
|
69
|
+
'honeypot',
|
|
70
|
+
])
|
|
71
|
+
|
|
72
|
+
export function hasInput(type: FormFieldType): boolean {
|
|
73
|
+
return !NO_INPUT_TYPES.has(type)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function slugify(value: string): string {
|
|
77
|
+
return value
|
|
78
|
+
.toLowerCase()
|
|
79
|
+
.trim()
|
|
80
|
+
.replace(/[^a-z0-9]+/g, '_')
|
|
81
|
+
.replace(/^_+|_+$/g, '')
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** A key that starts with a letter (server `KEY_PATTERN`) and is unique in `taken`. */
|
|
85
|
+
export function uniqueKey(label: string, taken: ReadonlySet<string>): string {
|
|
86
|
+
let base = slugify(label).slice(0, 40) || 'field'
|
|
87
|
+
if (!/^[a-z]/.test(base)) base = `f_${base}`
|
|
88
|
+
let key = base
|
|
89
|
+
let n = 2
|
|
90
|
+
while (taken.has(key)) key = `${base}_${n++}`
|
|
91
|
+
return key
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function makeId(): string {
|
|
95
|
+
return typeof crypto !== 'undefined' && 'randomUUID' in crypto
|
|
96
|
+
? crypto.randomUUID()
|
|
97
|
+
: `field_${Math.random().toString(36).slice(2, 10)}`
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function defaultLabel(type: FormFieldType): string {
|
|
101
|
+
switch (type) {
|
|
102
|
+
case 'pagebreak':
|
|
103
|
+
return 'Next step'
|
|
104
|
+
case 'consent':
|
|
105
|
+
return 'I agree to be contacted about my request.'
|
|
106
|
+
case 'heading':
|
|
107
|
+
return 'Section heading'
|
|
108
|
+
default:
|
|
109
|
+
return typeLabel(type)
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** SPEC §4.1 new-field defaults. */
|
|
114
|
+
export function blankField(type: FormFieldType, existing: FormField[]): FormField {
|
|
115
|
+
const label = defaultLabel(type)
|
|
116
|
+
const field: FormField = {
|
|
117
|
+
id: makeId(),
|
|
118
|
+
label,
|
|
119
|
+
key: uniqueKey(label, new Set(existing.map((item) => item.key))),
|
|
120
|
+
autoKey: true,
|
|
121
|
+
type,
|
|
122
|
+
required: false,
|
|
123
|
+
width: 'full',
|
|
124
|
+
sortOrder: existing.length,
|
|
125
|
+
}
|
|
126
|
+
if (CHOICE_TYPES.has(type)) {
|
|
127
|
+
field.options = ['First choice', 'Second choice', 'Third choice'].map((choice) => ({
|
|
128
|
+
label: choice,
|
|
129
|
+
value: slugify(choice),
|
|
130
|
+
}))
|
|
131
|
+
}
|
|
132
|
+
return field
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function reorder(fields: FormField[]): FormField[] {
|
|
136
|
+
return fields.map((field, sortOrder) => ({ ...field, sortOrder }))
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export function insertField(fields: FormField[], field: FormField, at: number): FormField[] {
|
|
140
|
+
const copy = [...fields]
|
|
141
|
+
copy.splice(Math.max(0, Math.min(at, copy.length)), 0, field)
|
|
142
|
+
return reorder(copy)
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/** Insert below the selected field, or at the end when nothing is selected. */
|
|
146
|
+
export function insertIndexFor(fields: FormField[], selectedId: string | null): number {
|
|
147
|
+
const index = selectedId ? fields.findIndex((field) => field.id === selectedId) : -1
|
|
148
|
+
return index < 0 ? fields.length : index + 1
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export function moveField(fields: FormField[], from: number, to: number): FormField[] {
|
|
152
|
+
if (from === to || from < 0 || to < 0 || from >= fields.length || to >= fields.length) {
|
|
153
|
+
return fields
|
|
154
|
+
}
|
|
155
|
+
const copy = [...fields]
|
|
156
|
+
const [item] = copy.splice(from, 1)
|
|
157
|
+
copy.splice(to, 0, item!)
|
|
158
|
+
return reorder(copy)
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export function duplicateField(
|
|
162
|
+
fields: FormField[],
|
|
163
|
+
id: string,
|
|
164
|
+
): { fields: FormField[]; id: string } {
|
|
165
|
+
const index = fields.findIndex((field) => field.id === id)
|
|
166
|
+
const source = fields[index]
|
|
167
|
+
if (!source) return { fields, id }
|
|
168
|
+
const copy: FormField = {
|
|
169
|
+
...source,
|
|
170
|
+
id: makeId(),
|
|
171
|
+
label: `${source.label} (copy)`,
|
|
172
|
+
key: uniqueKey(`${source.key}_copy`, new Set(fields.map((field) => field.key))),
|
|
173
|
+
autoKey: false,
|
|
174
|
+
}
|
|
175
|
+
return { fields: insertField(fields, copy, index + 1), id: copy.id }
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export function removeField(fields: FormField[], id: string): FormField[] {
|
|
179
|
+
return reorder(fields.filter((field) => field.id !== id))
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/** Label edits carry the key along while `autoKey` is on (SPEC §4.2). */
|
|
183
|
+
export function withLabel(field: FormField, label: string, fields: FormField[]): FormField {
|
|
184
|
+
if (!field.autoKey) return { ...field, label }
|
|
185
|
+
const taken = new Set(fields.filter((f) => f.id !== field.id).map((f) => f.key))
|
|
186
|
+
return { ...field, label, key: uniqueKey(label || defaultLabel(field.type), taken) }
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/** Hand-edited keys stop following the label. */
|
|
190
|
+
export function withKey(field: FormField, raw: string): FormField {
|
|
191
|
+
return { ...field, key: slugify(raw), autoKey: false }
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
export function duplicateKeyError(field: FormField, fields: FormField[]): string | null {
|
|
195
|
+
if (!field.key) return 'A field key is required.'
|
|
196
|
+
if (!/^[a-z]/.test(field.key)) return 'Start the key with a letter.'
|
|
197
|
+
return fields.some((f) => f.id !== field.id && f.key === field.key)
|
|
198
|
+
? 'Another field already uses this key.'
|
|
199
|
+
: null
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// ─── Steps ───────────────────────────────────────────────────────────────
|
|
203
|
+
|
|
204
|
+
export interface StepInfo {
|
|
205
|
+
/** Step titles in order; the first is the form's first step. */
|
|
206
|
+
titles: string[]
|
|
207
|
+
/** Step number (2…n) for each page break, by field id. */
|
|
208
|
+
numberById: Map<string, number>
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
export function stepsOf(fields: FormField[], firstStep = 'About you'): StepInfo {
|
|
212
|
+
const titles = [firstStep]
|
|
213
|
+
const numberById = new Map<string, number>()
|
|
214
|
+
for (const field of fields) {
|
|
215
|
+
if (field.type !== 'pagebreak') continue
|
|
216
|
+
titles.push(field.label)
|
|
217
|
+
numberById.set(field.id, titles.length)
|
|
218
|
+
}
|
|
219
|
+
return { titles, numberById }
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// ─── Logic (kit UI ⇄ repo shape) ─────────────────────────────────────────
|
|
223
|
+
|
|
224
|
+
export type LogicOp = 'is' | 'not' | 'has' | 'empty' | 'filled'
|
|
225
|
+
|
|
226
|
+
export interface LogicRuleDraft {
|
|
227
|
+
field: string
|
|
228
|
+
op: LogicOp
|
|
229
|
+
value: string
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
export interface LogicDraft {
|
|
233
|
+
on: boolean
|
|
234
|
+
action: 'show' | 'hide'
|
|
235
|
+
match: 'all' | 'any'
|
|
236
|
+
rules: LogicRuleDraft[]
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
const OP_TO_REPO: Record<LogicOp, ConditionalOperator> = {
|
|
240
|
+
is: 'equals',
|
|
241
|
+
not: 'notEquals',
|
|
242
|
+
has: 'contains',
|
|
243
|
+
empty: 'isEmpty',
|
|
244
|
+
filled: 'isNotEmpty',
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
const REPO_TO_OP: Record<ConditionalOperator, LogicOp> = {
|
|
248
|
+
equals: 'is',
|
|
249
|
+
notEquals: 'not',
|
|
250
|
+
contains: 'has',
|
|
251
|
+
isEmpty: 'empty',
|
|
252
|
+
isNotEmpty: 'filled',
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
export function opNeedsValue(op: LogicOp): boolean {
|
|
256
|
+
return op !== 'empty' && op !== 'filled'
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
export const EMPTY_RULE: LogicRuleDraft = { field: '', op: 'is', value: '' }
|
|
260
|
+
|
|
261
|
+
export function logicDraftOf(field: FormField): LogicDraft {
|
|
262
|
+
const logic = field.conditionalLogic
|
|
263
|
+
const show = logic?.show ?? []
|
|
264
|
+
const hide = logic?.hide ?? []
|
|
265
|
+
const rules = show.length > 0 ? show : hide
|
|
266
|
+
return {
|
|
267
|
+
on: rules.length > 0,
|
|
268
|
+
action: show.length === 0 && hide.length > 0 ? 'hide' : 'show',
|
|
269
|
+
match: logic?.match === 'any' ? 'any' : 'all',
|
|
270
|
+
rules:
|
|
271
|
+
rules.length > 0
|
|
272
|
+
? rules.map((rule) => ({
|
|
273
|
+
field: rule.fieldKey,
|
|
274
|
+
op: REPO_TO_OP[rule.operator] ?? 'is',
|
|
275
|
+
value: rule.value ?? '',
|
|
276
|
+
}))
|
|
277
|
+
: [{ ...EMPTY_RULE }],
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
export function hasLogic(field: FormField): boolean {
|
|
282
|
+
return Boolean(field.conditionalLogic?.show?.length || field.conditionalLogic?.hide?.length)
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* Write a draft back to `conditionalLogic`. Rules without a field are left
|
|
287
|
+
* out (a half-built rule must never hide a live field); `require` rules the
|
|
288
|
+
* kit UI doesn't show are kept.
|
|
289
|
+
*/
|
|
290
|
+
export function applyLogicDraft(field: FormField, draft: LogicDraft): FormField {
|
|
291
|
+
const require = field.conditionalLogic?.require
|
|
292
|
+
const rules: ConditionalRule[] = draft.on
|
|
293
|
+
? draft.rules
|
|
294
|
+
.filter((rule) => rule.field)
|
|
295
|
+
.map((rule) => ({
|
|
296
|
+
fieldKey: rule.field,
|
|
297
|
+
operator: OP_TO_REPO[rule.op],
|
|
298
|
+
...(opNeedsValue(rule.op) ? { value: rule.value } : {}),
|
|
299
|
+
}))
|
|
300
|
+
: []
|
|
301
|
+
const next = {
|
|
302
|
+
...(rules.length > 0 ? { [draft.action]: rules } : {}),
|
|
303
|
+
...(require && require.length > 0 ? { require } : {}),
|
|
304
|
+
}
|
|
305
|
+
if (Object.keys(next).length === 0) {
|
|
306
|
+
const { conditionalLogic: _dropped, ...rest } = field
|
|
307
|
+
return rest
|
|
308
|
+
}
|
|
309
|
+
return {
|
|
310
|
+
...field,
|
|
311
|
+
conditionalLogic: { ...next, ...(draft.match === 'any' ? { match: 'any' as const } : {}) },
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/** Fields a rule may reference: inputs that come earlier in the form. */
|
|
316
|
+
export function logicSources(fields: FormField[], id: string): FormField[] {
|
|
317
|
+
const index = fields.findIndex((field) => field.id === id)
|
|
318
|
+
return fields.slice(0, Math.max(0, index)).filter((field) => hasInput(field.type))
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
// ─── File types (kit extensions ⇄ stored MIME types) ─────────────────────
|
|
322
|
+
|
|
323
|
+
const EXTENSION_MIME: Record<string, string> = {
|
|
324
|
+
pdf: 'application/pdf',
|
|
325
|
+
jpg: 'image/jpeg',
|
|
326
|
+
jpeg: 'image/jpeg',
|
|
327
|
+
png: 'image/png',
|
|
328
|
+
gif: 'image/gif',
|
|
329
|
+
webp: 'image/webp',
|
|
330
|
+
svg: 'image/svg+xml',
|
|
331
|
+
txt: 'text/plain',
|
|
332
|
+
csv: 'text/csv',
|
|
333
|
+
doc: 'application/msword',
|
|
334
|
+
docx: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
|
335
|
+
xls: 'application/vnd.ms-excel',
|
|
336
|
+
xlsx: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
const DEFAULT_FILE_TYPES = 'pdf, jpg, png'
|
|
340
|
+
|
|
341
|
+
export function fileTypesToText(types: string[] | undefined): string {
|
|
342
|
+
if (!types || types.length === 0) return DEFAULT_FILE_TYPES
|
|
343
|
+
const seen = new Set<string>()
|
|
344
|
+
const out: string[] = []
|
|
345
|
+
for (const mime of types) {
|
|
346
|
+
const ext = Object.keys(EXTENSION_MIME).find((key) => EXTENSION_MIME[key] === mime) ?? mime
|
|
347
|
+
if (!seen.has(ext)) {
|
|
348
|
+
seen.add(ext)
|
|
349
|
+
out.push(ext)
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
return out.join(', ')
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
/** Known extensions become MIME types; `type/subtype` tokens pass through. */
|
|
356
|
+
export function fileTypesFromText(text: string): string[] {
|
|
357
|
+
const out = new Set<string>()
|
|
358
|
+
for (const raw of text.split(',')) {
|
|
359
|
+
const token = raw.trim().toLowerCase().replace(/^\./, '')
|
|
360
|
+
if (!token) continue
|
|
361
|
+
const mime = EXTENSION_MIME[token] ?? (token.includes('/') ? token : null)
|
|
362
|
+
if (mime) out.add(mime)
|
|
363
|
+
}
|
|
364
|
+
return [...out]
|
|
365
|
+
}
|