@papermap/papermap 1.1.1 → 1.1.2
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/index.d.mts +198 -3
- package/dist/index.d.ts +198 -3
- package/dist/index.js +3078 -1007
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +3033 -975
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/readme.md +212 -5
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -10,10 +10,11 @@ For **server-side setup** (HMAC auth, dashboards per tenant, embed tokens, API e
|
|
|
10
10
|
|
|
11
11
|
- **`PaperChat`** — Full AI chat assistant with streaming, conversation history, and chart generation. Supports four layouts: **default** (floating toolbar + modal assistant), **side** (fixed side panel for sheet-style pages), **floating** (chart preview overlay), and **dialog** (tawk.to-style floating launcher + popup chat widget).
|
|
12
12
|
- **`PaperCard`** — Standalone chart card with toolbar actions. Use `variant="streaming"` for an embedded chart + conversation dialog (without the floating assistant).
|
|
13
|
-
- **`
|
|
13
|
+
- **`PaperInsight`** — "Quick Insights" panel: streams up to 3 AI-generated insights (highlight / trends / recommendation) for a dashboard + date range.
|
|
14
|
+
- **`PaperBoard`** — Responsive grid layout of chart cards, toolbar (screenshot, generate dashboard, theme), optional chat assistant + `PaperInsight` tile, and controlled or uncontrolled layouts.
|
|
14
15
|
|
|
15
16
|
```tsx
|
|
16
|
-
import { PaperChat, PaperCard, PaperBoard } from '@papermap/papermap'
|
|
17
|
+
import { PaperChat, PaperCard, PaperInsight, PaperBoard } from '@papermap/papermap'
|
|
17
18
|
|
|
18
19
|
// Default: floating toolbar + expandable assistant (dashboard-style)
|
|
19
20
|
<PaperChat
|
|
@@ -71,12 +72,22 @@ import { PaperChat, PaperCard, PaperBoard } from '@papermap/papermap'
|
|
|
71
72
|
chartId="your-chart-id" // optional; card shows empty state if omitted
|
|
72
73
|
/>
|
|
73
74
|
|
|
74
|
-
//
|
|
75
|
+
// Standalone Quick Insights panel (streams 3 AI insights for the period)
|
|
76
|
+
<PaperInsight
|
|
77
|
+
token="your-base64-api-token"
|
|
78
|
+
workspaceId="your-workspace-id"
|
|
79
|
+
dashboardId="your-dashboard-id"
|
|
80
|
+
startDate="2026-04-25"
|
|
81
|
+
endDate="2026-05-25"
|
|
82
|
+
/>
|
|
83
|
+
|
|
84
|
+
// Full grid dashboard (wraps chart cards + optional PaperChat + insight tile)
|
|
75
85
|
<PaperBoard
|
|
76
86
|
token="..."
|
|
77
87
|
workspaceId="..."
|
|
78
88
|
dashboardId="..."
|
|
79
89
|
showChatAssistant
|
|
90
|
+
showInsights
|
|
80
91
|
/>
|
|
81
92
|
```
|
|
82
93
|
|
|
@@ -329,6 +340,36 @@ const chart: TChartResponse = {
|
|
|
329
340
|
/>
|
|
330
341
|
```
|
|
331
342
|
|
|
343
|
+
#### `PaperInsight` props
|
|
344
|
+
|
|
345
|
+
| Prop | Type | Required | Default | Description |
|
|
346
|
+
| ------------------------- | -------------------------------------------------- | -------- | ----------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
347
|
+
| `token` | `string` | Yes\* | -- | Base64-encoded API key token |
|
|
348
|
+
| `workspaceId` | `string` | Yes\* | -- | Workspace ID |
|
|
349
|
+
| `dashboardId` | `string` | Yes\* | -- | Dashboard ID |
|
|
350
|
+
| `apiUrl` | `string` | No | `https://dataapi.papermap.ai` | API base URL |
|
|
351
|
+
| `startDate` | `Date \| string` (`yyyy-MM-dd`) | Yes | -- | Inclusive start of the insight window |
|
|
352
|
+
| `endDate` | `Date \| string` (`yyyy-MM-dd`) | Yes | -- | Inclusive end of the insight window |
|
|
353
|
+
| `theme` | `'light' \| 'dark' \| 'system'` | No | -- | Scoped color scheme (independent of host page) |
|
|
354
|
+
| `dashboardTheme` | `DashboardTheme \| null` | No | -- | Themed mark color + module surface (matches main app workspace theme) |
|
|
355
|
+
| `isEditMode` | `boolean` | No | `false` | Disable interactions while a parent grid is in layout-edit mode |
|
|
356
|
+
| `periodPreset` | `InsightsPeriodPreset` | No | -- | Show the period dropdown (`last_3_months \| this_week \| this_month \| this_year \| custom`). Hide by omitting. |
|
|
357
|
+
| `onPeriodPresetChange` | `(preset: InsightsPeriodPreset) => void` | No | -- | Fired when the user picks a preset |
|
|
358
|
+
| `onRangeChange` | `(start: Date, end: Date) => void` | No | -- | Required for the inline custom-range scrubber to function — the host owns the dates and updates them when this fires |
|
|
359
|
+
| `showCustomRangeScrubber` | `boolean` | No | `true` | Render the inline `TimelineRange` scrubber when `periodPreset === 'custom'`. Set `false` when a parent (e.g. `PaperBoard`) renders its own. |
|
|
360
|
+
| `onExplore` | `(chatId: string) => void` | No | (opens chat assistant) | Per-row "Explore in Chat" arrow. Defaults to calling `openPapermapChatAssistant` when a store is mounted. |
|
|
361
|
+
| `onInsight` | `(insight: DashboardInsight) => void` | No | -- | Fired once per `insight` SSE event |
|
|
362
|
+
| `onComplete` | `(result: DashboardInsightsResult) => void` | No | -- | Fired when the server emits `insights_complete` |
|
|
363
|
+
| `onError` | `(error: Error) => void` | No | -- | Fired on transport / `error` SSE event |
|
|
364
|
+
| `className` | `string` | No | -- | Root element class |
|
|
365
|
+
| `style` | `CSSProperties` | No | -- | Root element inline style |
|
|
366
|
+
| `classNames` | `Partial<Record<PaperInsightSlot, string>>` | No | -- | Per-slot class overrides (`header`, `title`, `dateLabel`, `refreshButton`, `row`, `body`, `footer`, …) |
|
|
367
|
+
| `styles` | `Partial<Record<PaperInsightSlot, CSSProperties>>` | No | -- | Per-slot inline style overrides |
|
|
368
|
+
|
|
369
|
+
\*Omit on the component when values come from `PapermapProvider`.
|
|
370
|
+
|
|
371
|
+
The SSE call is `POST /api/v1/analytics/dashboards/:dashboardId/insights/stream` with body `{ start_date, end_date }`. The component renders the panel's chrome (Activity icon, "Quick Insights" title, animated `TickSpinner` + cycling "Thinking… / Crunching… / Cooking…", optional period dropdown, Refresh button) and up to 3 streamed insights with metric chips and an "Explore in Chat" arrow.
|
|
372
|
+
|
|
332
373
|
#### `PaperBoard` props (high level)
|
|
333
374
|
|
|
334
375
|
| Prop | Notes |
|
|
@@ -338,6 +379,10 @@ const chart: TChartResponse = {
|
|
|
338
379
|
| `layouts` / `onLayoutsChange` | Controlled grid layouts per breakpoint. |
|
|
339
380
|
| `isEditMode`, `editLayout`, `isViewer` | Edit vs view behavior. |
|
|
340
381
|
| `showToolbar`, `showScreenshot`, `showGenerateDashboard`, `showHeader`, `showChatAssistant` | Feature toggles. |
|
|
382
|
+
| `showInsights` | Mount the `PaperInsight` tile at the top of the grid (mirrors main app `TimelineInsights`). |
|
|
383
|
+
| `insightsPeriodPreset`, `onInsightsPeriodPresetChange` | Controlled period for the insight tile. Defaults internally to `'last_3_months'`. |
|
|
384
|
+
| `insightsStartDate`, `insightsEndDate` | Controlled range overrides (use with `'custom'` to drive the dashboard `TimelineRange` scrubber from the host). |
|
|
385
|
+
| `onInsightExplore` | Per-row "Explore in Chat" arrow. Defaults to opening the floating chat assistant when one is mounted. |
|
|
341
386
|
| `variant` | `'default' \| 'streaming'` for embedded chart cards (matches `PaperCard`). |
|
|
342
387
|
| `dashboardTheme`, `onDashboardThemeChange`, `persistWorkspaceTheme`, `renderThemeModal` | Theming; built-in modal uses `ThemeCustomizationSettings`. |
|
|
343
388
|
| Callbacks | `onEditChart`, `onDeleteChart`, `onPinChange`, `onGenerateDashboard`, `onTakeScreenshot`, `onThemeModalOpen`, etc. |
|
|
@@ -564,6 +609,112 @@ Refetch host state after a chart is pinned or the embedded assistant closes.
|
|
|
564
609
|
/>
|
|
565
610
|
```
|
|
566
611
|
|
|
612
|
+
### PaperInsight
|
|
613
|
+
|
|
614
|
+
#### Minimal — fixed date range
|
|
615
|
+
|
|
616
|
+
```tsx
|
|
617
|
+
<PaperInsight
|
|
618
|
+
token="..."
|
|
619
|
+
workspaceId="..."
|
|
620
|
+
dashboardId="..."
|
|
621
|
+
startDate="2026-04-25"
|
|
622
|
+
endDate="2026-05-25"
|
|
623
|
+
/>
|
|
624
|
+
```
|
|
625
|
+
|
|
626
|
+
#### With period dropdown + custom-range scrubber
|
|
627
|
+
|
|
628
|
+
When `periodPreset === 'custom'` the inline `TimelineRange` scrubber renders between the header and the insight rows; dragging it fires `onRangeChange`.
|
|
629
|
+
|
|
630
|
+
```tsx
|
|
631
|
+
import {
|
|
632
|
+
PaperInsight,
|
|
633
|
+
computeInsightsPeriodRange,
|
|
634
|
+
type InsightsPeriodPreset,
|
|
635
|
+
type InsightsPeriodMenuPreset,
|
|
636
|
+
} from '@papermap/papermap'
|
|
637
|
+
|
|
638
|
+
function MyInsights() {
|
|
639
|
+
const [preset, setPreset] = useState<InsightsPeriodPreset>('last_3_months')
|
|
640
|
+
const [range, setRange] = useState(() => computeInsightsPeriodRange('last_3_months'))
|
|
641
|
+
|
|
642
|
+
return (
|
|
643
|
+
<PaperInsight
|
|
644
|
+
token="..."
|
|
645
|
+
workspaceId="..."
|
|
646
|
+
dashboardId="..."
|
|
647
|
+
startDate={range.start}
|
|
648
|
+
endDate={range.end}
|
|
649
|
+
periodPreset={preset}
|
|
650
|
+
onPeriodPresetChange={(next) => {
|
|
651
|
+
setPreset(next)
|
|
652
|
+
if (next !== 'custom') {
|
|
653
|
+
setRange(computeInsightsPeriodRange(next as InsightsPeriodMenuPreset))
|
|
654
|
+
}
|
|
655
|
+
}}
|
|
656
|
+
onRangeChange={(start, end) => {
|
|
657
|
+
setRange({ start, end })
|
|
658
|
+
setPreset('custom')
|
|
659
|
+
}}
|
|
660
|
+
/>
|
|
661
|
+
)
|
|
662
|
+
}
|
|
663
|
+
```
|
|
664
|
+
|
|
665
|
+
#### Wire "Explore in Chat" to the floating assistant
|
|
666
|
+
|
|
667
|
+
`PaperInsight` defaults `onExplore` to `openPapermapChatAssistant(storeApi, { editChartId: chatId })` whenever a `PapermapProvider` is mounted. Override to route somewhere else (e.g. your own router).
|
|
668
|
+
|
|
669
|
+
```tsx
|
|
670
|
+
<PaperInsight
|
|
671
|
+
token="..."
|
|
672
|
+
workspaceId="..."
|
|
673
|
+
dashboardId="..."
|
|
674
|
+
startDate="2026-04-25"
|
|
675
|
+
endDate="2026-05-25"
|
|
676
|
+
onExplore={(chatId) => router.push(`/dashboard?conversation_id=${chatId}`)}
|
|
677
|
+
/>
|
|
678
|
+
```
|
|
679
|
+
|
|
680
|
+
#### Custom styling via slots
|
|
681
|
+
|
|
682
|
+
```tsx
|
|
683
|
+
<PaperInsight
|
|
684
|
+
token="..."
|
|
685
|
+
workspaceId="..."
|
|
686
|
+
dashboardId="..."
|
|
687
|
+
startDate="2026-04-25"
|
|
688
|
+
endDate="2026-05-25"
|
|
689
|
+
className="rounded-2xl shadow-xl"
|
|
690
|
+
classNames={{
|
|
691
|
+
title: 'font-serif text-amber-200',
|
|
692
|
+
refreshButton: 'bg-amber-500 text-black hover:bg-amber-400',
|
|
693
|
+
row: 'hover:bg-amber-500/10',
|
|
694
|
+
}}
|
|
695
|
+
styles={{
|
|
696
|
+
body: { paddingInline: 24 },
|
|
697
|
+
}}
|
|
698
|
+
/>
|
|
699
|
+
```
|
|
700
|
+
|
|
701
|
+
#### Listen to stream events (analytics)
|
|
702
|
+
|
|
703
|
+
```tsx
|
|
704
|
+
<PaperInsight
|
|
705
|
+
token="..."
|
|
706
|
+
workspaceId="..."
|
|
707
|
+
dashboardId="..."
|
|
708
|
+
startDate="2026-04-25"
|
|
709
|
+
endDate="2026-05-25"
|
|
710
|
+
onInsight={(insight) => track('insight_received', { type: insight.insightType })}
|
|
711
|
+
onComplete={(result) => track('insights_complete', { count: result.insights.length })}
|
|
712
|
+
onError={(err) => Sentry.captureException(err)}
|
|
713
|
+
/>
|
|
714
|
+
```
|
|
715
|
+
|
|
716
|
+
---
|
|
717
|
+
|
|
567
718
|
### PaperBoard
|
|
568
719
|
|
|
569
720
|
#### Default streaming grid
|
|
@@ -649,9 +800,60 @@ Adds an opt-in tour button to the header (does not auto-start).
|
|
|
649
800
|
/>
|
|
650
801
|
```
|
|
651
802
|
|
|
803
|
+
#### With the Quick Insights tile
|
|
804
|
+
|
|
805
|
+
`showInsights` mounts the `PaperInsight` tile at the top of the grid and renders the dashboard-level `TimelineRange` scrubber between the header and the grid when the user picks `Custom range`. The insight tile and the scrubber share the same preset / range state internally.
|
|
806
|
+
|
|
807
|
+
```tsx
|
|
808
|
+
<PaperBoard
|
|
809
|
+
token="..."
|
|
810
|
+
workspaceId="..."
|
|
811
|
+
dashboardId="..."
|
|
812
|
+
variant="streaming"
|
|
813
|
+
showToolbar
|
|
814
|
+
showChatAssistant
|
|
815
|
+
showInsights
|
|
816
|
+
/>
|
|
817
|
+
```
|
|
818
|
+
|
|
819
|
+
Pass a controlled preset / range if the host owns the dashboard timeline:
|
|
820
|
+
|
|
821
|
+
```tsx
|
|
822
|
+
import {
|
|
823
|
+
PaperBoard,
|
|
824
|
+
computeInsightsPeriodRange,
|
|
825
|
+
type InsightsPeriodPreset,
|
|
826
|
+
type InsightsPeriodMenuPreset,
|
|
827
|
+
} from '@papermap/papermap'
|
|
828
|
+
|
|
829
|
+
function MyDashboard() {
|
|
830
|
+
const [preset, setPreset] = useState<InsightsPeriodPreset>('last_3_months')
|
|
831
|
+
const [range, setRange] = useState(() => computeInsightsPeriodRange('last_3_months'))
|
|
832
|
+
|
|
833
|
+
return (
|
|
834
|
+
<PaperBoard
|
|
835
|
+
token="..."
|
|
836
|
+
workspaceId="..."
|
|
837
|
+
dashboardId="..."
|
|
838
|
+
showInsights
|
|
839
|
+
insightsPeriodPreset={preset}
|
|
840
|
+
onInsightsPeriodPresetChange={(next) => {
|
|
841
|
+
setPreset(next)
|
|
842
|
+
if (next !== 'custom') {
|
|
843
|
+
setRange(computeInsightsPeriodRange(next as InsightsPeriodMenuPreset))
|
|
844
|
+
}
|
|
845
|
+
}}
|
|
846
|
+
insightsStartDate={range.start}
|
|
847
|
+
insightsEndDate={range.end}
|
|
848
|
+
onInsightExplore={(chatId) => router.push(`?conversation_id=${chatId}`)}
|
|
849
|
+
/>
|
|
850
|
+
)
|
|
851
|
+
}
|
|
852
|
+
```
|
|
853
|
+
|
|
652
854
|
---
|
|
653
855
|
|
|
654
|
-
## Advanced exports
|
|
856
|
+
<!-- ## Advanced exports
|
|
655
857
|
|
|
656
858
|
For custom layouts, the package also exports:
|
|
657
859
|
|
|
@@ -659,10 +861,15 @@ For custom layouts, the package also exports:
|
|
|
659
861
|
- **Store:** `usePapermapStore`, `usePapermapStoreApi`, `createPapermapStore`, `PapermapProvider`, `CHAT_MODAL_TAB`, and **`openPapermapChatAssistant(storeApi, options?)`** — opens/focuses the assistant and optionally primes edit mode from a chart (`editChartId`, `chart`, `suppressOpen` for embedded streaming UIs).
|
|
660
862
|
- **Hooks:** `useAnalyticsStream`, `useKeyboardShortcuts`, `useAutoResize`, `useAutoFade`, `useTour`, …
|
|
661
863
|
- **API:** `createApiClient`, `decodeToken`, `buildAuthHeaders`, `papermapQueryKeys`
|
|
864
|
+
- **Insights:**
|
|
865
|
+
- **Component:** `PaperInsight`, slot types (`PaperInsightSlot`, `PaperInsightClassNames`, `PaperInsightStyles`)
|
|
866
|
+
- **Service:** `streamDashboardInsights`, `normalizeInsightType`, `orderInsightsForDisplay`, `formatInsightDate`, `parseInsightMetricToTrend` — and types `DashboardInsight`, `DashboardInsightType`, `DashboardInsightsResult`, `StreamDashboardInsightsOptions`.
|
|
867
|
+
- **Period helpers:** `computeInsightsPeriodRange`, `formatInsightsDateLabel`, `INSIGHTS_PERIOD_LABELS`, `INSIGHTS_PERIOD_SELECT_OPTIONS`, types `InsightsPeriodPreset`, `InsightsPeriodMenuPreset`.
|
|
868
|
+
- **Grid layout:** `PAPER_INSIGHT_GRID_ID`, `ensurePaperInsightLayoutItem(layouts, gridId, defaults?)` — inject the insight slot into custom `PaperBoardLayouts`.
|
|
662
869
|
- **Types:** streaming (`TimelineEvent`, `ToolCall`, …), charts (`TChartResponse`, …), messages
|
|
663
870
|
- **Theming:** `themePresets`, `defaultTheme`, `ThemeCustomizationSettings`
|
|
664
871
|
- **Persistence:** chart card `id` ↔ backend chat id helpers (`getChartCardIdLink`, `resolveChartFetchChatId`, …)
|
|
665
|
-
- **Platform (hosts / extensions):** `PAPERMAP_SDK_VERSION`, `PAPERMAP_PLUGIN_CONTRACT_VERSION`, `checkPluginPeerCompatibility`, `createPluginContext`, `createPapermapObservability`, and related types
|
|
872
|
+
- **Platform (hosts / extensions):** `PAPERMAP_SDK_VERSION`, `PAPERMAP_PLUGIN_CONTRACT_VERSION`, `checkPluginPeerCompatibility`, `createPluginContext`, `createPapermapObservability`, and related types -->
|
|
666
873
|
|
|
667
874
|
All paths use the package entry: `@papermap/papermap`.
|
|
668
875
|
|