@tldraw/commenting 0.0.0-bootstrap → 5.3.0-canary.04044ed9e96d
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 +0 -2
- package/commenting.css +1152 -350
- package/dist-cjs/canvas/anchor-lifecycle.js +148 -0
- package/dist-cjs/canvas/anchor-lifecycle.js.map +7 -0
- package/dist-cjs/{ui/avatar.js → canvas/canvas-events.js} +14 -22
- package/dist-cjs/canvas/canvas-events.js.map +7 -0
- package/dist-cjs/canvas/cluster-badge.js +121 -0
- package/dist-cjs/canvas/cluster-badge.js.map +7 -0
- package/dist-cjs/canvas/cluster-fade.js +85 -0
- package/dist-cjs/canvas/cluster-fade.js.map +7 -0
- package/dist-cjs/canvas/cluster-input.js +53 -3
- package/dist-cjs/canvas/cluster-input.js.map +2 -2
- package/dist-cjs/canvas/cluster-model.js +252 -0
- package/dist-cjs/canvas/cluster-model.js.map +7 -0
- package/dist-cjs/canvas/comment-body.js +1 -1
- package/dist-cjs/canvas/comment-body.js.map +2 -2
- package/dist-cjs/canvas/comment-drafts.js +54 -0
- package/dist-cjs/canvas/comment-drafts.js.map +7 -0
- package/dist-cjs/canvas/comment-mutations.js +152 -0
- package/dist-cjs/canvas/comment-mutations.js.map +7 -0
- package/dist-cjs/canvas/comment-reactions.js +160 -0
- package/dist-cjs/canvas/comment-reactions.js.map +7 -0
- package/dist-cjs/canvas/comment-render.js +9 -6
- package/dist-cjs/canvas/comment-render.js.map +2 -2
- package/dist-cjs/canvas/comment-store.js +19 -9
- package/dist-cjs/canvas/comment-store.js.map +2 -2
- package/dist-cjs/canvas/comment-tool.js +63 -14
- package/dist-cjs/canvas/comment-tool.js.map +2 -2
- package/dist-cjs/canvas/comments-filter-menu.js +17 -37
- package/dist-cjs/canvas/comments-filter-menu.js.map +2 -2
- package/dist-cjs/canvas/comments-overflow-menu.js +25 -22
- package/dist-cjs/canvas/comments-overflow-menu.js.map +2 -2
- package/dist-cjs/canvas/comments-overlay.js +151 -989
- package/dist-cjs/canvas/comments-overlay.js.map +3 -3
- package/dist-cjs/canvas/comments-sidebar.js +49 -41
- package/dist-cjs/canvas/comments-sidebar.js.map +2 -2
- package/dist-cjs/canvas/comments-visibility-toggle.js +45 -0
- package/dist-cjs/canvas/comments-visibility-toggle.js.map +7 -0
- package/dist-cjs/canvas/context.js +17 -0
- package/dist-cjs/canvas/context.js.map +7 -0
- package/dist-cjs/canvas/hooks.js +28 -3
- package/dist-cjs/canvas/hooks.js.map +2 -2
- package/dist-cjs/canvas/license.js.map +1 -1
- package/dist-cjs/canvas/mobile-placement.js +91 -0
- package/dist-cjs/canvas/mobile-placement.js.map +7 -0
- package/dist-cjs/canvas/options.js +57 -2
- package/dist-cjs/canvas/options.js.map +2 -2
- package/dist-cjs/canvas/pending-composer.js +134 -0
- package/dist-cjs/canvas/pending-composer.js.map +7 -0
- package/dist-cjs/canvas/pin-stacking.js +81 -0
- package/dist-cjs/canvas/pin-stacking.js.map +7 -0
- package/dist-cjs/canvas/region-box.js +113 -0
- package/dist-cjs/canvas/region-box.js.map +7 -0
- package/dist-cjs/canvas/sidebar-filters.js +2 -2
- package/dist-cjs/canvas/sidebar-filters.js.map +2 -2
- package/dist-cjs/canvas/state.js +28 -14
- package/dist-cjs/canvas/state.js.map +2 -2
- package/dist-cjs/canvas/thread-pin.js +304 -0
- package/dist-cjs/canvas/thread-pin.js.map +7 -0
- package/dist-cjs/canvas/thread-preview.js +177 -0
- package/dist-cjs/canvas/thread-preview.js.map +7 -0
- package/dist-cjs/canvas/thread-stack.js +199 -0
- package/dist-cjs/canvas/thread-stack.js.map +7 -0
- package/dist-cjs/canvas/thread-state.js +82 -21
- package/dist-cjs/canvas/thread-state.js.map +2 -2
- package/dist-cjs/canvas/thread-view.js +450 -0
- package/dist-cjs/canvas/thread-view.js.map +7 -0
- package/dist-cjs/clustering/computeClusterTable.js +6 -6
- package/dist-cjs/clustering/computeClusterTable.js.map +2 -2
- package/dist-cjs/clustering/replay.js +89 -22
- package/dist-cjs/clustering/replay.js.map +3 -3
- package/dist-cjs/clustering/runtime.js +126 -7
- package/dist-cjs/clustering/runtime.js.map +2 -2
- package/dist-cjs/clustering/types.js.map +1 -1
- package/dist-cjs/index.d.ts +904 -353
- package/dist-cjs/index.js +52 -28
- package/dist-cjs/index.js.map +2 -2
- package/dist-cjs/ui/byline.js +10 -6
- package/dist-cjs/ui/byline.js.map +2 -2
- package/dist-cjs/ui/comment-card.js +15 -8
- package/dist-cjs/ui/comment-card.js.map +2 -2
- package/dist-cjs/ui/comment-composer.js +124 -39
- package/dist-cjs/ui/comment-composer.js.map +2 -2
- package/dist-cjs/ui/comment-pin.js +11 -2
- package/dist-cjs/ui/comment-pin.js.map +2 -2
- package/dist-cjs/ui/comment-thread.js +9 -7
- package/dist-cjs/ui/comment-thread.js.map +2 -2
- package/dist-cjs/ui/comments-list.js +39 -40
- package/dist-cjs/ui/comments-list.js.map +2 -2
- package/dist-cjs/ui/count-badge.js +3 -2
- package/dist-cjs/ui/count-badge.js.map +2 -2
- package/dist-cjs/ui/emoji-picker.js +54 -0
- package/dist-cjs/ui/emoji-picker.js.map +7 -0
- package/dist-cjs/ui/empty-state.js +3 -3
- package/dist-cjs/ui/empty-state.js.map +2 -2
- package/dist-cjs/ui/format-time.js +16 -1
- package/dist-cjs/ui/format-time.js.map +2 -2
- package/dist-cjs/ui/icons.js +115 -0
- package/dist-cjs/ui/icons.js.map +7 -0
- package/dist-cjs/ui/reaction-picker.js +71 -0
- package/dist-cjs/ui/reaction-picker.js.map +7 -0
- package/dist-cjs/ui/reaction.js +58 -6
- package/dist-cjs/ui/reaction.js.map +2 -2
- package/dist-cjs/ui/reactions.js +20 -7
- package/dist-cjs/ui/reactions.js.map +2 -2
- package/dist-cjs/ui/{mention.js → reply-count.js} +9 -11
- package/dist-cjs/ui/reply-count.js.map +7 -0
- package/dist-cjs/ui/send-button.js +13 -1
- package/dist-cjs/ui/send-button.js.map +2 -2
- package/dist-cjs/ui/{comment-text.js → visual-viewport.js} +12 -9
- package/dist-cjs/ui/visual-viewport.js.map +7 -0
- package/dist-esm/canvas/anchor-lifecycle.mjs +128 -0
- package/dist-esm/canvas/anchor-lifecycle.mjs.map +7 -0
- package/dist-esm/canvas/canvas-events.mjs +15 -0
- package/dist-esm/canvas/canvas-events.mjs.map +7 -0
- package/dist-esm/canvas/cluster-badge.mjs +106 -0
- package/dist-esm/canvas/cluster-badge.mjs.map +7 -0
- package/dist-esm/canvas/cluster-fade.mjs +65 -0
- package/dist-esm/canvas/cluster-fade.mjs.map +7 -0
- package/dist-esm/canvas/cluster-input.mjs +54 -4
- package/dist-esm/canvas/cluster-input.mjs.map +2 -2
- package/dist-esm/canvas/cluster-model.mjs +236 -0
- package/dist-esm/canvas/cluster-model.mjs.map +7 -0
- package/dist-esm/canvas/comment-body.mjs +1 -1
- package/dist-esm/canvas/comment-body.mjs.map +2 -2
- package/dist-esm/canvas/comment-drafts.mjs +34 -0
- package/dist-esm/canvas/comment-drafts.mjs.map +7 -0
- package/dist-esm/canvas/comment-mutations.mjs +132 -0
- package/dist-esm/canvas/comment-mutations.mjs.map +7 -0
- package/dist-esm/canvas/comment-reactions.mjs +145 -0
- package/dist-esm/canvas/comment-reactions.mjs.map +7 -0
- package/dist-esm/canvas/comment-render.mjs +10 -7
- package/dist-esm/canvas/comment-render.mjs.map +2 -2
- package/dist-esm/canvas/comment-store.mjs +19 -9
- package/dist-esm/canvas/comment-store.mjs.map +2 -2
- package/dist-esm/canvas/comment-tool.mjs +66 -17
- package/dist-esm/canvas/comment-tool.mjs.map +2 -2
- package/dist-esm/canvas/comments-filter-menu.mjs +17 -36
- package/dist-esm/canvas/comments-filter-menu.mjs.map +2 -2
- package/dist-esm/canvas/comments-overflow-menu.mjs +27 -22
- package/dist-esm/canvas/comments-overflow-menu.mjs.map +2 -2
- package/dist-esm/canvas/comments-overlay.mjs +157 -1010
- package/dist-esm/canvas/comments-overlay.mjs.map +3 -3
- package/dist-esm/canvas/comments-sidebar.mjs +53 -46
- package/dist-esm/canvas/comments-sidebar.mjs.map +2 -2
- package/dist-esm/canvas/comments-visibility-toggle.mjs +25 -0
- package/dist-esm/canvas/comments-visibility-toggle.mjs.map +7 -0
- package/dist-esm/canvas/context.mjs +1 -0
- package/dist-esm/canvas/context.mjs.map +7 -0
- package/dist-esm/canvas/hooks.mjs +35 -5
- package/dist-esm/canvas/hooks.mjs.map +2 -2
- package/dist-esm/canvas/license.mjs.map +1 -1
- package/dist-esm/canvas/mobile-placement.mjs +71 -0
- package/dist-esm/canvas/mobile-placement.mjs.map +7 -0
- package/dist-esm/canvas/options.mjs +59 -3
- package/dist-esm/canvas/options.mjs.map +2 -2
- package/dist-esm/canvas/pending-composer.mjs +126 -0
- package/dist-esm/canvas/pending-composer.mjs.map +7 -0
- package/dist-esm/canvas/pin-stacking.mjs +61 -0
- package/dist-esm/canvas/pin-stacking.mjs.map +7 -0
- package/dist-esm/canvas/region-box.mjs +93 -0
- package/dist-esm/canvas/region-box.mjs.map +7 -0
- package/dist-esm/canvas/sidebar-filters.mjs +2 -2
- package/dist-esm/canvas/sidebar-filters.mjs.map +2 -2
- package/dist-esm/canvas/state.mjs +29 -19
- package/dist-esm/canvas/state.mjs.map +2 -2
- package/dist-esm/canvas/thread-pin.mjs +310 -0
- package/dist-esm/canvas/thread-pin.mjs.map +7 -0
- package/dist-esm/canvas/thread-preview.mjs +163 -0
- package/dist-esm/canvas/thread-preview.mjs.map +7 -0
- package/dist-esm/canvas/thread-stack.mjs +189 -0
- package/dist-esm/canvas/thread-stack.mjs.map +7 -0
- package/dist-esm/canvas/thread-state.mjs +86 -22
- package/dist-esm/canvas/thread-state.mjs.map +2 -2
- package/dist-esm/canvas/thread-view.mjs +461 -0
- package/dist-esm/canvas/thread-view.mjs.map +7 -0
- package/dist-esm/clustering/computeClusterTable.mjs +6 -6
- package/dist-esm/clustering/computeClusterTable.mjs.map +2 -2
- package/dist-esm/clustering/replay.mjs +89 -22
- package/dist-esm/clustering/replay.mjs.map +3 -3
- package/dist-esm/clustering/runtime.mjs +126 -7
- package/dist-esm/clustering/runtime.mjs.map +2 -2
- package/dist-esm/index.d.mts +904 -353
- package/dist-esm/index.mjs +102 -43
- package/dist-esm/index.mjs.map +2 -2
- package/dist-esm/ui/byline.mjs +11 -7
- package/dist-esm/ui/byline.mjs.map +2 -2
- package/dist-esm/ui/comment-card.mjs +15 -8
- package/dist-esm/ui/comment-card.mjs.map +2 -2
- package/dist-esm/ui/comment-composer.mjs +135 -39
- package/dist-esm/ui/comment-composer.mjs.map +2 -2
- package/dist-esm/ui/comment-pin.mjs +11 -2
- package/dist-esm/ui/comment-pin.mjs.map +2 -2
- package/dist-esm/ui/comment-thread.mjs +9 -7
- package/dist-esm/ui/comment-thread.mjs.map +2 -2
- package/dist-esm/ui/comments-list.mjs +51 -50
- package/dist-esm/ui/comments-list.mjs.map +2 -2
- package/dist-esm/ui/count-badge.mjs +3 -2
- package/dist-esm/ui/count-badge.mjs.map +2 -2
- package/dist-esm/ui/emoji-picker.mjs +34 -0
- package/dist-esm/ui/emoji-picker.mjs.map +7 -0
- package/dist-esm/ui/empty-state.mjs +3 -3
- package/dist-esm/ui/empty-state.mjs.map +2 -2
- package/dist-esm/ui/format-time.mjs +16 -1
- package/dist-esm/ui/format-time.mjs.map +2 -2
- package/dist-esm/ui/icons.mjs +95 -0
- package/dist-esm/ui/icons.mjs.map +7 -0
- package/dist-esm/ui/reaction-picker.mjs +59 -0
- package/dist-esm/ui/reaction-picker.mjs.map +7 -0
- package/dist-esm/ui/reaction.mjs +59 -7
- package/dist-esm/ui/reaction.mjs.map +2 -2
- package/dist-esm/ui/reactions.mjs +21 -8
- package/dist-esm/ui/reactions.mjs.map +2 -2
- package/dist-esm/ui/reply-count.mjs +9 -0
- package/dist-esm/ui/reply-count.mjs.map +7 -0
- package/dist-esm/ui/send-button.mjs +13 -1
- package/dist-esm/ui/send-button.mjs.map +2 -2
- package/dist-esm/ui/visual-viewport.mjs +12 -0
- package/dist-esm/ui/visual-viewport.mjs.map +7 -0
- package/package.json +6 -6
- package/src/canvas/anchor-lifecycle.test.ts +290 -0
- package/src/canvas/anchor-lifecycle.ts +191 -0
- package/src/canvas/canvas-events.ts +18 -0
- package/src/canvas/canvas.css +464 -55
- package/src/canvas/cluster-badge.tsx +133 -0
- package/src/canvas/cluster-fade.ts +102 -0
- package/src/canvas/cluster-input.test.ts +178 -36
- package/src/canvas/cluster-input.ts +95 -9
- package/src/canvas/cluster-model.ts +378 -0
- package/src/canvas/comment-body.tsx +1 -1
- package/src/canvas/comment-drafts.test.ts +55 -0
- package/src/canvas/comment-drafts.ts +46 -0
- package/src/canvas/comment-mutations.test.ts +452 -0
- package/src/canvas/comment-mutations.ts +299 -0
- package/src/canvas/comment-reactions.test.ts +154 -0
- package/src/canvas/comment-reactions.tsx +246 -0
- package/src/canvas/comment-render.test.ts +1 -1
- package/src/canvas/comment-render.ts +17 -13
- package/src/canvas/comment-store.ts +68 -33
- package/src/canvas/comment-tool.test.ts +162 -0
- package/src/canvas/comment-tool.tsx +103 -25
- package/src/canvas/comments-filter-menu.tsx +20 -36
- package/src/canvas/comments-overflow-menu.tsx +17 -19
- package/src/canvas/comments-overlay.tsx +252 -1369
- package/src/canvas/comments-sidebar.test.ts +45 -0
- package/src/canvas/comments-sidebar.tsx +112 -73
- package/src/canvas/comments-visibility-toggle.tsx +25 -0
- package/src/canvas/context.ts +48 -0
- package/src/canvas/hooks.test.ts +94 -0
- package/src/canvas/hooks.ts +66 -11
- package/src/canvas/license.ts +1 -1
- package/src/canvas/mobile-placement.ts +115 -0
- package/src/canvas/options.test.ts +176 -4
- package/src/canvas/options.ts +276 -18
- package/src/canvas/pending-composer.tsx +157 -0
- package/src/canvas/pin-stacking.test.ts +224 -0
- package/src/canvas/pin-stacking.ts +103 -0
- package/src/canvas/region-box.tsx +124 -0
- package/src/canvas/sidebar-filters.ts +4 -3
- package/src/canvas/state.ts +88 -39
- package/src/canvas/thread-pin.tsx +418 -0
- package/src/canvas/thread-preview.test.ts +91 -0
- package/src/canvas/thread-preview.tsx +294 -0
- package/src/canvas/thread-stack.tsx +242 -0
- package/src/canvas/thread-state.test.ts +260 -0
- package/src/canvas/thread-state.ts +171 -37
- package/src/canvas/thread-view.test.ts +72 -0
- package/src/canvas/thread-view.tsx +614 -0
- package/src/clustering/computeClusterTable.test.ts +24 -23
- package/src/clustering/computeClusterTable.ts +17 -8
- package/src/clustering/replay.test.ts +0 -7
- package/src/clustering/replay.ts +131 -32
- package/src/clustering/runtime.test.ts +267 -13
- package/src/clustering/runtime.ts +176 -19
- package/src/clustering/schedule.test.ts +0 -6
- package/src/clustering/screen-offsets.test.ts +171 -0
- package/src/clustering/types.ts +19 -9
- package/src/index.ts +91 -42
- package/src/ui/byline.tsx +21 -9
- package/src/ui/comment-card.tsx +20 -10
- package/src/ui/comment-composer.tsx +178 -56
- package/src/ui/comment-pin.tsx +13 -2
- package/src/ui/comment-thread.tsx +13 -6
- package/src/ui/comments-list.test.ts +31 -0
- package/src/ui/comments-list.tsx +82 -47
- package/src/ui/comments.css +577 -294
- package/src/ui/count-badge.tsx +9 -2
- package/src/ui/emoji-picker.test.ts +25 -0
- package/src/ui/emoji-picker.tsx +76 -0
- package/src/ui/empty-state.tsx +3 -3
- package/src/ui/format-time.test.ts +69 -0
- package/src/ui/format-time.ts +27 -2
- package/src/ui/icons.tsx +116 -0
- package/src/ui/reaction-picker.tsx +102 -0
- package/src/ui/reaction.tsx +125 -6
- package/src/ui/reactions.tsx +69 -10
- package/src/ui/reply-count.ts +16 -0
- package/src/ui/send-button.tsx +13 -3
- package/src/ui/visual-viewport.test.ts +36 -0
- package/src/ui/visual-viewport.ts +27 -0
- package/dist-cjs/canvas/region-options.js +0 -49
- package/dist-cjs/canvas/region-options.js.map +0 -7
- package/dist-cjs/ui/avatar.js.map +0 -7
- package/dist-cjs/ui/comment-mention.js +0 -42
- package/dist-cjs/ui/comment-mention.js.map +0 -7
- package/dist-cjs/ui/comment-text.js.map +0 -7
- package/dist-cjs/ui/mention-list.js +0 -70
- package/dist-cjs/ui/mention-list.js.map +0 -7
- package/dist-cjs/ui/mention-suggestion.js +0 -206
- package/dist-cjs/ui/mention-suggestion.js.map +0 -7
- package/dist-cjs/ui/mention.js.map +0 -7
- package/dist-cjs/ui/render-markdown.js +0 -63
- package/dist-cjs/ui/render-markdown.js.map +0 -7
- package/dist-esm/canvas/region-options.mjs +0 -29
- package/dist-esm/canvas/region-options.mjs.map +0 -7
- package/dist-esm/ui/avatar.mjs +0 -23
- package/dist-esm/ui/avatar.mjs.map +0 -7
- package/dist-esm/ui/comment-mention.mjs +0 -22
- package/dist-esm/ui/comment-mention.mjs.map +0 -7
- package/dist-esm/ui/comment-text.mjs +0 -9
- package/dist-esm/ui/comment-text.mjs.map +0 -7
- package/dist-esm/ui/mention-list.mjs +0 -50
- package/dist-esm/ui/mention-list.mjs.map +0 -7
- package/dist-esm/ui/mention-suggestion.mjs +0 -186
- package/dist-esm/ui/mention-suggestion.mjs.map +0 -7
- package/dist-esm/ui/mention.mjs +0 -11
- package/dist-esm/ui/mention.mjs.map +0 -7
- package/dist-esm/ui/render-markdown.mjs +0 -45
- package/dist-esm/ui/render-markdown.mjs.map +0 -7
- package/src/canvas/region-options.ts +0 -57
- package/src/ui/avatar.tsx +0 -31
- package/src/ui/comment-mention.ts +0 -47
- package/src/ui/comment-text.tsx +0 -12
- package/src/ui/mention-list.tsx +0 -106
- package/src/ui/mention-suggestion.test.ts +0 -18
- package/src/ui/mention-suggestion.tsx +0 -285
- package/src/ui/mention.tsx +0 -9
- package/src/ui/render-markdown.tsx +0 -72
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { Fragment } from "react";
|
|
3
|
-
function renderMarkdown(text) {
|
|
4
|
-
return text.trim().split(/\n{2,}/).map((block, i) => {
|
|
5
|
-
const lines = block.split("\n");
|
|
6
|
-
if (lines.every((line) => /^\s*[-*]\s+/.test(line))) {
|
|
7
|
-
return (
|
|
8
|
-
/* @__PURE__ */ jsx("ul", { className: "md-list", children: lines.map((line, j) => /* @__PURE__ */ jsx("li", { children: renderInline(line.replace(/^\s*[-*]\s+/, "")) }, j)) }, i)
|
|
9
|
-
);
|
|
10
|
-
}
|
|
11
|
-
return /* @__PURE__ */ jsx("p", { className: "md-p", children: lines.map((line, j) => /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
12
|
-
j > 0 && /* @__PURE__ */ jsx("br", {}),
|
|
13
|
-
renderInline(line)
|
|
14
|
-
] }, j)) }, i);
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
const INLINE = /(\*\*[^*]+\*\*|\*[^*]+\*|_[^_]+_|`[^`]+`|\[[^\]]+\]\([^)]+\))/g;
|
|
18
|
-
function renderInline(text) {
|
|
19
|
-
const out = [];
|
|
20
|
-
let last = 0;
|
|
21
|
-
let key = 0;
|
|
22
|
-
for (const match of text.matchAll(INLINE)) {
|
|
23
|
-
const index = match.index ?? 0;
|
|
24
|
-
if (index > last) out.push(text.slice(last, index));
|
|
25
|
-
out.push(renderToken(match[0], key++));
|
|
26
|
-
last = index + match[0].length;
|
|
27
|
-
}
|
|
28
|
-
if (last < text.length) out.push(text.slice(last));
|
|
29
|
-
return out;
|
|
30
|
-
}
|
|
31
|
-
function renderToken(token, key) {
|
|
32
|
-
if (token.startsWith("**")) return /* @__PURE__ */ jsx("strong", { children: token.slice(2, -2) }, key);
|
|
33
|
-
if (token.startsWith("`"))
|
|
34
|
-
return /* @__PURE__ */ jsx("code", { className: "md-code", children: token.slice(1, -1) }, key);
|
|
35
|
-
if (token.startsWith("[")) {
|
|
36
|
-
const link = /\[([^\]]+)\]\(([^)]+)\)/.exec(token);
|
|
37
|
-
if (!link) return token;
|
|
38
|
-
return /* @__PURE__ */ jsx("a", { href: link[2], target: "_blank", rel: "noreferrer", children: link[1] }, key);
|
|
39
|
-
}
|
|
40
|
-
return /* @__PURE__ */ jsx("em", { children: token.slice(1, -1) }, key);
|
|
41
|
-
}
|
|
42
|
-
export {
|
|
43
|
-
renderMarkdown
|
|
44
|
-
};
|
|
45
|
-
//# sourceMappingURL=render-markdown.mjs.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/ui/render-markdown.tsx"],
|
|
4
|
-
"sourcesContent": ["import { Fragment, ReactNode } from 'react'\n\n/**\n * Minimal markdown for comment bodies: paragraphs, line breaks, bullet lists, and\n * inline **bold**, *italic*, `code`, and [links](url). Not a full CommonMark parser \u2014\n * just the markdown people actually write in comments. Renders React elements only \u2014\n * never raw HTML \u2014 so there's no HTML-injection surface.\n * @public\n */\nexport function renderMarkdown(text: string): ReactNode {\n\treturn text\n\t\t.trim()\n\t\t.split(/\\n{2,}/)\n\t\t.map((block, i) => {\n\t\t\tconst lines = block.split('\\n')\n\t\t\tif (lines.every((line) => /^\\s*[-*]\\s+/.test(line))) {\n\t\t\t\treturn (\n\t\t\t\t\t<ul key={i} className=\"md-list\">\n\t\t\t\t\t\t{lines.map((line, j) => (\n\t\t\t\t\t\t\t<li key={j}>{renderInline(line.replace(/^\\s*[-*]\\s+/, ''))}</li>\n\t\t\t\t\t\t))}\n\t\t\t\t\t</ul>\n\t\t\t\t)\n\t\t\t}\n\t\t\treturn (\n\t\t\t\t<p key={i} className=\"md-p\">\n\t\t\t\t\t{lines.map((line, j) => (\n\t\t\t\t\t\t<Fragment key={j}>\n\t\t\t\t\t\t\t{j > 0 && <br />}\n\t\t\t\t\t\t\t{renderInline(line)}\n\t\t\t\t\t\t</Fragment>\n\t\t\t\t\t))}\n\t\t\t\t</p>\n\t\t\t)\n\t\t})\n}\n\nconst INLINE = /(\\*\\*[^*]+\\*\\*|\\*[^*]+\\*|_[^_]+_|`[^`]+`|\\[[^\\]]+\\]\\([^)]+\\))/g\n\nfunction renderInline(text: string): ReactNode {\n\tconst out: ReactNode[] = []\n\tlet last = 0\n\tlet key = 0\n\tfor (const match of text.matchAll(INLINE)) {\n\t\tconst index = match.index ?? 0\n\t\tif (index > last) out.push(text.slice(last, index))\n\t\tout.push(renderToken(match[0], key++))\n\t\tlast = index + match[0].length\n\t}\n\tif (last < text.length) out.push(text.slice(last))\n\treturn out\n}\n\nfunction renderToken(token: string, key: number): ReactNode {\n\tif (token.startsWith('**')) return <strong key={key}>{token.slice(2, -2)}</strong>\n\tif (token.startsWith('`'))\n\t\treturn (\n\t\t\t<code key={key} className=\"md-code\">\n\t\t\t\t{token.slice(1, -1)}\n\t\t\t</code>\n\t\t)\n\tif (token.startsWith('[')) {\n\t\tconst link = /\\[([^\\]]+)\\]\\(([^)]+)\\)/.exec(token)\n\t\tif (!link) return token\n\t\treturn (\n\t\t\t<a key={key} href={link[2]} target=\"_blank\" rel=\"noreferrer\">\n\t\t\t\t{link[1]}\n\t\t\t</a>\n\t\t)\n\t}\n\treturn <em key={key}>{token.slice(1, -1)}</em>\n}\n"],
|
|
5
|
-
"mappings": "AAmBO,cAQD,YARC;AAnBP,SAAS,gBAA2B;AAS7B,SAAS,eAAe,MAAyB;AACvD,SAAO,KACL,KAAK,EACL,MAAM,QAAQ,EACd,IAAI,CAAC,OAAO,MAAM;AAClB,UAAM,QAAQ,MAAM,MAAM,IAAI;AAC9B,QAAI,MAAM,MAAM,CAAC,SAAS,cAAc,KAAK,IAAI,CAAC,GAAG;AACpD,aACC,oBAAC,QAAW,WAAU,WACpB,gBAAM,IAAI,CAAC,MAAM,MACjB,oBAAC,QAAY,uBAAa,KAAK,QAAQ,eAAe,EAAE,CAAC,KAAhD,CAAkD,CAC3D,KAHO,CAIT;AAAA,IAEF;AACA,WACC,oBAAC,OAAU,WAAU,QACnB,gBAAM,IAAI,CAAC,MAAM,MACjB,qBAAC,YACC;AAAA,UAAI,KAAK,oBAAC,QAAG;AAAA,MACb,aAAa,IAAI;AAAA,SAFJ,CAGf,CACA,KANM,CAOR;AAAA,EAEF,CAAC;AACH;AAEA,MAAM,SAAS;AAEf,SAAS,aAAa,MAAyB;AAC9C,QAAM,MAAmB,CAAC;AAC1B,MAAI,OAAO;AACX,MAAI,MAAM;AACV,aAAW,SAAS,KAAK,SAAS,MAAM,GAAG;AAC1C,UAAM,QAAQ,MAAM,SAAS;AAC7B,QAAI,QAAQ,KAAM,KAAI,KAAK,KAAK,MAAM,MAAM,KAAK,CAAC;AAClD,QAAI,KAAK,YAAY,MAAM,CAAC,GAAG,KAAK,CAAC;AACrC,WAAO,QAAQ,MAAM,CAAC,EAAE;AAAA,EACzB;AACA,MAAI,OAAO,KAAK,OAAQ,KAAI,KAAK,KAAK,MAAM,IAAI,CAAC;AACjD,SAAO;AACR;AAEA,SAAS,YAAY,OAAe,KAAwB;AAC3D,MAAI,MAAM,WAAW,IAAI,EAAG,QAAO,oBAAC,YAAkB,gBAAM,MAAM,GAAG,EAAE,KAAvB,GAAyB;AACzE,MAAI,MAAM,WAAW,GAAG;AACvB,WACC,oBAAC,UAAe,WAAU,WACxB,gBAAM,MAAM,GAAG,EAAE,KADR,GAEX;AAEF,MAAI,MAAM,WAAW,GAAG,GAAG;AAC1B,UAAM,OAAO,0BAA0B,KAAK,KAAK;AACjD,QAAI,CAAC,KAAM,QAAO;AAClB,WACC,oBAAC,OAAY,MAAM,KAAK,CAAC,GAAG,QAAO,UAAS,KAAI,cAC9C,eAAK,CAAC,KADA,GAER;AAAA,EAEF;AACA,SAAO,oBAAC,QAAc,gBAAM,MAAM,GAAG,EAAE,KAAvB,GAAyB;AAC1C;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { atom, Atom, Editor, VecLike } from 'tldraw'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* The configurable dimensions of region comments — a design surface for prototyping the interaction
|
|
5
|
-
* before settling it. Region is **off by default**, so a consumer that leaves it unset keeps plain
|
|
6
|
-
* click-only point/shape commenting. Set it per editor through `<CanvasComments regionOptions>`.
|
|
7
|
-
* @public
|
|
8
|
-
*/
|
|
9
|
-
export interface RegionCommentOptions {
|
|
10
|
-
/** Whether dragging the comment tool out creates a region anchor. Off → click-only. */
|
|
11
|
-
enabled: boolean
|
|
12
|
-
/** Which corner the pin and composer sit on, as a normalized 0–1 offset. Default bottom-right. */
|
|
13
|
-
pinCorner: VecLike
|
|
14
|
-
/** When the dashed box and its handles reveal: while the pointer is within the region, while the
|
|
15
|
-
* pin is hovered, or only while the thread is open. */
|
|
16
|
-
reveal: 'pointer' | 'pin-hover' | 'open'
|
|
17
|
-
/** How a region is moved: dragging its pin, dragging its body, or either. */
|
|
18
|
-
move: 'pin' | 'body' | 'both'
|
|
19
|
-
/** The resize affordance: corner handles, edge handles, or none. */
|
|
20
|
-
resize: 'corners' | 'edges' | 'none'
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/** The out-of-the-box region config: disabled, and — when a consumer enables it — the current
|
|
24
|
-
* bottom-right / pointer-reveal / pin-move / corner-resize behaviour.
|
|
25
|
-
* @public */
|
|
26
|
-
export const DEFAULT_REGION_COMMENT_OPTIONS: RegionCommentOptions = {
|
|
27
|
-
enabled: false,
|
|
28
|
-
pinCorner: { x: 1, y: 1 },
|
|
29
|
-
reveal: 'pointer',
|
|
30
|
-
move: 'pin',
|
|
31
|
-
resize: 'corners',
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// Per-editor region config. The overlay publishes its merged `regionOptions` here so the comment
|
|
35
|
-
// tool — which has no props of its own — can read the same per-instance config at interaction time.
|
|
36
|
-
// Held in an atom so reactive readers (e.g. `anchorPagePoint`, called inside `useValue`) recompute
|
|
37
|
-
// when the config changes; a plain map read wouldn't, leaving the pin at the stale default corner.
|
|
38
|
-
const byEditor = new WeakMap<Editor, Atom<RegionCommentOptions>>()
|
|
39
|
-
|
|
40
|
-
function getEditorAtom(editor: Editor): Atom<RegionCommentOptions> {
|
|
41
|
-
let a = byEditor.get(editor)
|
|
42
|
-
if (!a) {
|
|
43
|
-
a = atom('regionCommentOptions', DEFAULT_REGION_COMMENT_OPTIONS)
|
|
44
|
-
byEditor.set(editor, a)
|
|
45
|
-
}
|
|
46
|
-
return a
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/** Publish an editor's region config (called by the overlay from its `regionOptions` prop). */
|
|
50
|
-
export function setRegionCommentOptions(editor: Editor, options: RegionCommentOptions): void {
|
|
51
|
-
getEditorAtom(editor).set(options)
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/** The editor's region config, or the disabled default when none was set. */
|
|
55
|
-
export function getRegionCommentOptions(editor: Editor): RegionCommentOptions {
|
|
56
|
-
return getEditorAtom(editor).get()
|
|
57
|
-
}
|
package/src/ui/avatar.tsx
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { getFirstCharacter } from 'tldraw'
|
|
2
|
-
|
|
3
|
-
/** @public */
|
|
4
|
-
export interface AvatarProps {
|
|
5
|
-
name: string
|
|
6
|
-
/** Background colour, used when there's no `image`. Falls back to the default avatar tint. */
|
|
7
|
-
color?: string
|
|
8
|
-
/** Avatar image URL. When set, shows the image instead of the coloured initial. */
|
|
9
|
-
image?: string
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
function initial(name: string) {
|
|
13
|
-
return (getFirstCharacter(name.trim()) || '?').toUpperCase()
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/** A commenter's avatar — their image if provided, otherwise a single-initial coloured circle.
|
|
17
|
-
* @public @react */
|
|
18
|
-
export function Avatar({ name, color, image }: AvatarProps) {
|
|
19
|
-
if (image) {
|
|
20
|
-
return <img className="cmt-avatar cmt-avatar--image" src={image} alt="" aria-hidden="true" />
|
|
21
|
-
}
|
|
22
|
-
return (
|
|
23
|
-
<div
|
|
24
|
-
className="cmt-avatar"
|
|
25
|
-
aria-hidden="true"
|
|
26
|
-
style={color ? { backgroundColor: color } : undefined}
|
|
27
|
-
>
|
|
28
|
-
{initial(name)}
|
|
29
|
-
</div>
|
|
30
|
-
)
|
|
31
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { mergeAttributes } from '@tiptap/core'
|
|
2
|
-
import { Mention, type MentionNodeAttrs, type MentionOptions } from '@tiptap/extension-mention'
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* A mention node's display name: the member's current name, resolved live from its id when a
|
|
6
|
-
* resolver is given (so a rename shows through), falling back to the label captured at insert time
|
|
7
|
-
* when no source can name the id — e.g. a deleted account. The stored id is always the source of
|
|
8
|
-
* truth; live resolution only freshens the displayed name over that captured label.
|
|
9
|
-
*/
|
|
10
|
-
function mentionName(
|
|
11
|
-
attrs: MentionNodeAttrs,
|
|
12
|
-
resolveName?: (id: string) => string | undefined
|
|
13
|
-
): string {
|
|
14
|
-
const resolved = attrs.id && resolveName ? resolveName(attrs.id) : undefined
|
|
15
|
-
return resolved ?? attrs.label ?? attrs.id ?? ''
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export interface CommentMentionOptions {
|
|
19
|
-
/**
|
|
20
|
-
* Resolve a member id to its current display name — for the read-only render paths. Returns
|
|
21
|
-
* `undefined` when the id can't be resolved, so the render falls back to the mention's stored label.
|
|
22
|
-
*/
|
|
23
|
-
resolveName?(id: string): string | undefined
|
|
24
|
-
/** The `@`-picker suggestion config — for the composer (omit on the render paths). */
|
|
25
|
-
suggestion?: MentionOptions['suggestion']
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* The comment @-mention node — TipTap's `Mention` configured to render as a `.cmt-mention` pill.
|
|
30
|
-
*
|
|
31
|
-
* A factory rather than a shared constant because it's configured differently per context: the
|
|
32
|
-
* read-only render paths pass `resolveName` (so the stored `{ id }` node always shows the member's
|
|
33
|
-
* current name, not a copy frozen at insert time), while the composer passes a `suggestion` (the
|
|
34
|
-
* `@` picker). The node schema is identical either way — only these two levers differ.
|
|
35
|
-
*/
|
|
36
|
-
export function commentMention({ resolveName, suggestion }: CommentMentionOptions = {}) {
|
|
37
|
-
return Mention.configure({
|
|
38
|
-
HTMLAttributes: { class: 'cmt-mention' },
|
|
39
|
-
renderText: ({ node }) => `@${mentionName(node.attrs as MentionNodeAttrs, resolveName)}`,
|
|
40
|
-
renderHTML: ({ node, options }) => [
|
|
41
|
-
'span',
|
|
42
|
-
mergeAttributes(options.HTMLAttributes, { 'data-mention-id': node.attrs.id }),
|
|
43
|
-
`@${mentionName(node.attrs as MentionNodeAttrs, resolveName)}`,
|
|
44
|
-
],
|
|
45
|
-
...(suggestion ? { suggestion } : {}),
|
|
46
|
-
})
|
|
47
|
-
}
|
package/src/ui/comment-text.tsx
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { renderMarkdown } from './render-markdown'
|
|
2
|
-
|
|
3
|
-
/** @public */
|
|
4
|
-
export interface CommentTextProps {
|
|
5
|
-
/** Rich text body, authored as markdown. */
|
|
6
|
-
text: string
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
/** A comment's body, rendered as markdown (bold, italic, code, links, lists). @public @react */
|
|
10
|
-
export function CommentText({ text }: CommentTextProps) {
|
|
11
|
-
return <div className="cmt-text">{renderMarkdown(text)}</div>
|
|
12
|
-
}
|
package/src/ui/mention-list.tsx
DELETED
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import { ReactNode } from 'react'
|
|
2
|
-
import { useTranslation } from 'tldraw'
|
|
3
|
-
import { Avatar } from './avatar'
|
|
4
|
-
|
|
5
|
-
/** A person the composer's \@-mention picker can offer. @public */
|
|
6
|
-
export interface MentionMember {
|
|
7
|
-
id: string
|
|
8
|
-
name: string
|
|
9
|
-
/** Avatar image URL. Falls back to a coloured initial when omitted. */
|
|
10
|
-
avatar?: string
|
|
11
|
-
/** Avatar background colour, used when there's no `avatar` image. */
|
|
12
|
-
color?: string
|
|
13
|
-
/** A secondary line under the name — e.g. an email or handle. Omit for a single-line row. */
|
|
14
|
-
secondary?: string
|
|
15
|
-
/** Marks the current user; shown as a "(You)" suffix after the name. */
|
|
16
|
-
you?: boolean
|
|
17
|
-
/** Hosts may carry extra fields; a custom `renderMember` can read them. */
|
|
18
|
-
[key: string]: unknown
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/** @public */
|
|
22
|
-
export interface MentionListProps {
|
|
23
|
-
/** Members to choose from — already resolved for the current query by the host. */
|
|
24
|
-
members: MentionMember[]
|
|
25
|
-
/** Index of the highlighted row, driven by the composer's keyboard navigation. */
|
|
26
|
-
activeIndex?: number
|
|
27
|
-
/** Called when a member is chosen (click, or Enter on the active row). */
|
|
28
|
-
onSelect?(member: MentionMember): void
|
|
29
|
-
/** Shown when no member matches the query. Defaults to a translated "No matches". */
|
|
30
|
-
emptyLabel?: string
|
|
31
|
-
/** Override a row's content (inside the selectable button). Defaults to avatar + name (+ secondary). */
|
|
32
|
-
renderMember?(member: MentionMember): ReactNode
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/** The default row content: avatar, name (with a "(You)" marker), and an optional secondary line. */
|
|
36
|
-
function DefaultMemberRow({ member }: { member: MentionMember }) {
|
|
37
|
-
const msg = useTranslation()
|
|
38
|
-
return (
|
|
39
|
-
<>
|
|
40
|
-
<Avatar name={member.name} color={member.color} image={member.avatar} />
|
|
41
|
-
<span className="cmt-mention-list__text">
|
|
42
|
-
<span className="cmt-mention-list__name">
|
|
43
|
-
{member.name}
|
|
44
|
-
{member.you && (
|
|
45
|
-
<span className="cmt-mention-list__you">{`(${msg('comments.mention-you')})`}</span>
|
|
46
|
-
)}
|
|
47
|
-
</span>
|
|
48
|
-
{member.secondary && (
|
|
49
|
-
<span className="cmt-mention-list__secondary">{member.secondary}</span>
|
|
50
|
-
)}
|
|
51
|
-
</span>
|
|
52
|
-
</>
|
|
53
|
-
)
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* The \@-mention member picker: a popover list of people to mention, shown as the user types after
|
|
58
|
-
* `@`. Presentational — the composer's suggestion plugin owns resolution, keyboard navigation, and
|
|
59
|
-
* placement, and drives this with the host-resolved `members` and the highlighted `activeIndex`.
|
|
60
|
-
* @public @react
|
|
61
|
-
*/
|
|
62
|
-
export function MentionList({
|
|
63
|
-
members,
|
|
64
|
-
activeIndex = 0,
|
|
65
|
-
onSelect,
|
|
66
|
-
emptyLabel,
|
|
67
|
-
renderMember,
|
|
68
|
-
}: MentionListProps) {
|
|
69
|
-
const msg = useTranslation()
|
|
70
|
-
if (members.length === 0) {
|
|
71
|
-
return (
|
|
72
|
-
<div className="cmt-mention-list cmt-mention-list--empty">
|
|
73
|
-
{emptyLabel ?? msg('comments.mention-no-matches')}
|
|
74
|
-
</div>
|
|
75
|
-
)
|
|
76
|
-
}
|
|
77
|
-
return (
|
|
78
|
-
<div className="cmt-mention-list" role="listbox">
|
|
79
|
-
{members.map((member, i) => {
|
|
80
|
-
const active = i === activeIndex
|
|
81
|
-
return (
|
|
82
|
-
<button
|
|
83
|
-
key={member.id}
|
|
84
|
-
type="button"
|
|
85
|
-
role="option"
|
|
86
|
-
aria-selected={active}
|
|
87
|
-
className={
|
|
88
|
-
active
|
|
89
|
-
? 'cmt-mention-list__item cmt-mention-list__item--active'
|
|
90
|
-
: 'cmt-mention-list__item'
|
|
91
|
-
}
|
|
92
|
-
// Keep the composer focused on a row press: it's portaled outside the editor, so a
|
|
93
|
-
// bare mousedown would blur the composer — which now dismisses the picker — before
|
|
94
|
-
// the click could select. Selection runs on click; focus stays put.
|
|
95
|
-
onMouseDown={(e) => e.preventDefault()}
|
|
96
|
-
onClick={() => {
|
|
97
|
-
if (onSelect) onSelect(member)
|
|
98
|
-
}}
|
|
99
|
-
>
|
|
100
|
-
{renderMember ? renderMember(member) : <DefaultMemberRow member={member} />}
|
|
101
|
-
</button>
|
|
102
|
-
)
|
|
103
|
-
})}
|
|
104
|
-
</div>
|
|
105
|
-
)
|
|
106
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest'
|
|
2
|
-
import { filterMentionMembers } from './mention-suggestion'
|
|
3
|
-
|
|
4
|
-
const members = [
|
|
5
|
-
{ id: 'u1', name: 'Ada Lovelace' },
|
|
6
|
-
{ id: 'u2', name: 'Alan Turing' },
|
|
7
|
-
{ id: 'u3', name: 'Grace Hopper' },
|
|
8
|
-
]
|
|
9
|
-
const ids = (q: string) => filterMentionMembers(members, q).map((m) => m.id)
|
|
10
|
-
|
|
11
|
-
describe('filterMentionMembers', () => {
|
|
12
|
-
it('matches a case-insensitive substring; empty query keeps all', () => {
|
|
13
|
-
expect(ids('')).toEqual(['u1', 'u2', 'u3'])
|
|
14
|
-
expect(ids('grace')).toEqual(['u3'])
|
|
15
|
-
expect(ids('AL')).toEqual(['u2']) // "Alan", case-insensitive; "Ada Lovelace" has no "al"
|
|
16
|
-
expect(ids('zzz')).toEqual([])
|
|
17
|
-
})
|
|
18
|
-
})
|
|
@@ -1,285 +0,0 @@
|
|
|
1
|
-
import type { MentionNodeAttrs } from '@tiptap/extension-mention'
|
|
2
|
-
import { ReactRenderer } from '@tiptap/react'
|
|
3
|
-
import type { SuggestionKeyDownProps, SuggestionOptions } from '@tiptap/suggestion'
|
|
4
|
-
import { type ReactNode, forwardRef, useImperativeHandle, useState } from 'react'
|
|
5
|
-
import { type Editor as TldrawEditor, atom, react } from 'tldraw'
|
|
6
|
-
import { MentionList, MentionMember } from './mention-list'
|
|
7
|
-
|
|
8
|
-
/** The handle the suggestion plugin drives — it forwards navigation keys into the popup. */
|
|
9
|
-
export interface MentionPopupHandle {
|
|
10
|
-
onKeyDown(props: SuggestionKeyDownProps): boolean
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
interface MentionPopupProps {
|
|
14
|
-
items: MentionMember[]
|
|
15
|
-
command(attrs: MentionNodeAttrs): void
|
|
16
|
-
renderMember?(member: MentionMember): ReactNode
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/** The live @-picker popup: owns the highlighted index and keyboard, renders the presentational list. */
|
|
20
|
-
const MentionPopup = forwardRef<MentionPopupHandle, MentionPopupProps>(function MentionPopup(
|
|
21
|
-
{ items, command, renderMember },
|
|
22
|
-
ref
|
|
23
|
-
) {
|
|
24
|
-
const [activeIndex, setActiveIndex] = useState(0)
|
|
25
|
-
// A new query yields new items; reset the highlight to the top during render — not in an effect,
|
|
26
|
-
// which would leave a frame where `activeIndex` still points past a shrunk list and Enter selects
|
|
27
|
-
// its (now out-of-range, undefined) item, swallowing the key without inserting a mention.
|
|
28
|
-
const [prevItems, setPrevItems] = useState(items)
|
|
29
|
-
if (items !== prevItems) {
|
|
30
|
-
setPrevItems(items)
|
|
31
|
-
setActiveIndex(0)
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const select = (member: MentionMember | undefined) => {
|
|
35
|
-
if (member) command({ id: member.id, label: member.name })
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
useImperativeHandle(ref, () => ({
|
|
39
|
-
onKeyDown: ({ event }) => {
|
|
40
|
-
if (items.length === 0) return false
|
|
41
|
-
if (event.key === 'ArrowUp') {
|
|
42
|
-
setActiveIndex((i) => (i + items.length - 1) % items.length)
|
|
43
|
-
return true
|
|
44
|
-
}
|
|
45
|
-
if (event.key === 'ArrowDown') {
|
|
46
|
-
setActiveIndex((i) => (i + 1) % items.length)
|
|
47
|
-
return true
|
|
48
|
-
}
|
|
49
|
-
// Enter and Tab both complete the highlighted member (falling back to the top match so a
|
|
50
|
-
// stale index never selects `undefined`). The empty-roster case is handled a level up, in
|
|
51
|
-
// the suggestion's onKeyDown, which cancels the picker.
|
|
52
|
-
if (event.key === 'Enter' || event.key === 'Tab') {
|
|
53
|
-
select(items[activeIndex] ?? items[0])
|
|
54
|
-
return true
|
|
55
|
-
}
|
|
56
|
-
return false
|
|
57
|
-
},
|
|
58
|
-
}))
|
|
59
|
-
|
|
60
|
-
return (
|
|
61
|
-
<MentionList
|
|
62
|
-
members={items}
|
|
63
|
-
activeIndex={activeIndex}
|
|
64
|
-
onSelect={select}
|
|
65
|
-
renderMember={renderMember}
|
|
66
|
-
/>
|
|
67
|
-
)
|
|
68
|
-
})
|
|
69
|
-
|
|
70
|
-
const MAX_SUGGESTIONS = 8
|
|
71
|
-
|
|
72
|
-
/** Members whose name contains the query (case-insensitive), capped to the popup's length.
|
|
73
|
-
* @public */
|
|
74
|
-
export function filterMentionMembers(members: MentionMember[], query: string): MentionMember[] {
|
|
75
|
-
const q = query.toLowerCase()
|
|
76
|
-
return members.filter((m) => m.name.toLowerCase().includes(q)).slice(0, MAX_SUGGESTIONS)
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// A reactive flag for whether the @-picker is showing. Deliberately NOT tldraw's open-menu registry:
|
|
80
|
-
// registering there mounts MenuClickCapture, which covers the canvas with a click-capture overlay to
|
|
81
|
-
// make it inert while a menu is open. But the picker is an inline autocomplete, not a modal — the
|
|
82
|
-
// canvas must stay pannable/zoomable beneath it — so we track "open" ourselves instead.
|
|
83
|
-
const mentionPickerOpen = atom('isMentionPickerOpen', false)
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Whether the @-mention picker is currently showing. Host dismissal (Escape, outside-click) checks
|
|
87
|
-
* this so it can defer to the picker instead of tearing down the composer or thread beneath it.
|
|
88
|
-
*/
|
|
89
|
-
export function isMentionPickerOpen(): boolean {
|
|
90
|
-
return mentionPickerOpen.get()
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/** @public */
|
|
94
|
-
export interface MentionSuggestionOptions {
|
|
95
|
-
/** Override a member row's content in the picker. Defaults to avatar + name (+ secondary). */
|
|
96
|
-
renderMember?(member: MentionMember): ReactNode
|
|
97
|
-
/**
|
|
98
|
-
* The tldraw editor the composer lives in. When provided, the popup re-anchors reactively as the
|
|
99
|
-
* canvas camera moves (the composer rides it) instead of polling every frame. Omit off-canvas.
|
|
100
|
-
*/
|
|
101
|
-
editor?: TldrawEditor | null
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Build the TipTap `suggestion` config for the comment \@-picker. `getSuggestions(query)` is the
|
|
106
|
-
* host's resolver — it returns the members matching the query (sync or async); the SDK owns neither
|
|
107
|
-
* the roster nor the filtering. The plugin runs outside React, so `render` mounts `MentionPopup` via
|
|
108
|
-
* a `ReactRenderer`, forwards navigation keys through the popup's imperative handle, and lets it call
|
|
109
|
-
* `command` to insert.
|
|
110
|
-
* @public
|
|
111
|
-
*/
|
|
112
|
-
export function createMentionSuggestion(
|
|
113
|
-
getSuggestions: (query: string) => MentionMember[] | Promise<MentionMember[]>,
|
|
114
|
-
options: MentionSuggestionOptions = {}
|
|
115
|
-
): Omit<SuggestionOptions<MentionMember, MentionNodeAttrs>, 'editor'> {
|
|
116
|
-
return {
|
|
117
|
-
char: '@',
|
|
118
|
-
items: ({ query }) => getSuggestions(query),
|
|
119
|
-
render: () => {
|
|
120
|
-
let renderer: ReactRenderer<MentionPopupHandle, MentionPopupProps> | null = null
|
|
121
|
-
let container: HTMLElement | null = null
|
|
122
|
-
let editorEl: HTMLElement | null = null
|
|
123
|
-
let canvasEl: Element | null = null
|
|
124
|
-
let stopCameraReaction: (() => void) | null = null
|
|
125
|
-
// The composer field's top-left in page space, plus the popup's screen width. Captured on a
|
|
126
|
-
// fresh read so camera moves can re-derive the popup's screen position from the page anchor
|
|
127
|
-
// (see reposition) rather than the field's DOM rect.
|
|
128
|
-
let anchorPage: { x: number; y: number } | null = null
|
|
129
|
-
let popupWidth = 0
|
|
130
|
-
|
|
131
|
-
const applyScreen = (left: number, top: number, width: number) => {
|
|
132
|
-
if (!container) return
|
|
133
|
-
container.style.left = `${left}px`
|
|
134
|
-
container.style.top = `${top + 4}px`
|
|
135
|
-
container.style.width = `${width}px`
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
// Fresh placement: read the field's real screen rect, position the popup flush under it (not
|
|
139
|
-
// the caret, matching its width), and remember the field's page-space anchor for reposition.
|
|
140
|
-
const place = () => {
|
|
141
|
-
if (!container || !editorEl || container.style.display === 'none') return
|
|
142
|
-
const field = editorEl.closest('.cmt-composer__field') ?? editorEl
|
|
143
|
-
const rect = field.getBoundingClientRect()
|
|
144
|
-
popupWidth = rect.width
|
|
145
|
-
anchorPage = options.editor?.screenToPage({ x: rect.left, y: rect.bottom }) ?? null
|
|
146
|
-
applyScreen(rect.left, rect.bottom, rect.width)
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
// Re-derive the popup's screen position from the remembered page anchor — pure camera math,
|
|
150
|
-
// always current. Reading the field's DOM rect here instead would lag by a frame: the canvas
|
|
151
|
-
// composer re-positions itself on a React commit (a `useValue(pageToViewport(...))`), which
|
|
152
|
-
// lands after a camera reaction runs, so the rect is still last frame's during a pan.
|
|
153
|
-
const reposition = () => {
|
|
154
|
-
if (!anchorPage || !options.editor) return
|
|
155
|
-
const s = options.editor.pageToScreen(anchorPage)
|
|
156
|
-
applyScreen(s.x, s.y, popupWidth)
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
// The popup is `position: fixed`, but its anchor — a canvas composer — rides the camera:
|
|
160
|
-
// panning or zooming moves the composer with no scroll/resize event to hook. Re-anchor when
|
|
161
|
-
// the camera actually changes (via a tldraw reaction) rather than polling every frame, plus
|
|
162
|
-
// on window scroll/resize for the off-canvas case (which re-read the field directly).
|
|
163
|
-
const startFollowing = () => {
|
|
164
|
-
window.addEventListener('scroll', place, true)
|
|
165
|
-
window.addEventListener('resize', place)
|
|
166
|
-
if (options.editor) {
|
|
167
|
-
stopCameraReaction = react('anchor mention popup to camera', () => {
|
|
168
|
-
options.editor!.getCamera() // track the camera so this re-runs as it moves
|
|
169
|
-
reposition()
|
|
170
|
-
})
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
const stopFollowing = () => {
|
|
174
|
-
window.removeEventListener('scroll', place, true)
|
|
175
|
-
window.removeEventListener('resize', place)
|
|
176
|
-
stopCameraReaction?.()
|
|
177
|
-
stopCameraReaction = null
|
|
178
|
-
anchorPage = null
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
// Dismiss the roster — on Escape, or when the composer loses focus — by hiding it and
|
|
182
|
-
// clearing the open flag, so isMentionPickerOpen() stays accurate and the thread's own
|
|
183
|
-
// Escape/outside-click dismissal can take over. The TipTap suggestion stays active, so typing
|
|
184
|
-
// re-shows the roster via onUpdate.
|
|
185
|
-
const hide = () => {
|
|
186
|
-
if (container) container.style.display = 'none'
|
|
187
|
-
mentionPickerOpen.set(false)
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
// Wheel/panning over the popup drives the canvas beneath it, so scrolling to pan or zoom
|
|
191
|
-
// isn't swallowed by the roster — the same passthrough the rest of the comments UI gets from
|
|
192
|
-
// `usePassThroughWheelEvents`. The list still scrolls itself when the roster overflows (we
|
|
193
|
-
// only redispatch when it can't). Done imperatively because the popup lives outside React.
|
|
194
|
-
const onWheel = (e: WheelEvent) => {
|
|
195
|
-
if ((e as any).isSpecialRedispatchedEvent || !canvasEl) return
|
|
196
|
-
const list = container?.querySelector('.cmt-mention-list')
|
|
197
|
-
if (list && list.scrollHeight > list.clientHeight) return
|
|
198
|
-
e.preventDefault()
|
|
199
|
-
const redispatched = new WheelEvent('wheel', e)
|
|
200
|
-
;(redispatched as any).isSpecialRedispatchedEvent = true
|
|
201
|
-
canvasEl.dispatchEvent(redispatched)
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
return {
|
|
205
|
-
onStart: (props) => {
|
|
206
|
-
renderer = new ReactRenderer(MentionPopup, {
|
|
207
|
-
props: {
|
|
208
|
-
items: props.items,
|
|
209
|
-
command: props.command,
|
|
210
|
-
renderMember: options.renderMember,
|
|
211
|
-
},
|
|
212
|
-
editor: props.editor,
|
|
213
|
-
})
|
|
214
|
-
editorEl = props.editor.view.dom as HTMLElement
|
|
215
|
-
// The TipTap suggestion has no blur handling, so without this the picker would stay
|
|
216
|
-
// "open" (and the thread would defer its Escape to it) after focus moved away from the
|
|
217
|
-
// composer — leaving Escape a no-op and the roster stuck on screen.
|
|
218
|
-
editorEl.addEventListener('blur', hide)
|
|
219
|
-
container = document.createElement('div')
|
|
220
|
-
container.className = 'cmt-mention-popup'
|
|
221
|
-
container.appendChild(renderer.element)
|
|
222
|
-
// Mount inside the tldraw container so the popup inherits the theme variables
|
|
223
|
-
// (--tl-color-*); portaling to document.body would strip them and lose the panel.
|
|
224
|
-
const themed = editorEl.closest('.tl-container')
|
|
225
|
-
;(themed ?? document.body).appendChild(container)
|
|
226
|
-
canvasEl = themed?.querySelector('.tl-canvas') ?? null
|
|
227
|
-
container.addEventListener('wheel', onWheel, { passive: false })
|
|
228
|
-
place()
|
|
229
|
-
startFollowing()
|
|
230
|
-
mentionPickerOpen.set(true)
|
|
231
|
-
},
|
|
232
|
-
onUpdate: (props) => {
|
|
233
|
-
if (renderer)
|
|
234
|
-
renderer.updateProps({
|
|
235
|
-
items: props.items,
|
|
236
|
-
command: props.command,
|
|
237
|
-
renderMember: options.renderMember,
|
|
238
|
-
})
|
|
239
|
-
// Typing after an Escape re-shows the roster.
|
|
240
|
-
if (container) container.style.display = ''
|
|
241
|
-
mentionPickerOpen.set(true)
|
|
242
|
-
place()
|
|
243
|
-
},
|
|
244
|
-
onKeyDown: (props) => {
|
|
245
|
-
// Once the roster is hidden (a prior Escape), the TipTap suggestion is still active but
|
|
246
|
-
// this handler goes inert — every key passes through to the composer/thread (so a second
|
|
247
|
-
// Escape closes them, and Arrow/Enter don't select from an invisible list). Typing
|
|
248
|
-
// re-shows the roster via onUpdate.
|
|
249
|
-
if (!isMentionPickerOpen()) return false
|
|
250
|
-
if (props.event.key === 'Escape') {
|
|
251
|
-
// Dismiss only the roster: hide it and stop the key so the composer/thread beneath
|
|
252
|
-
// doesn't also treat Escape as "abandon".
|
|
253
|
-
hide()
|
|
254
|
-
props.event.stopPropagation()
|
|
255
|
-
return true
|
|
256
|
-
}
|
|
257
|
-
if (props.event.key === 'Enter' || props.event.key === 'Tab') {
|
|
258
|
-
// Complete the highlighted member if there is one to complete; if the roster is empty
|
|
259
|
-
// there's nothing to pick, so cancel the picker and swallow the key — the composer
|
|
260
|
-
// beneath neither submits (Enter) nor moves focus / indents (Tab).
|
|
261
|
-
const completed = renderer?.ref?.onKeyDown(props) ?? false
|
|
262
|
-
if (!completed) {
|
|
263
|
-
hide()
|
|
264
|
-
props.event.stopPropagation()
|
|
265
|
-
}
|
|
266
|
-
return true
|
|
267
|
-
}
|
|
268
|
-
if (renderer && renderer.ref) return renderer.ref.onKeyDown(props)
|
|
269
|
-
return false
|
|
270
|
-
},
|
|
271
|
-
onExit: () => {
|
|
272
|
-
stopFollowing()
|
|
273
|
-
if (editorEl) editorEl.removeEventListener('blur', hide)
|
|
274
|
-
if (container) container.removeEventListener('wheel', onWheel)
|
|
275
|
-
if (container) container.remove()
|
|
276
|
-
if (renderer) renderer.destroy()
|
|
277
|
-
renderer = null
|
|
278
|
-
container = null
|
|
279
|
-
canvasEl = null
|
|
280
|
-
mentionPickerOpen.set(false)
|
|
281
|
-
},
|
|
282
|
-
}
|
|
283
|
-
},
|
|
284
|
-
}
|
|
285
|
-
}
|
package/src/ui/mention.tsx
DELETED