@vite-hub/ui 0.1.0 → 0.3.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 +244 -18
- package/dist/attachments-BzTwqRTU.js +90 -0
- package/dist/choices-input-ByXJvDn1.d.ts +94 -0
- package/dist/{code-view-J4OsgEdh.js → code-view-D0bqhogi.js} +20 -4
- package/dist/colors-BghReA9C-CjF9gnmy.js +28 -0
- package/dist/comment-composer-Cc8Jvu6u.d.ts +243 -0
- package/dist/comment-composer-jYv2ULNP.js +591 -0
- package/dist/comment-layer-ClH4MLj4.d.ts +165 -0
- package/dist/comment-list-B8hphLfS.d.ts +62 -0
- package/dist/comment-marks.css +234 -0
- package/dist/comment-panel-fcKSKwLC.d.ts +197 -0
- package/dist/comment-person-CLPlW_SS.js +40 -0
- package/dist/comment-pin-CvwgRSDR.d.ts +68 -0
- package/dist/comment-row-Bbm9WwuF.js +39 -0
- package/dist/comment-thread-CoTLrdal.d.ts +368 -0
- package/dist/comment-visibility-DsVuVndP.d.ts +40 -0
- package/dist/{comments-ChNJkV1d.d.ts → comments-Bx2WRsYy.d.ts} +69 -7
- package/dist/{comments-C08J3z4e.js → comments-CkWc2Khc.js} +155 -60
- 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-Du58PlsG.js +18 -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-BD1e8vx5.d.ts} +8 -0
- package/dist/{code-view-vDM-hph-.d.ts → index-CNY1uNTh.d.ts} +14 -228
- package/dist/index.d.ts +53 -56
- package/dist/index.js +677 -25
- package/dist/markdown-editor-CMbNZOdN.js +2394 -0
- package/dist/markdown-editor-DqdZfIEn.d.ts +195 -0
- package/dist/markdown-editor.d.ts +108 -0
- package/dist/markdown-editor.js +3 -0
- package/dist/message-scroller-Bm1YWTeY.d.ts +175 -0
- package/dist/nuxt-ui-DSQFzq3s.js +38 -0
- package/dist/nuxt.d.ts +84 -2
- package/dist/nuxt.js +237 -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} +13 -14
- 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} +8 -9
- 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} +16 -24
- 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 +618 -0
- package/dist/parts/components/comment-list.d.ts +2 -0
- package/dist/parts/components/comment-list.js +167 -0
- package/dist/parts/components/comment-panel.d.ts +2 -0
- package/dist/parts/components/comment-panel.js +299 -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-thread.d.ts +2 -0
- package/dist/parts/components/comment-thread.js +571 -0
- package/dist/parts/components/comments.d.ts +7 -0
- package/dist/parts/components/comments.js +8 -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} +5 -6
- 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} +54 -11
- 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} +10 -11
- 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-xgBL6DO7.js} +209 -86
- 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 +2465 -594
- 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-Dyr6CfBW.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 +136 -150
- 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-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
|
@@ -0,0 +1,591 @@
|
|
|
1
|
+
import { AvatarStack } from "./parts/components/avatar-stack.js";
|
|
2
|
+
import { a as pathOf, c as swallowNextClick, l as useDocumentPointerDown, n as injectComments, r as consumedPointerEvents, s as shakeEventName } from "./comments-context-C2lOZyQ5.js";
|
|
3
|
+
import { i as toPerson, t as displayName } from "./comment-person-CLPlW_SS.js";
|
|
4
|
+
import { i as matchesAccept } from "./attachments-BzTwqRTU.js";
|
|
5
|
+
import { PromptInput } from "./parts/components/prompt-input.js";
|
|
6
|
+
import { computed, defineComponent, h, nextTick, onBeforeUnmount, onMounted, ref, useId, watch } from "vue";
|
|
7
|
+
import { foldName } from "@vite-hub/comments/client";
|
|
8
|
+
//#region src/internal/comment-mentions.ts
|
|
9
|
+
/** The tag of a mention chip in a rendered message. */
|
|
10
|
+
const mentionTag = "comment-mention";
|
|
11
|
+
/** A character that may stand before the `@` of a mention: the start of the text, a space, or an opening mark. */
|
|
12
|
+
const mentionLead = /[\s([{"'“]/u;
|
|
13
|
+
/** The `@…` at the caret: where its `@` sits and the words after it. Names have spaces, so the query may too. */
|
|
14
|
+
function mentionQuery(text, caret) {
|
|
15
|
+
const before = text.slice(0, caret);
|
|
16
|
+
const start = before.lastIndexOf("@");
|
|
17
|
+
if (start < 0 || start > 0 && !mentionLead.test(before[start - 1])) return void 0;
|
|
18
|
+
const query = before.slice(start + 1);
|
|
19
|
+
if (query.length > 40 || /^\s|\n|\s{2}|@/u.test(query)) return void 0;
|
|
20
|
+
return {
|
|
21
|
+
start,
|
|
22
|
+
query
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* People whose name starts with the query, then people with a later word that starts with it. People of the
|
|
27
|
+
* conversation come first in each group. A name that matches neither way is left out, so a finished `@Ana Ruiz `
|
|
28
|
+
* does not open the menu again.
|
|
29
|
+
*/
|
|
30
|
+
function rankPeople(people, query, options = {}) {
|
|
31
|
+
const q = foldName(query);
|
|
32
|
+
const participants = new Set(options.participants);
|
|
33
|
+
const seen = /* @__PURE__ */ new Set();
|
|
34
|
+
const groups = [
|
|
35
|
+
[],
|
|
36
|
+
[],
|
|
37
|
+
[],
|
|
38
|
+
[]
|
|
39
|
+
];
|
|
40
|
+
for (const person of people) {
|
|
41
|
+
if (person.id === options.exclude || seen.has(person.id)) continue;
|
|
42
|
+
seen.add(person.id);
|
|
43
|
+
const name = foldName(displayName(person));
|
|
44
|
+
const tier = name.startsWith(q) ? 0 : name.split(/\s+/u).some((word, index) => index > 0 && word.startsWith(q)) ? 1 : void 0;
|
|
45
|
+
if (tier !== void 0) groups[tier * 2 + (participants.has(person.id) ? 0 : 1)].push(person);
|
|
46
|
+
}
|
|
47
|
+
return groups.flat().slice(0, options.limit ?? 6);
|
|
48
|
+
}
|
|
49
|
+
const escape = (text) => text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
50
|
+
const pluginPeople = /* @__PURE__ */ new WeakMap();
|
|
51
|
+
/**
|
|
52
|
+
* A Markdown plugin that turns `@Name` of each given person into a `comment-mention` element. It reads text only, so
|
|
53
|
+
* code spans, code blocks, and link targets keep their `@`. Longer names win, so `@Ana Ruiz` is not cut to `@Ana`, and
|
|
54
|
+
* case does not matter, as in the composer.
|
|
55
|
+
*/
|
|
56
|
+
function mentionPlugin(people) {
|
|
57
|
+
const known = [...new Map(people.filter((person) => person.name).map((person) => [person.name, person])).values()].sort((a, b) => b.name.length - a.name.length);
|
|
58
|
+
const pattern = known.length > 0 ? new RegExp(`@(${known.map((person) => escape(person.name)).join("|")})(?![\\p{L}\\p{N}_])`, "iuy") : void 0;
|
|
59
|
+
const plugin = {
|
|
60
|
+
name: "vitehub-comment-mentions",
|
|
61
|
+
markdownItPlugins: [(md) => {
|
|
62
|
+
md.inline.ruler.before("text", "vitehub_comment_mention", (state, silent) => {
|
|
63
|
+
if (!pattern || state.src[state.pos] !== "@") return false;
|
|
64
|
+
const lead = state.src[state.pos - 1];
|
|
65
|
+
if (lead !== void 0 && !mentionLead.test(lead)) return false;
|
|
66
|
+
pattern.lastIndex = state.pos;
|
|
67
|
+
const match = pattern.exec(state.src);
|
|
68
|
+
if (!match) return false;
|
|
69
|
+
const typed = match[1].toLowerCase();
|
|
70
|
+
const person = known.find((entry) => entry.name.toLowerCase() === typed);
|
|
71
|
+
if (!person) return false;
|
|
72
|
+
if (!silent) {
|
|
73
|
+
const token = state.push("mdc_inline_component", mentionTag, 0);
|
|
74
|
+
token.attrs = [["user", person.id], ["label", person.name]];
|
|
75
|
+
}
|
|
76
|
+
state.pos += match[0].length;
|
|
77
|
+
return true;
|
|
78
|
+
});
|
|
79
|
+
}]
|
|
80
|
+
};
|
|
81
|
+
pluginPeople.set(plugin, known);
|
|
82
|
+
return plugin;
|
|
83
|
+
}
|
|
84
|
+
//#endregion
|
|
85
|
+
//#region src/components/comment-composer.ts
|
|
86
|
+
const emptyLineQuery = /^\S{2,}$/u;
|
|
87
|
+
const placeholders = {
|
|
88
|
+
comment: "Add a comment",
|
|
89
|
+
edit: "Edit your comment",
|
|
90
|
+
reply: "Reply"
|
|
91
|
+
};
|
|
92
|
+
/** The name of the send button. A comment on a page is sent as a comment, and an answer in a thread as a reply. */
|
|
93
|
+
const sendLabels = {
|
|
94
|
+
comment: "Comment",
|
|
95
|
+
edit: "Save",
|
|
96
|
+
reply: "Reply"
|
|
97
|
+
};
|
|
98
|
+
const labels = {
|
|
99
|
+
comment: "Comment",
|
|
100
|
+
edit: "Edit comment",
|
|
101
|
+
reply: "Reply"
|
|
102
|
+
};
|
|
103
|
+
const pastedFiles = (clipboard) => {
|
|
104
|
+
const hasText = clipboard.getData("text/plain").length > 0;
|
|
105
|
+
return Array.from(clipboard.files).filter((file) => file.type.startsWith("image/") || !hasText);
|
|
106
|
+
};
|
|
107
|
+
const escapeWindow = 2e3;
|
|
108
|
+
const CommentComposer = defineComponent({
|
|
109
|
+
name: "CommentComposer",
|
|
110
|
+
props: {
|
|
111
|
+
modelValue: {
|
|
112
|
+
default: "",
|
|
113
|
+
type: String
|
|
114
|
+
},
|
|
115
|
+
/** The ids of the people mentioned so far. */
|
|
116
|
+
mentions: {
|
|
117
|
+
default: () => [],
|
|
118
|
+
type: Array
|
|
119
|
+
},
|
|
120
|
+
/** The attached files. Use `v-model:files` to clear them after a send. Without it the composer keeps its own list. */
|
|
121
|
+
files: { type: Array },
|
|
122
|
+
/** Who writes. They are not suggested in the mention menu. */
|
|
123
|
+
user: { type: Object },
|
|
124
|
+
variant: {
|
|
125
|
+
default: "comment",
|
|
126
|
+
type: String
|
|
127
|
+
},
|
|
128
|
+
placeholder: { type: String },
|
|
129
|
+
/** A send is running. The box keeps its text and cannot send again. */
|
|
130
|
+
busy: {
|
|
131
|
+
default: false,
|
|
132
|
+
type: Boolean
|
|
133
|
+
},
|
|
134
|
+
/** Why the last send failed. */
|
|
135
|
+
error: { type: String },
|
|
136
|
+
/** Focus the box when it appears. */
|
|
137
|
+
autofocus: {
|
|
138
|
+
default: true,
|
|
139
|
+
type: Boolean
|
|
140
|
+
},
|
|
141
|
+
/** Treat a click outside as a close, or as a shake when there is text. Turn it off when the parent decides. */
|
|
142
|
+
guard: {
|
|
143
|
+
default: true,
|
|
144
|
+
type: Boolean
|
|
145
|
+
},
|
|
146
|
+
/** People whose names the text may hold, such as the authors of a thread. Only mentions of a person whose `@name` is still in the text are sent. */
|
|
147
|
+
people: {
|
|
148
|
+
default: () => [],
|
|
149
|
+
type: Array
|
|
150
|
+
},
|
|
151
|
+
/** The ids of the people in the conversation. The mention menu shows them first. */
|
|
152
|
+
participants: {
|
|
153
|
+
default: () => [],
|
|
154
|
+
type: Array
|
|
155
|
+
},
|
|
156
|
+
/** Finds people for `@mentions`. Defaults to the comments state of the nearest `CommentLayer` or `CommentPanel`, else to `people`. */
|
|
157
|
+
users: { type: Function },
|
|
158
|
+
/** Paste, drop, or pick files. An edit never has attachments. */
|
|
159
|
+
attachments: {
|
|
160
|
+
default: true,
|
|
161
|
+
type: Boolean
|
|
162
|
+
},
|
|
163
|
+
/** The file types to take, as the `accept` of a file input, such as `image/*`. */
|
|
164
|
+
accept: { type: String },
|
|
165
|
+
/** Send files without text. Default: on for a reply, off for a new comment. */
|
|
166
|
+
allowEmpty: {
|
|
167
|
+
default: void 0,
|
|
168
|
+
type: Boolean
|
|
169
|
+
},
|
|
170
|
+
/**
|
|
171
|
+
* `box` is a bordered field. `row` is one line with attach, the text and send, for a box that already sits inside a
|
|
172
|
+
* card, as the reply box of a thread and the box at the bottom of a panel do.
|
|
173
|
+
*/
|
|
174
|
+
layout: {
|
|
175
|
+
default: "box",
|
|
176
|
+
type: String
|
|
177
|
+
},
|
|
178
|
+
/** `sm` is a compact box for a small card: a shorter field, smaller buttons, and a focus edge without a halo. */
|
|
179
|
+
size: {
|
|
180
|
+
default: "md",
|
|
181
|
+
type: String
|
|
182
|
+
},
|
|
183
|
+
/**
|
|
184
|
+
* `none` is for a parent that is itself the frame, such as a bubble around a one-line box: the field draws no edge
|
|
185
|
+
* while it has the focus, so the parent shows the focus instead.
|
|
186
|
+
*/
|
|
187
|
+
frame: {
|
|
188
|
+
default: "field",
|
|
189
|
+
type: String
|
|
190
|
+
}
|
|
191
|
+
},
|
|
192
|
+
emits: [
|
|
193
|
+
"update:modelValue",
|
|
194
|
+
"update:mentions",
|
|
195
|
+
"update:files",
|
|
196
|
+
"submit",
|
|
197
|
+
"cancel"
|
|
198
|
+
],
|
|
199
|
+
slots: Object,
|
|
200
|
+
setup(props, { emit, expose, slots }) {
|
|
201
|
+
const comments = injectComments();
|
|
202
|
+
const root = ref(null);
|
|
203
|
+
const shaking = ref(null);
|
|
204
|
+
const menu = ref(null);
|
|
205
|
+
const hint = ref();
|
|
206
|
+
const dragging = ref(false);
|
|
207
|
+
const picked = /* @__PURE__ */ new Map();
|
|
208
|
+
const menuId = useId();
|
|
209
|
+
const optionId = (index) => `${menuId}-option-${index}`;
|
|
210
|
+
let timer;
|
|
211
|
+
const escaped = ref(false);
|
|
212
|
+
let escapeTimer;
|
|
213
|
+
watch(escaped, (value) => {
|
|
214
|
+
clearTimeout(escapeTimer);
|
|
215
|
+
if (value) escapeTimer = setTimeout(() => escaped.value = false, escapeWindow);
|
|
216
|
+
});
|
|
217
|
+
let lookup = 0;
|
|
218
|
+
let mentionCaret;
|
|
219
|
+
let dismissed;
|
|
220
|
+
const localFiles = ref([]);
|
|
221
|
+
const files = computed(() => props.files ?? localFiles.value);
|
|
222
|
+
watch([() => props.modelValue, files], () => escaped.value = false);
|
|
223
|
+
const attachmentsOn = computed(() => props.attachments && props.variant !== "edit");
|
|
224
|
+
const allowEmpty = computed(() => props.allowEmpty ?? props.variant === "reply");
|
|
225
|
+
const parts = /* @__PURE__ */ new WeakMap();
|
|
226
|
+
const urls = /* @__PURE__ */ new Set();
|
|
227
|
+
const partOf = (file) => {
|
|
228
|
+
let part = parts.get(file);
|
|
229
|
+
if (!part) {
|
|
230
|
+
part = {
|
|
231
|
+
filename: file.name,
|
|
232
|
+
mediaType: file.type || "application/octet-stream",
|
|
233
|
+
type: "file",
|
|
234
|
+
url: URL.createObjectURL(file)
|
|
235
|
+
};
|
|
236
|
+
parts.set(file, part);
|
|
237
|
+
urls.add(part.url);
|
|
238
|
+
}
|
|
239
|
+
return part;
|
|
240
|
+
};
|
|
241
|
+
const fileParts = computed(() => files.value.map(partOf));
|
|
242
|
+
watch(() => [...files.value], (next, previous) => {
|
|
243
|
+
for (const file of previous) {
|
|
244
|
+
const part = parts.get(file);
|
|
245
|
+
if (part && !next.includes(file)) {
|
|
246
|
+
URL.revokeObjectURL(part.url);
|
|
247
|
+
urls.delete(part.url);
|
|
248
|
+
parts.delete(file);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
function setFiles(next) {
|
|
253
|
+
if (props.busy) return;
|
|
254
|
+
localFiles.value = next;
|
|
255
|
+
hint.value = void 0;
|
|
256
|
+
emit("update:files", next);
|
|
257
|
+
}
|
|
258
|
+
function addFiles(list) {
|
|
259
|
+
if (!attachmentsOn.value) return [];
|
|
260
|
+
const accepted = Array.from(list).filter((file) => matchesAccept(file, props.accept));
|
|
261
|
+
if (accepted.length > 0) setFiles([...files.value, ...accepted]);
|
|
262
|
+
return accepted;
|
|
263
|
+
}
|
|
264
|
+
const knownPeople = computed(() => [...props.people, ...comments?.people.value ?? []]);
|
|
265
|
+
const nameOf = (id) => {
|
|
266
|
+
const person = knownPeople.value.find((entry) => entry.id === id);
|
|
267
|
+
return picked.get(id) ?? (person ? displayName(person) : void 0);
|
|
268
|
+
};
|
|
269
|
+
const search = () => {
|
|
270
|
+
if (props.users) return props.users;
|
|
271
|
+
if (comments) return comments.users;
|
|
272
|
+
return props.people.length > 0 ? async () => props.people : void 0;
|
|
273
|
+
};
|
|
274
|
+
const self = () => props.user?.id ?? comments?.user.value?.id;
|
|
275
|
+
const textarea = () => root.value?.querySelector("textarea") ?? null;
|
|
276
|
+
const hasText = () => props.modelValue.trim().length > 0;
|
|
277
|
+
const hasContent = () => hasText() || files.value.length > 0;
|
|
278
|
+
const focus = () => textarea()?.focus();
|
|
279
|
+
const multiline = ref(false);
|
|
280
|
+
let buttonsWidth = 0;
|
|
281
|
+
function measureLines() {
|
|
282
|
+
const field = textarea();
|
|
283
|
+
const group = field?.parentElement;
|
|
284
|
+
if (props.layout !== "row" || !field || !group || !props.modelValue) {
|
|
285
|
+
multiline.value = false;
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
const style = getComputedStyle(field);
|
|
289
|
+
const line = Number.parseFloat(style.lineHeight);
|
|
290
|
+
if (!(line > 0)) return;
|
|
291
|
+
if (multiline.value) {
|
|
292
|
+
field.style.boxSizing = "border-box";
|
|
293
|
+
field.style.maxWidth = `${group.clientWidth - buttonsWidth}px`;
|
|
294
|
+
} else buttonsWidth = group.clientWidth - field.offsetWidth;
|
|
295
|
+
const text = field.scrollHeight - Number.parseFloat(style.paddingTop) - Number.parseFloat(style.paddingBottom);
|
|
296
|
+
field.style.removeProperty("box-sizing");
|
|
297
|
+
field.style.removeProperty("max-width");
|
|
298
|
+
multiline.value = text > line * 1.5;
|
|
299
|
+
}
|
|
300
|
+
const lines = typeof ResizeObserver === "function" ? new ResizeObserver(() => measureLines()) : void 0;
|
|
301
|
+
watch([
|
|
302
|
+
() => props.modelValue,
|
|
303
|
+
() => props.layout,
|
|
304
|
+
() => props.size
|
|
305
|
+
], measureLines, { flush: "post" });
|
|
306
|
+
async function shake() {
|
|
307
|
+
const reduced = typeof window.matchMedia === "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
308
|
+
shaking.value = null;
|
|
309
|
+
await nextTick();
|
|
310
|
+
root.value?.offsetWidth;
|
|
311
|
+
shaking.value = reduced ? "flash" : "shake";
|
|
312
|
+
clearTimeout(timer);
|
|
313
|
+
timer = setTimeout(() => shaking.value = null, 450);
|
|
314
|
+
focus();
|
|
315
|
+
}
|
|
316
|
+
const onShake = (event) => {
|
|
317
|
+
if (event instanceof CustomEvent && event.detail?.escape === true) escaped.value = true;
|
|
318
|
+
shake();
|
|
319
|
+
};
|
|
320
|
+
onMounted(() => {
|
|
321
|
+
root.value?.addEventListener(shakeEventName, onShake);
|
|
322
|
+
const group = textarea()?.parentElement;
|
|
323
|
+
if (group) lines?.observe(group);
|
|
324
|
+
measureLines();
|
|
325
|
+
if (props.autofocus) nextTick(focus);
|
|
326
|
+
});
|
|
327
|
+
onBeforeUnmount(() => {
|
|
328
|
+
lines?.disconnect();
|
|
329
|
+
root.value?.removeEventListener(shakeEventName, onShake);
|
|
330
|
+
clearTimeout(timer);
|
|
331
|
+
clearTimeout(escapeTimer);
|
|
332
|
+
for (const url of urls) URL.revokeObjectURL(url);
|
|
333
|
+
});
|
|
334
|
+
expose({
|
|
335
|
+
focus,
|
|
336
|
+
shake
|
|
337
|
+
});
|
|
338
|
+
watch(menu, (open) => {
|
|
339
|
+
const field = textarea();
|
|
340
|
+
if (!field) return;
|
|
341
|
+
field.setAttribute("role", "combobox");
|
|
342
|
+
field.setAttribute("aria-autocomplete", "list");
|
|
343
|
+
const listed = open !== null && open.items.length > 0;
|
|
344
|
+
field.setAttribute("aria-expanded", String(listed));
|
|
345
|
+
if (listed) {
|
|
346
|
+
field.setAttribute("aria-controls", `${menuId}-list`);
|
|
347
|
+
field.setAttribute("aria-activedescendant", optionId(open.index));
|
|
348
|
+
} else {
|
|
349
|
+
field.removeAttribute("aria-controls");
|
|
350
|
+
field.removeAttribute("aria-activedescendant");
|
|
351
|
+
}
|
|
352
|
+
}, { deep: true });
|
|
353
|
+
useDocumentPointerDown((event) => {
|
|
354
|
+
if (!props.guard || !root.value || pathOf(event).includes(root.value)) return;
|
|
355
|
+
consumedPointerEvents.add(event);
|
|
356
|
+
if (hasContent()) {
|
|
357
|
+
event.stopPropagation();
|
|
358
|
+
swallowNextClick();
|
|
359
|
+
shake();
|
|
360
|
+
} else emit("cancel");
|
|
361
|
+
});
|
|
362
|
+
function checkSelection() {
|
|
363
|
+
const field = textarea();
|
|
364
|
+
if (!field || field.selectionStart === mentionCaret && field.selectionEnd === mentionCaret) return;
|
|
365
|
+
lookup++;
|
|
366
|
+
mentionCaret = void 0;
|
|
367
|
+
menu.value = null;
|
|
368
|
+
}
|
|
369
|
+
function choose(person) {
|
|
370
|
+
checkSelection();
|
|
371
|
+
const field = textarea();
|
|
372
|
+
const current = menu.value;
|
|
373
|
+
if (!field || !current) return;
|
|
374
|
+
if (field.selectionStart !== field.selectionEnd || field.value.slice(0, field.selectionStart) !== current.before) {
|
|
375
|
+
menu.value = null;
|
|
376
|
+
return;
|
|
377
|
+
}
|
|
378
|
+
const caret = field.selectionStart;
|
|
379
|
+
const insert = `@${displayName(person)} `;
|
|
380
|
+
const next = props.modelValue.slice(0, current.start) + insert + props.modelValue.slice(caret).replace(/^ /u, "");
|
|
381
|
+
picked.set(person.id, displayName(person));
|
|
382
|
+
emit("update:modelValue", next);
|
|
383
|
+
if (!props.mentions.includes(person.id)) emit("update:mentions", [...props.mentions, person.id]);
|
|
384
|
+
menu.value = null;
|
|
385
|
+
nextTick(() => {
|
|
386
|
+
const position = current.start + insert.length;
|
|
387
|
+
field.setSelectionRange(position, position);
|
|
388
|
+
field.focus();
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
async function findPeople(field) {
|
|
392
|
+
const run = ++lookup;
|
|
393
|
+
mentionCaret = field.selectionStart;
|
|
394
|
+
const find = search();
|
|
395
|
+
const before = field.value.slice(0, field.selectionStart);
|
|
396
|
+
const found = field.selectionStart === field.selectionEnd ? mentionQuery(field.value, field.selectionStart) : void 0;
|
|
397
|
+
if (found?.start !== dismissed) dismissed = void 0;
|
|
398
|
+
if (!find || !found || found.start === dismissed) {
|
|
399
|
+
menu.value = null;
|
|
400
|
+
return;
|
|
401
|
+
}
|
|
402
|
+
let results = [];
|
|
403
|
+
let failed = false;
|
|
404
|
+
try {
|
|
405
|
+
results = await find(found.query);
|
|
406
|
+
} catch (error) {
|
|
407
|
+
failed = true;
|
|
408
|
+
console.warn("[vitehub] The comment box could not load people to mention:", error);
|
|
409
|
+
}
|
|
410
|
+
const items = rankPeople(results, found.query, {
|
|
411
|
+
exclude: self(),
|
|
412
|
+
participants: props.participants
|
|
413
|
+
});
|
|
414
|
+
checkSelection();
|
|
415
|
+
if (run !== lookup || found.start === dismissed) return;
|
|
416
|
+
const sameToken = field.selectionStart === field.selectionEnd && field.value.slice(0, field.selectionStart) === before;
|
|
417
|
+
const show = items.length > 0 || emptyLineQuery.test(found.query);
|
|
418
|
+
menu.value = sameToken && show ? {
|
|
419
|
+
before,
|
|
420
|
+
failed,
|
|
421
|
+
index: 0,
|
|
422
|
+
items,
|
|
423
|
+
query: found.query,
|
|
424
|
+
start: found.start
|
|
425
|
+
} : null;
|
|
426
|
+
}
|
|
427
|
+
function submit(payload) {
|
|
428
|
+
if (props.busy) return;
|
|
429
|
+
const sent = [...files.value];
|
|
430
|
+
if (!payload.text && (sent.length === 0 || !allowEmpty.value)) {
|
|
431
|
+
if (sent.length > 0) hint.value = "Write a comment to send with the files.";
|
|
432
|
+
return;
|
|
433
|
+
}
|
|
434
|
+
const mentions = props.mentions.filter((id) => {
|
|
435
|
+
const name = nameOf(id);
|
|
436
|
+
if (name === void 0) return false;
|
|
437
|
+
const escaped = name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
438
|
+
return new RegExp(`(^|[^\\p{L}\\p{N}\\p{M}_])@${escaped}(?=$|[^\\p{L}\\p{N}\\p{M}_])`, "iu").test(payload.text);
|
|
439
|
+
});
|
|
440
|
+
emit("submit", {
|
|
441
|
+
body: payload.text,
|
|
442
|
+
files: sent,
|
|
443
|
+
mentions: [...mentions]
|
|
444
|
+
});
|
|
445
|
+
}
|
|
446
|
+
function keydown(event) {
|
|
447
|
+
if (event.isComposing) return;
|
|
448
|
+
const open = menu.value;
|
|
449
|
+
const listed = open !== null && open.items.length > 0;
|
|
450
|
+
if (listed && (event.key === "ArrowDown" || event.key === "ArrowUp")) {
|
|
451
|
+
event.preventDefault();
|
|
452
|
+
const step = event.key === "ArrowDown" ? 1 : -1;
|
|
453
|
+
open.index = (open.index + step + open.items.length) % open.items.length;
|
|
454
|
+
return;
|
|
455
|
+
}
|
|
456
|
+
if (listed && (event.key === "Enter" || event.key === "Tab") && !event.shiftKey) {
|
|
457
|
+
event.preventDefault();
|
|
458
|
+
event.stopPropagation();
|
|
459
|
+
choose(open.items[open.index]);
|
|
460
|
+
return;
|
|
461
|
+
}
|
|
462
|
+
if (event.key !== "Escape") return;
|
|
463
|
+
event.preventDefault();
|
|
464
|
+
event.stopPropagation();
|
|
465
|
+
if (event.repeat) return;
|
|
466
|
+
if (open) {
|
|
467
|
+
lookup++;
|
|
468
|
+
dismissed = open.start;
|
|
469
|
+
menu.value = null;
|
|
470
|
+
} else if (hasContent() && !escaped.value) {
|
|
471
|
+
escaped.value = true;
|
|
472
|
+
shake();
|
|
473
|
+
} else discard();
|
|
474
|
+
}
|
|
475
|
+
async function discard() {
|
|
476
|
+
if (props.busy) return;
|
|
477
|
+
escaped.value = false;
|
|
478
|
+
if (hasContent()) {
|
|
479
|
+
emit("update:modelValue", "");
|
|
480
|
+
emit("update:mentions", []);
|
|
481
|
+
setFiles([]);
|
|
482
|
+
await nextTick();
|
|
483
|
+
}
|
|
484
|
+
emit("cancel");
|
|
485
|
+
}
|
|
486
|
+
const hasFiles = (event) => attachmentsOn.value && (event.dataTransfer?.types.includes("Files") ?? false);
|
|
487
|
+
return () => h("div", {
|
|
488
|
+
"data-busy": props.busy ? "true" : void 0,
|
|
489
|
+
"data-dirty": hasContent() ? "true" : void 0,
|
|
490
|
+
"data-dragging": dragging.value ? "true" : void 0,
|
|
491
|
+
"data-frame": props.frame,
|
|
492
|
+
"data-layout": props.layout,
|
|
493
|
+
"data-multiline": multiline.value ? "true" : void 0,
|
|
494
|
+
"data-shake": shaking.value ?? void 0,
|
|
495
|
+
"data-size": props.size,
|
|
496
|
+
"data-slot": "comment-composer",
|
|
497
|
+
"data-variant": props.variant,
|
|
498
|
+
onKeydownCapture: keydown,
|
|
499
|
+
onKeyupCapture: checkSelection,
|
|
500
|
+
onClickCapture: checkSelection,
|
|
501
|
+
onSelectCapture: checkSelection,
|
|
502
|
+
onInputCapture: (event) => {
|
|
503
|
+
if (event.target instanceof HTMLTextAreaElement) findPeople(event.target);
|
|
504
|
+
},
|
|
505
|
+
onPasteCapture: (event) => {
|
|
506
|
+
if (!attachmentsOn.value || !event.clipboardData) return;
|
|
507
|
+
if (pastedFiles(event.clipboardData).some((file) => matchesAccept(file, props.accept))) event.preventDefault();
|
|
508
|
+
},
|
|
509
|
+
onDragover: (event) => {
|
|
510
|
+
if (!hasFiles(event)) return;
|
|
511
|
+
event.preventDefault();
|
|
512
|
+
dragging.value = true;
|
|
513
|
+
},
|
|
514
|
+
onDragleave: (event) => {
|
|
515
|
+
if (!(event.relatedTarget instanceof Node) || !root.value?.contains(event.relatedTarget)) dragging.value = false;
|
|
516
|
+
},
|
|
517
|
+
onDrop: (event) => {
|
|
518
|
+
dragging.value = false;
|
|
519
|
+
if (!hasFiles(event)) return;
|
|
520
|
+
event.preventDefault();
|
|
521
|
+
addFiles(event.dataTransfer?.files ?? []);
|
|
522
|
+
focus();
|
|
523
|
+
},
|
|
524
|
+
ref: root
|
|
525
|
+
}, [h("div", { "data-slot": "comment-composer-box" }, [
|
|
526
|
+
slots.extra ? h("div", { "data-slot": "comment-composer-extra" }, slots.extra()) : null,
|
|
527
|
+
h(PromptInput, {
|
|
528
|
+
accept: props.accept,
|
|
529
|
+
"aria-label": labels[props.variant],
|
|
530
|
+
attachments: attachmentsOn.value,
|
|
531
|
+
attachVariant: props.layout === "row" ? "ghost" : "outline",
|
|
532
|
+
files: fileParts.value,
|
|
533
|
+
filesDisabled: props.busy,
|
|
534
|
+
readonly: props.busy,
|
|
535
|
+
filterFiles: (list) => {
|
|
536
|
+
addFiles(list);
|
|
537
|
+
return [];
|
|
538
|
+
},
|
|
539
|
+
modelValue: props.modelValue,
|
|
540
|
+
placeholder: props.placeholder ?? placeholders[props.variant],
|
|
541
|
+
submitLabel: sendLabels[props.variant],
|
|
542
|
+
onSubmit: submit,
|
|
543
|
+
"onUpdate:files": (next) => setFiles(files.value.filter((file) => next.includes(partOf(file)))),
|
|
544
|
+
"onUpdate:modelValue": (value) => emit("update:modelValue", value)
|
|
545
|
+
}),
|
|
546
|
+
menu.value && menu.value.items.length === 0 ? h("div", {
|
|
547
|
+
"data-slot": "comment-composer-mentions",
|
|
548
|
+
"data-state": menu.value.failed ? "error" : "empty",
|
|
549
|
+
role: "status"
|
|
550
|
+
}, h("p", { "data-slot": "comment-composer-mention-empty" }, slots["mention-empty"]?.({
|
|
551
|
+
failed: menu.value.failed,
|
|
552
|
+
query: menu.value.query
|
|
553
|
+
}) ?? (menu.value.failed ? "Could not load people." : "No one by that name can be mentioned here."))) : menu.value ? h("ul", {
|
|
554
|
+
"aria-label": "People",
|
|
555
|
+
"data-slot": "comment-composer-mentions",
|
|
556
|
+
id: `${menuId}-list`,
|
|
557
|
+
role: "listbox"
|
|
558
|
+
}, menu.value.items.map((person, index) => {
|
|
559
|
+
const active = index === menu.value?.index;
|
|
560
|
+
return h("li", {
|
|
561
|
+
"aria-selected": String(active),
|
|
562
|
+
"data-slot": "comment-composer-mention",
|
|
563
|
+
id: optionId(index),
|
|
564
|
+
key: person.id,
|
|
565
|
+
onMousedown: (event) => {
|
|
566
|
+
event.preventDefault();
|
|
567
|
+
choose(person);
|
|
568
|
+
},
|
|
569
|
+
role: "option"
|
|
570
|
+
}, slots["mention-item"]?.({
|
|
571
|
+
active,
|
|
572
|
+
person
|
|
573
|
+
}) ?? [h(AvatarStack, {
|
|
574
|
+
"aria-hidden": "true",
|
|
575
|
+
people: [toPerson(person)],
|
|
576
|
+
size: "sm"
|
|
577
|
+
}), h("span", { "data-slot": "comment-composer-mention-name" }, displayName(person))]);
|
|
578
|
+
})) : null,
|
|
579
|
+
props.error ?? hint.value ? h("p", {
|
|
580
|
+
"data-slot": "comment-composer-error",
|
|
581
|
+
role: "alert"
|
|
582
|
+
}, props.error ?? hint.value) : null,
|
|
583
|
+
h("p", {
|
|
584
|
+
"aria-live": "polite",
|
|
585
|
+
"data-slot": "comment-composer-status"
|
|
586
|
+
}, escaped.value ? "Press Esc again to discard." : "")
|
|
587
|
+
])]);
|
|
588
|
+
}
|
|
589
|
+
});
|
|
590
|
+
//#endregion
|
|
591
|
+
export { mentionPlugin as n, mentionTag as r, CommentComposer as t };
|