@vite-hub/ui 0.1.0 → 0.4.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.
- package/README.md +247 -21
- package/dist/attachments-BzTwqRTU.js +90 -0
- package/dist/{avatar-stack-DXmCQhxd.d.ts → avatar-stack-DPRFuezh.d.ts} +1 -1
- package/dist/choices-input-ByXJvDn1.d.ts +94 -0
- package/dist/{code-view-J4OsgEdh.js → code-view-DsU-xzic.js} +20 -4
- package/dist/colors-BghReA9C-CjF9gnmy.js +28 -0
- package/dist/comment-attachments-C4yNbcx5.js +20 -0
- package/dist/comment-composer-fINL5bxo.d.ts +243 -0
- package/dist/comment-composer-jYv2ULNP.js +591 -0
- package/dist/comment-layer-C_sbPIR5.d.ts +176 -0
- package/dist/comment-list-BcSaLngS.d.ts +62 -0
- package/dist/comment-marks.css +234 -0
- package/dist/comment-panel-CfvdRUMX.d.ts +208 -0
- package/dist/comment-person-CLPlW_SS.js +40 -0
- package/dist/comment-pin-DHOdRvUw.d.ts +68 -0
- package/dist/comment-row-Bn3nr8l5.js +39 -0
- package/dist/comment-selection-bar-CyVBNYl9.d.ts +42 -0
- package/dist/comment-thread-DKJjmWN0.d.ts +385 -0
- package/dist/comment-visibility-DsVuVndP.d.ts +40 -0
- package/dist/{comments-C08J3z4e.js → comments-D0d26ghV.js} +210 -59
- package/dist/comments-D8hulVPy.d.ts +198 -0
- package/dist/comments-context-C2lOZyQ5.js +38 -0
- package/dist/config-DgxBW013.d.ts +80 -0
- package/dist/config-Dk67emQt.js +63 -0
- package/dist/copy-button-CRN3kmSD.js +253 -0
- package/dist/draw-DzSmD7uo-Dwz8zoH2.js +72976 -0
- package/dist/editor-C_wt4RRV.js +582 -0
- package/dist/error-diagnostics-SXtnk6bz.js +38 -0
- package/dist/{file-tree-C1pv4_AI.js → file-tree-C4OYgbV-.js} +292 -145
- package/dist/{file-tree-Ctb8hZ_g.d.ts → file-tree-DlT9RGhu.d.ts} +51 -15
- package/dist/format-orwcdZL_.js +39 -0
- package/dist/handlers-DMl-Na3x.js +182 -0
- package/dist/headless.d.ts +5 -176
- package/dist/headless.js +5 -3
- package/dist/icon-swap.css +69 -0
- package/dist/{image-preview-VfknBEFu.js → image-preview-C9tdkmEj.js} +8 -5
- package/dist/{index-DcH0QSI5.d.ts → index-BYRFQfCd.d.ts} +14 -0
- package/dist/{code-view-vDM-hph-.d.ts → index-CNY1uNTh.d.ts} +14 -228
- package/dist/index.d.ts +55 -57
- package/dist/index.js +678 -25
- package/dist/markdown-editor-CMbNZOdN.js +2394 -0
- package/dist/markdown-editor-wQF0yD5o.d.ts +195 -0
- package/dist/markdown-editor.d.ts +108 -0
- package/dist/markdown-editor.js +3 -0
- package/dist/message-scroller-jrYN9dG9.d.ts +175 -0
- package/dist/nuxt-ui-DSQFzq3s.js +38 -0
- package/dist/nuxt.d.ts +84 -2
- package/dist/nuxt.js +243 -35
- package/dist/parts/components/agent-session.d.ts +254 -0
- package/dist/parts/components/agent-session.js +640 -0
- package/dist/{attachment-BBndG9_P.d.ts → parts/components/attachment.d.ts} +14 -15
- package/dist/{attachment-B3dXC7jM.js → parts/components/attachment.js} +6 -4
- package/dist/{avatar-stack.d.ts → parts/components/avatar-stack.d.ts} +1 -1
- package/dist/{avatar-stack-DM6HRnc0.js → parts/components/avatar-stack.js} +2 -5
- package/dist/{bubble-BJH2rfii.d.ts → parts/components/bubble.d.ts} +7 -8
- package/dist/{bubble-BPyFQlW7.js → parts/components/bubble.js} +2 -2
- package/dist/{chat-message-mpDmZbIC.d.ts → parts/components/chat-message.d.ts} +2 -3
- package/dist/{chat-message-BNK9G7xF.js → parts/components/chat-message.js} +4 -4
- package/dist/{chat-session-D6C7VJBR.d.ts → parts/components/chat-session.d.ts} +3 -4
- package/dist/{chat-session-DYEHB1HC.js → parts/components/chat-session.js} +2 -2
- package/dist/{chat-B9HlZWA2.d.ts → parts/components/chat.d.ts} +8 -4
- package/dist/{chat-BoFHlu9V.js → parts/components/chat.js} +42 -9
- package/dist/{highlighted-code-Dzf6o54i.d.ts → parts/components/code-block.d.ts} +15 -23
- package/dist/{code-block-Br-02hn-.js → parts/components/code-block.js} +9 -38
- package/dist/parts/components/code-view.d.ts +270 -0
- package/dist/parts/components/code-view.js +2 -0
- package/dist/parts/components/comment-composer.d.ts +2 -0
- package/dist/parts/components/comment-composer.js +2 -0
- package/dist/parts/components/comment-layer.d.ts +2 -0
- package/dist/parts/components/comment-layer.js +631 -0
- package/dist/parts/components/comment-list.d.ts +2 -0
- package/dist/parts/components/comment-list.js +168 -0
- package/dist/parts/components/comment-panel.d.ts +2 -0
- package/dist/parts/components/comment-panel.js +311 -0
- package/dist/parts/components/comment-pin.d.ts +2 -0
- package/dist/parts/components/comment-pin.js +75 -0
- package/dist/parts/components/comment-selection-bar.d.ts +2 -0
- package/dist/parts/components/comment-selection-bar.js +116 -0
- package/dist/parts/components/comment-thread.d.ts +2 -0
- package/dist/parts/components/comment-thread.js +598 -0
- package/dist/parts/components/comments.d.ts +8 -0
- package/dist/parts/components/comments.js +9 -0
- package/dist/{connection-status-DjGBw6xX.d.ts → parts/components/connection-status.d.ts} +6 -7
- package/dist/{connection-status-CzuWBENf.js → parts/components/connection-status.js} +1 -1
- package/dist/parts/components/copy-button.d.ts +118 -0
- package/dist/parts/components/copy-button.js +2 -0
- package/dist/parts/components/device-frame.d.ts +130 -0
- package/dist/parts/components/device-frame.js +471 -0
- package/dist/parts/components/file-tree.d.ts +2 -0
- package/dist/parts/components/file-tree.js +2 -0
- package/dist/parts/components/filter-search.d.ts +47 -0
- package/dist/parts/components/filter-search.js +58 -0
- package/dist/parts/components/markdown-editor.d.ts +2 -0
- package/dist/parts/components/markdown-editor.js +2 -0
- package/dist/parts/components/markdown-renderer.d.ts +52 -0
- package/dist/parts/components/markdown-renderer.js +23077 -0
- package/dist/{markdown-Dse5ldJe.d.ts → parts/components/markdown.d.ts} +7 -7
- package/dist/parts/components/markdown.js +47 -0
- package/dist/{marker-ea-tvx-J.d.ts → parts/components/marker.d.ts} +6 -7
- package/dist/{marker-Di2ZG_k1.js → parts/components/marker.js} +2 -2
- package/dist/{message-parts-BBFUkluC.d.ts → parts/components/message-parts.d.ts} +2 -3
- package/dist/{message-parts-DQnfioAH.js → parts/components/message-parts.js} +6 -6
- package/dist/{message-CW_paC1k.d.ts → parts/components/message.d.ts} +8 -9
- package/dist/{message-DiyBthIq.js → parts/components/message.js} +2 -2
- package/dist/parts/components/patch-parsers.d.ts +2 -0
- package/dist/parts/components/patch-parsers.js +2 -0
- package/dist/{prompt-input-Cy_Ue6B5.d.ts → parts/components/prompt-input.d.ts} +53 -10
- package/dist/{prompt-input-BbnCb80O.js → parts/components/prompt-input.js} +66 -111
- package/dist/parts/components/relative-time.d.ts +73 -0
- package/dist/parts/components/relative-time.js +2 -0
- package/dist/parts/components/status.d.ts +60 -0
- package/dist/parts/components/status.js +48 -0
- package/dist/{sync-status-refELOZn.d.ts → parts/components/sync-status.d.ts} +5 -6
- package/dist/{sync-status-BpxYdZIJ.js → parts/components/sync-status.js} +1 -1
- package/dist/{tool-list-E7CA52rz.d.ts → parts/components/tool-list.d.ts} +3 -4
- package/dist/{tool-list-BdSr5CT4.js → parts/components/tool-list.js} +7 -38
- package/dist/{trace-run-COeXn46Z.d.ts → parts/components/trace-run.d.ts} +3 -4
- package/dist/{trace-run-BIQ17CED.js → parts/components/trace-run.js} +15 -23
- package/dist/{trace-V7rM3Pyd.d.ts → parts/components/trace.d.ts} +11 -12
- package/dist/{trace-llBCDiSW.js → parts/components/trace.js} +20 -13
- package/dist/parts/composables/attachments.d.ts +32 -0
- package/dist/parts/composables/attachments.js +2 -0
- package/dist/parts/composables/highlighted-code.d.ts +9 -0
- package/dist/{highlighted-code-Ck4zexJX.js → parts/composables/highlighted-code.js} +5 -2
- package/dist/parts/headless/choices-input.d.ts +2 -0
- package/dist/parts/headless/choices-input.js +162 -0
- package/dist/parts/headless/comment-visibility.d.ts +2 -0
- package/dist/parts/headless/comment-visibility.js +128 -0
- package/dist/parts/headless/comments.d.ts +2 -0
- package/dist/parts/headless/comments.js +2 -0
- package/dist/parts/headless/message-scroller.d.ts +2 -0
- package/dist/{message-scroller-CX6NJTdm.js → parts/headless/message-scroller.js} +2 -2
- package/dist/parts/playground/highlight.d.ts +5 -0
- package/dist/parts/playground/highlight.js +23 -0
- package/dist/parts/playground/paths.d.ts +4 -0
- package/dist/parts/playground/paths.js +7 -0
- package/dist/parts/playground/playground-render.d.ts +126 -0
- package/dist/parts/playground/playground-render.js +356 -0
- package/dist/parts/playground/share.d.ts +2 -0
- package/dist/parts/playground/share.js +92 -0
- package/dist/parts/playground/zip.d.ts +6 -0
- package/dist/parts/playground/zip.js +76 -0
- package/dist/parts/workspace/browser-support-notice.d.ts +76 -0
- package/dist/parts/workspace/browser-support-notice.js +105 -0
- package/dist/parts/workspace/codemirror.d.ts +16 -0
- package/dist/parts/workspace/codemirror.js +243 -0
- package/dist/parts/workspace/connect-panel.d.ts +129 -0
- package/dist/parts/workspace/connect-panel.js +285 -0
- package/dist/parts/workspace/connect-store.d.ts +26 -0
- package/dist/parts/workspace/connect-store.js +59 -0
- package/dist/parts/workspace/icons.d.ts +34 -0
- package/dist/parts/workspace/icons.js +46 -0
- package/dist/parts/workspace/playground-container.d.ts +192 -0
- package/dist/parts/workspace/playground-container.js +603 -0
- package/dist/parts/workspace/workspace-boot-status.d.ts +75 -0
- package/dist/parts/workspace/workspace-boot-status.js +207 -0
- package/dist/parts/workspace/workspace-editor.d.ts +43 -0
- package/dist/parts/workspace/workspace-editor.js +54 -0
- package/dist/parts/workspace/workspace-file-tree.d.ts +53 -0
- package/dist/parts/workspace/workspace-file-tree.js +68 -0
- package/dist/parts/workspace/workspace-preview.d.ts +72 -0
- package/dist/parts/workspace/workspace-preview.js +307 -0
- package/dist/parts/workspace/workspace-shell.d.ts +88 -0
- package/dist/parts/workspace/workspace-shell.js +291 -0
- package/dist/parts/workspace/workspace-terminal.d.ts +39 -0
- package/dist/parts/workspace/workspace-terminal.js +130 -0
- package/dist/payload-text-sjkYAwvw.js +32 -0
- package/dist/{pierre-code-view-T7V67hwT.js → pierre-code-view-NE35tkmR.js} +245 -102
- package/dist/{pierre-dark-DDWDl8g6.js → pierre-dark-CzUmjETS.js} +3 -1
- package/dist/{pierre-light-CWhW4NrH.js → pierre-light-Dn6E0sWv.js} +3 -1
- package/dist/playground.d.ts +4 -0
- package/dist/playground.js +4 -0
- package/dist/relative-time-BVmjOsYG.js +309 -0
- package/dist/rolldown-runtime-C9mWXvCC.js +29 -0
- package/dist/runtime/nuxt-plugin.js +23 -4
- package/dist/sankey-CAYwt82B-D4uDQoMR.js +2887 -0
- package/dist/share-DM4eNy4q.d.ts +37 -0
- package/dist/{slot-part-C7Ocxn3b.js → slot-part-Doic71uh.js} +7 -1
- package/dist/styles.css +2609 -620
- package/dist/temml-BilSAAws.js +12362 -0
- package/dist/theme-focus-ring.css +42 -0
- package/dist/theme.css +376 -0
- package/dist/theme.d.ts +355 -0
- package/dist/theme.js +265 -0
- package/dist/{types-CqDwuJAm.d.ts → types-Dj7vp0lZ.d.ts} +1 -1
- package/dist/vue-BDmSCtay.js +30779 -0
- package/dist/vue-DGstVdGn.js +2492 -0
- package/dist/workspace.d.ts +15 -0
- package/dist/workspace.js +12 -0
- package/package.json +135 -149
- package/dist/andromeeda-BASpqCeJ.js +0 -4
- package/dist/attachment.d.ts +0 -2
- package/dist/attachment.js +0 -2
- package/dist/aurora-x-DugsLcii.js +0 -4
- package/dist/avatar-stack.js +0 -2
- package/dist/ayu-dark-BT3qdi3o.js +0 -4
- package/dist/ayu-light-BVZyHoh9.js +0 -4
- package/dist/ayu-mirage-XFwUVZQZ.js +0 -4
- package/dist/bubble.d.ts +0 -2
- package/dist/bubble.js +0 -2
- package/dist/catppuccin-frappe-D20KODDN.js +0 -4
- package/dist/catppuccin-latte-eGLVHIUJ.js +0 -4
- package/dist/catppuccin-macchiato-bQGch4PY.js +0 -4
- package/dist/catppuccin-mocha-Bes8-0Mr.js +0 -4
- package/dist/chat-message.d.ts +0 -2
- package/dist/chat-message.js +0 -2
- package/dist/chat-session.d.ts +0 -2
- package/dist/chat-session.js +0 -2
- package/dist/chat.d.ts +0 -2
- package/dist/chat.js +0 -2
- package/dist/code-block.d.ts +0 -2
- package/dist/code-block.js +0 -3
- package/dist/code-view.d.ts +0 -2
- package/dist/code-view.js +0 -2
- package/dist/comment-layer-CBlxJ8eK.js +0 -1113
- package/dist/comments-ChNJkV1d.d.ts +0 -108
- package/dist/comments-Cq5eewsu.d.ts +0 -537
- package/dist/comments.d.ts +0 -2
- package/dist/comments.js +0 -2
- package/dist/config-Bux_AJzm.d.ts +0 -29
- package/dist/config-bHqE4JOs.js +0 -38
- package/dist/connection-status.d.ts +0 -2
- package/dist/connection-status.js +0 -2
- package/dist/dark-plus-BGuiqa1B.js +0 -4
- package/dist/dracula-0CVA2XY5.js +0 -4
- package/dist/dracula-soft-Dk9bpbVU.js +0 -4
- package/dist/error-diagnostics-B4hMpJRL.js +0 -13
- package/dist/everforest-dark-CRjTbhh5.js +0 -4
- package/dist/everforest-light-CEeYFLn8.js +0 -4
- package/dist/file-diff.d.ts +0 -2
- package/dist/file-diff.js +0 -2
- package/dist/file-tree.d.ts +0 -2
- package/dist/file-tree.js +0 -2
- package/dist/file-view.d.ts +0 -2
- package/dist/file-view.js +0 -2
- package/dist/github-dark-BXgKmOw_.js +0 -4
- package/dist/github-dark-default-DzJQXksd.js +0 -4
- package/dist/github-dark-dimmed-B1pEmGtS.js +0 -4
- package/dist/github-dark-high-contrast-BkHIa6jc.js +0 -4
- package/dist/github-light-BKRlUbaB.js +0 -4
- package/dist/github-light-default-BU3eYkzs.js +0 -4
- package/dist/github-light-high-contrast-B3MumDcI.js +0 -4
- package/dist/gruvbox-dark-hard-B0ecF443.js +0 -4
- package/dist/gruvbox-dark-medium-BQnpC39k.js +0 -4
- package/dist/gruvbox-dark-soft-DFZUgESr.js +0 -4
- package/dist/gruvbox-light-hard-CuB_LOJr.js +0 -4
- package/dist/gruvbox-light-medium-idDHgxjs.js +0 -4
- package/dist/gruvbox-light-soft-CfWH49MY.js +0 -4
- package/dist/horizon-bright-Ba6M8QSV.js +0 -4
- package/dist/horizon-h92C5OlZ.js +0 -4
- package/dist/houston-EQnPegWq.js +0 -4
- package/dist/kanagawa-dragon-DgDvwi3B.js +0 -4
- package/dist/kanagawa-lotus-BgoQro20.js +0 -4
- package/dist/kanagawa-wave-DgXEowHs.js +0 -4
- package/dist/laserwave-IxBH_3yW.js +0 -4
- package/dist/light-plus-S8JBx6is.js +0 -4
- package/dist/markdown-BoLBN0qH.js +0 -197
- package/dist/markdown.d.ts +0 -2
- package/dist/markdown.js +0 -2
- package/dist/marker.d.ts +0 -2
- package/dist/marker.js +0 -2
- package/dist/material-theme-D1f3HBq-.js +0 -4
- package/dist/material-theme-darker-ExzYhT0j.js +0 -4
- package/dist/material-theme-lighter-D6gH9nnA.js +0 -4
- package/dist/material-theme-ocean-D1w5BPAa.js +0 -4
- package/dist/material-theme-palenight-CkqWmVpF.js +0 -4
- package/dist/message-parts.d.ts +0 -2
- package/dist/message-parts.js +0 -2
- package/dist/message.d.ts +0 -2
- package/dist/message.js +0 -2
- package/dist/min-dark-npsJH98j.js +0 -4
- package/dist/min-light-DUk1XsVt.js +0 -4
- package/dist/monokai-CfFRWUNl.js +0 -4
- package/dist/multi-file-diff.d.ts +0 -2
- package/dist/multi-file-diff.js +0 -2
- package/dist/night-owl-BS7V-av_.js +0 -4
- package/dist/night-owl-light-CZtRawYE.js +0 -4
- package/dist/nord-BFh54Nqz.js +0 -4
- package/dist/one-dark-pro-zDovGosB.js +0 -4
- package/dist/one-light-gmHK3iK6.js +0 -4
- package/dist/patch-diff.d.ts +0 -2
- package/dist/patch-diff.js +0 -2
- package/dist/plastic-DtdaCjub.js +0 -4
- package/dist/poimandres-Hdda6aHK.js +0 -4
- package/dist/primitive-rail.d.ts +0 -222
- package/dist/primitive-rail.js +0 -348
- package/dist/prompt-input.d.ts +0 -2
- package/dist/prompt-input.js +0 -2
- package/dist/red-VqZFRByZ.js +0 -4
- package/dist/rose-pine-DiTkEueR.js +0 -4
- package/dist/rose-pine-dawn-tfo5y2X0.js +0 -4
- package/dist/rose-pine-moon-C0gON9XN.js +0 -4
- package/dist/runtime-type-DlCscMfw.js +0 -59
- package/dist/slack-dark-v8P_eXr6.js +0 -4
- package/dist/slack-ochin-D8SyEdKz.js +0 -4
- package/dist/snazzy-light-BtkQkvXb.js +0 -4
- package/dist/solarized-dark-B8nAdMfM.js +0 -4
- package/dist/solarized-light-B-3F1INj.js +0 -4
- package/dist/sync-status.d.ts +0 -2
- package/dist/sync-status.js +0 -2
- package/dist/synthwave-84-DcsXCF_c.js +0 -4
- package/dist/tokyo-night-Bvpqduda.js +0 -4
- package/dist/tool-list.d.ts +0 -2
- package/dist/tool-list.js +0 -2
- package/dist/trace-run.d.ts +0 -2
- package/dist/trace-run.js +0 -2
- package/dist/trace.d.ts +0 -2
- package/dist/trace.js +0 -2
- package/dist/unresolved-file.d.ts +0 -2
- package/dist/unresolved-file.js +0 -2
- package/dist/vesper-CfxmMOy3.js +0 -4
- package/dist/vitesse-black-D9-_1mjV.js +0 -4
- package/dist/vitesse-dark-DlSMLlr9.js +0 -4
- package/dist/vitesse-light-KRWWWztf.js +0 -4
|
@@ -1,39 +1,68 @@
|
|
|
1
|
-
import { t as uiErrorDiagnostics } from "./error-diagnostics-
|
|
2
|
-
import {
|
|
1
|
+
import { t as uiErrorDiagnostics } from "./error-diagnostics-SXtnk6bz.js";
|
|
2
|
+
import { i as hasDirtyComposer, n as injectComments, o as shakeDirtyComposers, t as commentsKey } from "./comments-context-C2lOZyQ5.js";
|
|
3
|
+
import { createCommentVisibility } from "./parts/headless/comment-visibility.js";
|
|
4
|
+
import { computed, getCurrentInstance, isRef, onBeforeUnmount, onMounted, provide, reactive, ref, shallowRef, toRaw, toValue, watch } from "vue";
|
|
3
5
|
import { createAnchor, resolveAnchor } from "@vite-hub/comments/client";
|
|
4
|
-
//#region src/internal/comment-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const cleanup = () => {
|
|
13
|
-
document.removeEventListener("click", stop, true);
|
|
14
|
-
document.removeEventListener("pointerdown", cleanup, true);
|
|
15
|
-
};
|
|
16
|
-
document.addEventListener("click", stop, true);
|
|
17
|
-
document.addEventListener("pointerdown", cleanup, true);
|
|
6
|
+
//#region src/internal/comment-selection.ts
|
|
7
|
+
function commentThreadKey(thread) {
|
|
8
|
+
return thread.requestId === void 0 ? thread.id : JSON.stringify([
|
|
9
|
+
thread.subject.kind,
|
|
10
|
+
thread.subject.id,
|
|
11
|
+
thread.author.id,
|
|
12
|
+
thread.requestId
|
|
13
|
+
]);
|
|
18
14
|
}
|
|
19
|
-
function
|
|
20
|
-
|
|
21
|
-
|
|
15
|
+
function useSelectedComment(threads, id) {
|
|
16
|
+
const selection = computed((previous) => {
|
|
17
|
+
const selectedId = id.value;
|
|
18
|
+
const items = threads.value;
|
|
19
|
+
const direct = items.find((thread) => thread.id === selectedId);
|
|
20
|
+
const last = previous?.id === selectedId ? previous.thread : void 0;
|
|
21
|
+
const key = last?.requestId === void 0 ? void 0 : commentThreadKey(last);
|
|
22
|
+
return {
|
|
23
|
+
id: selectedId,
|
|
24
|
+
thread: direct ?? (key === void 0 ? void 0 : items.find((thread) => commentThreadKey(thread) === key))
|
|
25
|
+
};
|
|
26
|
+
});
|
|
27
|
+
return computed(() => selection.value.thread);
|
|
22
28
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
29
|
+
//#endregion
|
|
30
|
+
//#region src/internal/comment-status.ts
|
|
31
|
+
/** The messages written after the thread was resolved. Empty for an open thread. */
|
|
32
|
+
function messagesSinceResolved(thread) {
|
|
33
|
+
const { resolvedAt } = thread;
|
|
34
|
+
if (thread.status !== "resolved" || resolvedAt === void 0) return [];
|
|
35
|
+
return thread.messages.filter((message) => message.createdAt > resolvedAt);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Whether someone replied after the thread was resolved, such as an agent that says what it changed. The thread stays
|
|
39
|
+
* resolved, and lists show it with the open threads until someone resolves it again.
|
|
40
|
+
*/
|
|
41
|
+
const repliedSinceResolved = (thread) => messagesSinceResolved(thread).length > 0;
|
|
42
|
+
/** "Comment 3". A comment that waits in the outbox has no number yet. */
|
|
43
|
+
function commentTitle(thread) {
|
|
44
|
+
return thread.n ? `Comment ${thread.n}` : "Comment";
|
|
27
45
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
46
|
+
/** `data-pending` or `data-failed` for a thread, message, or row that the outbox holds. */
|
|
47
|
+
function deliveryAttributes(delivery) {
|
|
48
|
+
return {
|
|
49
|
+
"data-failed": delivery?.status === "failed" ? "true" : void 0,
|
|
50
|
+
"data-pending": delivery?.status === "pending" ? "true" : void 0
|
|
51
|
+
};
|
|
32
52
|
}
|
|
33
|
-
const pathOf = (event) => event.composedPath().filter((node) => node instanceof Element);
|
|
34
53
|
//#endregion
|
|
35
54
|
//#region src/headless/comments.ts
|
|
36
|
-
|
|
55
|
+
/**
|
|
56
|
+
* The permissions that the parts assume without a `can` option: a signed-in user may reply to and resolve any thread,
|
|
57
|
+
* and edit and delete their own messages. Nobody may do anything without a user.
|
|
58
|
+
*/
|
|
59
|
+
function defaultCommentCan(user) {
|
|
60
|
+
return (action, { message }) => {
|
|
61
|
+
if (!user) return false;
|
|
62
|
+
if (action === "edit" || action === "delete") return message?.author.id === user.id;
|
|
63
|
+
return true;
|
|
64
|
+
};
|
|
65
|
+
}
|
|
37
66
|
const draftPositionKey = "draft";
|
|
38
67
|
const uiSelector = "[data-comments-ui]";
|
|
39
68
|
function defaultIgnore(element) {
|
|
@@ -83,14 +112,27 @@ function useComments(options) {
|
|
|
83
112
|
});
|
|
84
113
|
const status = ref(client.status);
|
|
85
114
|
const threads = shallowRef(client.threads);
|
|
115
|
+
const outboxEntries = shallowRef(client.outbox?.entries ?? []);
|
|
86
116
|
const positions = shallowRef(/* @__PURE__ */ new Map());
|
|
87
117
|
const draft = ref(null);
|
|
88
118
|
const openId = ref(null);
|
|
119
|
+
const retained = shallowRef(/* @__PURE__ */ new Map());
|
|
120
|
+
const retainedIds = computed(() => new Set(retained.value.values()));
|
|
121
|
+
const retainMark = (id) => {
|
|
122
|
+
const key = Symbol();
|
|
123
|
+
retained.value = new Map(retained.value).set(key, id);
|
|
124
|
+
return () => {
|
|
125
|
+
const next = new Map(retained.value);
|
|
126
|
+
next.delete(key);
|
|
127
|
+
retained.value = next;
|
|
128
|
+
};
|
|
129
|
+
};
|
|
89
130
|
const hoverId = ref(null);
|
|
90
131
|
const listOpen = ref(false);
|
|
91
132
|
const blocked = ref(0);
|
|
133
|
+
const isOpen = (thread) => thread.status === "open" || repliedSinceResolved(thread);
|
|
92
134
|
const passes = (thread) => {
|
|
93
|
-
if (
|
|
135
|
+
if (!(filters.open && isOpen(thread) || filters.resolved && thread.status === "resolved")) return false;
|
|
94
136
|
return !filters.mine || thread.author.id === user.value?.id;
|
|
95
137
|
};
|
|
96
138
|
const onPage = (thread) => sameSubject(thread.subject, subject.value);
|
|
@@ -99,26 +141,56 @@ function useComments(options) {
|
|
|
99
141
|
const counts = computed(() => {
|
|
100
142
|
const scoped = threads.value.filter((thread) => scope.value === "site" || onPage(thread));
|
|
101
143
|
return {
|
|
102
|
-
open: scoped.filter(
|
|
144
|
+
open: scoped.filter(isOpen).length,
|
|
103
145
|
resolved: scoped.filter((thread) => thread.status === "resolved").length
|
|
104
146
|
};
|
|
105
147
|
});
|
|
106
|
-
const opened =
|
|
148
|
+
const opened = useSelectedComment(threads, openId);
|
|
149
|
+
watch(opened, (thread) => {
|
|
150
|
+
if (thread && thread.id !== openId.value) openId.value = thread.id;
|
|
151
|
+
}, { flush: "sync" });
|
|
152
|
+
const visibility = isRef(options.visibility) ? options.visibility : ref(options.visibility ?? "all");
|
|
153
|
+
const seen = createCommentVisibility({
|
|
154
|
+
visibility: visibility.value,
|
|
155
|
+
flashMs: options.flashMs
|
|
156
|
+
});
|
|
157
|
+
const seenChanges = ref(0);
|
|
158
|
+
seen.subscribe(() => seenChanges.value++);
|
|
159
|
+
watch(visibility, (value) => seen.set(value), { flush: "sync" });
|
|
160
|
+
watch(openId, (id) => seen.open(id), { flush: "sync" });
|
|
161
|
+
watch(hoverId, (id) => seen.hover(id), { flush: "sync" });
|
|
162
|
+
const marked = computed(() => {
|
|
163
|
+
seenChanges.value;
|
|
164
|
+
const ids = new Set(pageThreads.value.map((thread) => thread.id));
|
|
165
|
+
if (opened.value && onPage(opened.value)) ids.add(opened.value.id);
|
|
166
|
+
for (const thread of threads.value) {
|
|
167
|
+
const temporary = visibility.value === "hidden" && (seen.isShown(thread.id) || seen.leaving.includes(thread.id));
|
|
168
|
+
if (onPage(thread) && (retainedIds.value.has(thread.id) || temporary)) ids.add(thread.id);
|
|
169
|
+
}
|
|
170
|
+
return ids;
|
|
171
|
+
});
|
|
172
|
+
const shown = computed(() => {
|
|
173
|
+
seenChanges.value;
|
|
174
|
+
return new Set([...marked.value].filter((id) => seen.isShown(id) || retainedIds.value.has(id)));
|
|
175
|
+
});
|
|
176
|
+
const leaving = computed(() => {
|
|
177
|
+
seenChanges.value;
|
|
178
|
+
return new Set(seen.leaving.filter((id) => marked.value.has(id) && !retainedIds.value.has(id)));
|
|
179
|
+
});
|
|
180
|
+
const flash = (id) => seen.flash(id);
|
|
107
181
|
const root = () => toValue(options.root) ?? document;
|
|
108
182
|
const uiRoot = () => toValue(options.uiRoot) ?? document;
|
|
109
183
|
function measure() {
|
|
110
184
|
const next = /* @__PURE__ */ new Map();
|
|
111
|
-
for (const thread of
|
|
112
|
-
const current = opened.value;
|
|
113
|
-
if (current && onPage(current) && !next.has(current.id)) next.set(current.id, resolveAnchor(current.anchor, root()));
|
|
185
|
+
for (const thread of threads.value.filter((thread) => marked.value.has(thread.id))) next.set(thread.id, resolveAnchor(thread.anchor, root()));
|
|
114
186
|
if (draft.value) next.set(draftPositionKey, resolveAnchor(draft.value.anchor, root()));
|
|
115
187
|
const previous = positions.value;
|
|
116
188
|
if (!(next.size === previous.size && [...next].every(([key, position]) => samePosition(position, previous.get(key))))) positions.value = next;
|
|
117
189
|
}
|
|
118
190
|
const hasText = () => (draft.value?.body.trim().length ?? 0) > 0 || hasDirtyComposer(uiRoot());
|
|
119
|
-
const block = () => {
|
|
191
|
+
const block = (escape = false) => {
|
|
120
192
|
blocked.value++;
|
|
121
|
-
shakeDirtyComposers(uiRoot());
|
|
193
|
+
shakeDirtyComposers(uiRoot(), escape);
|
|
122
194
|
};
|
|
123
195
|
function enter() {
|
|
124
196
|
active.value = true;
|
|
@@ -126,13 +198,15 @@ function useComments(options) {
|
|
|
126
198
|
if (selection && !selection.isCollapsed && selection.rangeCount > 0) {
|
|
127
199
|
const container = selection.getRangeAt(0).commonAncestorContainer;
|
|
128
200
|
const element = container instanceof Element ? container : container.parentElement;
|
|
129
|
-
if (element && !ignore(element)) {
|
|
201
|
+
if (element?.isConnected && !ignore(element)) {
|
|
130
202
|
const rect = selection.getRangeAt(0).getBoundingClientRect();
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
203
|
+
try {
|
|
204
|
+
startDraft(selection, { point: {
|
|
205
|
+
x: rect.left,
|
|
206
|
+
y: rect.top
|
|
207
|
+
} });
|
|
208
|
+
selection.removeAllRanges();
|
|
209
|
+
} catch {}
|
|
136
210
|
}
|
|
137
211
|
}
|
|
138
212
|
}
|
|
@@ -148,8 +222,8 @@ function useComments(options) {
|
|
|
148
222
|
hoverId.value = null;
|
|
149
223
|
return true;
|
|
150
224
|
}
|
|
151
|
-
function exit() {
|
|
152
|
-
if (hasText()) return block();
|
|
225
|
+
function exit(escape = false) {
|
|
226
|
+
if (hasText()) return block(escape);
|
|
153
227
|
cancelDraft();
|
|
154
228
|
close();
|
|
155
229
|
active.value = false;
|
|
@@ -158,7 +232,7 @@ function useComments(options) {
|
|
|
158
232
|
if (active.value) exit();
|
|
159
233
|
else enter();
|
|
160
234
|
}
|
|
161
|
-
function startDraft(target, anchorOptions = {}) {
|
|
235
|
+
function startDraft(target, { files, ...anchorOptions } = {}) {
|
|
162
236
|
if (hasText()) return block();
|
|
163
237
|
close();
|
|
164
238
|
const anchor = createAnchor(target, {
|
|
@@ -186,17 +260,21 @@ function useComments(options) {
|
|
|
186
260
|
point,
|
|
187
261
|
body: "",
|
|
188
262
|
mentions: [],
|
|
263
|
+
attachments: [],
|
|
264
|
+
...files?.length ? { files } : {},
|
|
189
265
|
busy: false,
|
|
190
266
|
error: void 0
|
|
191
267
|
};
|
|
192
268
|
measure();
|
|
193
269
|
}
|
|
194
|
-
async function send() {
|
|
270
|
+
async function send(sendOptions = {}) {
|
|
195
271
|
const current = draft.value;
|
|
196
272
|
const body = current?.body.trim() ?? "";
|
|
197
|
-
|
|
273
|
+
const files = sendOptions.files ?? [];
|
|
274
|
+
if (!current || current.busy || !body && current.attachments.length === 0 && files.length === 0) return void 0;
|
|
198
275
|
const submittedBody = current.body;
|
|
199
276
|
const mentions = [...current.mentions];
|
|
277
|
+
const attachments = [...current.attachments];
|
|
200
278
|
current.busy = true;
|
|
201
279
|
current.error = void 0;
|
|
202
280
|
try {
|
|
@@ -204,9 +282,12 @@ function useComments(options) {
|
|
|
204
282
|
subject: subject.value,
|
|
205
283
|
anchor: toRaw(current.anchor),
|
|
206
284
|
body,
|
|
207
|
-
mentions
|
|
285
|
+
mentions,
|
|
286
|
+
...attachments.length > 0 ? { attachments } : {},
|
|
287
|
+
...files.length > 0 ? { files } : {}
|
|
208
288
|
});
|
|
209
289
|
current.busy = false;
|
|
290
|
+
flash(thread.id);
|
|
210
291
|
if (draft.value === current && current.body === submittedBody && current.mentions.length === mentions.length && current.mentions.every((id, index) => id === mentions[index])) draft.value = null;
|
|
211
292
|
return thread;
|
|
212
293
|
} catch (error) {
|
|
@@ -267,7 +348,7 @@ function useComments(options) {
|
|
|
267
348
|
const origin = path[0];
|
|
268
349
|
if (event.key === "Escape") {
|
|
269
350
|
if (path.some((element) => element.matches("[data-slot='comment-composer']"))) return;
|
|
270
|
-
if (active.value || draft.value || openId.value) exit();
|
|
351
|
+
if (active.value || draft.value || openId.value) exit(true);
|
|
271
352
|
return;
|
|
272
353
|
}
|
|
273
354
|
if (event.ctrlKey || event.metaKey || event.altKey || event.shiftKey || isEditable(path)) return;
|
|
@@ -288,6 +369,7 @@ function useComments(options) {
|
|
|
288
369
|
stops.push(client.onChange(() => {
|
|
289
370
|
status.value = client.status;
|
|
290
371
|
threads.value = client.threads;
|
|
372
|
+
outboxEntries.value = client.outbox?.entries ?? [];
|
|
291
373
|
}));
|
|
292
374
|
status.value = client.status;
|
|
293
375
|
threads.value = client.threads;
|
|
@@ -314,6 +396,7 @@ function useComments(options) {
|
|
|
314
396
|
applyDeepLink();
|
|
315
397
|
};
|
|
316
398
|
window.addEventListener("popstate", onPopstate);
|
|
399
|
+
stops.push(watch(() => options.location?.().search, onPopstate));
|
|
317
400
|
const observer = new MutationObserver((records) => {
|
|
318
401
|
if (records.every((record) => record.target instanceof Element && defaultIgnore(record.target))) return;
|
|
319
402
|
schedule();
|
|
@@ -357,10 +440,11 @@ function useComments(options) {
|
|
|
357
440
|
resizes?.disconnect();
|
|
358
441
|
clearTimeout(revealTimer);
|
|
359
442
|
if (frame) cancelAnimationFrame(frame);
|
|
443
|
+
seen.stop();
|
|
360
444
|
});
|
|
361
445
|
stops.push(watch(positions, follow, { flush: "post" }));
|
|
362
446
|
stops.push(watch([
|
|
363
|
-
|
|
447
|
+
marked,
|
|
364
448
|
() => draft.value?.anchor,
|
|
365
449
|
openId
|
|
366
450
|
], () => measure(), { flush: "post" }));
|
|
@@ -377,15 +461,58 @@ function useComments(options) {
|
|
|
377
461
|
for (const stop of stops.splice(0)) stop();
|
|
378
462
|
};
|
|
379
463
|
}
|
|
464
|
+
const found = shallowRef(/* @__PURE__ */ new Map());
|
|
465
|
+
const people = computed(() => {
|
|
466
|
+
const known = /* @__PURE__ */ new Map();
|
|
467
|
+
const add = (person) => {
|
|
468
|
+
if (person && (!known.has(person.id) || person.name)) known.set(person.id, person);
|
|
469
|
+
};
|
|
470
|
+
for (const person of found.value.values()) add(person);
|
|
471
|
+
for (const person of toValue(options.people) ?? []) add(person);
|
|
472
|
+
for (const thread of threads.value) {
|
|
473
|
+
add(thread.author);
|
|
474
|
+
add(thread.resolvedBy);
|
|
475
|
+
for (const message of thread.messages) add(message.author);
|
|
476
|
+
}
|
|
477
|
+
add(user.value);
|
|
478
|
+
return [...known.values()];
|
|
479
|
+
});
|
|
480
|
+
async function users(query, threadId) {
|
|
481
|
+
const result = await client.users({
|
|
482
|
+
query,
|
|
483
|
+
...threadId ? { threadId } : { subject: subject.value }
|
|
484
|
+
});
|
|
485
|
+
if (result.some((person) => found.value.get(person.id) !== person)) {
|
|
486
|
+
const next = new Map(found.value);
|
|
487
|
+
for (const person of result) next.set(person.id, person);
|
|
488
|
+
found.value = next;
|
|
489
|
+
}
|
|
490
|
+
return result;
|
|
491
|
+
}
|
|
492
|
+
const can = (action, target) => user.value !== void 0 && (options.can ?? defaultCommentCan(user.value))(action, target);
|
|
380
493
|
const state = {
|
|
381
494
|
client,
|
|
382
495
|
subject,
|
|
383
496
|
user,
|
|
497
|
+
can,
|
|
498
|
+
people,
|
|
384
499
|
active,
|
|
385
500
|
scope,
|
|
386
501
|
filters,
|
|
387
502
|
status,
|
|
388
503
|
threads,
|
|
504
|
+
outbox: {
|
|
505
|
+
enabled: client.outbox !== void 0,
|
|
506
|
+
queued: computed(() => outboxEntries.value.filter((entry) => entry.status !== "failed")),
|
|
507
|
+
failures: computed(() => outboxEntries.value.filter((entry) => entry.status === "failed")),
|
|
508
|
+
delivery(threadId, messageId) {
|
|
509
|
+
const thread = threads.value.find((item) => item.id === threadId);
|
|
510
|
+
return messageId === void 0 ? thread?.delivery : thread?.messages.find((item) => item.id === messageId)?.delivery;
|
|
511
|
+
},
|
|
512
|
+
retry: async (id) => client.outbox?.retry(id),
|
|
513
|
+
dismiss: async (id) => await client.outbox?.dismiss(id) ?? false,
|
|
514
|
+
edit: async (id, body, mentions) => await client.outbox?.edit(id, body, mentions) ?? false
|
|
515
|
+
},
|
|
389
516
|
pageThreads,
|
|
390
517
|
listed,
|
|
391
518
|
counts,
|
|
@@ -396,6 +523,12 @@ function useComments(options) {
|
|
|
396
523
|
opened,
|
|
397
524
|
listOpen,
|
|
398
525
|
blocked,
|
|
526
|
+
visibility,
|
|
527
|
+
shown,
|
|
528
|
+
leaving,
|
|
529
|
+
retainMark,
|
|
530
|
+
isShown: (id) => shown.value.has(id),
|
|
531
|
+
flash,
|
|
399
532
|
enter,
|
|
400
533
|
exit,
|
|
401
534
|
toggle,
|
|
@@ -404,11 +537,29 @@ function useComments(options) {
|
|
|
404
537
|
send,
|
|
405
538
|
open,
|
|
406
539
|
close,
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
540
|
+
create: async ({ anchor = { kind: "page" }, attachments, body, files, mentions }) => {
|
|
541
|
+
const thread = await client.create({
|
|
542
|
+
subject: subject.value,
|
|
543
|
+
anchor,
|
|
544
|
+
body,
|
|
545
|
+
mentions,
|
|
546
|
+
...attachments?.length ? { attachments } : {},
|
|
547
|
+
...files?.length ? { files } : {}
|
|
548
|
+
});
|
|
549
|
+
flash(thread.id);
|
|
550
|
+
return thread;
|
|
551
|
+
},
|
|
552
|
+
reply: async (threadId, body, mentions, attachments, files) => {
|
|
553
|
+
const thread = await client.reply({
|
|
554
|
+
threadId,
|
|
555
|
+
body,
|
|
556
|
+
mentions,
|
|
557
|
+
...attachments?.length ? { attachments } : {},
|
|
558
|
+
...files?.length ? { files } : {}
|
|
559
|
+
});
|
|
560
|
+
flash(threadId);
|
|
561
|
+
return thread;
|
|
562
|
+
},
|
|
412
563
|
edit: (threadId, messageId, body, mentions) => client.edit({
|
|
413
564
|
threadId,
|
|
414
565
|
messageId,
|
|
@@ -428,7 +579,7 @@ function useComments(options) {
|
|
|
428
579
|
},
|
|
429
580
|
resolve: (threadId) => client.resolve({ threadId }),
|
|
430
581
|
reopen: (threadId) => client.reopen({ threadId }),
|
|
431
|
-
users
|
|
582
|
+
users,
|
|
432
583
|
link,
|
|
433
584
|
measure,
|
|
434
585
|
start
|
|
@@ -448,9 +599,9 @@ function provideComments(state) {
|
|
|
448
599
|
}
|
|
449
600
|
/** The state that a comment part uses: the one you pass, else the one of the nearest `CommentLayer` or `provideComments()`. Call it in `setup()`. */
|
|
450
601
|
function useCommentsContext(state) {
|
|
451
|
-
const found = state ??
|
|
602
|
+
const found = state ?? injectComments();
|
|
452
603
|
if (!found) throw uiErrorDiagnostics.UI_R0002({ message: "Comment parts need a comments state. Put them inside CommentLayer, or pass the result of useComments() as the `comments` prop." });
|
|
453
604
|
return found;
|
|
454
605
|
}
|
|
455
606
|
//#endregion
|
|
456
|
-
export {
|
|
607
|
+
export { useCommentsContext as a, messagesSinceResolved as c, useSelectedComment as d, useComments as i, repliedSinceResolved as l, draftPositionKey as n, commentTitle as o, provideComments as r, deliveryAttributes as s, defaultCommentCan as t, commentThreadKey as u };
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { t as CommentVisibility } from "./comment-visibility-DsVuVndP.js";
|
|
2
|
+
import { ComputedRef, MaybeRefOrGetter, Ref, ShallowRef } from "vue";
|
|
3
|
+
import { AnchorPoint, AnchorPosition, AnchorTarget, CommentAnchor, CommentDelivery, CommentMessage, CommentSubject, CommentThread, CommentUser, CommentsClient, CommentsClientStatus, CommentsOutboxEntry, CreateAnchorOptions } from "@vite-hub/comments/client";
|
|
4
|
+
//#region src/headless/comments.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Each switch shows one kind of thread. Resolved threads stay hidden until `resolved` is on. A resolved thread with a
|
|
7
|
+
* reply since it was resolved also counts as open, so the reply is seen.
|
|
8
|
+
*/
|
|
9
|
+
interface CommentFilterState {
|
|
10
|
+
open: boolean;
|
|
11
|
+
resolved: boolean;
|
|
12
|
+
/** Only threads that the signed-in user started. */
|
|
13
|
+
mine: boolean;
|
|
14
|
+
}
|
|
15
|
+
/** `page` lists the threads of this page. `site` lists the threads of every page. */
|
|
16
|
+
type CommentScope = "page" | "site";
|
|
17
|
+
/** A comment that is being written. It becomes a thread when it is sent. */
|
|
18
|
+
interface CommentDraft {
|
|
19
|
+
anchor: CommentAnchor;
|
|
20
|
+
/** Where the click landed in client coordinates. The pin sits here until its element is measured. */
|
|
21
|
+
point: AnchorPoint;
|
|
22
|
+
body: string;
|
|
23
|
+
mentions: string[];
|
|
24
|
+
/** Attachment keys, such as Blob keys, that the comment sends. */
|
|
25
|
+
attachments: string[];
|
|
26
|
+
/** Files that the composer starts with, such as a screenshot. They upload with the comment, as picked files do. */
|
|
27
|
+
files?: File[];
|
|
28
|
+
busy: boolean;
|
|
29
|
+
error: string | undefined;
|
|
30
|
+
}
|
|
31
|
+
/** What the signed-in user may do to a thread. `edit` and `delete` name a message; deleting the first one deletes the thread. */
|
|
32
|
+
type CommentThreadAction = "reply" | "resolve" | "edit" | "delete";
|
|
33
|
+
/** Whether the signed-in user may do `action`. The parts show only the controls that it allows. The server still decides. */
|
|
34
|
+
type CommentCan = (action: CommentThreadAction, target: {
|
|
35
|
+
thread: CommentThread;
|
|
36
|
+
message?: CommentMessage;
|
|
37
|
+
}) => boolean;
|
|
38
|
+
/**
|
|
39
|
+
* The permissions that the parts assume without a `can` option: a signed-in user may reply to and resolve any thread,
|
|
40
|
+
* and edit and delete their own messages. Nobody may do anything without a user.
|
|
41
|
+
*/
|
|
42
|
+
declare function defaultCommentCan(user: CommentUser | undefined): CommentCan;
|
|
43
|
+
interface UseCommentsOptions {
|
|
44
|
+
client: CommentsClient;
|
|
45
|
+
/** What the threads of this page are about. For a page, `{ kind: "page", id: location.pathname }`. */
|
|
46
|
+
subject: MaybeRefOrGetter<CommentSubject>;
|
|
47
|
+
/** The signed-in user. Defaults to `client.user`. */
|
|
48
|
+
user?: MaybeRefOrGetter<CommentUser | undefined>;
|
|
49
|
+
/** People that the app already knows, such as the ones that a server answer named. Their mentions show as chips. */
|
|
50
|
+
people?: MaybeRefOrGetter<readonly CommentUser[]>;
|
|
51
|
+
/** Where anchors are looked up. Defaults to the document. */
|
|
52
|
+
root?: MaybeRefOrGetter<ParentNode | undefined>;
|
|
53
|
+
/** The query parameter that deep-links a thread. Default `"comment"`. */
|
|
54
|
+
param?: string;
|
|
55
|
+
/** The key that toggles comment mode. Default `"c"`. `false` turns the key off. */
|
|
56
|
+
hotkey?: string | false;
|
|
57
|
+
/** Elements that anchors skip. Defaults to the comment UI. */
|
|
58
|
+
ignore?: (element: Element) => boolean;
|
|
59
|
+
/** Where the comment UI lives: the document, or the shadow root of the overlay. Composers are looked up there. Defaults to the document. */
|
|
60
|
+
uiRoot?: MaybeRefOrGetter<ParentNode | undefined>;
|
|
61
|
+
/** The URL of the page that a subject lives on, for a link to a thread. Page subjects use their id as the path. Other subjects need this, or their link is the current page. */
|
|
62
|
+
subjectUrl?: (subject: CommentSubject) => string | undefined;
|
|
63
|
+
/** Where the deep link is read. Defaults to `window.location`. */
|
|
64
|
+
location?: () => Pick<Location, "href" | "origin" | "search">;
|
|
65
|
+
/** Load the threads and listen for keys when the component mounts. Default `true`. Call `start()` yourself when `false`. */
|
|
66
|
+
autoStart?: boolean;
|
|
67
|
+
/** What the signed-in user may do, such as your app's sharing rules. Defaults to `defaultCommentCan()`. */
|
|
68
|
+
can?: CommentCan;
|
|
69
|
+
/**
|
|
70
|
+
* Which comments show on the page. Default `"all"`. Pass a ref to keep the reader's choice, such as one saved in
|
|
71
|
+
* `localStorage`: the state reads and writes it.
|
|
72
|
+
*/
|
|
73
|
+
visibility?: CommentVisibility | Ref<CommentVisibility>;
|
|
74
|
+
/** How long a comment or reply that was just sent shows while comments are hidden. Default `2500`. */
|
|
75
|
+
flashMs?: number;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* The comments and replies that the client's outbox saved and did not send yet. Without the `outbox` option of
|
|
79
|
+
* `createCommentsClient()`, it is empty and its actions do nothing.
|
|
80
|
+
*/
|
|
81
|
+
interface CommentsOutboxState {
|
|
82
|
+
/** `true` when the client has an outbox. */
|
|
83
|
+
readonly enabled: boolean;
|
|
84
|
+
/** The entries that wait or go out now, in order. */
|
|
85
|
+
readonly queued: ComputedRef<readonly CommentsOutboxEntry[]>;
|
|
86
|
+
/** The entries that the server refused. */
|
|
87
|
+
readonly failures: ComputedRef<readonly CommentsOutboxEntry[]>;
|
|
88
|
+
/** Whether the thread, or one of its messages, is waiting or refused. `undefined` when the server has it. */
|
|
89
|
+
delivery: (threadId: string, messageId?: string) => CommentDelivery | undefined;
|
|
90
|
+
/** Sends the waiting comment or reply `id` now. Without `id`, the whole queue tries again, such as after a sign-in. */
|
|
91
|
+
retry: (id?: string) => Promise<void>;
|
|
92
|
+
/** Removes the waiting comment or reply. `false` while it is on its way. */
|
|
93
|
+
dismiss: (id: string) => Promise<boolean>;
|
|
94
|
+
/** Changes the text of the waiting comment or reply. A refused one goes back in the queue. `false` while it is on its way. */
|
|
95
|
+
edit: (id: string, body: string, mentions?: string[]) => Promise<boolean>;
|
|
96
|
+
}
|
|
97
|
+
interface CommentsState {
|
|
98
|
+
readonly client: CommentsClient;
|
|
99
|
+
readonly subject: ComputedRef<CommentSubject>;
|
|
100
|
+
readonly user: ComputedRef<CommentUser | undefined>;
|
|
101
|
+
/** Whether the signed-in user may reply, resolve, edit, or delete. Always false without a user. */
|
|
102
|
+
readonly can: CommentCan;
|
|
103
|
+
/** Every person the state knows: the user, the authors of threads, the people that `users()` found, and `people`. Mentions get their names here. */
|
|
104
|
+
readonly people: ComputedRef<CommentUser[]>;
|
|
105
|
+
/** Comment mode: a click drops a pin. */
|
|
106
|
+
readonly active: Ref<boolean>;
|
|
107
|
+
readonly scope: Ref<CommentScope>;
|
|
108
|
+
readonly filters: CommentFilterState;
|
|
109
|
+
readonly status: Ref<CommentsClientStatus>;
|
|
110
|
+
/** Every thread that the client holds, with the ones that wait in the outbox. */
|
|
111
|
+
readonly threads: ShallowRef<readonly CommentThread[]>;
|
|
112
|
+
readonly outbox: CommentsOutboxState;
|
|
113
|
+
/** The threads of this page that pass the filters. They get pins. */
|
|
114
|
+
readonly pageThreads: ComputedRef<CommentThread[]>;
|
|
115
|
+
/** The threads that pass the filters, for the page or the whole site as `scope` says. The list shows them. */
|
|
116
|
+
readonly listed: ComputedRef<CommentThread[]>;
|
|
117
|
+
readonly counts: ComputedRef<{
|
|
118
|
+
open: number;
|
|
119
|
+
resolved: number;
|
|
120
|
+
}>;
|
|
121
|
+
/** Pin positions by thread id, and `"draft"` for the comment being written. */
|
|
122
|
+
readonly positions: ShallowRef<ReadonlyMap<string, AnchorPosition>>;
|
|
123
|
+
readonly draft: Ref<CommentDraft | null>;
|
|
124
|
+
readonly openId: Ref<string | null>;
|
|
125
|
+
readonly hoverId: Ref<string | null>;
|
|
126
|
+
readonly opened: ComputedRef<CommentThread | undefined>;
|
|
127
|
+
readonly listOpen: Ref<boolean>;
|
|
128
|
+
/** Goes up when a composer with text stopped a click or a key. The composer shakes by itself. */
|
|
129
|
+
readonly blocked: Ref<number>;
|
|
130
|
+
/** Which comments show. Writing or opening a comment never changes it. */
|
|
131
|
+
readonly visibility: Ref<CommentVisibility>;
|
|
132
|
+
/**
|
|
133
|
+
* The ids of the threads of this page that get a pin or a mark: all of them, or while comments are hidden, the open
|
|
134
|
+
* thread and each one that was just sent or replied to. The draft always shows.
|
|
135
|
+
*/
|
|
136
|
+
readonly shown: ComputedRef<ReadonlySet<string>>;
|
|
137
|
+
/** The ids of threads that stopped showing while comments are hidden, for 180 ms. Their marks play the pop-out. */
|
|
138
|
+
readonly leaving: ComputedRef<ReadonlySet<string>>;
|
|
139
|
+
/** Keeps page marks visible without opening a popover. Call the returned release function when the panel closes. */
|
|
140
|
+
retainMark: (id: string) => () => void;
|
|
141
|
+
isShown: (id: string) => boolean;
|
|
142
|
+
/** Shows the thread for `flashMs` while comments are hidden. `send()`, `create()`, and `reply()` call it. */
|
|
143
|
+
flash: (id: string) => void;
|
|
144
|
+
enter: () => void;
|
|
145
|
+
exit: () => void;
|
|
146
|
+
toggle: () => void;
|
|
147
|
+
/**
|
|
148
|
+
* Starts a draft on a point, an element, a selection, or `"page"`. Ends an empty draft first, and keeps one with text.
|
|
149
|
+
* A pin has no number until the server assigns one. `files` start in its composer, such as a screenshot of the area.
|
|
150
|
+
*/
|
|
151
|
+
startDraft: (target: AnchorTarget, options?: CreateAnchorOptions & {
|
|
152
|
+
files?: File[];
|
|
153
|
+
}) => void;
|
|
154
|
+
cancelDraft: () => void;
|
|
155
|
+
/**
|
|
156
|
+
* Sends the draft. Resolves with the new thread, or `undefined` when there is nothing to send or the send failed. With
|
|
157
|
+
* an outbox it resolves, and the draft closes, once the comment is saved, before the server answers. `files` go with
|
|
158
|
+
* the comment, for a client with an outbox.
|
|
159
|
+
*/
|
|
160
|
+
send: (options?: {
|
|
161
|
+
files?: Blob[];
|
|
162
|
+
}) => Promise<CommentThread | undefined>;
|
|
163
|
+
open: (thread: CommentThread | string, options?: {
|
|
164
|
+
scroll?: boolean;
|
|
165
|
+
}) => void;
|
|
166
|
+
/** Closes the thread, returning false when unsent text prevents closing or navigation. */
|
|
167
|
+
close: () => boolean;
|
|
168
|
+
/** Starts a thread on the subject. The anchor defaults to the whole page. */
|
|
169
|
+
create: (input: {
|
|
170
|
+
body: string;
|
|
171
|
+
mentions?: string[];
|
|
172
|
+
attachments?: string[];
|
|
173
|
+
files?: Blob[];
|
|
174
|
+
anchor?: CommentAnchor;
|
|
175
|
+
}) => Promise<CommentThread>;
|
|
176
|
+
reply: (threadId: string, body: string, mentions?: string[], attachments?: string[], files?: Blob[]) => Promise<CommentThread>;
|
|
177
|
+
edit: (threadId: string, messageId: string, body: string, mentions?: string[]) => Promise<CommentThread>;
|
|
178
|
+
remove: (threadId: string, messageId?: string) => Promise<CommentThread | null>;
|
|
179
|
+
resolve: (threadId: string) => Promise<CommentThread>;
|
|
180
|
+
reopen: (threadId: string) => Promise<CommentThread>;
|
|
181
|
+
/** Finds people for a reply or edit in `threadId`, or for a new thread on the current subject. */
|
|
182
|
+
users: (query: string, threadId?: string) => Promise<CommentUser[]>;
|
|
183
|
+
/** The URL that opens the thread: its page with `?comment=<n>`. */
|
|
184
|
+
link: (thread: CommentThread) => string;
|
|
185
|
+
/** Measures every pin again. The state does it on scroll, resize, and DOM changes. */
|
|
186
|
+
measure: () => void;
|
|
187
|
+
/** Loads the threads and starts the key, layout, and deep-link handling. Returns a function that stops them. */
|
|
188
|
+
start: () => () => void;
|
|
189
|
+
}
|
|
190
|
+
declare const draftPositionKey = "draft";
|
|
191
|
+
/** The comment state of one page. The styled parts, `CommentLayer` and the others, are built on it. */
|
|
192
|
+
declare function useComments(options: UseCommentsOptions): CommentsState;
|
|
193
|
+
/** Makes `state` the one that `CommentToolbar`, `CommentList`, and `CommentFilters` use inside this component tree. */
|
|
194
|
+
declare function provideComments(state: CommentsState): void;
|
|
195
|
+
/** The state that a comment part uses: the one you pass, else the one of the nearest `CommentLayer` or `provideComments()`. Call it in `setup()`. */
|
|
196
|
+
declare function useCommentsContext(state?: CommentsState): CommentsState;
|
|
197
|
+
//#endregion
|
|
198
|
+
export { CommentThreadAction as a, UseCommentsOptions as c, provideComments as d, useComments as f, CommentScope as i, defaultCommentCan as l, CommentDraft as n, CommentsOutboxState as o, useCommentsContext as p, CommentFilterState as r, CommentsState as s, CommentCan as t, draftPositionKey as u };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { inject, onBeforeUnmount, onMounted } from "vue";
|
|
2
|
+
//#region src/internal/comment-outside.ts
|
|
3
|
+
const consumedPointerEvents = /* @__PURE__ */ new WeakSet();
|
|
4
|
+
function swallowNextClick() {
|
|
5
|
+
const stop = (event) => {
|
|
6
|
+
event.stopPropagation();
|
|
7
|
+
event.preventDefault();
|
|
8
|
+
cleanup();
|
|
9
|
+
};
|
|
10
|
+
const cleanup = () => {
|
|
11
|
+
document.removeEventListener("click", stop, true);
|
|
12
|
+
document.removeEventListener("pointerdown", cleanup, true);
|
|
13
|
+
};
|
|
14
|
+
document.addEventListener("click", stop, true);
|
|
15
|
+
document.addEventListener("pointerdown", cleanup, true);
|
|
16
|
+
}
|
|
17
|
+
function useDocumentPointerDown(handler) {
|
|
18
|
+
onMounted(() => document.addEventListener("pointerdown", handler, true));
|
|
19
|
+
onBeforeUnmount(() => document.removeEventListener("pointerdown", handler, true));
|
|
20
|
+
}
|
|
21
|
+
const shakeEventName = "comments:shake";
|
|
22
|
+
const dirtySelector = "[data-slot='comment-composer'][data-dirty='true']";
|
|
23
|
+
function hasDirtyComposer(root = document) {
|
|
24
|
+
return root.querySelector(dirtySelector) !== null;
|
|
25
|
+
}
|
|
26
|
+
function shakeDirtyComposers(root = document, escape = false) {
|
|
27
|
+
const dirty = [...root.querySelectorAll(dirtySelector)];
|
|
28
|
+
for (const composer of dirty) composer.dispatchEvent(new CustomEvent(shakeEventName, { detail: { escape } }));
|
|
29
|
+
return dirty.length > 0;
|
|
30
|
+
}
|
|
31
|
+
const pathOf = (event) => event.composedPath().filter((node) => node instanceof Element);
|
|
32
|
+
//#endregion
|
|
33
|
+
//#region src/internal/comments-context.ts
|
|
34
|
+
const commentsKey = Symbol("ViteHubComments");
|
|
35
|
+
/** The state of the nearest `CommentLayer`, `CommentPanel`, or `provideComments()`, if there is one. Call it in `setup()`. */
|
|
36
|
+
const injectComments = () => inject(commentsKey, null) ?? void 0;
|
|
37
|
+
//#endregion
|
|
38
|
+
export { pathOf as a, swallowNextClick as c, hasDirtyComposer as i, useDocumentPointerDown as l, injectComments as n, shakeDirtyComposers as o, consumedPointerEvents as r, shakeEventName as s, commentsKey as t };
|