@tldraw/commenting 5.7.0-canary.fb3426ffa934 → 5.7.0-internal.5fe8922939ec
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/commenting.css +277 -275
- package/dist-cjs/canvas/canvas-events.js +25 -1
- package/dist-cjs/canvas/canvas-events.js.map +2 -2
- package/dist-cjs/canvas/comment-mutations.js +5 -0
- package/dist-cjs/canvas/comment-mutations.js.map +2 -2
- package/dist-cjs/canvas/comment-tool.js +29 -28
- package/dist-cjs/canvas/comment-tool.js.map +2 -2
- package/dist-cjs/canvas/comments-filter-menu.js +55 -38
- package/dist-cjs/canvas/comments-filter-menu.js.map +2 -2
- package/dist-cjs/canvas/comments-overflow-menu.js +6 -24
- package/dist-cjs/canvas/comments-overflow-menu.js.map +2 -2
- package/dist-cjs/canvas/comments-overlay.js +1 -0
- package/dist-cjs/canvas/comments-overlay.js.map +2 -2
- package/dist-cjs/canvas/comments-sidebar.js +15 -3
- package/dist-cjs/canvas/comments-sidebar.js.map +2 -2
- package/dist-cjs/canvas/comments-visibility-toggle.js +1 -1
- package/dist-cjs/canvas/comments-visibility-toggle.js.map +1 -1
- package/dist-cjs/canvas/options.js +12 -0
- package/dist-cjs/canvas/options.js.map +2 -2
- package/dist-cjs/canvas/pending-composer.js +139 -9
- package/dist-cjs/canvas/pending-composer.js.map +2 -2
- package/dist-cjs/canvas/region-box.js +150 -35
- package/dist-cjs/canvas/region-box.js.map +3 -3
- package/dist-cjs/canvas/thread-pin.js +20 -4
- package/dist-cjs/canvas/thread-pin.js.map +2 -2
- package/dist-cjs/canvas/thread-view.js +134 -58
- package/dist-cjs/canvas/thread-view.js.map +2 -2
- package/dist-cjs/index.d.ts +46 -12
- package/dist-cjs/index.js +1 -1
- package/dist-cjs/ui/byline.js +2 -2
- package/dist-cjs/ui/byline.js.map +2 -2
- package/dist-cjs/ui/comment-card.js +3 -1
- package/dist-cjs/ui/comment-card.js.map +2 -2
- package/dist-cjs/ui/comment-extensions.js +4 -1
- package/dist-cjs/ui/comment-extensions.js.map +2 -2
- package/dist-cjs/ui/comments-list.js +6 -7
- package/dist-cjs/ui/comments-list.js.map +2 -2
- package/dist-cjs/ui/icons.js +4 -4
- package/dist-cjs/ui/icons.js.map +2 -2
- package/dist-cjs/ui/reaction-picker.js +2 -2
- package/dist-cjs/ui/reaction-picker.js.map +1 -1
- package/dist-cjs/ui/send-button.js.map +1 -1
- package/dist-esm/canvas/canvas-events.mjs +25 -1
- package/dist-esm/canvas/canvas-events.mjs.map +2 -2
- package/dist-esm/canvas/comment-mutations.mjs +5 -0
- package/dist-esm/canvas/comment-mutations.mjs.map +2 -2
- package/dist-esm/canvas/comment-tool.mjs +30 -29
- package/dist-esm/canvas/comment-tool.mjs.map +2 -2
- package/dist-esm/canvas/comments-filter-menu.mjs +57 -39
- package/dist-esm/canvas/comments-filter-menu.mjs.map +2 -2
- package/dist-esm/canvas/comments-overflow-menu.mjs +8 -24
- package/dist-esm/canvas/comments-overflow-menu.mjs.map +2 -2
- package/dist-esm/canvas/comments-overlay.mjs +1 -0
- package/dist-esm/canvas/comments-overlay.mjs.map +2 -2
- package/dist-esm/canvas/comments-sidebar.mjs +16 -4
- package/dist-esm/canvas/comments-sidebar.mjs.map +2 -2
- package/dist-esm/canvas/comments-visibility-toggle.mjs +1 -1
- package/dist-esm/canvas/comments-visibility-toggle.mjs.map +1 -1
- package/dist-esm/canvas/options.mjs +12 -0
- package/dist-esm/canvas/options.mjs.map +2 -2
- package/dist-esm/canvas/pending-composer.mjs +150 -11
- package/dist-esm/canvas/pending-composer.mjs.map +2 -2
- package/dist-esm/canvas/region-box.mjs +161 -38
- package/dist-esm/canvas/region-box.mjs.map +3 -3
- package/dist-esm/canvas/thread-pin.mjs +22 -6
- package/dist-esm/canvas/thread-pin.mjs.map +2 -2
- package/dist-esm/canvas/thread-view.mjs +145 -60
- package/dist-esm/canvas/thread-view.mjs.map +2 -2
- package/dist-esm/index.d.mts +46 -12
- package/dist-esm/index.mjs +1 -1
- package/dist-esm/ui/byline.mjs +2 -2
- package/dist-esm/ui/byline.mjs.map +2 -2
- package/dist-esm/ui/comment-card.mjs +3 -1
- package/dist-esm/ui/comment-card.mjs.map +2 -2
- package/dist-esm/ui/comment-extensions.mjs +11 -2
- package/dist-esm/ui/comment-extensions.mjs.map +2 -2
- package/dist-esm/ui/comments-list.mjs +6 -7
- package/dist-esm/ui/comments-list.mjs.map +2 -2
- package/dist-esm/ui/icons.mjs +4 -4
- package/dist-esm/ui/icons.mjs.map +2 -2
- package/dist-esm/ui/reaction-picker.mjs +2 -2
- package/dist-esm/ui/reaction-picker.mjs.map +1 -1
- package/dist-esm/ui/send-button.mjs.map +1 -1
- package/package.json +5 -5
- package/src/canvas/canvas-events.ts +39 -2
- package/src/canvas/canvas.css +73 -38
- package/src/canvas/comment-mutations.test.ts +51 -0
- package/src/canvas/comment-mutations.ts +14 -0
- package/src/canvas/comment-render.test.ts +8 -1
- package/src/canvas/comment-tool.test.ts +34 -44
- package/src/canvas/comment-tool.tsx +51 -55
- package/src/canvas/comments-filter-menu.tsx +19 -6
- package/src/canvas/comments-overflow-menu.tsx +12 -18
- package/src/canvas/comments-overlay.tsx +5 -2
- package/src/canvas/comments-sidebar.tsx +20 -5
- package/src/canvas/comments-visibility-toggle.tsx +1 -1
- package/src/canvas/options.test.ts +23 -1
- package/src/canvas/options.ts +41 -3
- package/src/canvas/pending-composer.tsx +190 -19
- package/src/canvas/region-box.tsx +192 -42
- package/src/canvas/thread-pin.tsx +28 -6
- package/src/canvas/thread-view.test.ts +39 -0
- package/src/canvas/thread-view.tsx +192 -72
- package/src/ui/byline.tsx +5 -2
- package/src/ui/comment-card.tsx +7 -1
- package/src/ui/comment-extensions.ts +18 -5
- package/src/ui/comments-list.tsx +23 -17
- package/src/ui/comments.css +175 -201
- package/src/ui/icons.tsx +5 -5
- package/src/ui/reaction-picker.tsx +2 -2
- package/src/ui/send-button.tsx +2 -2
|
@@ -19,9 +19,11 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
19
19
|
var canvas_events_exports = {};
|
|
20
20
|
__export(canvas_events_exports, {
|
|
21
21
|
forwardPointerEventToCanvas: () => forwardPointerEventToCanvas,
|
|
22
|
-
isCanvasPanGesture: () => isCanvasPanGesture
|
|
22
|
+
isCanvasPanGesture: () => isCanvasPanGesture,
|
|
23
|
+
startCommentDrag: () => startCommentDrag
|
|
23
24
|
});
|
|
24
25
|
module.exports = __toCommonJS(canvas_events_exports);
|
|
26
|
+
var import_tldraw = require("tldraw");
|
|
25
27
|
function isCanvasPanGesture(editor, e) {
|
|
26
28
|
return e.button !== 0 || editor.inputs.keys.has("Space");
|
|
27
29
|
}
|
|
@@ -32,4 +34,26 @@ function forwardPointerEventToCanvas(container, e) {
|
|
|
32
34
|
newEvent.isSpecialRedispatchedEvent = true;
|
|
33
35
|
cvs.dispatchEvent(newEvent);
|
|
34
36
|
}
|
|
37
|
+
function startCommentDrag(editor, { cursor, onCameraMove }) {
|
|
38
|
+
const prevCursor = { ...editor.getInstanceState().cursor };
|
|
39
|
+
const stopCursor = (0, import_tldraw.react)("comment drag cursor", () => {
|
|
40
|
+
if (editor.getInstanceState().cursor.type !== cursor) {
|
|
41
|
+
editor.setCursor({ type: cursor, rotation: 0 });
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
let started = false;
|
|
45
|
+
const stopCamera = (0, import_tldraw.react)("comment drag follows camera", () => {
|
|
46
|
+
editor.getCamera();
|
|
47
|
+
if (!started) {
|
|
48
|
+
started = true;
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
(0, import_tldraw.unsafe__withoutCapture)(onCameraMove);
|
|
52
|
+
});
|
|
53
|
+
return () => {
|
|
54
|
+
stopCamera();
|
|
55
|
+
stopCursor();
|
|
56
|
+
editor.setCursor(prevCursor);
|
|
57
|
+
};
|
|
58
|
+
}
|
|
35
59
|
//# sourceMappingURL=canvas-events.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/canvas/canvas-events.ts"],
|
|
4
|
-
"sourcesContent": ["import { type PointerEvent as ReactPointerEvent } from 'react'\nimport { Editor } from 'tldraw'\n\n/** A pointer-down that belongs to the camera, not the comment UI: any non-primary button\n * (middle/right-button pans), or a primary press with the spacebar pan key held. */\nexport function isCanvasPanGesture(editor: Editor, e:
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
4
|
+
"sourcesContent": ["import { type PointerEvent as ReactPointerEvent } from 'react'\nimport { Editor, react, TLCursorType, unsafe__withoutCapture } from 'tldraw'\n\n/** A pointer-down that belongs to the camera, not the comment UI: any non-primary button\n * (middle/right-button pans), or a primary press with the spacebar pan key held. */\nexport function isCanvasPanGesture(editor: Editor, e: { button: number }) {\n\treturn e.button !== 0 || editor.inputs.keys.has('Space')\n}\n\n/** Hand a pointer event to the canvas beneath the comments layer, marked the same way the\n * pass-through wheel/hover hooks mark their re-dispatched events. */\nexport function forwardPointerEventToCanvas(container: HTMLElement, e: ReactPointerEvent) {\n\tconst cvs = container.querySelector('.tl-canvas')\n\tif (!cvs) return\n\tconst newEvent = new PointerEvent(e.type, e.nativeEvent as any)\n\t;(newEvent as any).isSpecialRedispatchedEvent = true\n\tcvs.dispatchEvent(newEvent)\n}\n\n/**\n * Start a comment drag (pin move or region resize) run by the comment UI's own pointer handlers\n * rather than a tool state. Shows `cursor` for the whole drag and re-runs `onCameraMove` when the\n * camera moves, from the drag's last pointer position, so a mid-drag scroll keeps the dragged thing\n * under the pointer as a shape drag does. Returns the cleanup.\n *\n * The drag's pointer moves still reach the editor (its inputs and the presence cursor others see\n * must keep tracking), so the active tool's hover handling may set its own cursor on each one; the\n * drag's cursor is put back whenever that happens.\n */\nexport function startCommentDrag(\n\teditor: Editor,\n\t{ cursor, onCameraMove }: { cursor: TLCursorType; onCameraMove(): void }\n): () => void {\n\tconst prevCursor = { ...editor.getInstanceState().cursor }\n\tconst stopCursor = react('comment drag cursor', () => {\n\t\tif (editor.getInstanceState().cursor.type !== cursor) {\n\t\t\teditor.setCursor({ type: cursor, rotation: 0 })\n\t\t}\n\t})\n\tlet started = false\n\tconst stopCamera = react('comment drag follows camera', () => {\n\t\teditor.getCamera()\n\t\tif (!started) {\n\t\t\tstarted = true\n\t\t\treturn\n\t\t}\n\t\t// Untracked: the callback writes state it may also read.\n\t\tunsafe__withoutCapture(onCameraMove)\n\t})\n\treturn () => {\n\t\tstopCamera()\n\t\tstopCursor()\n\t\teditor.setCursor(prevCursor)\n\t}\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,oBAAoE;AAI7D,SAAS,mBAAmB,QAAgB,GAAuB;AACzE,SAAO,EAAE,WAAW,KAAK,OAAO,OAAO,KAAK,IAAI,OAAO;AACxD;AAIO,SAAS,4BAA4B,WAAwB,GAAsB;AACzF,QAAM,MAAM,UAAU,cAAc,YAAY;AAChD,MAAI,CAAC,IAAK;AACV,QAAM,WAAW,IAAI,aAAa,EAAE,MAAM,EAAE,WAAkB;AAC7D,EAAC,SAAiB,6BAA6B;AAChD,MAAI,cAAc,QAAQ;AAC3B;AAYO,SAAS,iBACf,QACA,EAAE,QAAQ,aAAa,GACV;AACb,QAAM,aAAa,EAAE,GAAG,OAAO,iBAAiB,EAAE,OAAO;AACzD,QAAM,iBAAa,qBAAM,uBAAuB,MAAM;AACrD,QAAI,OAAO,iBAAiB,EAAE,OAAO,SAAS,QAAQ;AACrD,aAAO,UAAU,EAAE,MAAM,QAAQ,UAAU,EAAE,CAAC;AAAA,IAC/C;AAAA,EACD,CAAC;AACD,MAAI,UAAU;AACd,QAAM,iBAAa,qBAAM,+BAA+B,MAAM;AAC7D,WAAO,UAAU;AACjB,QAAI,CAAC,SAAS;AACb,gBAAU;AACV;AAAA,IACD;AAEA,8CAAuB,YAAY;AAAA,EACpC,CAAC;AACD,SAAO,MAAM;AACZ,eAAW;AACX,eAAW;AACX,WAAO,UAAU,UAAU;AAAA,EAC5B;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -19,6 +19,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
19
19
|
var comment_mutations_exports = {};
|
|
20
20
|
__export(comment_mutations_exports, {
|
|
21
21
|
commitCommentMutation: () => commitCommentMutation,
|
|
22
|
+
commitCommentPost: () => commitCommentPost,
|
|
22
23
|
deleteComment: () => deleteComment,
|
|
23
24
|
deleteThread: () => deleteThread,
|
|
24
25
|
editComment: () => editComment,
|
|
@@ -89,6 +90,10 @@ function commitCommentMutation(editor, fn, kind = "mutation") {
|
|
|
89
90
|
}
|
|
90
91
|
}
|
|
91
92
|
}
|
|
93
|
+
function commitCommentPost(editor, fn) {
|
|
94
|
+
const comment = commitCommentMutation(editor, fn);
|
|
95
|
+
return (0, import_comment_store.getCommentRecord)(editor, comment.id) ? comment : null;
|
|
96
|
+
}
|
|
92
97
|
function putCommentRecords(editor, records) {
|
|
93
98
|
commitCommentMutation(editor, ({ put }) => put(records));
|
|
94
99
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/canvas/comment-mutations.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n\tEditor,\n\tTLComment,\n\tTLCommentId,\n\tTLCommentReactionId,\n\tTLCommentThread,\n\tTLCommentThreadId,\n\tTLHistoryBatchOptions,\n\tTLRecord,\n\tTLRichText,\n} from 'tldraw'\nimport { getCommentRecord, getLiveComments, type TLCommentRecord } from './comment-store'\nimport { getCommentingOptions, type CommentingOptions } from './options'\nimport { openThreadId } from './state'\n\n/**\n * Every write to a comment record, and the undo/redo policy governing them.\n *\n * The file layers bottom-up: {@link commitCommentMutation} resolves the history mode and hands its\n * callback a writer, {@link putCommentRecords} and {@link removeCommentRecords} are the typed\n * writes that run under it, and the verbs below are those writes plus the one rule each carries.\n * Every verb takes the record it acts on as the identity of what to change, not the value to write\n * back \u2014 see {@link readLatest}.\n *\n * Posting carries no such rule, so it isn't a verb here: build the records with\n * `createCommentThread`/`createComment` and write them with {@link putCommentRecords}.\n */\n\n/**\n * Which history policy a comment write follows:\n *\n * - `mutation` \u2014 {@link CommentingOptions.history}: posts, replies, edits, resolves.\n * - `drag` \u2014 {@link CommentingOptions.dragHistory}, falling back to `history`: pin and region\n * re-anchors, which are spatial edits a host may reasonably want undoable alongside a shape move.\n * - `delete` \u2014 always `'ignore'`, whatever the options say. A soft-delete flag is write-once\n * server-side, so an undo clearing it would be vetoed and rebased rather than restore anything.\n *\n * @internal\n */\nexport type CommentMutationKind = 'delete' | 'drag' | 'mutation'\n\ninterface CommentMutationWriter {\n\tput(records: TLCommentRecord[]): void\n\tremove(ids: (TLCommentId | TLCommentReactionId | TLCommentThreadId)[]): void\n}\n\nconst activeCommentMutations = new WeakMap<Editor, { history: TLHistoryBatchOptions['history'] }>()\n\n/** The undo/redo mode a write of the given kind runs under. See {@link CommentMutationKind}. */\nfunction historyModeFor(\n\toptions: CommentingOptions,\n\tkind: CommentMutationKind\n): TLHistoryBatchOptions['history'] {\n\tswitch (kind) {\n\t\tcase 'delete':\n\t\t\treturn 'ignore'\n\t\tcase 'drag':\n\t\t\treturn options.dragHistory ?? options.history\n\t\tcase 'mutation':\n\t\t\treturn options.history\n\t}\n}\n\n/**\n * Commit a comment mutation with the configured undo/redo behavior, so the\n * {@link CommentingOptions.history} option governs whether it lands on the undo stack. Defaults to\n * `'ignore'`. See {@link CommentMutationKind} for what each kind resolves to.\n *\n * `editor.run`'s history option isn't additive \u2014 a nested run overwrites the enclosing mode \u2014 so\n * constituent records go through the callback's writer instead of opening a commit of their own,\n * which would quietly make a `drag` write non-undoable.\n *\n * Commits that nest are only a problem when they resolve to different modes, and then neither is\n * the right one to keep, so it throws. Matching modes have to nest: a store side effect runs inside\n * the write that triggered it, with no \"after the commit\" to defer to. (A `store.listen` handler\n * normally flushes on a later frame, so its writes open a commit of their own, but a synchronous\n * flush \u2014 as under test \u2014 lands it inside too.)\n * @internal\n */\nexport function commitCommentMutation<T>(\n\teditor: Editor,\n\tfn: (writer: CommentMutationWriter) => T,\n\tkind: CommentMutationKind = 'mutation'\n): T {\n\tconst history = historyModeFor(getCommentingOptions(editor), kind)\n\tconst enclosing = activeCommentMutations.get(editor)\n\tif (enclosing && enclosing.history !== history) {\n\t\tthrow new Error(\n\t\t\t`A comment mutation that records history as '${history}' can't run inside one recording it as '${enclosing.history}': one of the two modes would be silently discarded. Use the provided writer for constituent records, or run this operation after the enclosing one has committed.`\n\t\t)\n\t}\n\n\tactiveCommentMutations.set(editor, { history })\n\ttry {\n\t\tlet result: T\n\t\teditor.run(\n\t\t\t() => {\n\t\t\t\tlet isWriterActive = true\n\t\t\t\tconst assertWriterActive = () => {\n\t\t\t\t\tif (!isWriterActive) {\n\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t'A comment mutation writer cannot be used after its commit has finished.'\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\ttry {\n\t\t\t\t\tresult = fn({\n\t\t\t\t\t\tput: (records) => {\n\t\t\t\t\t\t\tassertWriterActive()\n\t\t\t\t\t\t\teditor.store.put(records as unknown as TLRecord[])\n\t\t\t\t\t\t},\n\t\t\t\t\t\tremove: (ids) => {\n\t\t\t\t\t\t\tassertWriterActive()\n\t\t\t\t\t\t\teditor.store.remove(ids as unknown as TLRecord['id'][])\n\t\t\t\t\t\t},\n\t\t\t\t\t})\n\t\t\t\t} finally {\n\t\t\t\t\tisWriterActive = false\n\t\t\t\t}\n\t\t\t},\n\t\t\t{ history }\n\t\t)\n\t\treturn result!\n\t} finally {\n\t\tif (enclosing) {\n\t\t\tactiveCommentMutations.set(editor, enclosing)\n\t\t} else {\n\t\t\tactiveCommentMutations.delete(editor)\n\t\t}\n\t}\n}\n\n/**\n * Write comment records to the store, under the configured {@link CommentingOptions.history}\n * behavior. Defaults to `'ignore'`.\n *\n * Use it to seed or import threads, and to save an edit. To delete, prefer {@link deleteComment}\n * and {@link deleteThread}: comments are soft-deleted, and a synced server rejects the hard delete.\n *\n * @public\n */\nexport function putCommentRecords(editor: Editor, records: TLCommentRecord[]): void {\n\tcommitCommentMutation(editor, ({ put }) => put(records))\n}\n\n/**\n * Remove comment records from the store by id, under the configured\n * {@link CommentingOptions.history} behavior.\n *\n * This is a hard delete, which is rarely what you want: the built-in UI soft-deletes\n * ({@link deleteComment}, {@link deleteThread}) so the server can prune the records, and a server\n * enforcing per-record permissions vetoes a hard delete outright. Reach for this on a local,\n * unsynced store, or to drop a reaction (see {@link toggleCommentReaction}).\n *\n * @public\n */\nexport function removeCommentRecords(\n\teditor: Editor,\n\tids: (TLCommentId | TLCommentReactionId | TLCommentThreadId)[]\n): void {\n\tcommitCommentMutation(editor, ({ remove }) => remove(ids))\n}\n\n/**\n * The record as the store currently holds it, or `undefined` if it isn't there any more.\n *\n * A verb is handed a record, but that record is a snapshot and comment records move underneath it:\n * deleting a pinned shape converts the anchor to a point, reparenting rehomes the thread, a drag\n * re-anchors it. Writing the caller's snapshot back would revert those fields for everyone. `put`\n * is also an upsert, so a record a remote delete already removed would come back.\n *\n * So a verb reads what it's changing rather than trusting what it was given, and a record that's\n * gone is a no-op.\n */\nfunction readLatest<T extends TLComment | TLCommentThread>(\n\teditor: Editor,\n\trecord: T\n): T | undefined {\n\tconst current = getCommentRecord(editor, record.id)\n\t// Record ids carry their type, so a matching `typeName` means a record of exactly T.\n\treturn current?.typeName === record.typeName ? (current as T) : undefined\n}\n\n/**\n * Replace a comment's body and stamp it as edited, which renders the \"(edited)\" marker on its\n * byline. Editing is the author's to do by default ({@link CommentingOptions.canModifyComment}),\n * and a server enforcing per-record permissions rejects anyone else's. Widening one end without the\n * other leaves an edit that's offered and then rejected, so widen both.\n *\n * The body lands on the version the store currently holds, so a stale copy can't revert a later\n * change or re-create a removed comment \u2014 editing one of those does nothing.\n *\n * @example\n * ```ts\n * editComment(editor, comment, toRichText('Actually, make it dashed'))\n * ```\n *\n * @public\n */\nexport function editComment(editor: Editor, comment: TLComment, body: TLRichText): void {\n\tcommitCommentMutation(editor, ({ put }) => {\n\t\tconst current = readLatest(editor, comment)\n\t\tif (!current) return\n\t\tput([{ ...current, body, editedAt: Date.now() }])\n\t})\n}\n\n/**\n * Mark a thread resolved, stamping who resolved it and when. Resolved threads keep their pin (a\n * checked one) and are hidden from the sidebar until its \"show resolved\" filter is on.\n *\n * Only the resolution is written \u2014 the rest of the thread is read fresh, so a stale copy can't drag\n * a pin back. A no-op on a thread that's gone.\n *\n * @public\n */\nexport function resolveThread(editor: Editor, thread: TLCommentThread, userId: string): void {\n\tcommitCommentMutation(editor, ({ put }) => {\n\t\tconst current = readLatest(editor, thread)\n\t\tif (!current) return\n\t\tput([{ ...current, resolved: { at: Date.now(), by: userId } }])\n\t})\n}\n\n/**\n * Reopen a resolved thread, clearing the resolution. A no-op on a thread that isn't resolved, and\n * on one that's gone. Like {@link resolveThread}, it touches only the resolution.\n *\n * @public\n */\nexport function reopenThread(editor: Editor, thread: TLCommentThread): void {\n\tcommitCommentMutation(editor, ({ put }) => {\n\t\tconst current = readLatest(editor, thread)\n\t\tif (!current) return\n\t\tput([{ ...current, resolved: null }])\n\t})\n}\n\n/**\n * Delete a comment.\n *\n * This is a soft delete: it sets `isDeleted` rather than removing the record, and the server prunes\n * the comment and its reactions once the flag is persisted \u2014 so no client removes records it\n * doesn't own, and a server enforcing per-record permissions has a write it can check.\n *\n * Deleting is the author's to do by default; {@link CommentingOptions.canModifyComment} widens\n * that, as does its counterpart on the server.\n *\n * Never undoable, whatever {@link CommentingOptions.history} says: the flag is write-once\n * server-side, so an undo clearing it would be vetoed rather than bring the comment back.\n *\n * Deleting a thread's last comment closes it and leaves the thread record for the server to prune,\n * since the deleter may not be its creator. An already-deleted comment is a no-op.\n *\n * @public\n */\nexport function deleteComment(editor: Editor, comment: TLComment): void {\n\tcommitCommentMutation(\n\t\teditor,\n\t\t({ put }) => {\n\t\t\tconst current = readLatest(editor, comment)\n\t\t\t// Deleting twice is nothing to do rather than something to redo. The check below counts this\n\t\t\t// comment among the live ones, so it only reads as \"the last one\" while this delete takes it away.\n\t\t\tif (!current || current.isDeleted) return\n\t\t\tconst isLastInThread =\n\t\t\t\tgetLiveComments(editor).filter((c) => c.threadId === current.threadId).length <= 1\n\t\t\tif (isLastInThread && openThreadId.get(editor) === current.threadId) {\n\t\t\t\topenThreadId.set(editor, null)\n\t\t\t}\n\t\t\tput([{ ...current, isDeleted: true }])\n\t\t},\n\t\t'delete'\n\t)\n}\n\n/**\n * Delete a thread and, with it, the whole conversation.\n *\n * A soft delete on the same model as {@link deleteComment}: the server prunes the thread, its\n * comments, and their reactions once the flag is persisted. Deleting a thread is its creator's to\n * do by default ({@link CommentingOptions.canModifyComment}), and the write is never undoable.\n * Closes the thread if it's the open one; a pruned thread is a no-op.\n *\n * @public\n */\nexport function deleteThread(editor: Editor, thread: TLCommentThread): void {\n\tcommitCommentMutation(\n\t\teditor,\n\t\t({ put }) => {\n\t\t\tconst current = readLatest(editor, thread)\n\t\t\tif (!current) return\n\t\t\tif (openThreadId.get(editor) === current.id) {\n\t\t\t\topenThreadId.set(editor, null)\n\t\t\t}\n\t\t\tput([{ ...current, isDeleted: true }])\n\t\t},\n\t\t'delete'\n\t)\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAWA,2BAAwE;AACxE,qBAA6D;AAC7D,mBAA6B;AAiC7B,MAAM,yBAAyB,oBAAI,QAA+D;AAGlG,SAAS,eACR,SACA,MACmC;AACnC,UAAQ,MAAM;AAAA,IACb,KAAK;AACJ,aAAO;AAAA,IACR,KAAK;AACJ,aAAO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A,UAAI,CAAC,EAAE,GAAG,SAAS,WAAW,KAAK,CAAC,CAAC;AAAA,IACtC;AAAA,IACA;AAAA,EACD;AACD;AAYO,SAAS,aAAa,QAAgB,QAA+B;AAC3E;AAAA,IACC;AAAA,IACA,CAAC,EAAE,IAAI,MAAM;AACZ,YAAM,UAAU,WAAW,QAAQ,MAAM;AACzC,UAAI,CAAC,QAAS;AACd,UAAI,0BAAa,IAAI,MAAM,MAAM,QAAQ,IAAI;AAC5C,kCAAa,IAAI,QAAQ,IAAI;AAAA,MAC9B;AACA,UAAI,CAAC,EAAE,GAAG,SAAS,WAAW,KAAK,CAAC,CAAC;AAAA,IACtC;AAAA,IACA;AAAA,EACD;AACD;",
|
|
4
|
+
"sourcesContent": ["import {\n\tEditor,\n\tTLComment,\n\tTLCommentId,\n\tTLCommentReactionId,\n\tTLCommentThread,\n\tTLCommentThreadId,\n\tTLHistoryBatchOptions,\n\tTLRecord,\n\tTLRichText,\n} from 'tldraw'\nimport { getCommentRecord, getLiveComments, type TLCommentRecord } from './comment-store'\nimport { getCommentingOptions, type CommentingOptions } from './options'\nimport { openThreadId } from './state'\n\n/**\n * Every write to a comment record, and the undo/redo policy governing them.\n *\n * The file layers bottom-up: {@link commitCommentMutation} resolves the history mode and hands its\n * callback a writer, {@link putCommentRecords} and {@link removeCommentRecords} are the typed\n * writes that run under it, and the verbs below are those writes plus the one rule each carries.\n * Every verb takes the record it acts on as the identity of what to change, not the value to write\n * back \u2014 see {@link readLatest}.\n *\n * Posting carries no such rule, so it isn't a verb here: build the records with\n * `createCommentThread`/`createComment` and write them with {@link putCommentRecords}.\n */\n\n/**\n * Which history policy a comment write follows:\n *\n * - `mutation` \u2014 {@link CommentingOptions.history}: posts, replies, edits, resolves.\n * - `drag` \u2014 {@link CommentingOptions.dragHistory}, falling back to `history`: pin and region\n * re-anchors, which are spatial edits a host may reasonably want undoable alongside a shape move.\n * - `delete` \u2014 always `'ignore'`, whatever the options say. A soft-delete flag is write-once\n * server-side, so an undo clearing it would be vetoed and rebased rather than restore anything.\n *\n * @internal\n */\nexport type CommentMutationKind = 'delete' | 'drag' | 'mutation'\n\ninterface CommentMutationWriter {\n\tput(records: TLCommentRecord[]): void\n\tremove(ids: (TLCommentId | TLCommentReactionId | TLCommentThreadId)[]): void\n}\n\nconst activeCommentMutations = new WeakMap<Editor, { history: TLHistoryBatchOptions['history'] }>()\n\n/** The undo/redo mode a write of the given kind runs under. See {@link CommentMutationKind}. */\nfunction historyModeFor(\n\toptions: CommentingOptions,\n\tkind: CommentMutationKind\n): TLHistoryBatchOptions['history'] {\n\tswitch (kind) {\n\t\tcase 'delete':\n\t\t\treturn 'ignore'\n\t\tcase 'drag':\n\t\t\treturn options.dragHistory ?? options.history\n\t\tcase 'mutation':\n\t\t\treturn options.history\n\t}\n}\n\n/**\n * Commit a comment mutation with the configured undo/redo behavior, so the\n * {@link CommentingOptions.history} option governs whether it lands on the undo stack. Defaults to\n * `'ignore'`. See {@link CommentMutationKind} for what each kind resolves to.\n *\n * `editor.run`'s history option isn't additive \u2014 a nested run overwrites the enclosing mode \u2014 so\n * constituent records go through the callback's writer instead of opening a commit of their own,\n * which would quietly make a `drag` write non-undoable.\n *\n * Commits that nest are only a problem when they resolve to different modes, and then neither is\n * the right one to keep, so it throws. Matching modes have to nest: a store side effect runs inside\n * the write that triggered it, with no \"after the commit\" to defer to. (A `store.listen` handler\n * normally flushes on a later frame, so its writes open a commit of their own, but a synchronous\n * flush \u2014 as under test \u2014 lands it inside too.)\n * @internal\n */\nexport function commitCommentMutation<T>(\n\teditor: Editor,\n\tfn: (writer: CommentMutationWriter) => T,\n\tkind: CommentMutationKind = 'mutation'\n): T {\n\tconst history = historyModeFor(getCommentingOptions(editor), kind)\n\tconst enclosing = activeCommentMutations.get(editor)\n\tif (enclosing && enclosing.history !== history) {\n\t\tthrow new Error(\n\t\t\t`A comment mutation that records history as '${history}' can't run inside one recording it as '${enclosing.history}': one of the two modes would be silently discarded. Use the provided writer for constituent records, or run this operation after the enclosing one has committed.`\n\t\t)\n\t}\n\n\tactiveCommentMutations.set(editor, { history })\n\ttry {\n\t\tlet result: T\n\t\teditor.run(\n\t\t\t() => {\n\t\t\t\tlet isWriterActive = true\n\t\t\t\tconst assertWriterActive = () => {\n\t\t\t\t\tif (!isWriterActive) {\n\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t'A comment mutation writer cannot be used after its commit has finished.'\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\ttry {\n\t\t\t\t\tresult = fn({\n\t\t\t\t\t\tput: (records) => {\n\t\t\t\t\t\t\tassertWriterActive()\n\t\t\t\t\t\t\teditor.store.put(records as unknown as TLRecord[])\n\t\t\t\t\t\t},\n\t\t\t\t\t\tremove: (ids) => {\n\t\t\t\t\t\t\tassertWriterActive()\n\t\t\t\t\t\t\teditor.store.remove(ids as unknown as TLRecord['id'][])\n\t\t\t\t\t\t},\n\t\t\t\t\t})\n\t\t\t\t} finally {\n\t\t\t\t\tisWriterActive = false\n\t\t\t\t}\n\t\t\t},\n\t\t\t{ history }\n\t\t)\n\t\treturn result!\n\t} finally {\n\t\tif (enclosing) {\n\t\t\tactiveCommentMutations.set(editor, enclosing)\n\t\t} else {\n\t\t\tactiveCommentMutations.delete(editor)\n\t\t}\n\t}\n}\n\n/**\n * Post a comment through {@link commitCommentMutation}, and return it only if it was stored. The\n * editor's `authorize.write` can refuse the post, which reverts it without throwing, so a composer\n * that took the return value as success would drop the draft of a comment that was never posted.\n * @internal\n */\nexport function commitCommentPost(\n\teditor: Editor,\n\tfn: (writer: CommentMutationWriter) => TLComment\n): TLComment | null {\n\tconst comment = commitCommentMutation(editor, fn)\n\treturn getCommentRecord(editor, comment.id) ? comment : null\n}\n\n/**\n * Write comment records to the store, under the configured {@link CommentingOptions.history}\n * behavior. Defaults to `'ignore'`.\n *\n * Use it to seed or import threads, and to save an edit. To delete, prefer {@link deleteComment}\n * and {@link deleteThread}: comments are soft-deleted, and a synced server rejects the hard delete.\n *\n * @public\n */\nexport function putCommentRecords(editor: Editor, records: TLCommentRecord[]): void {\n\tcommitCommentMutation(editor, ({ put }) => put(records))\n}\n\n/**\n * Remove comment records from the store by id, under the configured\n * {@link CommentingOptions.history} behavior.\n *\n * This is a hard delete, which is rarely what you want: the built-in UI soft-deletes\n * ({@link deleteComment}, {@link deleteThread}) so the server can prune the records, and a server\n * enforcing per-record permissions vetoes a hard delete outright. Reach for this on a local,\n * unsynced store, or to drop a reaction (see {@link toggleCommentReaction}).\n *\n * @public\n */\nexport function removeCommentRecords(\n\teditor: Editor,\n\tids: (TLCommentId | TLCommentReactionId | TLCommentThreadId)[]\n): void {\n\tcommitCommentMutation(editor, ({ remove }) => remove(ids))\n}\n\n/**\n * The record as the store currently holds it, or `undefined` if it isn't there any more.\n *\n * A verb is handed a record, but that record is a snapshot and comment records move underneath it:\n * deleting a pinned shape converts the anchor to a point, reparenting rehomes the thread, a drag\n * re-anchors it. Writing the caller's snapshot back would revert those fields for everyone. `put`\n * is also an upsert, so a record a remote delete already removed would come back.\n *\n * So a verb reads what it's changing rather than trusting what it was given, and a record that's\n * gone is a no-op.\n */\nfunction readLatest<T extends TLComment | TLCommentThread>(\n\teditor: Editor,\n\trecord: T\n): T | undefined {\n\tconst current = getCommentRecord(editor, record.id)\n\t// Record ids carry their type, so a matching `typeName` means a record of exactly T.\n\treturn current?.typeName === record.typeName ? (current as T) : undefined\n}\n\n/**\n * Replace a comment's body and stamp it as edited, which renders the \"(edited)\" marker on its\n * byline. Editing is the author's to do by default ({@link CommentingOptions.canModifyComment}),\n * and a server enforcing per-record permissions rejects anyone else's. Widening one end without the\n * other leaves an edit that's offered and then rejected, so widen both.\n *\n * The body lands on the version the store currently holds, so a stale copy can't revert a later\n * change or re-create a removed comment \u2014 editing one of those does nothing.\n *\n * @example\n * ```ts\n * editComment(editor, comment, toRichText('Actually, make it dashed'))\n * ```\n *\n * @public\n */\nexport function editComment(editor: Editor, comment: TLComment, body: TLRichText): void {\n\tcommitCommentMutation(editor, ({ put }) => {\n\t\tconst current = readLatest(editor, comment)\n\t\tif (!current) return\n\t\tput([{ ...current, body, editedAt: Date.now() }])\n\t})\n}\n\n/**\n * Mark a thread resolved, stamping who resolved it and when. Resolved threads keep their pin (a\n * checked one) and are hidden from the sidebar until its \"show resolved\" filter is on.\n *\n * Only the resolution is written \u2014 the rest of the thread is read fresh, so a stale copy can't drag\n * a pin back. A no-op on a thread that's gone.\n *\n * @public\n */\nexport function resolveThread(editor: Editor, thread: TLCommentThread, userId: string): void {\n\tcommitCommentMutation(editor, ({ put }) => {\n\t\tconst current = readLatest(editor, thread)\n\t\tif (!current) return\n\t\tput([{ ...current, resolved: { at: Date.now(), by: userId } }])\n\t})\n}\n\n/**\n * Reopen a resolved thread, clearing the resolution. A no-op on a thread that isn't resolved, and\n * on one that's gone. Like {@link resolveThread}, it touches only the resolution.\n *\n * @public\n */\nexport function reopenThread(editor: Editor, thread: TLCommentThread): void {\n\tcommitCommentMutation(editor, ({ put }) => {\n\t\tconst current = readLatest(editor, thread)\n\t\tif (!current) return\n\t\tput([{ ...current, resolved: null }])\n\t})\n}\n\n/**\n * Delete a comment.\n *\n * This is a soft delete: it sets `isDeleted` rather than removing the record, and the server prunes\n * the comment and its reactions once the flag is persisted \u2014 so no client removes records it\n * doesn't own, and a server enforcing per-record permissions has a write it can check.\n *\n * Deleting is the author's to do by default; {@link CommentingOptions.canModifyComment} widens\n * that, as does its counterpart on the server.\n *\n * Never undoable, whatever {@link CommentingOptions.history} says: the flag is write-once\n * server-side, so an undo clearing it would be vetoed rather than bring the comment back.\n *\n * Deleting a thread's last comment closes it and leaves the thread record for the server to prune,\n * since the deleter may not be its creator. An already-deleted comment is a no-op.\n *\n * @public\n */\nexport function deleteComment(editor: Editor, comment: TLComment): void {\n\tcommitCommentMutation(\n\t\teditor,\n\t\t({ put }) => {\n\t\t\tconst current = readLatest(editor, comment)\n\t\t\t// Deleting twice is nothing to do rather than something to redo. The check below counts this\n\t\t\t// comment among the live ones, so it only reads as \"the last one\" while this delete takes it away.\n\t\t\tif (!current || current.isDeleted) return\n\t\t\tconst isLastInThread =\n\t\t\t\tgetLiveComments(editor).filter((c) => c.threadId === current.threadId).length <= 1\n\t\t\tif (isLastInThread && openThreadId.get(editor) === current.threadId) {\n\t\t\t\topenThreadId.set(editor, null)\n\t\t\t}\n\t\t\tput([{ ...current, isDeleted: true }])\n\t\t},\n\t\t'delete'\n\t)\n}\n\n/**\n * Delete a thread and, with it, the whole conversation.\n *\n * A soft delete on the same model as {@link deleteComment}: the server prunes the thread, its\n * comments, and their reactions once the flag is persisted. Deleting a thread is its creator's to\n * do by default ({@link CommentingOptions.canModifyComment}), and the write is never undoable.\n * Closes the thread if it's the open one; a pruned thread is a no-op.\n *\n * @public\n */\nexport function deleteThread(editor: Editor, thread: TLCommentThread): void {\n\tcommitCommentMutation(\n\t\teditor,\n\t\t({ put }) => {\n\t\t\tconst current = readLatest(editor, thread)\n\t\t\tif (!current) return\n\t\t\tif (openThreadId.get(editor) === current.id) {\n\t\t\t\topenThreadId.set(editor, null)\n\t\t\t}\n\t\t\tput([{ ...current, isDeleted: true }])\n\t\t},\n\t\t'delete'\n\t)\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAWA,2BAAwE;AACxE,qBAA6D;AAC7D,mBAA6B;AAiC7B,MAAM,yBAAyB,oBAAI,QAA+D;AAGlG,SAAS,eACR,SACA,MACmC;AACnC,UAAQ,MAAM;AAAA,IACb,KAAK;AACJ,aAAO;AAAA,IACR,KAAK;AACJ,aAAO,QAAQ,eAAe,QAAQ;AAAA,IACvC,KAAK;AACJ,aAAO,QAAQ;AAAA,EACjB;AACD;AAkBO,SAAS,sBACf,QACA,IACA,OAA4B,YACxB;AACJ,QAAM,UAAU,mBAAe,qCAAqB,MAAM,GAAG,IAAI;AACj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AAC,CAAC;AAAA,IACtC;AAAA,IACA;AAAA,EACD;AACD;AAYO,SAAS,aAAa,QAAgB,QAA+B;AAC3E;AAAA,IACC;AAAA,IACA,CAAC,EAAE,IAAI,MAAM;AACZ,YAAM,UAAU,WAAW,QAAQ,MAAM;AACzC,UAAI,CAAC,QAAS;AACd,UAAI,0BAAa,IAAI,MAAM,MAAM,QAAQ,IAAI;AAC5C,kCAAa,IAAI,QAAQ,IAAI;AAAA,MAC9B;AACA,UAAI,CAAC,EAAE,GAAG,SAAS,WAAW,KAAK,CAAC,CAAC;AAAA,IACtC;AAAA,IACA;AAAA,EACD;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -21,6 +21,7 @@ __export(comment_tool_exports, {
|
|
|
21
21
|
CommentTool: () => CommentTool,
|
|
22
22
|
commentToolOverrides: () => commentToolOverrides,
|
|
23
23
|
commentTools: () => commentTools,
|
|
24
|
+
pendingCommentAt: () => pendingCommentAt,
|
|
24
25
|
regionBetween: () => regionBetween,
|
|
25
26
|
startCommentAt: () => startCommentAt
|
|
26
27
|
});
|
|
@@ -73,19 +74,25 @@ class CommentTool extends import_tldraw.StateNode {
|
|
|
73
74
|
options = import_options.defaultCommentingOptions;
|
|
74
75
|
onEnter() {
|
|
75
76
|
this.editor.setCursor({ type: "comment", rotation: 0 });
|
|
76
|
-
import_state.commentsSidebarOpen.set(this.editor, false);
|
|
77
77
|
}
|
|
78
78
|
onExit() {
|
|
79
79
|
this.editor.setHintingShapes([]);
|
|
80
|
-
import_state.pendingComment.set(this.editor, null);
|
|
81
80
|
import_state.regionDraft.set(this.editor, null);
|
|
82
81
|
}
|
|
83
|
-
// Escape
|
|
82
|
+
// Escape (the editor dispatches `cancel`) steps back one level: an open composer closes and the
|
|
83
|
+
// tool stays; with none open, the tool returns to select. Mid-placement it also drops the
|
|
84
|
+
// composer that's following the pointer: this handler runs before the child state's, and
|
|
85
|
+
// leaving the tool skips the child's own cancel.
|
|
84
86
|
onCancel() {
|
|
87
|
+
if (this.getCurrent()?.id === "idle" && import_state.pendingComment.get(this.editor)) {
|
|
88
|
+
import_state.pendingComment.set(this.editor, null);
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
if (this.getCurrent()?.id !== "idle") import_state.pendingComment.set(this.editor, null);
|
|
85
92
|
this.editor.setCurrentTool("select");
|
|
86
93
|
}
|
|
87
94
|
}
|
|
88
|
-
function pendingCommentAt(editor, point) {
|
|
95
|
+
function pendingCommentAt(editor, point, altKey = editor.inputs.getAltKey()) {
|
|
89
96
|
const hit = (0, import_thread_state.commentTargetShapeAt)(editor, point);
|
|
90
97
|
const anchor = hit ? (0, import_thread_state.shapeAnchorAt)(
|
|
91
98
|
editor,
|
|
@@ -94,16 +101,18 @@ function pendingCommentAt(editor, point) {
|
|
|
94
101
|
(0, import_options.getCommentingOptions)(editor).shouldBePrecise(editor, {
|
|
95
102
|
shapeId: hit.id,
|
|
96
103
|
point,
|
|
97
|
-
altKey
|
|
104
|
+
altKey
|
|
98
105
|
})
|
|
99
106
|
) : { type: "point", x: point.x, y: point.y };
|
|
100
107
|
return { anchor, point: { x: point.x, y: point.y } };
|
|
101
108
|
}
|
|
102
109
|
function startCommentAt(editor, point) {
|
|
103
|
-
editor.setCurrentTool("
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
110
|
+
editor.setCurrentTool("select");
|
|
111
|
+
import_state.pendingComment.set(editor, pendingCommentAt(editor, point));
|
|
112
|
+
}
|
|
113
|
+
function finishPlacement(state, pending) {
|
|
114
|
+
import_state.pendingComment.set(state.editor, pending);
|
|
115
|
+
state.parent.transition("idle");
|
|
107
116
|
}
|
|
108
117
|
function updateAnchorHint(editor) {
|
|
109
118
|
const hit = (0, import_thread_state.commentTargetShapeAt)(editor, editor.inputs.getCurrentPagePoint());
|
|
@@ -123,10 +132,6 @@ class CommentIdle extends import_tldraw.StateNode {
|
|
|
123
132
|
updateAnchorHint(this.editor);
|
|
124
133
|
}
|
|
125
134
|
onPointerDown() {
|
|
126
|
-
if (import_state.pendingComment.get(this.editor)) {
|
|
127
|
-
this.editor.setCurrentTool("select");
|
|
128
|
-
return;
|
|
129
|
-
}
|
|
130
135
|
this.parent.transition("pointing");
|
|
131
136
|
}
|
|
132
137
|
}
|
|
@@ -147,6 +152,9 @@ class CommentPointing extends import_tldraw.StateNode {
|
|
|
147
152
|
this.parent.transition("dragging");
|
|
148
153
|
return;
|
|
149
154
|
}
|
|
155
|
+
if (editor.inputs.getIsDragging() && editor.getInstanceState().cursor.type !== "move") {
|
|
156
|
+
editor.setCursor({ type: "move", rotation: 0 });
|
|
157
|
+
}
|
|
150
158
|
updateAnchorHint(editor);
|
|
151
159
|
const point = editor.inputs.getCurrentPagePoint();
|
|
152
160
|
import_state.pendingComment.update(editor, (p) => p ? { ...p, point: { x: point.x, y: point.y } } : p);
|
|
@@ -155,19 +163,16 @@ class CommentPointing extends import_tldraw.StateNode {
|
|
|
155
163
|
onPointerUp() {
|
|
156
164
|
const { editor } = this;
|
|
157
165
|
const point = editor.inputs.getCurrentPagePoint();
|
|
158
|
-
|
|
159
|
-
this.parent.transition("idle");
|
|
160
|
-
}
|
|
161
|
-
onCancel() {
|
|
162
|
-
this.cancel();
|
|
166
|
+
finishPlacement(this, pendingCommentAt(editor, point));
|
|
163
167
|
}
|
|
164
168
|
onInterrupt() {
|
|
165
169
|
this.cancel();
|
|
166
170
|
}
|
|
167
|
-
// Abandon the follow composer if placement is interrupted (
|
|
168
|
-
// tool's
|
|
171
|
+
// Abandon the follow composer if placement is interrupted (focus loss, etc.). Its text survives
|
|
172
|
+
// in the draft store. Escape is the tool's own onCancel, which runs first.
|
|
169
173
|
cancel() {
|
|
170
|
-
this.editor
|
|
174
|
+
import_state.pendingComment.set(this.editor, null);
|
|
175
|
+
this.parent.transition("idle");
|
|
171
176
|
}
|
|
172
177
|
}
|
|
173
178
|
class CommentDragging extends import_tldraw.StateNode {
|
|
@@ -189,14 +194,10 @@ class CommentDragging extends import_tldraw.StateNode {
|
|
|
189
194
|
const region = regionBetween(origin, current);
|
|
190
195
|
const pin = { x: current.x >= origin.x ? 1 : 0, y: current.y >= origin.y ? 1 : 0 };
|
|
191
196
|
import_state.regionDraft.set(editor, null);
|
|
192
|
-
|
|
197
|
+
finishPlacement(this, {
|
|
193
198
|
anchor: { type: "region", ...region, pinX: pin.x, pinY: pin.y },
|
|
194
199
|
point: (0, import_thread_state.regionPinPoint)(region, pin)
|
|
195
200
|
});
|
|
196
|
-
this.parent.transition("idle");
|
|
197
|
-
}
|
|
198
|
-
onCancel() {
|
|
199
|
-
this.cancel();
|
|
200
201
|
}
|
|
201
202
|
onInterrupt() {
|
|
202
203
|
this.cancel();
|
|
@@ -208,9 +209,9 @@ class CommentDragging extends import_tldraw.StateNode {
|
|
|
208
209
|
regionBetween(editor.inputs.getOriginPagePoint(), editor.inputs.getCurrentPagePoint())
|
|
209
210
|
);
|
|
210
211
|
}
|
|
211
|
-
// The tool's onExit drops the region draft.
|
|
212
212
|
cancel() {
|
|
213
|
-
this.editor
|
|
213
|
+
import_state.regionDraft.set(this.editor, null);
|
|
214
|
+
this.parent.transition("idle");
|
|
214
215
|
}
|
|
215
216
|
}
|
|
216
217
|
const commentTools = [CommentTool];
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/canvas/comment-tool.tsx"],
|
|
4
|
-
"sourcesContent": ["import {\n\tBoxModel,\n\tEditor,\n\tStateNode,\n\tTLCommentAnchor,\n\tTLStateNodeConstructor,\n\tTLUiOverrides,\n\tVecLike,\n\tdefineMessages,\n} from 'tldraw'\nimport { type CommentingOptions, defaultCommentingOptions, getCommentingOptions } from './options'\nimport { commentsSidebarOpen, pendingComment, regionDraft } from './state'\nimport { commentTargetShapeAt, regionPinPoint, shapeAnchorAt } from './thread-state'\n\n/** A comment being placed but not yet posted: where its composer sits and what it will anchor\n * to. Shared between the tool (which sets it on click) and the overlay (which renders the\n * composer) through the internal `pendingComment` atom.\n * @internal */\nexport interface PendingComment {\n\tanchor: TLCommentAnchor\n\t/** Page point where the composer opens (the click location, or a region's pin corner). */\n\tpoint: VecLike\n}\n\n/**\n * Merge configure options over a base. Shallow for scalars; `components` is merged rather than\n * replaced so chained `configure` calls layer their slots \u2014 a later `{ components: { PinContent } }`\n * doesn't drop an earlier `{ components: { CommentBody } }`.\n */\nfunction mergeCommentingOptions(\n\tbase: CommentingOptions,\n\toverrides: Partial<CommentingOptions>\n): CommentingOptions {\n\treturn {\n\t\t...base,\n\t\t...overrides,\n\t\tcomponents: { ...base.components, ...overrides.components },\n\t}\n}\n\n/** The page-space rectangle spanned by two points, normalized so w/h are non-negative. Shared by\n * region creation (pointer-down \u2192 cursor) and corner resize (fixed corner \u2192 cursor). */\nexport function regionBetween(a: VecLike, b: VecLike): BoxModel {\n\treturn {\n\t\tx: Math.min(a.x, b.x),\n\t\ty: Math.min(a.y, b.y),\n\t\tw: Math.abs(a.x - b.x),\n\t\th: Math.abs(a.y - b.y),\n\t}\n}\n\n/**\n * The comment tool. Pressing down opens the comment composer at the pointer and it follows until\n * release \u2014 like placing a sticky note \u2014 settling on a point, or on a shape when released over one.\n * With region comments enabled, dragging past the threshold draws a region rectangle instead.\n * Placement only opens a composer; the records are created when the comment is posted. The tool\n * stays active while the composer is open \u2014 posting returns to select, and so does clicking the\n * canvas elsewhere, which cancels the placement.\n * @public\n */\nexport class CommentTool extends StateNode {\n\tstatic override id = 'comment'\n\tstatic override initial = 'idle'\n\tstatic override children(): TLStateNodeConstructor[] {\n\t\treturn [CommentIdle, CommentPointing, CommentDragging]\n\t}\n\n\t/**\n\t * Configure this tool's {@link CommentTool.options | `options`}, returning a configured subclass\n\t * to register via `tools`. Mirrors `ShapeUtil.configure`. Layers over any prior `configure`, so\n\t * calls can be chained.\n\t *\n\t * @example\n\t * ```tsx\n\t * <Tldraw tools={[CommentTool.configure({ history: 'ignore', enableClustering: false })]} />\n\t * ```\n\t */\n\tstatic configure<T extends TLStateNodeConstructor>(\n\t\tthis: T,\n\t\toptions: T extends new (...args: any[]) => { options: infer Options } ? Partial<Options> : never\n\t): T {\n\t\t// @ts-expect-error -- mirrors ShapeUtil.configure; extending `this` is sound at runtime.\n\t\treturn class extends this {\n\t\t\t// @ts-expect-error\n\t\t\toptions = mergeCommentingOptions(this.options, options)\n\t\t}\n\t}\n\n\t/**\n\t * The merged commenting options for this editor. Read from anywhere via\n\t * {@link getCommentingOptions}. Override with {@link CommentTool.configure}.\n\t */\n\toptions: CommentingOptions = defaultCommentingOptions\n\n\toverride onEnter() {\n\t\tthis.editor.setCursor({ type: 'comment', rotation: 0 })\n\t\t// Placing comments is canvas-focused \u2014 the thread list gets out of the way while the tool is\n\t\t// active. Reopened via its own control (a button), never by leaving the tool.\n\t\tcommentsSidebarOpen.set(this.editor, false)\n\t}\n\n\toverride onExit() {\n\t\t// Drop the hover hint painted while pointing at shapes (see CommentIdle). The cursor resets\n\t\t// when the next tool takes over. The draft composer and region draft belong to the tool, so\n\t\t// they leave with it; the draft's text survives in the comment draft store.\n\t\tthis.editor.setHintingShapes([])\n\t\tpendingComment.set(this.editor, null)\n\t\tregionDraft.set(this.editor, null)\n\t}\n\n\t// Escape leaves the tool, like the built-in tools (the editor dispatches `cancel` on Escape).\n\toverride onCancel() {\n\t\tthis.editor.setCurrentTool('select')\n\t}\n}\n\nfunction pendingCommentAt(editor: Editor, point: VecLike): PendingComment {\n\tconst hit = commentTargetShapeAt(editor, point)\n\tconst anchor: TLCommentAnchor = hit\n\t\t? shapeAnchorAt(\n\t\t\t\teditor,\n\t\t\t\thit.id,\n\t\t\t\tpoint,\n\t\t\t\tgetCommentingOptions(editor).shouldBePrecise(editor, {\n\t\t\t\t\tshapeId: hit.id,\n\t\t\t\t\tpoint,\n\t\t\t\t\taltKey: editor.inputs.getAltKey(),\n\t\t\t\t})\n\t\t\t)\n\t\t: { type: 'point', x: point.x, y: point.y }\n\treturn { anchor, point: { x: point.x, y: point.y } }\n}\n\n/**\n * Open the comment composer at a page point, anchored as a comment tool click there would be. Use\n * it to start a comment from outside the tool, such as a context menu item. Enters the comment tool\n * (which must be registered), since the draft composer closes when the tool exits. It doesn't check\n * `canComment`: a viewer who can't comment sees the `ComposerFallback` slot instead.\n *\n * @example\n * ```tsx\n * <TldrawUiMenuItem id=\"comment\" label=\"Comment\" onSelect={() => startCommentAt(editor, point)} />\n * ```\n * @public\n */\nexport function startCommentAt(editor: Editor, point: VecLike) {\n\teditor.setCurrentTool('comment')\n\tconst pending = pendingCommentAt(editor, point)\n\tpendingComment.set(editor, pending)\n\t// Entering the tool hints the shape under the live pointer, which is wherever the caller's UI\n\t// was (a menu item), not `point`.\n\teditor.setHintingShapes(pending.anchor.type === 'shape' ? [pending.anchor.shapeId] : [])\n}\n\n/** Hint the shape a comment placed at the pointer would anchor to, using the same hit-test as the\n * anchor resolution on release. Hinting shapes render an indicator ungated by the active tool, so\n * this shows the select-style outline while the comment tool \u2014 not select \u2014 is active. */\nfunction updateAnchorHint(editor: Editor) {\n\tconst hit = commentTargetShapeAt(editor, editor.inputs.getCurrentPagePoint())\n\teditor.setHintingShapes(hit ? [hit.id] : [])\n}\n\nclass CommentIdle extends StateNode {\n\tstatic override id = 'idle'\n\n\toverride onEnter() {\n\t\t// Back to hovering: restore the pin cursor (a prior placing state may have hidden it).\n\t\tthis.editor.setCursor({ type: 'comment', rotation: 0 })\n\t\t// With a region composer open, a shape outline under its pin corner would imply a shape\n\t\t// anchor the region will never use \u2014 and it would stick, since moves over the composer\n\t\t// never reach the canvas. Point placements keep the hint: it previews the next click.\n\t\tif (pendingComment.get(this.editor)?.anchor.type === 'region') {\n\t\t\tthis.editor.setHintingShapes([])\n\t\t} else {\n\t\t\tupdateAnchorHint(this.editor)\n\t\t}\n\t}\n\n\toverride onPointerMove() {\n\t\tupdateAnchorHint(this.editor)\n\t}\n\n\toverride onPointerDown() {\n\t\t// A press away from an open composer cancels the placement rather than moving it. The\n\t\t// tool's onExit drops the draft composer; its text survives in the draft store.\n\t\tif (pendingComment.get(this.editor)) {\n\t\t\tthis.editor.setCurrentTool('select')\n\t\t\treturn\n\t\t}\n\t\tthis.parent.transition('pointing')\n\t}\n}\n\nclass CommentPointing extends StateNode {\n\tstatic override id = 'pointing'\n\n\toverride onEnter() {\n\t\t// Open the composer immediately at the press point so it's visible from pointer-down (not just\n\t\t// on release), and let it trail the pointer while dragging \u2014 like placing a sticky note. The\n\t\t// anchor is a bare point for now; it's resolved (shape or point) on pointer up.\n\t\tconst { editor } = this\n\t\t// Hide the cursor while placing: the draft composer is the pointer's stand-in now, so the pin\n\t\t// cursor sitting over it just reads as clutter.\n\t\teditor.setCursor({ type: 'none', rotation: 0 })\n\t\tconst point = editor.inputs.getCurrentPagePoint()\n\t\tpendingComment.set(editor, {\n\t\t\tanchor: { type: 'point', x: point.x, y: point.y },\n\t\t\tpoint: { x: point.x, y: point.y },\n\t\t})\n\t}\n\n\toverride onPointerMove() {\n\t\tconst { editor } = this\n\t\t// Once the pointer passes the drag threshold with region comments enabled, this is a region,\n\t\t// not a follow \u2014 hand off to the region drag (which clears this composer and draws the box).\n\t\tif (getCommentingOptions(editor).enableRegions && editor.inputs.getIsDragging()) {\n\t\t\tthis.parent.transition('dragging')\n\t\t\treturn\n\t\t}\n\t\t// Otherwise the composer trails the pointer \u2014 keep hinting the shape a release here would\n\t\t// anchor to, like the idle hover does.\n\t\tupdateAnchorHint(editor)\n\t\tconst point = editor.inputs.getCurrentPagePoint()\n\t\tpendingComment.update(editor, (p) => (p ? { ...p, point: { x: point.x, y: point.y } } : p))\n\t}\n\n\t// Settle where the pointer is released: anchor to the shape under it, or drop a point.\n\toverride onPointerUp() {\n\t\tconst { editor } = this\n\t\tconst point = editor.inputs.getCurrentPagePoint()\n\t\tpendingComment.set(editor, pendingCommentAt(editor, point))\n\t\t// Stay in the tool while the composer is open \u2014 the interaction isn't over until the\n\t\t// comment is posted or dismissed, and staying keeps the surrounding UI (style panel,\n\t\t// sidebar) from churning mid-placement.\n\t\tthis.parent.transition('idle')\n\t}\n\n\toverride onCancel() {\n\t\tthis.cancel()\n\t}\n\n\toverride onInterrupt() {\n\t\tthis.cancel()\n\t}\n\n\t// Abandon the follow composer if placement is interrupted (Escape, focus loss, etc.). The\n\t// tool's onExit drops the draft.\n\tprivate cancel() {\n\t\tthis.editor.setCurrentTool('select')\n\t}\n}\n\nclass CommentDragging extends StateNode {\n\tstatic override id = 'dragging'\n\n\toverride onEnter() {\n\t\t// A region drag supersedes the point-follow composer opened in `pointing`. Show a crosshair again,\n\t\t// since the composer no longer stands in for the pointer, and drop the placement hint \u2014 a region\n\t\t// anchors to its rectangle, so a single-shape outline would be stale.\n\t\tpendingComment.set(this.editor, null)\n\t\tthis.editor.setHintingShapes([])\n\t\tthis.editor.setCursor({ type: 'cross', rotation: 0 })\n\t\tthis.updateDraft()\n\t}\n\n\toverride onPointerMove() {\n\t\tthis.updateDraft()\n\t}\n\n\t// Commit the dragged rectangle as a region anchor; the composer opens at its pin corner.\n\toverride onPointerUp() {\n\t\tconst { editor } = this\n\t\tconst origin = editor.inputs.getOriginPagePoint()\n\t\tconst current = editor.inputs.getCurrentPagePoint()\n\t\tconst region = regionBetween(origin, current)\n\t\t// The pin lives on the corner the drag released on \u2014 drag up-left, pin top-left.\n\t\tconst pin = { x: current.x >= origin.x ? 1 : 0, y: current.y >= origin.y ? 1 : 0 }\n\t\tregionDraft.set(editor, null)\n\t\tpendingComment.set(editor, {\n\t\t\tanchor: { type: 'region', ...region, pinX: pin.x, pinY: pin.y },\n\t\t\tpoint: regionPinPoint(region, pin),\n\t\t})\n\t\t// Same as the point placement: the tool stays active while the composer is open.\n\t\tthis.parent.transition('idle')\n\t}\n\n\toverride onCancel() {\n\t\tthis.cancel()\n\t}\n\n\toverride onInterrupt() {\n\t\tthis.cancel()\n\t}\n\n\tprivate updateDraft() {\n\t\tconst { editor } = this\n\t\tregionDraft.set(\n\t\t\teditor,\n\t\t\tregionBetween(editor.inputs.getOriginPagePoint(), editor.inputs.getCurrentPagePoint())\n\t\t)\n\t}\n\n\t// The tool's onExit drops the region draft.\n\tprivate cancel() {\n\t\tthis.editor.setCurrentTool('select')\n\t}\n}\n\n/** @public */\nexport const commentTools = [CommentTool]\n\nconst messages = defineMessages({\n\ttoolComment: { id: 'tool.comment', defaultMessage: 'Comment' },\n})\n\n/** Registers the comment tool in the UI (icon, label, shortcut). Compose into your overrides.\n * Once registered, tldraw's `DefaultQuickActionsContent` shows the comment button, and its\n * `DefaultContextMenuContent` shows a comment item that opens the composer where the menu was\n * opened.\n * @public */\nexport const commentToolOverrides: TLUiOverrides = {\n\ttools(editor, tools) {\n\t\ttools.comment = {\n\t\t\tid: 'comment',\n\t\t\ticon: 'comment',\n\t\t\tlabel: messages.toolComment.id,\n\t\t\tkbd: 'c',\n\t\t\tonSelect: (source) => {\n\t\t\t\t// The menu was opened by the last pointer down; the live pointer is over the menu now.\n\t\t\t\tif (source === 'context-menu') startCommentAt(editor, editor.inputs.getOriginPagePoint())\n\t\t\t\telse editor.setCurrentTool('comment')\n\t\t\t},\n\t\t}\n\t\treturn tools\n\t},\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBASO;AACP,qBAAuF;AACvF,
|
|
4
|
+
"sourcesContent": ["import {\n\tBoxModel,\n\tEditor,\n\tStateNode,\n\tTLCommentAnchor,\n\tTLStateNodeConstructor,\n\tTLUiOverrides,\n\tVecLike,\n\tdefineMessages,\n} from 'tldraw'\nimport { type CommentingOptions, defaultCommentingOptions, getCommentingOptions } from './options'\nimport { pendingComment, regionDraft } from './state'\nimport { commentTargetShapeAt, regionPinPoint, shapeAnchorAt } from './thread-state'\n\n/** A comment being placed but not yet posted: where its composer sits and what it will anchor\n * to. Shared between the tool (which sets it on click) and the overlay (which renders the\n * composer) through the internal `pendingComment` atom.\n * @internal */\nexport interface PendingComment {\n\tanchor: TLCommentAnchor\n\t/** Page point where the composer opens (the click location, or a region's pin corner). */\n\tpoint: VecLike\n}\n\n/**\n * Merge configure options over a base. Shallow for scalars; `components` is merged rather than\n * replaced so chained `configure` calls layer their slots \u2014 a later `{ components: { PinContent } }`\n * doesn't drop an earlier `{ components: { CommentBody } }`.\n */\nfunction mergeCommentingOptions(\n\tbase: CommentingOptions,\n\toverrides: Partial<CommentingOptions>\n): CommentingOptions {\n\treturn {\n\t\t...base,\n\t\t...overrides,\n\t\tcomponents: { ...base.components, ...overrides.components },\n\t}\n}\n\n/** The page-space rectangle spanned by two points, normalized so w/h are non-negative. Shared by\n * region creation (pointer-down \u2192 cursor) and corner resize (fixed corner \u2192 cursor). */\nexport function regionBetween(a: VecLike, b: VecLike): BoxModel {\n\treturn {\n\t\tx: Math.min(a.x, b.x),\n\t\ty: Math.min(a.y, b.y),\n\t\tw: Math.abs(a.x - b.x),\n\t\th: Math.abs(a.y - b.y),\n\t}\n}\n\n/**\n * The comment tool. Pressing down opens the comment composer at the pointer and it follows until\n * release \u2014 like placing a sticky note \u2014 settling on a point, or on a shape when released over one.\n * With region comments enabled, dragging past the threshold draws a region rectangle instead.\n * Placement only opens a composer; the records are created when the comment is posted. The tool\n * stays active after a placement, so comments can be placed one after another. Escape closes an\n * open composer first, then returns to the select tool.\n * @public\n */\nexport class CommentTool extends StateNode {\n\tstatic override id = 'comment'\n\tstatic override initial = 'idle'\n\tstatic override children(): TLStateNodeConstructor[] {\n\t\treturn [CommentIdle, CommentPointing, CommentDragging]\n\t}\n\n\t/**\n\t * Configure this tool's {@link CommentTool.options | `options`}, returning a configured subclass\n\t * to register via `tools`. Mirrors `ShapeUtil.configure`. Layers over any prior `configure`, so\n\t * calls can be chained.\n\t *\n\t * @example\n\t * ```tsx\n\t * <Tldraw tools={[CommentTool.configure({ history: 'ignore', enableClustering: false })]} />\n\t * ```\n\t */\n\tstatic configure<T extends TLStateNodeConstructor>(\n\t\tthis: T,\n\t\toptions: T extends new (...args: any[]) => { options: infer Options } ? Partial<Options> : never\n\t): T {\n\t\t// @ts-expect-error -- mirrors ShapeUtil.configure; extending `this` is sound at runtime.\n\t\treturn class extends this {\n\t\t\t// @ts-expect-error\n\t\t\toptions = mergeCommentingOptions(this.options, options)\n\t\t}\n\t}\n\n\t/**\n\t * The merged commenting options for this editor. Read from anywhere via\n\t * {@link getCommentingOptions}. Override with {@link CommentTool.configure}.\n\t */\n\toptions: CommentingOptions = defaultCommentingOptions\n\n\toverride onEnter() {\n\t\tthis.editor.setCursor({ type: 'comment', rotation: 0 })\n\t}\n\n\toverride onExit() {\n\t\t// Drop the hover hint painted while pointing at shapes (see CommentIdle) and any unfinished\n\t\t// region draft. The cursor resets when the next tool takes over. An open composer outlives\n\t\t// the tool.\n\t\tthis.editor.setHintingShapes([])\n\t\tregionDraft.set(this.editor, null)\n\t}\n\n\t// Escape (the editor dispatches `cancel`) steps back one level: an open composer closes and the\n\t// tool stays; with none open, the tool returns to select. Mid-placement it also drops the\n\t// composer that's following the pointer: this handler runs before the child state's, and\n\t// leaving the tool skips the child's own cancel.\n\toverride onCancel() {\n\t\tif (this.getCurrent()?.id === 'idle' && pendingComment.get(this.editor)) {\n\t\t\tpendingComment.set(this.editor, null)\n\t\t\treturn\n\t\t}\n\t\tif (this.getCurrent()?.id !== 'idle') pendingComment.set(this.editor, null)\n\t\tthis.editor.setCurrentTool('select')\n\t}\n}\n\n/** The pending placement a release at `point` resolves to: anchored to the shape under it, or a\n * bare point. Shared by the tool's click placement and the composer's drag handle. */\nexport function pendingCommentAt(\n\teditor: Editor,\n\tpoint: VecLike,\n\taltKey = editor.inputs.getAltKey()\n): PendingComment {\n\tconst hit = commentTargetShapeAt(editor, point)\n\tconst anchor: TLCommentAnchor = hit\n\t\t? shapeAnchorAt(\n\t\t\t\teditor,\n\t\t\t\thit.id,\n\t\t\t\tpoint,\n\t\t\t\tgetCommentingOptions(editor).shouldBePrecise(editor, {\n\t\t\t\t\tshapeId: hit.id,\n\t\t\t\t\tpoint,\n\t\t\t\t\taltKey,\n\t\t\t\t})\n\t\t\t)\n\t\t: { type: 'point', x: point.x, y: point.y }\n\treturn { anchor, point: { x: point.x, y: point.y } }\n}\n\n/**\n * Open the comment composer at a page point, anchored as a comment tool click there would be. Use\n * it to start a comment from outside the tool, such as a context menu item. It leaves the select\n * tool active with the composer open. It doesn't check `canComment`: a\n * viewer who can't comment sees the `ComposerFallback` slot instead.\n *\n * @example\n * ```tsx\n * <TldrawUiMenuItem id=\"comment\" label=\"Comment\" onSelect={() => startCommentAt(editor, point)} />\n * ```\n * @public\n */\nexport function startCommentAt(editor: Editor, point: VecLike) {\n\teditor.setCurrentTool('select')\n\tpendingComment.set(editor, pendingCommentAt(editor, point))\n}\n\n/** End a placement: the composer stays open at `pending` and the tool goes back to idle, ready\n * for the next one. */\nfunction finishPlacement(state: StateNode, pending: PendingComment) {\n\tpendingComment.set(state.editor, pending)\n\tstate.parent.transition('idle')\n}\n\n/** Hint the shape a comment placed at the pointer would anchor to, using the same hit-test as the\n * anchor resolution on release. Hinting shapes render an indicator ungated by the active tool, so\n * this shows the select-style outline while the comment tool \u2014 not select \u2014 is active. */\nfunction updateAnchorHint(editor: Editor) {\n\tconst hit = commentTargetShapeAt(editor, editor.inputs.getCurrentPagePoint())\n\teditor.setHintingShapes(hit ? [hit.id] : [])\n}\n\nclass CommentIdle extends StateNode {\n\tstatic override id = 'idle'\n\n\toverride onEnter() {\n\t\t// Back to hovering: restore the pin cursor (a cancelled placement may have changed it).\n\t\tthis.editor.setCursor({ type: 'comment', rotation: 0 })\n\t\t// After a region placement its composer is still open here. A shape outline under its pin\n\t\t// corner would imply a shape anchor the region never uses.\n\t\tif (pendingComment.get(this.editor)?.anchor.type === 'region') {\n\t\t\tthis.editor.setHintingShapes([])\n\t\t} else {\n\t\t\tupdateAnchorHint(this.editor)\n\t\t}\n\t}\n\n\toverride onPointerMove() {\n\t\tupdateAnchorHint(this.editor)\n\t}\n\n\toverride onPointerDown() {\n\t\tthis.parent.transition('pointing')\n\t}\n}\n\nclass CommentPointing extends StateNode {\n\tstatic override id = 'pointing'\n\n\toverride onEnter() {\n\t\t// Open the composer immediately at the press point so it's visible from pointer-down (not just\n\t\t// on release), and let it trail the pointer while dragging \u2014 like placing a sticky note. The\n\t\t// anchor is a bare point for now; it's resolved (shape or point) on pointer up.\n\t\tconst { editor } = this\n\t\t// The composer opens under the pointer and stands in for it, so the cursor hides; it becomes\n\t\t// `move` once a drag starts.\n\t\teditor.setCursor({ type: 'none', rotation: 0 })\n\t\tconst point = editor.inputs.getCurrentPagePoint()\n\t\tpendingComment.set(editor, {\n\t\t\tanchor: { type: 'point', x: point.x, y: point.y },\n\t\t\tpoint: { x: point.x, y: point.y },\n\t\t})\n\t}\n\n\toverride onPointerMove() {\n\t\tconst { editor } = this\n\t\t// Once the pointer passes the drag threshold with region comments enabled, this is a region,\n\t\t// not a follow \u2014 hand off to the region drag (which clears this composer and draws the box).\n\t\tif (getCommentingOptions(editor).enableRegions && editor.inputs.getIsDragging()) {\n\t\t\tthis.parent.transition('dragging')\n\t\t\treturn\n\t\t}\n\t\t// Otherwise the composer trails the pointer \u2014 keep hinting the shape a release here would\n\t\t// anchor to, like the idle hover does.\n\t\tif (editor.inputs.getIsDragging() && editor.getInstanceState().cursor.type !== 'move') {\n\t\t\teditor.setCursor({ type: 'move', rotation: 0 })\n\t\t}\n\t\tupdateAnchorHint(editor)\n\t\tconst point = editor.inputs.getCurrentPagePoint()\n\t\tpendingComment.update(editor, (p) => (p ? { ...p, point: { x: point.x, y: point.y } } : p))\n\t}\n\n\t// Settle where the pointer is released: anchor to the shape under it, or drop a point.\n\toverride onPointerUp() {\n\t\tconst { editor } = this\n\t\tconst point = editor.inputs.getCurrentPagePoint()\n\t\tfinishPlacement(this, pendingCommentAt(editor, point))\n\t}\n\n\toverride onInterrupt() {\n\t\tthis.cancel()\n\t}\n\n\t// Abandon the follow composer if placement is interrupted (focus loss, etc.). Its text survives\n\t// in the draft store. Escape is the tool's own onCancel, which runs first.\n\tprivate cancel() {\n\t\tpendingComment.set(this.editor, null)\n\t\tthis.parent.transition('idle')\n\t}\n}\n\nclass CommentDragging extends StateNode {\n\tstatic override id = 'dragging'\n\n\toverride onEnter() {\n\t\t// A region drag supersedes the point-follow composer opened in `pointing`. Show a crosshair again,\n\t\t// since the composer no longer stands in for the pointer, and drop the placement hint \u2014 a region\n\t\t// anchors to its rectangle, so a single-shape outline would be stale.\n\t\tpendingComment.set(this.editor, null)\n\t\tthis.editor.setHintingShapes([])\n\t\tthis.editor.setCursor({ type: 'cross', rotation: 0 })\n\t\tthis.updateDraft()\n\t}\n\n\toverride onPointerMove() {\n\t\tthis.updateDraft()\n\t}\n\n\t// Commit the dragged rectangle as a region anchor; the composer opens at its pin corner.\n\toverride onPointerUp() {\n\t\tconst { editor } = this\n\t\tconst origin = editor.inputs.getOriginPagePoint()\n\t\tconst current = editor.inputs.getCurrentPagePoint()\n\t\tconst region = regionBetween(origin, current)\n\t\t// The pin lives on the corner the drag released on \u2014 drag up-left, pin top-left.\n\t\tconst pin = { x: current.x >= origin.x ? 1 : 0, y: current.y >= origin.y ? 1 : 0 }\n\t\tregionDraft.set(editor, null)\n\t\tfinishPlacement(this, {\n\t\t\tanchor: { type: 'region', ...region, pinX: pin.x, pinY: pin.y },\n\t\t\tpoint: regionPinPoint(region, pin),\n\t\t})\n\t}\n\n\toverride onInterrupt() {\n\t\tthis.cancel()\n\t}\n\n\tprivate updateDraft() {\n\t\tconst { editor } = this\n\t\tregionDraft.set(\n\t\t\teditor,\n\t\t\tregionBetween(editor.inputs.getOriginPagePoint(), editor.inputs.getCurrentPagePoint())\n\t\t)\n\t}\n\n\tprivate cancel() {\n\t\tregionDraft.set(this.editor, null)\n\t\tthis.parent.transition('idle')\n\t}\n}\n\n/** @public */\nexport const commentTools = [CommentTool]\n\nconst messages = defineMessages({\n\ttoolComment: { id: 'tool.comment', defaultMessage: 'Comment' },\n})\n\n/** Registers the comment tool in the UI (icon, label, shortcut). Compose into your overrides.\n * Once registered, tldraw's `DefaultQuickActionsContent` shows the comment button, and its\n * `DefaultContextMenuContent` shows a comment item that opens the composer where the menu was\n * opened.\n * @public */\nexport const commentToolOverrides: TLUiOverrides = {\n\ttools(editor, tools) {\n\t\ttools.comment = {\n\t\t\tid: 'comment',\n\t\t\ticon: 'comment',\n\t\t\tlabel: messages.toolComment.id,\n\t\t\tkbd: 'c',\n\t\t\tonSelect: (source) => {\n\t\t\t\t// The menu was opened by the last pointer down; the live pointer is over the menu now.\n\t\t\t\tif (source === 'context-menu') startCommentAt(editor, editor.inputs.getOriginPagePoint())\n\t\t\t\telse editor.setCurrentTool('comment')\n\t\t\t},\n\t\t}\n\t\treturn tools\n\t},\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBASO;AACP,qBAAuF;AACvF,mBAA4C;AAC5C,0BAAoE;AAiBpE,SAAS,uBACR,MACA,WACoB;AACpB,SAAO;AAAA,IACN,GAAG;AAAA,IACH,GAAG;AAAA,IACH,YAAY,EAAE,GAAG,KAAK,YAAY,GAAG,UAAU,WAAW;AAAA,EAC3D;AACD;AAIO,SAAS,cAAc,GAAY,GAAsB;AAC/D,SAAO;AAAA,IACN,GAAG,KAAK,IAAI,EAAE,GAAG,EAAE,CAAC;AAAA,IACpB,GAAG,KAAK,IAAI,EAAE,GAAG,EAAE,CAAC;AAAA,IACpB,GAAG,KAAK,IAAI,EAAE,IAAI,EAAE,CAAC;AAAA,IACrB,GAAG,KAAK,IAAI,EAAE,IAAI,EAAE,CAAC;AAAA,EACtB;AACD;AAWO,MAAM,oBAAoB,wBAAU;AAAA,EAC1C,OAAgB,KAAK;AAAA,EACrB,OAAgB,UAAU;AAAA,EAC1B,OAAgB,WAAqC;AACpD,WAAO,CAAC,aAAa,iBAAiB,eAAe;AAAA,EACtD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;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,OAAO,IAAI,IAAI,EAAE;AACjF,6BAAY,IAAI,QAAQ,IAAI;AAC5B,oBAAgB,MAAM;AAAA,MACrB,QAAQ,EAAE,MAAM,UAAU,GAAG,QAAQ,MAAM,IAAI,GAAG,MAAM,IAAI,EAAE;AAAA,MAC9D,WAAO,oCAAe,QAAQ,GAAG;AAAA,IAClC,CAAC;AAAA,EACF;AAAA,EAES,cAAc;AACtB,SAAK,OAAO;AAAA,EACb;AAAA,EAEQ,cAAc;AACrB,UAAM,EAAE,OAAO,IAAI;AACnB,6BAAY;AAAA,MACX;AAAA,MACA,cAAc,OAAO,OAAO,mBAAmB,GAAG,OAAO,OAAO,oBAAoB,CAAC;AAAA,IACtF;AAAA,EACD;AAAA,EAEQ,SAAS;AAChB,6BAAY,IAAI,KAAK,QAAQ,IAAI;AACjC,SAAK,OAAO,WAAW,MAAM;AAAA,EAC9B;AACD;AAGO,MAAM,eAAe,CAAC,WAAW;AAExC,MAAM,eAAW,8BAAe;AAAA,EAC/B,aAAa,EAAE,IAAI,gBAAgB,gBAAgB,UAAU;AAC9D,CAAC;AAOM,MAAM,uBAAsC;AAAA,EAClD,MAAM,QAAQ,OAAO;AACpB,UAAM,UAAU;AAAA,MACf,IAAI;AAAA,MACJ,MAAM;AAAA,MACN,OAAO,SAAS,YAAY;AAAA,MAC5B,KAAK;AAAA,MACL,UAAU,CAAC,WAAW;AAErB,YAAI,WAAW,eAAgB,gBAAe,QAAQ,OAAO,OAAO,mBAAmB,CAAC;AAAA,YACnF,QAAO,eAAe,SAAS;AAAA,MACrC;AAAA,IACD;AACA,WAAO;AAAA,EACR;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -26,11 +26,12 @@ var import_tldraw = require("tldraw");
|
|
|
26
26
|
var import_icons = require("../ui/icons");
|
|
27
27
|
var import_state = require("./state");
|
|
28
28
|
const messages = (0, import_tldraw.defineMessages)({
|
|
29
|
+
commentsClose: { id: "comments.close", defaultMessage: "Close" },
|
|
29
30
|
commentsFilter: { id: "comments.filter", defaultMessage: "Filter comments" },
|
|
30
31
|
commentsOnlyMyComments: { id: "comments.only-my-comments", defaultMessage: "Only my comments" },
|
|
31
32
|
commentsOnlyUnread: { id: "comments.only-unread", defaultMessage: "Only unread" },
|
|
32
33
|
commentsShowAllPages: { id: "comments.show-all-pages", defaultMessage: "Show all pages" },
|
|
33
|
-
commentsShowResolved: { id: "comments.show-resolved", defaultMessage: "Show resolved
|
|
34
|
+
commentsShowResolved: { id: "comments.show-resolved", defaultMessage: "Show resolved" }
|
|
34
35
|
});
|
|
35
36
|
function CommentsFilterMenu({
|
|
36
37
|
canFilterByAuthor,
|
|
@@ -49,48 +50,64 @@ function CommentsFilterMenu({
|
|
|
49
50
|
type: "icon",
|
|
50
51
|
tooltip: msg(messages.commentsFilter),
|
|
51
52
|
title: msg(messages.commentsFilter),
|
|
52
|
-
className: "tlui-cmt-
|
|
53
|
+
className: "tlui-cmt-icon-btn",
|
|
53
54
|
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons.MoreMenuIcon, {})
|
|
54
55
|
}
|
|
55
56
|
) }),
|
|
56
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_tldraw.TldrawUiDropdownMenuContent, { side: "bottom", align: "end", alignOffset: 0, children: /* @__PURE__ */ (0, import_jsx_runtime.
|
|
57
|
-
/* @__PURE__ */ (0, import_jsx_runtime.
|
|
58
|
-
|
|
57
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_tldraw.TldrawUiDropdownMenuContent, { side: "bottom", align: "end", alignOffset: -6, sideOffset: 0, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_tldraw.TldrawUiMenuContextProvider, { type: "menu", sourceId: "menu", children: [
|
|
58
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_tldraw.TldrawUiMenuGroup, { id: "comments-filter", children: [
|
|
59
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
60
|
+
import_tldraw.TldrawUiMenuCheckboxItem,
|
|
61
|
+
{
|
|
62
|
+
toggle: true,
|
|
63
|
+
id: "show-all-pages",
|
|
64
|
+
label: messages.commentsShowAllPages.id,
|
|
65
|
+
checked: !filters.onlyCurrentPage,
|
|
66
|
+
onSelect: () => toggle("onlyCurrentPage")
|
|
67
|
+
}
|
|
68
|
+
),
|
|
69
|
+
canFilterByAuthor && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
70
|
+
import_tldraw.TldrawUiMenuCheckboxItem,
|
|
71
|
+
{
|
|
72
|
+
toggle: true,
|
|
73
|
+
id: "only-my-comments",
|
|
74
|
+
label: messages.commentsOnlyMyComments.id,
|
|
75
|
+
checked: filters.onlyMine,
|
|
76
|
+
onSelect: () => toggle("onlyMine")
|
|
77
|
+
}
|
|
78
|
+
),
|
|
79
|
+
canFilterByUnread && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
80
|
+
import_tldraw.TldrawUiMenuCheckboxItem,
|
|
81
|
+
{
|
|
82
|
+
toggle: true,
|
|
83
|
+
id: "only-unread",
|
|
84
|
+
label: messages.commentsOnlyUnread.id,
|
|
85
|
+
checked: filters.onlyUnread,
|
|
86
|
+
onSelect: () => toggle("onlyUnread")
|
|
87
|
+
}
|
|
88
|
+
),
|
|
89
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
90
|
+
import_tldraw.TldrawUiMenuCheckboxItem,
|
|
91
|
+
{
|
|
92
|
+
toggle: true,
|
|
93
|
+
id: "show-resolved",
|
|
94
|
+
label: messages.commentsShowResolved.id,
|
|
95
|
+
checked: filters.showResolved,
|
|
96
|
+
onSelect: () => toggle("showResolved")
|
|
97
|
+
}
|
|
98
|
+
)
|
|
99
|
+
] }),
|
|
100
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_tldraw.TldrawUiMenuGroup, { id: "comments-close", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
101
|
+
import_tldraw.TldrawUiMenuItem,
|
|
59
102
|
{
|
|
60
|
-
id: "
|
|
61
|
-
label: messages.
|
|
62
|
-
|
|
63
|
-
|
|
103
|
+
id: "close-comments",
|
|
104
|
+
label: messages.commentsClose.id,
|
|
105
|
+
onSelect: () => {
|
|
106
|
+
import_state.commentsSidebarOpen.set(editor, false);
|
|
107
|
+
}
|
|
64
108
|
}
|
|
65
|
-
)
|
|
66
|
-
|
|
67
|
-
import_tldraw.TldrawUiMenuCheckboxItem,
|
|
68
|
-
{
|
|
69
|
-
id: "only-my-comments",
|
|
70
|
-
label: messages.commentsOnlyMyComments.id,
|
|
71
|
-
checked: filters.onlyMine,
|
|
72
|
-
onSelect: () => toggle("onlyMine")
|
|
73
|
-
}
|
|
74
|
-
),
|
|
75
|
-
canFilterByUnread && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
76
|
-
import_tldraw.TldrawUiMenuCheckboxItem,
|
|
77
|
-
{
|
|
78
|
-
id: "only-unread",
|
|
79
|
-
label: messages.commentsOnlyUnread.id,
|
|
80
|
-
checked: filters.onlyUnread,
|
|
81
|
-
onSelect: () => toggle("onlyUnread")
|
|
82
|
-
}
|
|
83
|
-
),
|
|
84
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
85
|
-
import_tldraw.TldrawUiMenuCheckboxItem,
|
|
86
|
-
{
|
|
87
|
-
id: "show-resolved",
|
|
88
|
-
label: messages.commentsShowResolved.id,
|
|
89
|
-
checked: filters.showResolved,
|
|
90
|
-
onSelect: () => toggle("showResolved")
|
|
91
|
-
}
|
|
92
|
-
)
|
|
93
|
-
] }) }) })
|
|
109
|
+
) })
|
|
110
|
+
] }) })
|
|
94
111
|
] });
|
|
95
112
|
}
|
|
96
113
|
//# sourceMappingURL=comments-filter-menu.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/canvas/comments-filter-menu.tsx"],
|
|
4
|
-
"sourcesContent": ["import {\n\tdefineMessages,\n\tTldrawUiButton,\n\tTldrawUiDropdownMenuContent,\n\tTldrawUiDropdownMenuRoot,\n\tTldrawUiDropdownMenuTrigger,\n\tTldrawUiMenuCheckboxItem,\n\tTldrawUiMenuContextProvider,\n\tTldrawUiMenuGroup,\n\tuseEditor,\n\tuseTranslation,\n\tuseValue,\n} from 'tldraw'\nimport { MoreMenuIcon } from '../ui/icons'\nimport { SidebarFilters } from './sidebar-filters'\nimport { sidebarFilters } from './state'\n\nconst messages = defineMessages({\n\tcommentsFilter: { id: 'comments.filter', defaultMessage: 'Filter comments' },\n\tcommentsOnlyMyComments: { id: 'comments.only-my-comments', defaultMessage: 'Only my comments' },\n\tcommentsOnlyUnread: { id: 'comments.only-unread', defaultMessage: 'Only unread' },\n\tcommentsShowAllPages: { id: 'comments.show-all-pages', defaultMessage: 'Show all pages' },\n\tcommentsShowResolved: { id: 'comments.show-resolved', defaultMessage: 'Show resolved
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
4
|
+
"sourcesContent": ["import {\n\tdefineMessages,\n\tTldrawUiButton,\n\tTldrawUiDropdownMenuContent,\n\tTldrawUiDropdownMenuRoot,\n\tTldrawUiDropdownMenuTrigger,\n\tTldrawUiMenuCheckboxItem,\n\tTldrawUiMenuContextProvider,\n\tTldrawUiMenuGroup,\n\tTldrawUiMenuItem,\n\tuseEditor,\n\tuseTranslation,\n\tuseValue,\n} from 'tldraw'\nimport { MoreMenuIcon } from '../ui/icons'\nimport { SidebarFilters } from './sidebar-filters'\nimport { commentsSidebarOpen, sidebarFilters } from './state'\n\nconst messages = defineMessages({\n\tcommentsClose: { id: 'comments.close', defaultMessage: 'Close' },\n\tcommentsFilter: { id: 'comments.filter', defaultMessage: 'Filter comments' },\n\tcommentsOnlyMyComments: { id: 'comments.only-my-comments', defaultMessage: 'Only my comments' },\n\tcommentsOnlyUnread: { id: 'comments.only-unread', defaultMessage: 'Only unread' },\n\tcommentsShowAllPages: { id: 'comments.show-all-pages', defaultMessage: 'Show all pages' },\n\tcommentsShowResolved: { id: 'comments.show-resolved', defaultMessage: 'Show resolved' },\n})\n\n/** @public */\nexport interface CommentsFilterMenuProps {\n\t/** Whether to offer the \"only your threads\" toggle (needs a known current user). */\n\tcanFilterByAuthor?: boolean\n\t/** Whether to offer the \"only unread\" toggle (needs a read-status source). */\n\tcanFilterByUnread?: boolean\n}\n\n/** The funnel dropdown in the sidebar header: toggles for which threads the list shows.\n * @public @react */\nexport function CommentsFilterMenu({\n\tcanFilterByAuthor,\n\tcanFilterByUnread,\n}: CommentsFilterMenuProps) {\n\tconst editor = useEditor()\n\tconst msg = useTranslation()\n\tconst filters = useValue('sidebar filters', () => sidebarFilters.get(editor), [editor])\n\tconst toggle = (key: keyof SidebarFilters) => {\n\t\tsidebarFilters.update(editor, (f) => ({ ...f, [key]: !f[key] }))\n\t}\n\n\treturn (\n\t\t<TldrawUiDropdownMenuRoot id=\"comments-filter\">\n\t\t\t<TldrawUiDropdownMenuTrigger>\n\t\t\t\t<TldrawUiButton\n\t\t\t\t\ttype=\"icon\"\n\t\t\t\t\ttooltip={msg(messages.commentsFilter)}\n\t\t\t\t\ttitle={msg(messages.commentsFilter)}\n\t\t\t\t\tclassName=\"tlui-cmt-icon-btn\"\n\t\t\t\t>\n\t\t\t\t\t<MoreMenuIcon />\n\t\t\t\t</TldrawUiButton>\n\t\t\t</TldrawUiDropdownMenuTrigger>\n\t\t\t<TldrawUiDropdownMenuContent side=\"bottom\" align=\"end\" alignOffset={-6} sideOffset={0}>\n\t\t\t\t<TldrawUiMenuContextProvider type=\"menu\" sourceId=\"menu\">\n\t\t\t\t\t<TldrawUiMenuGroup id=\"comments-filter\">\n\t\t\t\t\t\t<TldrawUiMenuCheckboxItem\n\t\t\t\t\t\t\ttoggle\n\t\t\t\t\t\t\tid=\"show-all-pages\"\n\t\t\t\t\t\t\tlabel={messages.commentsShowAllPages.id}\n\t\t\t\t\t\t\tchecked={!filters.onlyCurrentPage}\n\t\t\t\t\t\t\tonSelect={() => toggle('onlyCurrentPage')}\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t{canFilterByAuthor && (\n\t\t\t\t\t\t\t<TldrawUiMenuCheckboxItem\n\t\t\t\t\t\t\t\ttoggle\n\t\t\t\t\t\t\t\tid=\"only-my-comments\"\n\t\t\t\t\t\t\t\tlabel={messages.commentsOnlyMyComments.id}\n\t\t\t\t\t\t\t\tchecked={filters.onlyMine}\n\t\t\t\t\t\t\t\tonSelect={() => toggle('onlyMine')}\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t)}\n\t\t\t\t\t\t{canFilterByUnread && (\n\t\t\t\t\t\t\t<TldrawUiMenuCheckboxItem\n\t\t\t\t\t\t\t\ttoggle\n\t\t\t\t\t\t\t\tid=\"only-unread\"\n\t\t\t\t\t\t\t\tlabel={messages.commentsOnlyUnread.id}\n\t\t\t\t\t\t\t\tchecked={filters.onlyUnread}\n\t\t\t\t\t\t\t\tonSelect={() => toggle('onlyUnread')}\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t)}\n\t\t\t\t\t\t<TldrawUiMenuCheckboxItem\n\t\t\t\t\t\t\ttoggle\n\t\t\t\t\t\t\tid=\"show-resolved\"\n\t\t\t\t\t\t\tlabel={messages.commentsShowResolved.id}\n\t\t\t\t\t\t\tchecked={filters.showResolved}\n\t\t\t\t\t\t\tonSelect={() => toggle('showResolved')}\n\t\t\t\t\t\t/>\n\t\t\t\t\t</TldrawUiMenuGroup>\n\t\t\t\t\t<TldrawUiMenuGroup id=\"comments-close\">\n\t\t\t\t\t\t<TldrawUiMenuItem\n\t\t\t\t\t\t\tid=\"close-comments\"\n\t\t\t\t\t\t\tlabel={messages.commentsClose.id}\n\t\t\t\t\t\t\tonSelect={() => {\n\t\t\t\t\t\t\t\tcommentsSidebarOpen.set(editor, false)\n\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t/>\n\t\t\t\t\t</TldrawUi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AAM,OAAM,aAAa,IAAI,YAAY,GACnF,uDAAC,6CAA4B,MAAK,QAAO,UAAS,QACjD;AAAA,mDAAC,mCAAkB,IAAG,mBACrB;AAAA;AAAA,UAAC;AAAA;AAAA,YACA,QAAM;AAAA,YACN,IAAG;AAAA,YACH,OAAO,SAAS,qBAAqB;AAAA,YACrC,SAAS,CAAC,QAAQ;AAAA,YAClB,UAAU,MAAM,OAAO,iBAAiB;AAAA;AAAA,QACzC;AAAA,QACC,qBACA;AAAA,UAAC;AAAA;AAAA,YACA,QAAM;AAAA,YACN,IAAG;AAAA,YACH,OAAO,SAAS,uBAAuB;AAAA,YACvC,SAAS,QAAQ;AAAA,YACjB,UAAU,MAAM,OAAO,UAAU;AAAA;AAAA,QAClC;AAAA,QAEA,qBACA;AAAA,UAAC;AAAA;AAAA,YACA,QAAM;AAAA,YACN,IAAG;AAAA,YACH,OAAO,SAAS,mBAAmB;AAAA,YACnC,SAAS,QAAQ;AAAA,YACjB,UAAU,MAAM,OAAO,YAAY;AAAA;AAAA,QACpC;AAAA,QAED;AAAA,UAAC;AAAA;AAAA,YACA,QAAM;AAAA,YACN,IAAG;AAAA,YACH,OAAO,SAAS,qBAAqB;AAAA,YACrC,SAAS,QAAQ;AAAA,YACjB,UAAU,MAAM,OAAO,cAAc;AAAA;AAAA,QACtC;AAAA,SACD;AAAA,MACA,4CAAC,mCAAkB,IAAG,kBACrB;AAAA,QAAC;AAAA;AAAA,UACA,IAAG;AAAA,UACH,OAAO,SAAS,cAAc;AAAA,UAC9B,UAAU,MAAM;AACf,6CAAoB,IAAI,QAAQ,KAAK;AAAA,UACtC;AAAA;AAAA,MACD,GACD;AAAA,OACD,GACD;AAAA,KACD;AAEF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -29,7 +29,7 @@ const messages = (0, import_tldraw.defineMessages)({
|
|
|
29
29
|
commentsHide: { id: "comments.hide", defaultMessage: "Hide comments" },
|
|
30
30
|
commentsShow: { id: "comments.show", defaultMessage: "Show comments" }
|
|
31
31
|
});
|
|
32
|
-
const HIDE_SHORTCUT = "
|
|
32
|
+
const HIDE_SHORTCUT = "!c";
|
|
33
33
|
function CommentsOverflowMenu() {
|
|
34
34
|
const editor = (0, import_tldraw.useEditor)();
|
|
35
35
|
const msg = (0, import_tldraw.useTranslation)();
|
|
@@ -41,32 +41,14 @@ function CommentsOverflowMenu() {
|
|
|
41
41
|
type: "icon",
|
|
42
42
|
tooltip: msg(messages.commentsMoreOptions),
|
|
43
43
|
title: msg(messages.commentsMoreOptions),
|
|
44
|
-
className: "tlui-cmt-
|
|
44
|
+
className: "tlui-cmt-icon-btn",
|
|
45
45
|
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_tldraw.TldrawUiIcon, { icon: "dots-vertical", label: msg(messages.commentsMoreOptions), small: true })
|
|
46
46
|
}
|
|
47
47
|
) }),
|
|
48
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
49
|
-
import_tldraw.
|
|
50
|
-
{
|
|
51
|
-
|
|
52
|
-
side: "bottom",
|
|
53
|
-
align: "end",
|
|
54
|
-
alignOffset: 0,
|
|
55
|
-
sideOffset: 4,
|
|
56
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_tldraw.TldrawUiDropdownMenuGroup, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_tldraw.TldrawUiDropdownMenuItem, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
57
|
-
"button",
|
|
58
|
-
{
|
|
59
|
-
type: "button",
|
|
60
|
-
className: "tlui-cmt-menu-item",
|
|
61
|
-
onClick: () => (0, import_state.toggleCommentsHidden)(editor),
|
|
62
|
-
children: [
|
|
63
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: hidden ? msg(messages.commentsShow) : msg(messages.commentsHide) }),
|
|
64
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "tlui-cmt-menu-item__shortcut", children: HIDE_SHORTCUT })
|
|
65
|
-
]
|
|
66
|
-
}
|
|
67
|
-
) }) })
|
|
68
|
-
}
|
|
69
|
-
)
|
|
48
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_tldraw.TldrawUiDropdownMenuContent, { side: "bottom", align: "end", alignOffset: 0, sideOffset: 0, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_tldraw.TldrawUiDropdownMenuGroup, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_tldraw.TldrawUiDropdownMenuItem, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_tldraw.TldrawUiButton, { type: "menu", onClick: () => (0, import_state.toggleCommentsHidden)(editor), children: [
|
|
49
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_tldraw.TldrawUiButtonLabel, { children: hidden ? msg(messages.commentsShow) : msg(messages.commentsHide) }),
|
|
50
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_tldraw.TldrawUiKbd, { children: HIDE_SHORTCUT })
|
|
51
|
+
] }) }) }) })
|
|
70
52
|
] });
|
|
71
53
|
}
|
|
72
54
|
//# sourceMappingURL=comments-overflow-menu.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/canvas/comments-overflow-menu.tsx"],
|
|
4
|
-
"sourcesContent": ["import {\n\tdefineMessages,\n\tTldrawUiButton,\n\tTldrawUiDropdownMenuContent,\n\tTldrawUiDropdownMenuGroup,\n\tTldrawUiDropdownMenuItem,\n\tTldrawUiDropdownMenuRoot,\n\tTldrawUiDropdownMenuTrigger,\n\tTldrawUiIcon,\n\tuseEditor,\n\tuseTranslation,\n\tuseValue,\n} from 'tldraw'\nimport { commentsHidden, toggleCommentsHidden } from './state'\n\nconst messages = defineMessages({\n\tcommentsMoreOptions: { id: 'comments.more-options', defaultMessage: 'More options' },\n\tcommentsHide: { id: 'comments.hide', defaultMessage: 'Hide comments' },\n\tcommentsShow: { id: 'comments.show', defaultMessage: 'Show comments' },\n})\n\n//
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
4
|
+
"sourcesContent": ["import {\n\tdefineMessages,\n\tTldrawUiButton,\n\tTldrawUiButtonLabel,\n\tTldrawUiDropdownMenuContent,\n\tTldrawUiDropdownMenuGroup,\n\tTldrawUiDropdownMenuItem,\n\tTldrawUiDropdownMenuRoot,\n\tTldrawUiDropdownMenuTrigger,\n\tTldrawUiIcon,\n\tTldrawUiKbd,\n\tuseEditor,\n\tuseTranslation,\n\tuseValue,\n} from 'tldraw'\nimport { commentsHidden, toggleCommentsHidden } from './state'\n\nconst messages = defineMessages({\n\tcommentsMoreOptions: { id: 'comments.more-options', defaultMessage: 'More options' },\n\tcommentsHide: { id: 'comments.hide', defaultMessage: 'Hide comments' },\n\tcommentsShow: { id: 'comments.show', defaultMessage: 'Show comments' },\n})\n\n// tldraw's kbd notation (`!` = shift), rendered per platform by TldrawUiKbd.\nconst HIDE_SHORTCUT = '!c'\n\n/** The overflow (\u22EF) dropdown in the sidebar header. For now it holds the hide/show-comments\n * toggle; it's the home for later comment-wide controls (notifications, mark all as read).\n * @public @react */\nexport function CommentsOverflowMenu() {\n\tconst editor = useEditor()\n\tconst msg = useTranslation()\n\tconst hidden = useValue('comments hidden', () => commentsHidden.get(editor), [editor])\n\n\treturn (\n\t\t<TldrawUiDropdownMenuRoot id=\"comments-overflow\">\n\t\t\t<TldrawUiDropdownMenuTrigger>\n\t\t\t\t<TldrawUiButton\n\t\t\t\t\ttype=\"icon\"\n\t\t\t\t\ttooltip={msg(messages.commentsMoreOptions)}\n\t\t\t\t\ttitle={msg(messages.commentsMoreOptions)}\n\t\t\t\t\tclassName=\"tlui-cmt-icon-btn\"\n\t\t\t\t>\n\t\t\t\t\t<TldrawUiIcon icon=\"dots-vertical\" label={msg(messages.commentsMoreOptions)} small />\n\t\t\t\t</TldrawUiButton>\n\t\t\t</TldrawUiDropdownMenuTrigger>\n\t\t\t<TldrawUiDropdownMenuContent side=\"bottom\" align=\"end\" alignOffset={0} sideOffset={0}>\n\t\t\t\t<TldrawUiDropdownMenuGroup>\n\t\t\t\t\t<TldrawUiDropdownMenuItem>\n\t\t\t\t\t\t<TldrawUiButton type=\"menu\" onClick={() => toggleCommentsHidden(editor)}>\n\t\t\t\t\t\t\t<TldrawUiButtonLabel>\n\t\t\t\t\t\t\t\t{hidden ? msg(messages.commentsShow) : msg(messages.commentsHide)}\n\t\t\t\t\t\t\t</TldrawUiButtonLabel>\n\t\t\t\t\t\t\t<TldrawUiKbd>{HIDE_SHORTCUT}</TldrawUiKbd>\n\t\t\t\t\t\t</TldrawUiButton>\n\t\t\t\t\t</TldrawUiDropdownMenuItem>\n\t\t\t\t</TldrawUiDropdownMenuGroup>\n\t\t\t</TldrawUiDropdownMenuContent>\n\t\t</TldrawUiDropdownMenuRoot>\n\t)\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA2CK;AA3CL,oBAcO;AACP,mBAAqD;AAErD,MAAM,eAAW,8BAAe;AAAA,EAC/B,qBAAqB,EAAE,IAAI,yBAAyB,gBAAgB,eAAe;AAAA,EACnF,cAAc,EAAE,IAAI,iBAAiB,gBAAgB,gBAAgB;AAAA,EACrE,cAAc,EAAE,IAAI,iBAAiB,gBAAgB,gBAAgB;AACtE,CAAC;AAGD,MAAM,gBAAgB;AAKf,SAAS,uBAAuB;AACtC,QAAM,aAAS,yBAAU;AACzB,QAAM,UAAM,8BAAe;AAC3B,QAAM,aAAS,wBAAS,mBAAmB,MAAM,4BAAe,IAAI,MAAM,GAAG,CAAC,MAAM,CAAC;AAErF,SACC,6CAAC,0CAAyB,IAAG,qBAC5B;AAAA,gDAAC,6CACA;AAAA,MAAC;AAAA;AAAA,QACA,MAAK;AAAA,QACL,SAAS,IAAI,SAAS,mBAAmB;AAAA,Q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