@devries-cameron20 / t3code Mirror · read-only / commits / 777cd68c6a
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 23, 08:00 UTC

perf(web): the composer editor compiles with the React Compiler (#20450)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Julius Marminge committed Oct 16, 2026 at 18:46 UTC 777cd68c6aa0b816f39d1e0dc79ad34590635755
2 files changed +303 -326
apps/web/reactCompiledFiles.ts
+1
@@ -25,4 +25,5 @@ export const REACT_COMPILED_FILES = [
25 "apps/web/src/hooks/useProactivePanels.ts",
26 "apps/web/src/hooks/useRightPanelSurfaceClose.ts",
27 "apps/web/src/components/ui/tooltip.tsx",
28 + "apps/web/src/components/ComposerPromptEditorTiptap.tsx",
29 ] as const;
apps/web/src/components/ComposerPromptEditorTiptap.tsx
+302 -326
@@ -36,12 +36,10 @@ import {
36 import {
37 createContext,
38 use,
39 - useCallback,
39 useEffect,
40 useEffectEvent,
41 useImperativeHandle,
42 useLayoutEffect,
44 - useMemo,
43 useRef,
44 useState,
45 type KeyboardEvent as ReactKeyboardEvent,
@@ -55,6 +53,7 @@ import {
53 isCollapsedCursorAdjacentToInlineToken,
54 pastedPathQueryLength,
55 } from "~/composer-logic";
56 +import { useStableCallback } from "~/hooks/useStableCallback";
57 import {
58 collectComposerPromptInlineTokens,
59 selectionTouchesMentionBoundary,
@@ -381,33 +380,30 @@ function ComposerCitationNodeView({ node, editor, getPos }: NodeViewProps) {
380 const commentTarget =
381 commentContext.openComment?.key === citeKey ? commentContext.openComment : null;
382
384 - const nodePos = useCallback(() => {
383 + const nodePos = () => {
384 const pos = typeof getPos === "function" ? getPos() : null;
385 return typeof pos === "number" ? pos : null;
387 - }, [getPos]);
388 -
389 - const onSaveComment = useCallback(
390 - (comment: string): boolean => {
391 - if (!editor.isEditable) return false;
392 - const pos = nodePos();
393 - if (pos === null) return false;
394 - const current = editor.state.doc.nodeAt(pos);
395 - if (!current || current.type.name !== "composer-citation") return false;
396 - const currentCitation = current.attrs.citation as AssistantCitation;
397 - const next = withAssistantCitationComment(currentCitation, comment);
398 - const tr = editor.state.tr.setNodeMarkup(pos, undefined, {
399 - ...current.attrs,
400 - citation: next,
401 - source: serializeAssistantCitation(next),
402 - });
403 - editor.view.dispatch(tr);
404 - return true;
405 - },
406 - [editor, nodePos],
407 - );
386 + };
387 +
388 + const onSaveComment = (comment: string): boolean => {
389 + if (!editor.isEditable) return false;
390 + const pos = nodePos();
391 + if (pos === null) return false;
392 + const current = editor.state.doc.nodeAt(pos);
393 + if (!current || current.type.name !== "composer-citation") return false;
394 + const currentCitation = current.attrs.citation as AssistantCitation;
395 + const next = withAssistantCitationComment(currentCitation, comment);
396 + const tr = editor.state.tr.setNodeMarkup(pos, undefined, {
397 + ...current.attrs,
398 + citation: next,
399 + source: serializeAssistantCitation(next),
400 + });
401 + editor.view.dispatch(tr);
402 + return true;
403 + };
404
405 const removeOnCancel = commentTarget?.removeOnCancel;
410 - const onRemove = useCallback(() => {
406 + const onRemove = () => {
407 if (!editor.isEditable || !removeOnCancel) return;
408 const pos = nodePos();
409 if (pos === null) return;
@@ -418,16 +414,16 @@ function ComposerCitationNodeView({ node, editor, getPos }: NodeViewProps) {
414 const from = removeOnCancel.before && doc.textBetween(pos - 1, pos) === " " ? pos - 1 : pos;
415 const to = removeOnCancel.after && doc.textBetween(end, end + 1) === " " ? end + 1 : end;
416 editor.chain().focus().deleteRange({ from, to }).run();
421 - }, [editor, nodePos, removeOnCancel]);
417 + };
418
423 - const onRestoreFocus = useCallback(() => {
419 + const onRestoreFocus = () => {
420 if (!editor.isEditable) return;
421 const pos = nodePos();
422 if (pos === null) return;
423 const current = editor.state.doc.nodeAt(pos);
424 if (!current || current.type.name !== "composer-citation") return;
425 editor.commands.focus(pos + current.nodeSize);
430 - }, [editor, nodePos]);
426 + };
427
428 return (
429 <NodeViewWrapper
@@ -775,6 +771,114 @@ const ComposerUndoGroupingExtension = Extension.create<
771 },
772 });
773
774 +// Module-level because Tiptap's extension hooks read their config from `this`,
775 +// and so the editor options keep one extensions identity across renders.
776 +function createComposerExtensions(richText: boolean) {
777 + return [
778 + StarterKit.configure({
779 + blockquote: false,
780 + bulletList: false,
781 + codeBlock: false,
782 + heading: false,
783 + horizontalRule: false,
784 + listItem: false,
785 + link: false,
786 + orderedList: false,
787 + underline: false,
788 + dropcursor: false,
789 + gapcursor: false,
790 + trailingNode: false,
791 + code: false,
792 + listKeymap: false,
793 + undoRedo: { newGroupDelay: COMPOSER_UNDO_GROUP_DELAY },
794 + ...(richText ? {} : { bold: false, italic: false, strike: false }),
795 + }),
796 + ComposerUndoGroupingExtension,
797 + ComposerMentionExtension,
798 + ComposerSkillExtension,
799 + ComposerCitationExtension,
800 + ComposerContextReferenceExtension,
801 + ComposerMarkersExtension,
802 + ...(richText
803 + ? [
804 + ComposerCodeExtension,
805 + ComposerCodeBlockExtension.extend({
806 + addNodeView() {
807 + return ReactNodeViewRenderer(ComposerCodeBlockNodeView, {
808 + // The header holds the language picker. Tiptap only shields
809 + // events aimed at the button element itself, so a click on
810 + // its icon or label would reach ProseMirror and move the
811 + // selection; keep every header event away from the editor.
812 + stopEvent: ({ event }) =>
813 + event.target instanceof Element &&
814 + event.target.closest(".chat-markdown-codeblock-header") !== null,
815 + });
816 + },
817 + // Tiptap's own ``` + space rule would open a fence inside a
818 + // list item or quote, where the serializer has no line for
819 + // it. Enter on a fence line covers the gesture at top level.
820 + addInputRules() {
821 + return [];
822 + },
823 + }),
824 + composerCodeBlockHighlight({
825 + resolveTheme: () =>
826 + resolveDiffThemeName(
827 + document.documentElement.classList.contains("dark") ? "dark" : "light",
828 + ),
829 + }),
830 + ...ComposerBlockExtensions.map((extension) =>
831 + extension.name === "blockquote"
832 + ? extension.extend({
833 + addInputRules() {
834 + return [blockquoteInputRule];
835 + },
836 + })
837 + : extension.name === "horizontalRule"
838 + ? extension.extend({
839 + addInputRules() {
840 + return [horizontalRuleInputRule];
841 + },
842 + })
843 + : extension.name === "heading"
844 + ? extension.extend({
845 + addInputRules() {
846 + return [headingInputRule];
847 + },
848 + })
849 + : extension,
850 + ),
851 + ...ComposerListExtensions.map((extension) =>
852 + extension.name === "listItem"
853 + ? extension
854 + : extension.extend({
855 + addInputRules() {
856 + return this.name === "bulletList"
857 + ? [
858 + listMarkerInputRule(/^(?<marker>[*+])(?<space>\s)$/, "bulletList"),
859 + listMarkerInputRule(
860 + /^(?<marker>-)(?<space>[ \t]+)(?<carried>[^\s[])$/,
861 + "bulletList",
862 + ),
863 + ]
864 + : [listMarkerInputRule(/^(?<marker>\d+[.)])(?<space>\s)$/, "orderedList")];
865 + },
866 + }),
867 + ),
868 + ComposerTaskListExtension,
869 + ComposerTaskItemExtension.extend({
870 + addInputRules() {
871 + return [taskInputRule(this.type), bulletToTaskInputRule];
872 + },
873 + }),
874 + ]
875 + : []),
876 + ];
877 +}
878 +
879 +const RICH_TEXT_EXTENSIONS = createComposerExtensions(true);
880 +const PLAIN_TEXT_EXTENSIONS = createComposerExtensions(false);
881 +
882 function ComposerPromptEditorTiptapInner(props: ComposerPromptEditorProps) {
883 const {
884 value,
@@ -806,21 +910,15 @@ function ComposerPromptEditorTiptapInner(props: ComposerPromptEditorProps) {
910 editorRef,
911 } = props;
912 const richText = !literalText && (richTextEnabled ?? false);
809 - const clampEditorCursor = useCallback(
810 - (text: string, position: number) =>
811 - literalText
812 - ? Math.max(
813 - 0,
814 - Math.min(text.length, Number.isFinite(position) ? Math.floor(position) : text.length),
815 - )
816 - : clampCollapsedComposerCursor(text, position),
817 - [literalText],
818 - );
819 - const expandEditorCursor = useCallback(
820 - (text: string, position: number) =>
821 - literalText ? position : expandCollapsedComposerCursor(text, position),
822 - [literalText],
823 - );
913 + const clampEditorCursor = (text: string, position: number) =>
914 + literalText
915 + ? Math.max(
916 + 0,
917 + Math.min(text.length, Number.isFinite(position) ? Math.floor(position) : text.length),
918 + )
919 + : clampCollapsedComposerCursor(text, position);
920 + const expandEditorCursor = (text: string, position: number) =>
921 + literalText ? position : expandCollapsedComposerCursor(text, position);
922
923 const onChangeRef = useRef(onChange);
924 const onVisibleSelectionChangeRef = useRef(onVisibleSelectionChange);
@@ -828,7 +926,6 @@ function ComposerPromptEditorTiptapInner(props: ComposerPromptEditorProps) {
926 const isPathQueryActiveRef = useRef(isPathQueryActive);
927 const buildFragmentRef = useRef(buildContextClipboardFragment);
928 const importFragmentRef = useRef(importContextFragment);
831 - const skillsRef = useRef(skills);
929 const latestValueRef = useRef(value);
930 const editorHolder = useRef<TiptapEditor | null>(null);
931
@@ -850,16 +947,14 @@ function ComposerPromptEditorTiptapInner(props: ComposerPromptEditorProps) {
947 useEffect(() => {
948 importFragmentRef.current = importContextFragment;
949 }, [importContextFragment]);
853 - useEffect(() => {
854 - skillsRef.current = skills;
855 - }, [skills]);
950 useLayoutEffect(() => {
951 latestValueRef.current = value;
952 }, [value]);
953
860 - const skillLabelFor = useCallback((name: string): SkillMeta => {
954 + // Stable so a skills refresh does not rerun the controlled-value effect.
955 + const skillLabelFor = useStableCallback((name: string): SkillMeta => {
956 const normalized = name.startsWith("$") ? name.slice(1) : name;
862 - const skill = skillsRef.current.find((candidate) => candidate.name === normalized);
957 + const skill = skills.find((candidate) => candidate.name === normalized);
958 if (!skill) {
959 return { label: formatProviderSkillDisplayName({ name: normalized }), description: null };
960 }
@@ -868,7 +963,7 @@ function ComposerPromptEditorTiptapInner(props: ComposerPromptEditorProps) {
963 label: formatProviderSkillDisplayName(skill),
964 description: shortDescription || skill.description?.trim() || null,
965 };
871 - }, []);
966 + });
967
968 const initialCursor = clampEditorCursor(value, cursor);
969 const initialExpandedCursor = expandEditorCursor(value, initialCursor);
@@ -886,221 +981,108 @@ function ComposerPromptEditorTiptapInner(props: ComposerPromptEditorProps) {
981 const citationDraftRef = useRef<{ key: string; comment: string } | null>(null);
982 const [isEmpty, setIsEmpty] = useState(value.length === 0);
983
889 - const citationCommentActions = useMemo(
890 - () => ({
891 - openComment: openCitation,
892 - onOpenChange: (nodeKey: string, open: boolean) => {
893 - if (!open && citationDraftRef.current?.key === nodeKey) citationDraftRef.current = null;
894 - setOpenCitation((current) => {
895 - if (open) {
896 - if (current?.key === nodeKey) return current;
897 - return { key: nodeKey };
898 - }
899 - return current?.key === nodeKey ? null : current;
900 - });
901 - },
902 - onDraftChange: (nodeKey: string, comment: string) => {
903 - citationDraftRef.current = { key: nodeKey, comment };
904 - },
905 - onSubmitAndSend: onCitationSubmitAndSend ?? (() => {}),
906 - }),
907 - [onCitationSubmitAndSend, openCitation],
908 - );
909 -
910 - const handleEditorChange = useCallback(
911 - (updated: TiptapEditor) => {
912 - const map = serializeEditorDoc(updated.state.doc);
913 - const contextIds = literalText ? [] : map.contextIds;
914 - const { from, to } = updated.state.selection;
915 - const fromFlat = pmToFlat(map, from);
916 - const toFlat = pmToFlat(map, to);
917 - const nextValue = map.value;
918 - const nextCursor = clampEditorCursor(map.value, flatToCollapsed(map, fromFlat));
919 - const nextExpandedCursor = Math.max(
920 - 0,
921 - Math.min(map.value.length, flatToMarkdown(map, fromFlat)),
922 - );
923 - const nextSelectionRange = {
924 - start: Math.min(nextExpandedCursor, flatToMarkdown(map, toFlat)),
925 - end: Math.max(nextExpandedCursor, flatToMarkdown(map, toFlat)),
926 - };
927 - const previousSelectionRange = selectionRangeRef.current;
928 - selectionRangeRef.current = nextSelectionRange;
929 - setIsEmpty(nextValue.length === 0);
930 - const previousSnapshot = snapshotRef.current;
931 - const snapshotChanged = !(
932 - previousSnapshot.value === nextValue &&
933 - previousSnapshot.cursor === nextCursor &&
934 - previousSnapshot.expandedCursor === nextExpandedCursor &&
935 - previousSnapshot.contextIds.length === contextIds.length &&
936 - previousSnapshot.contextIds.every((id, index) => id === contextIds[index])
937 - );
938 - if (isApplyingControlledUpdateRef.current) return;
939 - if (!snapshotChanged) {
940 - if (didComposerSelectionChangeVisibly(previousSelectionRange, nextSelectionRange)) {
941 - onVisibleSelectionChangeRef.current?.();
984 + const citationCommentActions = {
985 + openComment: openCitation,
986 + onOpenChange: (nodeKey: string, open: boolean) => {
987 + if (!open && citationDraftRef.current?.key === nodeKey) citationDraftRef.current = null;
988 + setOpenCitation((current) => {
989 + if (open) {
990 + if (current?.key === nodeKey) return current;
991 + return { key: nodeKey };
992 }
943 - return;
944 - }
945 - // A selection-only update while a newer prompt waits to be applied (a chip
946 - // was just inserted through the store) would report stale text and clobber
947 - // the prompt. Let the controlled rewrite land instead.
948 - if (previousSnapshot.value === nextValue && nextValue !== latestValueRef.current) {
949 - return;
950 - }
951 - snapshotRef.current = {
952 - value: nextValue,
953 - cursor: nextCursor,
954 - expandedCursor: nextExpandedCursor,
955 - contextIds,
956 - };
957 - const inCodeBlock = updated.state.selection.$from.parent.type.spec.code === true;
958 - const suppressTrigger =
959 - literalText ||
960 - inCodeBlock ||
961 - isCollapsedCursorAdjacentToInlineToken(nextValue, nextCursor, "left") ||
962 - isCollapsedCursorAdjacentToInlineToken(nextValue, nextCursor, "right");
963 - onChangeRef.current(nextValue, nextCursor, nextExpandedCursor, suppressTrigger, contextIds);
993 + return current?.key === nodeKey ? null : current;
994 + });
995 },
965 - [clampEditorCursor, literalText],
966 - );
996 + onDraftChange: (nodeKey: string, comment: string) => {
997 + citationDraftRef.current = { key: nodeKey, comment };
998 + },
999 + onSubmitAndSend: onCitationSubmitAndSend ?? (() => {}),
1000 + };
1001
968 - const editorAttributes = useMemo(
969 - () => ({
970 - class: cn(
971 - "composer-tiptap -m-1 block max-h-52 min-h-19.5 overflow-y-auto p-1 whitespace-pre-wrap wrap-break-word bg-transparent leading-relaxed text-foreground focus:outline-none",
972 - className,
973 - ),
974 - "data-testid": "composer-editor",
975 - "data-composer-rich-text": richText ? "true" : "false",
976 - role: "textbox",
977 - "aria-multiline": "true",
978 - ...(ariaLabel ? { "aria-label": ariaLabel } : {}),
979 - ...(disabled ? { "aria-readonly": "true" } : {}),
980 - ...(!disabled && suggestionListId
981 - ? {
982 - "aria-autocomplete": "list",
983 - "aria-haspopup": "listbox",
984 - ...(activeSuggestionId
985 - ? {
986 - "aria-controls": suggestionListId,
987 - "aria-activedescendant": activeSuggestionId,
988 - }
989 - : {}),
990 - }
991 - : {}),
992 - "aria-placeholder": placeholder,
993 - }),
994 - [activeSuggestionId, ariaLabel, className, disabled, placeholder, richText, suggestionListId],
995 - );
1002 + const handleEditorChange = (updated: TiptapEditor) => {
1003 + const map = serializeEditorDoc(updated.state.doc);
1004 + const contextIds = literalText ? [] : map.contextIds;
1005 + const { from, to } = updated.state.selection;
1006 + const fromFlat = pmToFlat(map, from);
1007 + const toFlat = pmToFlat(map, to);
1008 + const nextValue = map.value;
1009 + const nextCursor = clampEditorCursor(map.value, flatToCollapsed(map, fromFlat));
1010 + const nextExpandedCursor = Math.max(
1011 + 0,
1012 + Math.min(map.value.length, flatToMarkdown(map, fromFlat)),
1013 + );
1014 + const nextSelectionRange = {
1015 + start: Math.min(nextExpandedCursor, flatToMarkdown(map, toFlat)),
1016 + end: Math.max(nextExpandedCursor, flatToMarkdown(map, toFlat)),
1017 + };
1018 + const previousSelectionRange = selectionRangeRef.current;
1019 + selectionRangeRef.current = nextSelectionRange;
1020 + setIsEmpty(nextValue.length === 0);
1021 + const previousSnapshot = snapshotRef.current;
1022 + const snapshotChanged = !(
1023 + previousSnapshot.value === nextValue &&
1024 + previousSnapshot.cursor === nextCursor &&
1025 + previousSnapshot.expandedCursor === nextExpandedCursor &&
1026 + previousSnapshot.contextIds.length === contextIds.length &&
1027 + previousSnapshot.contextIds.every((id, index) => id === contextIds[index])
1028 + );
1029 + if (isApplyingControlledUpdateRef.current) return;
1030 + if (!snapshotChanged) {
1031 + if (didComposerSelectionChangeVisibly(previousSelectionRange, nextSelectionRange)) {
1032 + onVisibleSelectionChangeRef.current?.();
1033 + }
1034 + return;
1035 + }
1036 + // A selection-only update while a newer prompt waits to be applied (a chip
1037 + // was just inserted through the store) would report stale text and clobber
1038 + // the prompt. Let the controlled rewrite land instead.
1039 + if (previousSnapshot.value === nextValue && nextValue !== latestValueRef.current) {
1040 + return;
1041 + }
1042 + snapshotRef.current = {
1043 + value: nextValue,
1044 + cursor: nextCursor,
1045 + expandedCursor: nextExpandedCursor,
1046 + contextIds,
1047 + };
1048 + const inCodeBlock = updated.state.selection.$from.parent.type.spec.code === true;
1049 + const suppressTrigger =
1050 + literalText ||
1051 + inCodeBlock ||
1052 + isCollapsedCursorAdjacentToInlineToken(nextValue, nextCursor, "left") ||
1053 + isCollapsedCursorAdjacentToInlineToken(nextValue, nextCursor, "right");
1054 + onChangeRef.current(nextValue, nextCursor, nextExpandedCursor, suppressTrigger, contextIds);
1055 + };
1056 +
1057 + const editorAttributes = {
1058 + class: cn(
1059 + "composer-tiptap -m-1 block max-h-52 min-h-19.5 overflow-y-auto p-1 whitespace-pre-wrap wrap-break-word bg-transparent leading-relaxed text-foreground focus:outline-none",
1060 + className,
1061 + ),
1062 + "data-testid": "composer-editor",
1063 + "data-composer-rich-text": richText ? "true" : "false",
1064 + role: "textbox",
1065 + "aria-multiline": "true",
1066 + ...(ariaLabel ? { "aria-label": ariaLabel } : {}),
1067 + ...(disabled ? { "aria-readonly": "true" } : {}),
1068 + ...(!disabled && suggestionListId
1069 + ? {
1070 + "aria-autocomplete": "list",
1071 + "aria-haspopup": "listbox",
1072 + ...(activeSuggestionId
1073 + ? {
1074 + "aria-controls": suggestionListId,
1075 + "aria-activedescendant": activeSuggestionId,
1076 + }
1077 + : {}),
1078 + }
1079 + : {}),
1080 + "aria-placeholder": placeholder,
1081 + };
1082
1083 const editor = useEditor(
1084 {
999 - extensions: [
1000 - StarterKit.configure({
1001 - blockquote: false,
1002 - bulletList: false,
1003 - codeBlock: false,
1004 - heading: false,
1005 - horizontalRule: false,
1006 - listItem: false,
1007 - link: false,
1008 - orderedList: false,
1009 - underline: false,
1010 - dropcursor: false,
1011 - gapcursor: false,
1012 - trailingNode: false,
1013 - code: false,
1014 - listKeymap: false,
1015 - undoRedo: { newGroupDelay: COMPOSER_UNDO_GROUP_DELAY },
1016 - ...(richText ? {} : { bold: false, italic: false, strike: false }),
1017 - }),
1018 - ComposerUndoGroupingExtension,
1019 - ComposerMentionExtension,
1020 - ComposerSkillExtension,
1021 - ComposerCitationExtension,
1022 - ComposerContextReferenceExtension,
1023 - ComposerMarkersExtension,
1024 - ...(richText
1025 - ? [
1026 - ComposerCodeExtension,
1027 - ComposerCodeBlockExtension.extend({
1028 - addNodeView() {
1029 - return ReactNodeViewRenderer(ComposerCodeBlockNodeView, {
1030 - // The header holds the language picker. Tiptap only shields
1031 - // events aimed at the button element itself, so a click on
1032 - // its icon or label would reach ProseMirror and move the
1033 - // selection; keep every header event away from the editor.
1034 - stopEvent: ({ event }) =>
1035 - event.target instanceof Element &&
1036 - event.target.closest(".chat-markdown-codeblock-header") !== null,
1037 - });
1038 - },
1039 - // Tiptap's own ``` + space rule would open a fence inside a
1040 - // list item or quote, where the serializer has no line for
1041 - // it. Enter on a fence line covers the gesture at top level.
1042 - addInputRules() {
1043 - return [];
1044 - },
1045 - }),
1046 - composerCodeBlockHighlight({
1047 - resolveTheme: () =>
1048 - resolveDiffThemeName(
1049 - document.documentElement.classList.contains("dark") ? "dark" : "light",
1050 - ),
1051 - }),
1052 - ...ComposerBlockExtensions.map((extension) =>
1053 - extension.name === "blockquote"
1054 - ? extension.extend({
1055 - addInputRules() {
1056 - return [blockquoteInputRule];
1057 - },
1058 - })
1059 - : extension.name === "horizontalRule"
1060 - ? extension.extend({
1061 - addInputRules() {
1062 - return [horizontalRuleInputRule];
1063 - },
1064 - })
1065 - : extension.name === "heading"
1066 - ? extension.extend({
1067 - addInputRules() {
1068 - return [headingInputRule];
1069 - },
1070 - })
1071 - : extension,
1072 - ),
1073 - ...ComposerListExtensions.map((extension) =>
1074 - extension.name === "listItem"
1075 - ? extension
1076 - : extension.extend({
1077 - addInputRules() {
1078 - return this.name === "bulletList"
1079 - ? [
1080 - listMarkerInputRule(/^(?<marker>[*+])(?<space>\s)$/, "bulletList"),
1081 - listMarkerInputRule(
1082 - /^(?<marker>-)(?<space>[ \t]+)(?<carried>[^\s[])$/,
1083 - "bulletList",
1084 - ),
1085 - ]
1086 - : [
1087 - listMarkerInputRule(
1088 - /^(?<marker>\d+[.)])(?<space>\s)$/,
1089 - "orderedList",
1090 - ),
1091 - ];
1092 - },
1093 - }),
1094 - ),
1095 - ComposerTaskListExtension,
1096 - ComposerTaskItemExtension.extend({
1097 - addInputRules() {
1098 - return [taskInputRule(this.type), bulletToTaskInputRule];
1099 - },
1100 - }),
1101 - ]
1102 - : []),
1103 - ],
1085 + extensions: richText ? RICH_TEXT_EXTENSIONS : PLAIN_TEXT_EXTENSIONS,
1086 content: buildDocJson(
1087 value,
1088 (name) => {
@@ -1454,7 +1436,7 @@ function ComposerPromptEditorTiptapInner(props: ComposerPromptEditorProps) {
1436 editor.view.setProps({ attributes: editorAttributes });
1437 }, [editor, editorAttributes]);
1438
1457 - const readSnapshot = useCallback(() => {
1439 + const readSnapshot = () => {
1440 const snapshot = snapshotRef.current;
1441 if (!editor) return snapshot;
1442 const map = serializeEditorDoc(editor.state.doc);
@@ -1473,7 +1455,7 @@ function ComposerPromptEditorTiptapInner(props: ComposerPromptEditorProps) {
1455 };
1456 snapshotRef.current = next;
1457 return next;
1476 - }, [clampEditorCursor, editor, literalText]);
1458 + };
1459
1460 // A question or approval swaps the controlled value while a citation comment
1461 // is open. Its node view unmounts with the old document, so save the comment
@@ -1587,41 +1569,38 @@ function ComposerPromptEditorTiptapInner(props: ComposerPromptEditorProps) {
1569 value,
1570 ]);
1571
1590 - const focusAt = useCallback(
1591 - (nextCursor: number) => {
1592 - if (!editor) return;
1593 - // view.focus() writes the state selection to the DOM as it focuses. A
1594 - // bare DOM focus leaves the native caret at the start until
1595 - // ProseMirror resyncs it 20ms later, and dictation tools type fast
1596 - // enough to land keys there, ahead of the text already inserted.
1597 - editor.view.focus();
1598 - if (snapshotRef.current.value !== latestValueRef.current) return;
1599 - const boundedCursor = clampEditorCursor(snapshotRef.current.value, nextCursor);
1600 - const map = serializeEditorDoc(editor.state.doc);
1601 - const flat = collapsedToFlat(map, boundedCursor);
1602 - editor.commands.setTextSelection(flatToPm(map, flat));
1603 - scrollTiptapCaretIntoView(editor);
1604 - if (boundedCursor === snapshotRef.current.cursor) return;
1605 - snapshotRef.current = {
1606 - value: snapshotRef.current.value,
1607 - cursor: boundedCursor,
1608 - expandedCursor: expandEditorCursor(snapshotRef.current.value, boundedCursor),
1609 - contextIds: snapshotRef.current.contextIds,
1610 - };
1611 - selectionRangeRef.current = {
1612 - start: snapshotRef.current.expandedCursor,
1613 - end: snapshotRef.current.expandedCursor,
1614 - };
1615 - onChangeRef.current(
1616 - snapshotRef.current.value,
1617 - boundedCursor,
1618 - snapshotRef.current.expandedCursor,
1619 - literalText,
1620 - snapshotRef.current.contextIds,
1621 - );
1622 - },
1623 - [clampEditorCursor, editor, expandEditorCursor, literalText],
1624 - );
1572 + const focusAt = (nextCursor: number) => {
1573 + if (!editor) return;
1574 + // view.focus() writes the state selection to the DOM as it focuses. A
1575 + // bare DOM focus leaves the native caret at the start until
1576 + // ProseMirror resyncs it 20ms later, and dictation tools type fast
1577 + // enough to land keys there, ahead of the text already inserted.
1578 + editor.view.focus();
1579 + if (snapshotRef.current.value !== latestValueRef.current) return;
1580 + const boundedCursor = clampEditorCursor(snapshotRef.current.value, nextCursor);
1581 + const map = serializeEditorDoc(editor.state.doc);
1582 + const flat = collapsedToFlat(map, boundedCursor);
1583 + editor.commands.setTextSelection(flatToPm(map, flat));
1584 + scrollTiptapCaretIntoView(editor);
1585 + if (boundedCursor === snapshotRef.current.cursor) return;
1586 + snapshotRef.current = {
1587 + value: snapshotRef.current.value,
1588 + cursor: boundedCursor,
1589 + expandedCursor: expandEditorCursor(snapshotRef.current.value, boundedCursor),
1590 + contextIds: snapshotRef.current.contextIds,
1591 + };
1592 + selectionRangeRef.current = {
1593 + start: snapshotRef.current.expandedCursor,
1594 + end: snapshotRef.current.expandedCursor,
1595 + };
1596 + onChangeRef.current(
1597 + snapshotRef.current.value,
1598 + boundedCursor,
1599 + snapshotRef.current.expandedCursor,
1600 + literalText,
1601 + snapshotRef.current.contextIds,
1602 + );
1603 + };
1604
1605 useImperativeHandle(
1606 editorRef,
@@ -1702,36 +1681,33 @@ function ComposerPromptEditorTiptapInner(props: ComposerPromptEditorProps) {
1681 [editor, focusAt, literalText, readSnapshot],
1682 );
1683
1705 - const handleCopyCut = useCallback(
1706 - (event: React.ClipboardEvent, cut: boolean) => {
1707 - const build = buildFragmentRef.current;
1708 - if (!editor || (cut && !editor.isEditable)) return;
1709 - const clipboardData = event.clipboardData;
1710 - const { from, to } = editor.state.selection;
1711 - if (from === to) return;
1712 - const text = serializeSelection(editor.state.doc, from, to);
1713 - const contextIds = literalText ? [] : Array.from(new Set(collectInlineContextIds(text)));
1714 - const fragment = contextIds.length > 0 ? build?.(contextIds) : null;
1715 - event.preventDefault();
1716 - clipboardData.setData("text/plain", text);
1717 - if (fragment) {
1718 - clipboardData.setData(COMPOSER_CONTEXT_CLIPBOARD_MIME, fragment);
1719 - clipboardData.setData("text/html", encodeComposerContextClipboardHtml(text, fragment));
1720 - }
1721 - if (cut) {
1722 - editor
1723 - .chain()
1724 - .focus()
1725 - .command(({ tr }) => {
1726 - markAsClipboardEdit(tr, "cut");
1727 - return true;
1728 - })
1729 - .deleteSelection()
1730 - .run();
1731 - }
1732 - },
1733 - [editor, literalText],
1734 - );
1684 + const handleCopyCut = (event: React.ClipboardEvent, cut: boolean) => {
1685 + const build = buildFragmentRef.current;
1686 + if (!editor || (cut && !editor.isEditable)) return;
1687 + const clipboardData = event.clipboardData;
1688 + const { from, to } = editor.state.selection;
1689 + if (from === to) return;
1690 + const text = serializeSelection(editor.state.doc, from, to);
1691 + const contextIds = literalText ? [] : Array.from(new Set(collectInlineContextIds(text)));
1692 + const fragment = contextIds.length > 0 ? build?.(contextIds) : null;
1693 + event.preventDefault();
1694 + clipboardData.setData("text/plain", text);
1695 + if (fragment) {
1696 + clipboardData.setData(COMPOSER_CONTEXT_CLIPBOARD_MIME, fragment);
1697 + clipboardData.setData("text/html", encodeComposerContextClipboardHtml(text, fragment));
1698 + }
1699 + if (cut) {
1700 + editor
1701 + .chain()
1702 + .focus()
1703 + .command(({ tr }) => {
1704 + markAsClipboardEdit(tr, "cut");
1705 + return true;
1706 + })
1707 + .deleteSelection()
1708 + .run();
1709 + }
1710 + };
1711
1712 return (
1713 <RichComposerSkillsContext value={skills}>