@commentkit/comment-kit 0.6.9 → 0.7.1

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 (73) hide show
  1. package/CHANGELOG.md +63 -4
  2. package/LICENSE +18 -2
  3. package/README.md +133 -88
  4. package/SECURITY.md +48 -0
  5. package/dist/THIRD_PARTY_NOTICES.txt +284 -0
  6. package/dist/angular.es.js +25 -12
  7. package/dist/comment-kit.es.js +25 -13
  8. package/dist/demo.es.js +148 -70
  9. package/dist/headless.es.js +3 -3
  10. package/dist/preact.es.js +3 -3
  11. package/dist/qwik.es.js +1 -110
  12. package/dist/qwik.qwik.mjs +114 -0
  13. package/dist/react.es.js +3 -3
  14. package/dist/shared/annotation-icons-Dh-bmNYK.js +172 -0
  15. package/dist/shared/annotation-toolbar-cGC1p-SP.js +1093 -0
  16. package/dist/shared/attachment-refresh-CzQFXHkL.js +94 -0
  17. package/dist/shared/{bridge-DRE03N9X.js → bridge-CJoGYngu.js} +6 -3
  18. package/dist/shared/{button-group-CHfMRXyA.js → button-group-CWdKaOlC.js} +14 -16
  19. package/dist/shared/capture-colors-CxSLsU5-.js +74 -0
  20. package/dist/shared/comment-drawing-canvas-DdXlMgbF.js +124 -0
  21. package/dist/shared/comment-icon-Dg9ZWpz-.js +608 -0
  22. package/dist/shared/comment-image-lightbox-B7iHjnAz.js +190 -0
  23. package/dist/shared/comment-images-content-D7YNUgo5.js +214 -0
  24. package/dist/shared/{comment-kit-core-D0kY00St.js → comment-kit-core-C862uNAm.js} +1371 -853
  25. package/dist/shared/comment-kit-ui-0vd-DY4S.js +19977 -0
  26. package/dist/shared/comment-screenshot-annotator-DcaSSuWB.js +151 -0
  27. package/dist/shared/comment-screenshot-overlay-D_nFoJmM.js +207 -0
  28. package/dist/shared/{dev-export-panel-BLngcr5q.js → dev-export-panel-pWBlhlse.js} +8 -8
  29. package/dist/shared/dev-grab-eQ9EgEGY.js +210 -0
  30. package/dist/shared/dist-De294MVF.js +623 -0
  31. package/dist/shared/{element-selector-CtFzgHvq.js → element-selector-DC-_XJ0k.js} +350 -305
  32. package/dist/shared/{icons-BSHCWYO1.js → icons-nzMOLzrm.js} +2 -3
  33. package/dist/shared/{mount-ui-CVivB_eQ.js → mount-ui-B68j8r6I.js} +4 -4
  34. package/dist/shared/{pusher-BEl7Qn-8.js → pusher-C1FHQGXV.js} +1 -1
  35. package/dist/shared/realtime-Diqz7G_y.js +317 -0
  36. package/dist/shared/realtime-recovery-DJ_adc-H.js +135 -0
  37. package/dist/shared/{separator-DusFNTs-.js → separator-XDBsaWyw.js} +891 -785
  38. package/dist/shared/{shadow-root-CmYXiSRR.js → shadow-root-CrO75sED.js} +1 -1
  39. package/dist/shared/styles-C9Jwvm0Q.js +2 -0
  40. package/dist/shared/useRender-D1z_X_BY.js +5 -0
  41. package/dist/shared/{useValueChanged-DQXLia-2.js → useValueChanged-CrzfD8l-.js} +15 -15
  42. package/dist/shared/{validation-C7QG8j7Z.js → validation-D-8u4M7I.js} +14 -1
  43. package/dist/shared/{websocket-manager-BTRqNTB7.js → websocket-manager-CFak_YHy.js} +148 -89
  44. package/dist/solid.es.js +3 -3
  45. package/dist/svelte.es.js +3 -3
  46. package/dist/types/adapters/bridge.d.ts +9 -12
  47. package/dist/types/angular/index.d.ts +15 -5
  48. package/dist/types/core/api-client.d.ts +24 -18
  49. package/dist/types/core/comment-kit-core.d.ts +28 -11
  50. package/dist/types/core/local-demo.d.ts +1 -0
  51. package/dist/types/core/types.d.ts +103 -0
  52. package/dist/types/core/websocket-manager.d.ts +12 -0
  53. package/dist/types/core/write-access.d.ts +9 -0
  54. package/dist/types/headless.d.ts +1 -1
  55. package/dist/types/index.d.ts +8 -4
  56. package/dist/types/qwik/index.d.ts +4 -1
  57. package/dist/vue.es.js +3 -3
  58. package/docs/api-reference.md +378 -0
  59. package/docs/local-demo.md +60 -0
  60. package/package.json +17 -6
  61. package/dist/shared/annotation-toolbar-pX17NLmJ.js +0 -1104
  62. package/dist/shared/clamp-CcFVX0vC.js +0 -55
  63. package/dist/shared/comment-drawing-canvas-CYu5SwRf.js +0 -126
  64. package/dist/shared/comment-image-lightbox-0VdAs2iT.js +0 -178
  65. package/dist/shared/comment-kit-ui-D2j2gvnm.js +0 -16685
  66. package/dist/shared/comment-screenshot-annotator-BuojwviY.js +0 -137
  67. package/dist/shared/comment-screenshot-overlay-BZX0Vcb8.js +0 -144
  68. package/dist/shared/dev-grab-pDAfH2lr.js +0 -203
  69. package/dist/shared/local-demo-context-BohlYbHt.js +0 -6
  70. package/dist/shared/realtime-BG_t_ze7.js +0 -281
  71. package/dist/shared/resolveAriaLabelledBy-CIKpnjNJ.js +0 -669
  72. package/dist/shared/styles-D_FEJZ9G.js +0 -2
  73. package/dist/shared/useLabelableId-DGbfdMi_.js +0 -155
@@ -0,0 +1,378 @@
1
+ # API Reference
2
+
3
+ Reference for the CommentKit engine and integration APIs. This file is included in the npm package alongside its public TypeScript declarations.
4
+
5
+ ---
6
+
7
+ ## Core Methods
8
+
9
+ The tables describe `CommentKitCore`. The vanilla `CommentKit` instance delegates the integration methods and exposes the engine through `getCore()`. React exposes `core` from `useCommentKit()`; other adapters expose their core through a ref, store, signal or observable and delegate their documented action methods. For a low-level engine method such as `blockEscape()`, use that core handle. Headless consumers import `CommentKitCore` from `@commentkit/comment-kit/headless`.
10
+
11
+ Many action methods return `Promise<void>` and report validation or backend failures through the `error` event and `getState().error`. A resolved promise can also mean an offline mutation was queued. Custom interfaces should observe the relevant comment/offline events and state before declaring a save successful; upload and capture helpers can also reject or return `null`.
12
+
13
+ Qwik uses `useCommentKit` from `@commentkit/comment-kit/qwik` inside `component$`; the hook handles client mounting with `useVisibleTask$`. Destructure its `core` signal and use `core.value?.method()` inside Qwik event handlers rather than capturing plain bridge callbacks across an `onClick$` boundary. The deprecated `useCommentKit$` alias remains available for compatibility. The built-in Qwik widget requires React and ReactDOM, like the other UI adapters.
14
+
15
+ ### Authentication
16
+
17
+ | Method | Returns | Description |
18
+ | ----------------------- | --------------- | ------------------------------------------------------------------ |
19
+ | `validateInvite(email)` | `Promise<void>` | Validate a member invite token + email, then auto-trigger OTP flow |
20
+ | `login(email)` | `Promise<void>` | Request OTP code sent to the given email |
21
+ | `verifyOtp(code)` | `Promise<void>` | Verify the OTP code and authenticate |
22
+ | `cancelOtp()` | `void` | Cancel the OTP flow and return to email entry |
23
+ | `resendOtp()` | `Promise<void>` | Resend OTP to the same email |
24
+ | `logout()` | `void` | Clear authentication and disconnect real-time |
25
+
26
+ ### UI Controls
27
+
28
+ | Method | Returns | Description |
29
+ | -------------------------- | ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------ |
30
+ | `toggleOverlay()` | `void` | Show or hide the comment overlay |
31
+ | `toggleSidebar()` | `void` | Show or hide the comment sidebar |
32
+ | `toggleLoginModal()` | `void` | Show or hide the login modal |
33
+ | `setTool(tool)` | `void` | Set the active tool. Pass `"comment"`, `"select"`, `"draw"`, `"highlight"`, `"screenshot"`, or `null` to deactivate |
34
+ | `toggleShortcutsOverlay()` | `void` | Show or hide the keyboard shortcuts overlay |
35
+ | `setPanelView(view)` | `void` | Set the sidebar panel view: `"list"`, `"detail"`, `"settings"`, `"activity"`, or `"dev-export"` (localhost only) |
36
+ | `blockEscape()` | `() => void` | Block the core's Escape chain while an overlay UI is open. Returns a release function. Used by built-in overlays (context menu); also available to custom UI |
37
+
38
+ ### Comments
39
+
40
+ | Method | Returns | Description |
41
+ | ------------------------------------------------------------------------------------------- | --------------- | ------------------------------------------------------------------------------------------------------------------------------- |
42
+ | `createComment(type, content, position, priority?, textSelection?, drawingData?, options?)` | `Promise<void>` | Create a new comment with optimistic UI update. `type` is `"pin"`, `"highlight"`, or `"drawing"` |
43
+ | `createHighlight(textSelection, content)` | `Promise<void>` | Convenience wrapper around `createComment("highlight", …)` |
44
+ | `createDrawing(drawingData, position, content)` | `Promise<void>` | Convenience wrapper around `createComment("drawing", …)` |
45
+ | `updateComment(commentId, updates)` | `Promise<void>` | Update fields on an existing comment (content, status, priority, description, assignees, checklist, drawingData, textSelection) |
46
+ | `deleteComment(id)` | `Promise<void>` | Delete a comment (optimistic, rolls back on failure) |
47
+ | `resolveComment(id)` | `Promise<void>` | Mark a comment as resolved |
48
+ | `unresolveComment(id)` | `Promise<void>` | Reopen a resolved comment |
49
+ | `completeComment(id)` | `Promise<void>` | Mark a comment as complete |
50
+ | `selectComment(comment)` | `void` | Select a comment (pass `null` to deselect) |
51
+ | `addReply(commentId, content, options?)` | `Promise<void>` | Add a reply, optional draft attachment IDs, mentions and a quote target; a reply reopens a closed thread |
52
+ | `updateReply(commentId, replyId, content, options?)` | `Promise<void>` | Update reply content and optional attachment/mention metadata |
53
+ | `deleteReply(commentId, replyId)` | `Promise<void>` | Delete a reply |
54
+ | `reactToComment(commentId, emoji, replyId?)` | `Promise<void>` | Toggle a parent reaction, or a specific reply reaction when `replyId` is supplied |
55
+ | `updateCommentPosition(commentId, x, y)` | `Promise<void>` | Move a comment pin to new coordinates |
56
+ | `loadMoreComments()` | `Promise<void>` | Load the next page of comments (pagination) |
57
+
58
+ ### Project context, branches and retrieval
59
+
60
+ | Method | Returns | Description |
61
+ | ------------------------ | --------------- | ----------------------------------------------------------------------------------------------------------------------------- |
62
+ | `reloadComments()` | `Promise<void>` | Replace loaded comments with the first page for the active project/branch. |
63
+ | `setBranch(branch)` | `Promise<void>` | Select a nonempty branch name or `null` for all branches; clear the current selection/list and load that branch’s first page. |
64
+ | `reloadProjectContext()` | `Promise<void>` | Refresh authenticated project, organization, member, usage, branch and permission context. |
65
+
66
+ Read `getState().projectContext`, `getState().activeBranch`, `getState().comments` and `getState().pagination` for the results. Context is null until an authenticated response is available. A missing context route on an older API is tolerated; it does not enable new server features. `loadMoreComments()` appends another page and becomes a no-op when there are no more pages.
67
+
68
+ Set `config.branch` to the branch actually deployed on the host, such as `main`. This controls the branch recorded on new pins, highlights, drawings and screenshots, including offline replay. `setBranch()` changes the viewing filter; selecting another branch or **All branches** does not relabel feedback created on a configured deployment. A caller can explicitly override the branch of `createComment` through `CommentCreateOptions.branch`. For older integrations without `config.branch`, creation retains the selected branch as its fallback.
69
+
70
+ The API fetches across project pages. The built-in **Page** tab filters loaded records to the current path; **All** includes other pages. A `#comment-ID` link retrieves its authorized target even beyond the first loaded page. The engine resolves this internally after authentication; do not call a private loader. Cross-page links retain the comment’s original page URL, and markers only target the current page’s DOM.
71
+
72
+ Panel text search and its local filters apply to the comments already loaded. When more pages exist, the panel explains this scope and keeps **Load more comments** available even if the current search has no matches. They are not server-wide search endpoints.
73
+
74
+ `projectContext.permissions.canWriteComments` and `writeRestriction` describe the current backend write capability. An expired paid plan keeps authenticated viewing and export, while creation, replies, edits, deletion, reactions, status changes, pin moves and uploads are disabled. A project-level disabled-comments setting is shown separately from a missing paid plan. The backend enforces these rules; hiding UI controls is not authorization. Storage or individual tool limits do not disable ordinary text feedback. The public browser-local demo is a separate sandbox and does not grant access to production projects.
75
+
76
+ ```ts
77
+ // With an authenticated core from your integration:
78
+ await core.setBranch("preview");
79
+ await core.loadMoreComments();
80
+ await core.reloadProjectContext();
81
+ const { projectContext, activeBranch, pagination } = core.getState();
82
+
83
+ await core.setBranch(null); // All branches, including older untagged comments.
84
+ ```
85
+
86
+ ### Composer payloads and message identity
87
+
88
+ `CommentCreateOptions` carries `description`, `assignees`, `checklist`, `mentions`, `files`, preuploaded `attachmentIds`, `branch` and `deviceInfo`. It is the final argument of `createComment`. `ReplyOptions` carries `attachmentIds`, `mentions` and `replyTo`. These APIs require the matching backend deployment and migrations described in the [installation guide](../README.md#backend-upgrade-order).
89
+
90
+ ```ts
91
+ const attachmentIds = await core.uploadFiles([file]);
92
+ await core.addReply(threadId, "Here is the revised layout", {
93
+ attachmentIds,
94
+ replyTo: { type: "comment", id: threadId },
95
+ });
96
+
97
+ // Parent and reply IDs belong to separate namespaces.
98
+ await core.reactToComment(threadId, "👍", replyId);
99
+ ```
100
+
101
+ A quote target is `{ type: "comment" | "reply", id: string }`. The backend validates that it belongs to the thread and returns the saved author/body snapshot; callers do not supply trusted author text. Temporary optimistic IDs are not valid persisted quote or reaction targets. Preserve successful upload IDs if your custom interface retries a failed save; the built-in composer does this automatically.
102
+
103
+ Comments expose canonical `createdAt`/`updatedAt` and optional `resolvedAt`/`completedAt` timestamps. Real workflow transitions set lifecycle dates, repeated transitions preserve them, and reopening or replying clears them. Legacy records can omit historical lifecycle dates. Format dates only for display; keep their canonical values for equality and ordering.
104
+
105
+ ### Drawing / Screenshot / Files
106
+
107
+ | Method | Returns | Description |
108
+ | ------------------------------------------------- | ----------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- |
109
+ | `captureScreenshot(element?)` | `Promise<ScreenshotResult \| null>` | Capture a screenshot of the page or a specific element |
110
+ | `uploadScreenshot(screenshot, content, position)` | `Promise<Comment \| null>` | Upload a screenshot and create a comment |
111
+ | `setActiveScreenshot(screenshot)` | `void` | Set the currently-active screenshot (drives the screenshot composer UI) |
112
+ | `setActiveDrawing(drawing)` | `void` | Set the currently-active drawing (drives the drawing composer UI) |
113
+ | `sendDrawingStroke(path)` | `void` | Broadcast a drawing stroke to other connected users via the realtime channel |
114
+ | `uploadFiles(files, options?)` | `Promise<string[]>` | Upload supported attachment files and return IDs. Omit options for drafts, or use `{ commentId?, replyId? }` to attach directly to an authorized record |
115
+
116
+ ### Agent Handoff
117
+
118
+ Pass stakeholder feedback or grabbed elements to your coding agent — Claude Desktop, Cursor, Codex, Continue, Zed AI, or any clipboard-aware tool.
119
+
120
+ | Method | Returns | Description |
121
+ | ----------------------------------- | -------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
122
+ | `getAgentContext(options?)` | `AgentContextExport` | Build a comments-only export (sync). Uses selector + XPath only |
123
+ | `getAgentContextAsync(options?)` | `Promise<AgentContextExport>` | Same as above but also resolves each comment's element to a source-file location when the optional source-resolver peer dep is installed |
124
+ | `formatAgentContext(options?)` | `string` | Build the sync export, then render it as Markdown |
125
+ | `formatAgentContextAsync(options?)` | `Promise<string>` | Build the async (source-enriched) export, then render it as Markdown |
126
+ | `copyAgentContext(options?)` | `Promise<string>` | Build the async export, format it as Markdown, and copy it to the clipboard. Emits `agent:context-copied` |
127
+ | `grabElement(element, options?)` | `Promise<DevGrabResult \| null>` | Capture an element: screenshot + source-resolved location + HTML + selector/XPath. Writes Markdown + `image/png` to the clipboard. Emits `agent:element-grabbed` |
128
+ | `grabElements(elements, options?)` | `Promise<DevGrabBundle \| null>` | Same as `grabElement` for an array. Inlines each screenshot as a Markdown data URL. Emits `agent:elements-grabbed` |
129
+
130
+ `AgentContextOptions`:
131
+
132
+ | Field | Type | Default | Description |
133
+ | ----------------- | ---------- | ----------- | ------------------------------------------------------------------------- |
134
+ | `includeResolved` | `boolean` | `false` | Include resolved + completed comments in the export |
135
+ | `currentPageOnly` | `boolean` | `false` | Include only comments anchored to the current page |
136
+ | `includeHtml` | `boolean` | `false` | Include a clipped `outerHTML` preview for each comment's resolved element |
137
+ | `commentIds` | `string[]` | `undefined` | Restrict the export to specific comment ids |
138
+ | `maxComments` | `number` | `200` | Hard cap on number of comments exported (max `500`) |
139
+ | `instructions` | `string` | (built-in) | Replace the leading instructions block sent to the agent |
140
+
141
+ ### Utility
142
+
143
+ | Method | Returns | Description |
144
+ | --------------------------- | ---------------------------- | --------------------------------------------------------------------------------------- |
145
+ | `getState()` | `CommentKitState` | Get the current state snapshot (deep-cloned — safe to mutate) |
146
+ | `getFeatures()` | `object` | Get resolved feature flags |
147
+ | `getConfig()` | `Readonly<CommentKitConfig>` | Get a public configuration copy; internal project and realtime credentials are excluded |
148
+ | `getProjectMembers()` | `Promise<User[]>` | Fetch team members for @mention autocomplete |
149
+ | `getOnlineUsers()` | `User[]` | Get currently connected users |
150
+ | `getUnreadActivityCount()` | `number` | Get unread activity feed count |
151
+ | `getPendingMutationCount()` | `number` | Get queued offline mutations count |
152
+ | `markThreadSeen(threadId)` | `void` | Mark a thread as seen |
153
+ | `isThreadNew(threadId)` | `boolean` | Check if a thread is unseen |
154
+ | `markAllActivitiesRead()` | `void` | Mark all activities as read |
155
+ | `destroy()` | `void` | Clean up all listeners, timers, and WebSocket connections |
156
+
157
+ ---
158
+
159
+ ## Events
160
+
161
+ Listen to SDK events for custom integrations.
162
+
163
+ ```typescript
164
+ // Subscribe
165
+ const unsub = ck.on("comment:created", (comment) => {
166
+ console.log("New comment:", comment);
167
+ });
168
+
169
+ // Unsubscribe
170
+ unsub();
171
+ // or: ck.off("comment:created", handler);
172
+ ```
173
+
174
+ ### Comment Events
175
+
176
+ | Event | Payload | When |
177
+ | ------------------- | ------------------------------- | -------------------------------- |
178
+ | `comment:created` | `Comment` | A new comment was created |
179
+ | `comment:updated` | `Comment` | A comment was modified |
180
+ | `comment:deleted` | `{ id: string }` | A comment was deleted |
181
+ | `comment:resolved` | `Comment` | A comment was marked as resolved |
182
+ | `comment:completed` | `Comment` | A comment was marked as complete |
183
+ | `comment:reaction` | `{ commentId, emoji, comment }` | A reaction was toggled |
184
+ | `comment:position` | `{ commentId, position }` | A comment was repositioned |
185
+
186
+ ### Auth Events
187
+
188
+ | Event | Payload | When |
189
+ | -------------------- | ----------------------- | ------------------------------- |
190
+ | `auth:login` | `User` | User authenticated successfully |
191
+ | `auth:logout` | `void` | User logged out |
192
+ | `auth:otp-requested` | `{ email, expiresIn? }` | OTP was sent to email |
193
+ | `auth:otp-verified` | `User` | OTP was verified successfully |
194
+
195
+ ### UI Events
196
+
197
+ | Event | Payload | When |
198
+ | ------------------- | ----------------- | ----------------------------- |
199
+ | `tool:changed` | `ToolType` | Active tool changed |
200
+ | `overlay:toggled` | `boolean` | Overlay visibility changed |
201
+ | `sidebar:toggled` | `boolean` | Sidebar visibility changed |
202
+ | `shortcuts:toggled` | `boolean` | Shortcuts overlay toggled |
203
+ | `state:changed` | `CommentKitState` | Any state changed (catch-all) |
204
+
205
+ ### Agent Events
206
+
207
+ | Event | Payload | When |
208
+ | ------------------------ | ----------------------------------------------------------- | ------------------------------------------------------- |
209
+ | `agent:context-copied` | `{ commentCount: number; sourceResolved?: boolean }` | Stakeholder-comment context was copied to the clipboard |
210
+ | `agent:element-grabbed` | `{ source: string \| null; componentName: string \| null }` | A single element was grabbed for the agent |
211
+ | `agent:elements-grabbed` | `{ count: number }` | A multi-element bundle was grabbed for the agent |
212
+
213
+ ### SDK Events
214
+
215
+ | Event | Payload | When |
216
+ | -------------- | ------------------------------------- | ---------------------------------------------------- |
217
+ | `sdk:outdated` | `{ current: string; latest: string }` | The backend reports a newer SDK version is available |
218
+ | `error` | `ApiError` | An error was produced anywhere in the SDK |
219
+
220
+ ### Real-Time Events
221
+
222
+ | Event | Payload | When |
223
+ | -------------------- | ------------------- | ---------------------------------- |
224
+ | `cursor:move` | `CursorPosition` | Another user moved their cursor |
225
+ | `cursor:leave` | `{ userId }` | A user's cursor left the page |
226
+ | `user:joined` | `User` | A user came online |
227
+ | `user:left` | `{ userId }` | A user went offline |
228
+ | `presence:update` | `{ users: User[] }` | Online users list changed |
229
+ | `connection:changed` | `ConnectionStatus` | WebSocket connection state changed |
230
+ | `drawing:stroke` | `{ userId, path }` | Another user drew a stroke |
231
+
232
+ ### Offline Events
233
+
234
+ | Event | Payload | When |
235
+ | ------------------- | ----------------- | ------------------------------------------------------------------------------------------ |
236
+ | `offline:queued` | `QueuedMutation` | A mutation was queued for retry |
237
+ | `offline:retrying` | `{ id, attempt }` | A queued mutation is being retried |
238
+ | `offline:completed` | `{ id }` | A queued mutation succeeded |
239
+ | `offline:failed` | `{ id, error }` | A queued mutation was rejected, lost its authorized owner/dependency, or exhausted retries |
240
+
241
+ ---
242
+
243
+ ## Selective Subscriptions
244
+
245
+ For performance-sensitive integrations, subscribe to specific state slices instead of the catch-all `state:changed` event.
246
+
247
+ ### Slice Subscriptions
248
+
249
+ ```typescript
250
+ // Only fires when auth-related state changes
251
+ const unsub = ck.onSlice("auth", (state) => {
252
+ console.log("Auth changed:", state.isAuthenticated);
253
+ });
254
+ ```
255
+
256
+ Available slices:
257
+
258
+ | Slice | Keys |
259
+ | ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
260
+ | `auth` | `isAuthenticated`, `currentUser`, `project`, `projectContext`, `isLoginModalVisible`, `otpStep`, `otpEmail` |
261
+ | `ui` | `isOverlayVisible`, `isSidebarVisible`, `isShortcutsOverlayVisible`, `activeTool`, `isCommentModeActive`, `isDrawingModeActive`, `isHighlightModeActive`, `isScreenshotModeActive`, `selectedComment`, `activeComment`, `activeDrawing`, `activeScreenshot`, `panelView`, `activities`, `isLoading`, `error` |
262
+ | `comments` | `comments`, `pagination`, `seenThreadIds`, `activeBranch` |
263
+ | `realtime` | `onlineUsers`, `connectionStatus`, `pendingMutations`, `isOnline` |
264
+
265
+ ### Selector Subscriptions
266
+
267
+ ```typescript
268
+ // Only fires when the selected value changes
269
+ const unsub = ck.select(
270
+ (state) => state.comments.length,
271
+ (count) => console.log(`Now have ${count} comments`),
272
+ );
273
+ ```
274
+
275
+ ---
276
+
277
+ ## TypeScript Types
278
+
279
+ Import shared protocol types from the headless entry. Framework entries also export selected integration types; their generated declarations are the source of truth:
280
+
281
+ ```typescript
282
+ import type {
283
+ // Core models
284
+ Comment,
285
+ CommentReaction,
286
+ Reply,
287
+ ReplyOptions,
288
+ ReplyTarget,
289
+ CommentCreateOptions,
290
+ CommentDeviceInfo,
291
+ ProjectContext,
292
+ User,
293
+ Position,
294
+ Attachment,
295
+ TextSelection,
296
+ DrawingData,
297
+ DrawingPath,
298
+ ScreenshotResult,
299
+ ScreenshotProvider,
300
+ ActivityItem,
301
+ Mention,
302
+ Organization,
303
+ OrganizationMember,
304
+ Project,
305
+
306
+ // Config + state
307
+ CommentKitConfig,
308
+ CommentKitState,
309
+ CommentKitEvents,
310
+ StateSlice,
311
+ PanelView,
312
+ ToolType,
313
+ CommentMode,
314
+ ConnectionStatus,
315
+ PaginationInfo,
316
+ CursorPosition,
317
+ DeviceInfo,
318
+ TaskStatus,
319
+ TaskChecklistItem,
320
+
321
+ // Auth
322
+ AuthResponse,
323
+ OtpStep,
324
+ OtpResponse,
325
+ OtpVerifyResponse,
326
+ InviteValidationResponse,
327
+
328
+ // Agent handoff
329
+ AgentContextOptions,
330
+ AgentContextExport,
331
+ AgentCommentContext,
332
+ AgentElementContext,
333
+
334
+ // Dev grab
335
+ DevGrabOptions,
336
+ DevGrabAttachment,
337
+
338
+ // Errors + events
339
+ ApiError,
340
+ EventListener,
341
+ Unsubscribe,
342
+
343
+ // Filters
344
+ CommentFilter,
345
+ StatusFilter,
346
+ PriorityFilter,
347
+ AssigneeFilter,
348
+ PageFilter,
349
+ UserFilter,
350
+ SortOrder,
351
+ } from "@commentkit/comment-kit/headless";
352
+ ```
353
+
354
+ ### Key Types
355
+
356
+ **`Comment`** — A comment thread with author, position, replies, reactions, attachments, and task metadata.
357
+
358
+ **`ProjectContext`** — Authenticated project/organization identity, members and roles, storage usage (`limit: null` for unlimited), branch names and `canManageComments`/`canInvite` capabilities.
359
+
360
+ **`ReplyOptions`** — Optional attachment IDs, mentions and a typed quote target for reply creation/editing.
361
+
362
+ **`User`** — A user with id, name, email, optional avatar, and optional organizationId.
363
+
364
+ **`CommentKitConfig`** — Configuration object passed to the SDK constructor. Includes `apiKey`, optional `baseUrl`, `branch`, `enabled`, `screenshotProvider`, `ui` (theme, position, activation) and realtime options.
365
+
366
+ **`CommentKitState`** — The full state tree. Includes auth, `projectContext`, `activeBranch`, UI, comments, realtime, offline queue, pagination and activities.
367
+
368
+ **`CommentKitEvents`** — Maps event names to their payload types for type-safe `on()`/`off()` calls.
369
+
370
+ **`ApiError`** — Structured error with `error` code, `message`, and HTTP `code`, plus an optional `details` object.
371
+
372
+ **`AgentContextExport`** — The bundle returned by `getAgentContext` / `getAgentContextAsync`. Versioned, includes per-comment element + source frames + replies plus a `sourceResolved` flag.
373
+
374
+ **`DevGrabResult`** — Result of `grabElement`. Element context, HTML, optional screenshot data URL, and the Markdown payload that hit the clipboard.
375
+
376
+ **`DevGrabBundle`** — Result of `grabElements`. An array of `DevGrabResult` plus one bundled Markdown payload.
377
+
378
+ See the installed [public protocol declarations](../dist/types/core/types.d.ts) for complete details. Result types that are not named exports can be inferred with `Awaited<ReturnType<CommentKitCore["grabElement"]>>` and the corresponding method name.
@@ -0,0 +1,60 @@
1
+ # Private browser demo
2
+
3
+ `createCommentKitDemo` mounts the real CommentKit core and Shadow DOM UI with a
4
+ browser-local store. It is an explicit sandbox, separate from project API keys,
5
+ OTP sessions, backend data and the offline mutation queue.
6
+
7
+ ```ts
8
+ const { createCommentKitDemo } = await import("@commentkit/comment-kit/demo");
9
+ const demo = await createCommentKitDemo({
10
+ storageKey: "website:v1", // Stored as commentkit:demo:website:v1
11
+ ui: { theme: "auto" },
12
+ });
13
+
14
+ const unsubscribe = demo.onSessionChange((session) => {
15
+ console.log(session.expiresAt, session.persistence, session.commentCount);
16
+ });
17
+
18
+ // Call from a visitor's explicit action.
19
+ await demo.getCore().copyAgentContext({ currentPageOnly: true });
20
+
21
+ // Clear only this demo and create a fresh 24-hour window.
22
+ demo.reset();
23
+
24
+ // Reopen pin mode after dismissing it.
25
+ demo.start();
26
+
27
+ // On navigation/unmount: retained demo data can be resumed before expiry.
28
+ unsubscribe();
29
+ demo.destroy();
30
+ ```
31
+
32
+ The factory is asynchronous and rejects when a widget is already mounted. Call
33
+ it on demand, and destroy any instance that finishes loading after its host
34
+ component unmounts. The ordinary SDK constructor and framework adapters keep
35
+ their normal production behavior.
36
+
37
+ ## Behavior
38
+
39
+ - Pins and element comments, replies, edits, deletions, resolution, reactions and
40
+ clipboard context use the normal core/UI paths with a local data client.
41
+ - The identity is explicitly local “You”; no account is created and no email is
42
+ sent. The internal `you@demo.invalid` identifier is never an address to contact.
43
+ - The expiration deadline is fixed at creation or Reset. Reads and edits do not
44
+ extend it. Expired data is rejected and cleared on access, visibility/focus,
45
+ writes and a timer while the page is open. Closed browsers cannot execute a
46
+ scheduled deletion; reopening checks expiration before hydration into the UI.
47
+ - Storage is scoped under `commentkit:demo:` and capped at 50 comments, 20 replies
48
+ per comment and 512,000 serialized characters. Stored records are validated
49
+ and reconstructed before use; external avatars, files and drawing data cannot
50
+ hydrate into the demo.
51
+ - If browser storage is unavailable, the sandbox uses memory for the current
52
+ page lifetime. Surface `persistence` so the visitor can see this limitation.
53
+ - File uploads, screenshot capture, drawing, highlighting, OTP, realtime and
54
+ network requests are unavailable. The demo does not prove cross-device
55
+ collaboration or live-to-localhost synchronization; explain those separately.
56
+ - `reset()` starts fresh; `destroy()` releases listeners, timers and UI without
57
+ deleting a still-valid demo. Production sessions and queues are untouched.
58
+
59
+ Suggested disclosure: “Private to this browser. Available for up to 24 hours.
60
+ Reset anytime.” If `persistence === "memory"`, explain that refresh clears it.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@commentkit/comment-kit",
3
- "version": "0.6.9",
3
+ "version": "0.7.1",
4
4
  "description": "Figma-style collaborative commenting, drawing, and feedback tools for any website. Works with React, Vue, Svelte, Angular, and Vanilla JS.",
5
5
  "keywords": [
6
6
  "angular",
@@ -26,7 +26,10 @@
26
26
  "package.json",
27
27
  "README.md",
28
28
  "CHANGELOG.md",
29
- "LICENSE"
29
+ "LICENSE",
30
+ "SECURITY.md",
31
+ "docs/api-reference.md",
32
+ "docs/local-demo.md"
30
33
  ],
31
34
  "type": "module",
32
35
  "sideEffects": [
@@ -82,10 +85,14 @@
82
85
  "import": "./dist/demo.es.js"
83
86
  }
84
87
  },
88
+ "publishConfig": {
89
+ "access": "public",
90
+ "registry": "https://registry.npmjs.org/"
91
+ },
85
92
  "scripts": {
86
93
  "dev": "vp dev",
87
94
  "build": "vp run build:clean && vp run build:bundles && vp run build:types && vp run build:strip && vp run build:verify && vp run build:size",
88
- "build:strip": "find dist -name '*.js' -exec perl -i -ne 'print unless m{^\\s*//#(region|endregion)\\b}' {} +",
95
+ "build:strip": "find dist \\( -name '*.js' -o -name '*.mjs' \\) -exec perl -i -ne 'print unless m{^\\s*//#(region|endregion)\\b}' {} +",
89
96
  "build:verify": "node tools/verify-dist.mjs",
90
97
  "build:clean": "rm -rf dist",
91
98
  "build:types": "tsc -p tsconfig.types.json && node tools/prune-declarations.mjs",
@@ -100,6 +107,7 @@
100
107
  "analyze": "ANALYZE=true BUILD_TARGET=all vp build",
101
108
  "preview": "vp preview",
102
109
  "test": "vp test run",
110
+ "test:coverage": "vp test run --coverage",
103
111
  "test:watch": "vp test watch",
104
112
  "test:ui": "vp test --ui",
105
113
  "test:e2e": "playwright test",
@@ -116,7 +124,7 @@
116
124
  "fmt": "vp fmt --write",
117
125
  "typecheck": "tsc --noEmit --noUnusedLocals false --noUnusedParameters false",
118
126
  "typecheck:test": "tsc --noEmit -p tsconfig.test.json",
119
- "prepublishOnly": "vp check && vp run build && vp test run",
127
+ "prepublishOnly": "npm run release:package",
120
128
  "publish:beta": "npm publish --tag beta",
121
129
  "publish:latest": "npm publish --tag latest",
122
130
  "version:patch": "npm version patch",
@@ -124,7 +132,9 @@
124
132
  "version:major": "npm version major",
125
133
  "build:bundles": "BUILD_TARGET=all vp build",
126
134
  "build:size": "node tools/check-size.mjs",
127
- "test:consumers": "node tools/smoke-consumers.mjs --next"
135
+ "test:consumers": "node tools/smoke-consumers.mjs --next",
136
+ "release:check": "npm run release:package && npm run test:e2e",
137
+ "release:package": "npm run check && npm run typecheck:test && npm run lint:md && npm run build && npm run test:coverage && npm run test:consumers && npm audit --audit-level=high"
128
138
  },
129
139
  "devDependencies": {
130
140
  "@angular/common": "^22.2.3",
@@ -219,5 +229,6 @@
219
229
  "engines": {
220
230
  "node": ">=18"
221
231
  },
222
- "packageManager": "npm@11.12.1"
232
+ "packageManager": "npm@11.12.1",
233
+ "qwik": "./dist/qwik.qwik.mjs"
223
234
  }