Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

feat(ai): fold node (#1172)

Eric Hayesef47d693c3d3
diff --git a/js/app/packages/core/component/AI/component/input/useChatMarkdownArea.tsx b/js/app/packages/core/component/AI/component/input/useChatMarkdownArea.tsx
index 68c7f2ac7e..ab106905d4 100644
--- a/js/app/packages/core/component/AI/component/input/useChatMarkdownArea.tsx
+++ b/js/app/packages/core/component/AI/component/input/useChatMarkdownArea.tsx
@@ -44,6 +44,7 @@ import {
import type { PortalScope } from '@core/component/ScopedPortal';
import { shortcutBadgeStyles } from '@core/component/Themes';
import { toast } from '@core/component/Toast/Toast';
+import { ENABLE_SNAPSHOT_NODE } from '@core/constant/featureFlags';
import { TOKENS } from '@core/hotkey/tokens';
import { getPrettyHotkeyStringByToken } from '@core/hotkey/utils';
import { isMobile } from '@core/mobile/isMobile';
@@ -234,33 +235,10 @@ function MarkdownArea(
) {
const { editor, plugins, cleanup } = props.lexicalWrapper;
- // TODO: ask peter what do
- // const hotkeyScope = blockHotkeyScopeSignal.get;
const isActiveElementInBlock = () => {
return false;
- // const blockElement = blockElementSignal.get();
- // const currentActiveElement = activeElement();
-
- // if (!blockElement || !currentActiveElement) {
- // return false;
- // }
-
- // return blockElement.contains(currentActiveElement);
};
- // onMount(() => {
- // registerHotkey({
- // hotkeyToken: 'chat-input-focus',
- // scopeId: 'TODO-chatimus', // TODO
- // description: 'Focus chat input',
- // hotkey: 't',
- // keyDownHandler: () => {
- // editor.focus();
- // return true;
- // },
- // });
- // });
-
const focusShortcut = getPrettyHotkeyStringByToken(TOKENS.chat.input.focus);
const onConnect = () => {
@@ -457,6 +435,7 @@ function MarkdownArea(
block={'chat'}
useBlockBoundary={true}
portalScope={props.portalScope}
+ useSnapshotForDocuments={ENABLE_SNAPSHOT_NODE}
/>
<FloatingMenuGroup>
<FloatingLinkMenu />
diff --git a/js/app/packages/core/component/AI/constant/fileType.ts b/js/app/packages/core/component/AI/constant/fileType.ts
index ba5fbdb06f..3d214d6999 100644
--- a/js/app/packages/core/component/AI/constant/fileType.ts
+++ b/js/app/packages/core/component/AI/constant/fileType.ts
@@ -1,26 +1,18 @@
import type { BlockAlias, BlockName } from '@core/block';
-import type { FileType } from '@service-cognition/generated/schemas/fileType';
+import { FileType } from '@service-cognition/generated/schemas/fileType';
+import { FileTypeMap } from '@service-storage/fileTypeMap';
+
+function isFileType(k: string): k is FileType {
+ return k in FileType;
+}
// Code file extensions from the Rust FileType enum
-const codeFileExtensions: (keyof typeof FileType)[] = [
- 'py',
- 'js',
- 'ts',
- 'jsx',
- 'tsx',
- 'json',
- 'html',
- 'css',
- 'xml',
- 'yaml',
- 'yml',
- 'sql',
- 'sh',
- 'bash',
- 'markdown',
- 'txt',
- 'csv',
-] as const;
+const codeFileExtensions: (keyof typeof FileType)[] = Object.entries(
+ FileTypeMap
+)
+ .filter(([_, o]) => o.mime === 'text/plain')
+ .map(([ext, _]) => ext)
+ .filter(isFileType);
// these will be converted to a supported format before upload
const CONVERSION_SUPPORTED_IMAGE_EXTENSIONS = ['heic', 'heif'] as const;
diff --git a/js/app/packages/core/component/AI/signal/attachment.ts b/js/app/packages/core/component/AI/signal/attachment.ts
index 414d34a705..9d33254211 100644
--- a/js/app/packages/core/component/AI/signal/attachment.ts
+++ b/js/app/packages/core/component/AI/signal/attachment.ts
@@ -4,9 +4,9 @@ import {
} from '@core/component/AI/constant';
import type { Attachment, Attachments } from '@core/component/AI/types';
import { asFileType } from '@core/component/AI/util';
-import { useChannelsContext } from '@core/context/channels';
import type { ItemMention } from '@core/component/LexicalMarkdown/plugins/mentions';
import { ENABLE_CHAT_CHANNEL_ATTACHMENT } from '@core/constant/featureFlags';
+import { useChannelsContext } from '@core/context/channels';
import { getItemBlockName } from '@core/util/getItemBlockName';
import { useHistoryQuery } from '@queries/history/history';
import { createMemo, createSignal } from 'solid-js';
diff --git a/js/app/packages/core/component/DocumentPreview.tsx b/js/app/packages/core/component/DocumentPreview.tsx
index 079534a878..d9e7384e39 100644
--- a/js/app/packages/core/component/DocumentPreview.tsx
+++ b/js/app/packages/core/component/DocumentPreview.tsx
@@ -10,6 +10,8 @@ import {
useMaybeBlockId,
useMaybeBlockName,
} from '@core/block';
+// Components
+import { ClippedPanel } from '@core/component/ClippedPanel';
import { toast } from '@core/component/Toast/Toast';
import {
isAccessiblePreviewItem,
@@ -21,7 +23,6 @@ import {
type PreviewProjectAccess,
} from '@queries/preview';
import { matches } from '@core/util/match';
-
// Icon imports
import CollapseInlinePreview from '@icon/regular/arrows-in-line-horizontal.svg';
import OpenIcon from '@icon/regular/arrows-out.svg';
@@ -38,17 +39,14 @@ import LoadingSpinner from '@icon/regular/spinner.svg';
import TrashSimple from '@icon/regular/trash-simple.svg';
import UserIcon from '@icon/regular/user.svg';
import MacroEmbed from '@macro-icons/macro-embed.svg';
-
-// Components
-import { ClippedPanel } from '@core/component/ClippedPanel';
-import { beveledCorners } from '../../block-theme/signals/themeSignals';
import { createCallback } from '@solid-primitives/rootless';
import { useNavigate } from '@solidjs/router';
import { globalSplitManager } from 'app/signal/splitLayout';
import type { Component, JSX } from 'solid-js';
import { type Accessor, Match, Show, Switch } from 'solid-js';
import { Dynamic, Portal } from 'solid-js/web';
-import { formatDate } from '../util/date';
+import { beveledCorners } from '../../block-theme/signals/themeSignals';
+import { formatDate, isoToUnixTimestamp } from '../util/date';
import NotFound from './AccessErrorViews/NotFound';
import Unauthorized from './AccessErrorViews/Unauthorized';
import { EntityIcon } from './EntityIcon';
@@ -269,6 +267,10 @@ export function PopupPreview(props: {
isPreviewable: boolean;
handlePreviewToggle: () => void;
};
+ snapshotInfo?: {
+ date: string;
+ characterCount?: number;
+ };
}) {
// Hooks
const navigate = useNavigate();
@@ -572,6 +574,26 @@ export function PopupPreview(props: {
{/* Document metadata */}
{renderDocumentMetadata(accessibleItem())}
+
+ {/* Snapshot info */}
+ <Show when={props.snapshotInfo}>
+ {(snapshot) => (
+ <div class="mt-3 pt-2 border-t border-edge">
+ <div class="flex items-center gap-1.5 text-ink-muted">
+ <ClockIcon class="size-4" />
+ <span class="text-xs font-medium">
+ Snapshot from{' '}
+ {formatDate(
+ isoToUnixTimestamp(snapshot().date),
+ {
+ showTime: true,
+ }
+ )}
+ </span>
+ </div>
+ </div>
+ )}
+ </Show>
</div>
);
}}
diff --git a/js/app/packages/core/component/LexicalMarkdown/component/core/StaticMarkdown.tsx b/js/app/packages/core/component/LexicalMarkdown/component/core/StaticMarkdown.tsx
index 7dcbfbc018..ef2ef281ba 100644
--- a/js/app/packages/core/component/LexicalMarkdown/component/core/StaticMarkdown.tsx
+++ b/js/app/packages/core/component/LexicalMarkdown/component/core/StaticMarkdown.tsx
@@ -18,6 +18,7 @@ import {
type DocumentCardNode,
type DocumentMentionNode,
type EquationNode,
+ type SnapshotNode,
type GroupMentionNode,
type HorizontalRuleNode,
type ImageNode,
@@ -68,6 +69,7 @@ import { ContactMention as ContactMentionDecorator } from '../decorator/ContactM
import { DateMention as DateMentionDecorator } from '../decorator/DateMention';
import { DocumentCard as DocumentCardDecorator } from '../decorator/DocumentCard';
import { DocumentMention as DocumentMentionDecorator } from '../decorator/DocumentMention';
+import { Snapshot as SnapshotDecorator } from '../decorator/Snapshot';
import { GroupMention as GroupMentionDecorator } from '../decorator/GroupMention';
import { Equation as EquationDecorator } from '../decorator/Equation';
import { MarkdownImage as ImageDecorator } from '../decorator/MarkdownImage';
@@ -331,6 +333,20 @@ const GroupMention: RenderableEntity<GroupMentionNode> = {
),
};
+const Snapshot: RenderableEntity<SnapshotNode> = {
+ guard: (node: LexicalNode): node is SnapshotNode =>
+ node.__type === 'snapshot',
+ render: (props) => (
+ <span>
+ {SnapshotDecorator({
+ ...props.node.exportComponentProps(),
+ key: props.node.getKey(),
+ theme: props.theme,
+ })}
+ </span>
+ ),
+};
+
const Image: RenderableEntity<ImageNode> = {
guard: (node: LexicalNode): node is ImageNode => node.__type === 'image',
render: (props) => ImageDecorator(props.node.exportComponentProps()),
@@ -643,6 +659,7 @@ const InlineEntities: Array<RenderableEntity> = [
ContactMention,
DateMention,
GroupMention,
+ Snapshot,
Image,
Video,
HorizontalRule,
diff --git a/js/app/packages/core/component/LexicalMarkdown/component/decorator/Snapshot.tsx b/js/app/packages/core/component/LexicalMarkdown/component/decorator/Snapshot.tsx
new file mode 100644
index 0000000000..9bcfe8880d
--- /dev/null
+++ b/js/app/packages/core/component/LexicalMarkdown/component/decorator/Snapshot.tsx
@@ -0,0 +1,235 @@
+import { useMaybeBlockId } from '@core/block';
+import { PopupPreview } from '@core/component/DocumentPreview';
+import {
+ EntityIcon,
+ type EntityIconSelector,
+} from '@core/component/EntityIcon';
+import { verifyBlockName } from '@core/constant/allBlocks';
+import { isTouchDevice } from '@core/mobile/isTouchDevice';
+import { isAccessiblePreviewItem, useItemPreview } from '@queries/preview';
+import { matches } from '@core/util/match';
+import { openInNewSplitForMention } from '@core/util/openInNewSplit';
+import { useSplitNavigationHandler } from '@core/util/useSplitNavigationHandler';
+import EyeSlashDuo from '@icon/duotone/eye-slash-duotone.svg';
+import TrashSimple from '@icon/duotone/trash-simple-duotone.svg';
+import LoadingSpinner from '@icon/regular/spinner.svg';
+import { $isSnapshotNode, type SnapshotDecoratorProps } from '@lexical-core';
+import { blockNameToItemType } from '@service-storage/client';
+import { createCallback } from '@solid-primitives/rootless';
+import { debounce } from '@solid-primitives/scheduled';
+import {
+ $getNodeByKey,
+ COMMAND_PRIORITY_NORMAL,
+ KEY_ENTER_COMMAND,
+} from 'lexical';
+import type { JSX } from 'solid-js';
+import { createMemo, createSignal, Show, useContext } from 'solid-js';
+import { LexicalWrapperContext } from '../../context/LexicalWrapperContext';
+import { autoRegister } from '../../plugins';
+import { openDocument } from '../core/BlockLink';
+import { MentionTooltip } from './MentionTooltip';
+
+function MentionContainer(props: { icon: JSX.Element; text: JSX.Element }) {
+ return (
+ <span class="pointer-events-auto">
+ <span class="relative top-[0.125em] size-[1em] inline-flex mx-1">
+ {props.icon}
+ </span>
+ <span class="underline decoration-current/20 decoration-[max(1px,0.1em)] underline-offset-2">
+ {props.text}
+ </span>
+ </span>
+ );
+}
+
+function Spinner() {
+ return (
+ <div class="animate-spin">
+ <LoadingSpinner />
+ </div>
+ );
+}
+
+function Loading() {
+ return <MentionContainer icon={<Spinner />} text="Loading" />;
+}
+
+export function Snapshot(props: SnapshotDecoratorProps) {
+ const currentBlockId = useMaybeBlockId();
+
+ const lexicalWrapper = useContext(LexicalWrapperContext);
+ const editor = lexicalWrapper?.editor;
+ const selection = () => lexicalWrapper?.selection;
+
+ let inlinePreviewRef!: HTMLSpanElement;
+
+ const previewType = () =>
+ blockNameToItemType(verifyBlockName(props.blockName));
+
+ const [item] = useItemPreview(() => ({
+ id: props.documentId,
+ type: previewType(),
+ }));
+
+ const [popupOpen, setPopupOpen] = createSignal(false);
+ const debouncedSetPreviewOpen = debounce(setPopupOpen, 100);
+
+ const isSelectedAsNode = createMemo(() => {
+ const sel = selection();
+ if (!sel) return false;
+ return sel.type === 'node' && sel.nodeKeys.has(props.key);
+ });
+
+ const open = createCallback((e: MouseEvent | KeyboardEvent | null) => {
+ openDocument(
+ props.blockName,
+ props.documentId,
+ {},
+ openInNewSplitForMention(e?.altKey, e != null)
+ );
+ });
+
+ if (editor) {
+ autoRegister(
+ editor.registerCommand(
+ KEY_ENTER_COMMAND,
+ (e) => {
+ if (isSelectedAsNode()) {
+ open(e);
+ return true;
+ }
+ return false;
+ },
+ COMMAND_PRIORITY_NORMAL
+ )
+ );
+ }
+
+ const deleteSnapshot = () => {
+ editor?.update(() => {
+ const node = $getNodeByKey(props.key);
+ if (!$isSnapshotNode(node)) return false;
+ node.remove();
+ return true;
+ });
+ };
+
+ const navHandlers = useSplitNavigationHandler<HTMLSpanElement>((e) => {
+ e.stopPropagation();
+ if (matches(item(), (i) => !i.loading && i.access === 'access')) {
+ open(e);
+ }
+ });
+
+ const renderContent = () => {
+ const i = item();
+
+ if (i.loading) {
+ return <Loading />;
+ }
+
+ if (isAccessiblePreviewItem(i)) {
+ return (
+ <MentionContainer
+ icon={
+ <EntityIcon
+ targetType={props.blockName as EntityIconSelector}
+ size="fill"
+ />
+ }
+ text={props.documentName || 'Untitled'}
+ />
+ );
+ }
+
+ if (i.access === 'no_access') {
+ return <MentionContainer icon={<EyeSlashDuo />} text="No Access" />;
+ }
+
+ if (i.access === 'does_not_exist') {
+ return <MentionContainer icon={<TrashSimple />} text="Deleted" />;
+ }
+
+ return (
+ <MentionContainer
+ icon={
+ <EntityIcon
+ targetType={props.blockName as EntityIconSelector}
+ size="fill"
+ />
+ }
+ text={props.documentName || 'Untitled'}
+ />
+ );
+ };
+
+ return (
+ <>
+ <span class="relative">
+ <span
+ class="w-full h-full py-0.5 cursor-default rounded-xs hover:bg-hover focus:bg-active"
+ classList={{
+ 'bg-active text-ink bracket bracket-offset-2': isSelectedAsNode(),
+ }}
+ style={{
+ 'user-select': 'inherit',
+ }}
+ ref={inlinePreviewRef}
+ onMouseEnter={() => {
+ if (!isTouchDevice()) {
+ debouncedSetPreviewOpen(true);
+ }
+ }}
+ onMouseLeave={() => {
+ if (!isTouchDevice()) {
+ debouncedSetPreviewOpen.clear();
+ debouncedSetPreviewOpen(false);
+ }
+ }}
+ ontouchstart={(e) => {
+ if (isTouchDevice()) {
+ e.preventDefault();
+ }
+ }}
+ ontouchend={(e) => {
+ if (isTouchDevice()) {
+ e.preventDefault();
+ if (matches(item(), (i) => !i.loading && i.access === 'access')) {
+ open(null);
+ }
+ }
+ }}
+ {...navHandlers}
+ >
+ {renderContent()}
+ </span>
+ <MentionTooltip show={isSelectedAsNode()} text="Open" />
+ </span>
+
+ <Show when={popupOpen()}>
+ <PopupPreview
+ item={item}
+ floatRef={inlinePreviewRef}
+ mouseEnter={() => {
+ debouncedSetPreviewOpen(true);
+ }}
+ mouseLeave={() => {
+ debouncedSetPreviewOpen.clear();
+ debouncedSetPreviewOpen(false);
+ }}
+ delete={editor?.isEditable() ? deleteSnapshot : undefined}
+ documentInfo={{
+ id: props.documentId,
+ type: verifyBlockName(props.blockName),
+ params: {},
+ isOpenable: currentBlockId !== props.documentId,
+ }}
+ snapshotInfo={{
+ date: props.snapshotDate || new Date().toISOString(),
+ characterCount: props.content.length,
+ }}
+ />
+ </Show>
+ </>
+ );
+}
diff --git a/js/app/packages/core/component/LexicalMarkdown/component/menu/MentionsMenu.tsx b/js/app/packages/core/component/LexicalMarkdown/component/menu/MentionsMenu.tsx
index f6a11dbc46..ef15abc403 100644
--- a/js/app/packages/core/component/LexicalMarkdown/component/menu/MentionsMenu.tsx
+++ b/js/app/packages/core/component/LexicalMarkdown/component/menu/MentionsMenu.tsx
@@ -5,23 +5,24 @@ import {
} from '@core/block';
import { SUPPORTED_CHAT_ATTACHMENT_BLOCKS } from '@core/component/AI/constant/fileType';
import { BozzyBracketInnerSibling } from '@core/component/BozzyBracket';
-import {
- useChannelsContext,
- useDmActivityByUserId,
-} from '@core/context/channels';
import { EntityIcon } from '@core/component/EntityIcon';
import { type PortalScope, ScopedPortal } from '@core/component/ScopedPortal';
import { UserIcon } from '@core/component/UserIcon';
import { ENABLE_CHAT_CHANNEL_ATTACHMENT } from '@core/constant/featureFlags';
+import {
+ useChannelsContext,
+ useDmActivityByUserId,
+} from '@core/context/channels';
+import { useEmail } from '@core/context/user';
import clickOutside from '@core/directive/clickOutside';
import {
type ChannelWithParticipants,
type IUser,
useContacts,
} from '@core/user';
-import { useEmail } from '@core/context/user';
import { getDateSuggestions } from '@core/util/dateParser';
import { createFreshSearch, FreshSearchPresets } from '@core/util/freshSort';
+import { useIsKeyPressActive } from '@core/util/useIsKeyPressActive';
import ClockIcon from '@icon/regular/clock.svg';
import EmailIcon from '@icon/regular/envelope.svg';
import UsersIcon from '@icon/regular/users.svg';
@@ -77,7 +78,6 @@ import {
handleUserMention,
type UserMentionRecord,
} from '../../utils/mentionsUtils';
-import { useIsKeyPressActive } from '@core/util/useIsKeyPressActive';
false && clickOutside;
false && floatWithSelection;
@@ -138,6 +138,7 @@ function allItemFilter(item: CombinedEntity): boolean {
/**
* Create the universal item handler.
* @param dependencies
+ * @param useSnapshotForDocuments Whether to use SnapshotNode for supported document types
* @returns
*/
function createItemHandler(dependencies: HandlerDependencies) {
@@ -430,6 +431,8 @@ function MentionsMenuInner(props: {
onDocumentMention?: (item: Item | ChannelWithParticipants) => void;
onEmailMention?: (item: EmailEntity) => void;
disableMentionTracking?: boolean;
+ /** Fetch text then past in a fold-node for plain-text mentions (useful for AI)*/
+ useSnapshotForDocuments?: boolean;
}) {
const [searchTerm, setSearchTerm] = createSignal<string>(
props.menu.searchTerm()
@@ -724,7 +727,7 @@ function MentionsMenuInner(props: {
local: Entity<T>[],
unifiedSearch: Entity<T>[]
): Entity<T>[] {
- let ids = new Set(local.map((e) => e.id));
+ const ids = new Set(local.map((e) => e.id));
return [...local, ...unifiedSearch.filter((e) => !ids.has(e.id))];
}
@@ -836,6 +839,7 @@ function MentionsMenuInner(props: {
onDocumentMention: props.onDocumentMention,
onEmailMention: props.onEmailMention,
disableMentionTracking: props.disableMentionTracking,
+ useSnapshotNode: props.useSnapshotForDocuments,
});
createEffect(() => {
diff --git a/js/app/packages/core/component/LexicalMarkdown/init.ts b/js/app/packages/core/component/LexicalMarkdown/init.ts
index b04b79e3bd..129a98ecdf 100644
--- a/js/app/packages/core/component/LexicalMarkdown/init.ts
+++ b/js/app/packages/core/component/LexicalMarkdown/init.ts
@@ -5,6 +5,7 @@ import {
DocumentCardNode,
DocumentMentionNode,
EquationNode,
+ SnapshotNode,
GroupMentionNode,
HorizontalRuleNode,
HtmlRenderNode,
@@ -20,6 +21,7 @@ import { DiffInsert } from './component/decorator/DiffInsert';
import { DocumentCard } from './component/decorator/DocumentCard';
import { DocumentMention } from './component/decorator/DocumentMention';
import { Equation } from './component/decorator/Equation';
+import { Snapshot } from './component/decorator/Snapshot';
import { GroupMention } from './component/decorator/GroupMention';
import { HorizontalRule } from './component/decorator/HorizontalRule';
import { HtmlRender } from './component/decorator/HtmlRender';
@@ -45,6 +47,7 @@ export function initializeLexical() {
setDecorator(ImageNode, MarkdownImage);
setDecorator(VideoNode, MarkdownVideo);
setDecorator(EquationNode, Equation);
+ setDecorator(SnapshotNode, Snapshot);
setDecorator(HtmlRenderNode, HtmlRender);
setDecorator(WatermarkNode, Watermark);
registerDiffNodeFactory();
diff --git a/js/app/packages/core/component/LexicalMarkdown/plugins/mentions/mentionsPlugin.ts b/js/app/packages/core/component/LexicalMarkdown/plugins/mentions/mentionsPlugin.ts
index 01a90a0b26..449e85e37d 100644
--- a/js/app/packages/core/component/LexicalMarkdown/plugins/mentions/mentionsPlugin.ts
+++ b/js/app/packages/core/component/LexicalMarkdown/plugins/mentions/mentionsPlugin.ts
@@ -9,6 +9,7 @@ import {
$createDocumentMentionNode,
$createGroupMentionNode,
$createInlineSearchNode,
+ $createSnapshotNode,
$createUserMentionNode,
$handleInlineSearchNodeMutation,
$handleInlineSearchNodeTransform,
@@ -28,6 +29,7 @@ import {
GroupMentionNode,
InlineSearchNode,
InlineSearchNodesType,
+ type SnapshotNodeInfo,
type UserMentionInfo,
UserMentionNode,
validTriggerPosition,
@@ -65,6 +67,9 @@ import { mapRegisterDelete } from '../shared';
export const INSERT_DOCUMENT_MENTION_COMMAND: LexicalCommand<DocumentMentionInfo> =
createCommand('INSERT_DOCUMENT_MENTION_COMMAND');
+export const INSERT_SNAPSHOT_NODE_COMMAND: LexicalCommand<SnapshotNodeInfo> =
+ createCommand('INSERT_SNAPSHOT_NODE_COMMAND');
+
export const INSERT_CONTACT_MENTION_COMMAND: LexicalCommand<ContactMentionInfo> =
createCommand('INSERT_CONTACT_MENTION_COMMAND');
@@ -198,8 +203,8 @@ export function $mentionItemFromNode(node: MentionNode): ItemMention {
}
// Validators for the position of the @ trigger.
-const beforeRegex = /[(['"\`\s]$/;
-const afterRegex = /^[)\]'"\`\s]/;
+const beforeRegex = /[(['\"\`\s]$/;
+const afterRegex = /^[)\]'\"\`\s]/;
/**
* When mentions nodes are selected by using the arrow keys, we want to be able to delete them.
@@ -350,6 +355,31 @@ function registerMentionsPlugin(
COMMAND_PRIORITY_NORMAL
),
+ editor.registerCommand(
+ INSERT_SNAPSHOT_NODE_COMMAND,
+ (payload) => {
+ editor.update(() => {
+ const selection = $getSelection();
+ const snapshotNode = $createSnapshotNode(payload);
+
+ // Do not paste snapshot nodes over range-selected text -- append after.
+ if ($isRangeSelection(selection) && !selection.isCollapsed()) {
+ $collapseSelection(selection);
+ $insertNodes([$createTextNode(' '), snapshotNode]);
+ snapshotNode.selectEnd();
+ return true;
+ }
+ $insertNodes([snapshotNode]);
+ if ($isRootOrShadowRoot(snapshotNode.getParentOrThrow())) {
+ $wrapNodeInElement(snapshotNode, $createParagraphNode);
+ }
+ snapshotNode.selectEnd();
+ });
+ return true;
+ },
+ COMMAND_PRIORITY_NORMAL
+ ),
+
editor.registerCommand(
INSERT_USER_MENTION_COMMAND,
(payload) => {
diff --git a/js/app/packages/core/component/LexicalMarkdown/utils/mentionsUtils.ts b/js/app/packages/core/component/LexicalMarkdown/utils/mentionsUtils.ts
index 93dadba1cd..8292013d60 100644
--- a/js/app/packages/core/component/LexicalMarkdown/utils/mentionsUtils.ts
+++ b/js/app/packages/core/component/LexicalMarkdown/utils/mentionsUtils.ts
@@ -18,6 +18,7 @@ import {
INSERT_GROUP_MENTION_COMMAND,
INSERT_USER_MENTION_COMMAND,
} from '../plugins/mentions';
+import { handleSnapshotMention, supportsSnapshotNode } from './snapshotMention';
export type GroupItem = {
id: string;
@@ -139,6 +140,7 @@ export type HandlerDependencies = {
onDocumentMention?: (item: Item | ChannelWithParticipants) => void;
disableMentionTracking?: boolean;
onEmailMention?: (item: EmailEntity) => void;
+ useSnapshotNode?: boolean;
};
/**
@@ -299,15 +301,17 @@ export async function handleBasicMention(
const itemEntity = entityMapper('item')(item);
const itemBlock = getCombinedEntityBlockName(itemEntity);
const itemName = getItemName(itemEntity);
-
onDocumentMention?.(item);
-
- editor.dispatchCommand(INSERT_DOCUMENT_MENTION_COMMAND, {
- documentId: item.id,
- documentName: itemName,
- blockName: itemBlock,
- mentionUuid: mentionId,
- });
+ if (dependencies.useSnapshotNode && supportsSnapshotNode(itemBlock)) {
+ handleSnapshotMention(item, dependencies);
+ } else {
+ editor.dispatchCommand(INSERT_DOCUMENT_MENTION_COMMAND, {
+ documentId: item.id,
+ documentName: itemName,
+ blockName: itemBlock,
+ mentionUuid: mentionId,
+ });
+ }
}
/**
diff --git a/js/app/packages/core/component/LexicalMarkdown/utils/snapshotMention.ts b/js/app/packages/core/component/LexicalMarkdown/utils/snapshotMention.ts
new file mode 100644
index 0000000000..e9e8d31ffc
--- /dev/null
+++ b/js/app/packages/core/component/LexicalMarkdown/utils/snapshotMention.ts
@@ -0,0 +1,108 @@
+import type { BlockAlias, BlockName } from '@core/block';
+import { trackMention } from '@core/signal/mention';
+import { isErr } from '@core/util/maybeResult';
+import { fetchDocumentAsMarkdown } from '@queries/storage/markdownText';
+import { storageServiceClient } from '@service-storage/client';
+import type { Item } from '@service-storage/generated/schemas/item';
+import { INSERT_SNAPSHOT_NODE_COMMAND } from '../plugins/mentions';
+import {
+ entityMapper,
+ getCombinedEntityBlockName,
+ getItemName,
+ type HandlerDependencies,
+ handleBasicMention,
+} from './mentionsUtils';
+
+/** Document types that support SnapshotNode (text-based content) */
+// TODO
+const SNAPSHOT_SUPPORTED_BLOCK_NAMES: Set<BlockName | BlockAlias> = new Set([
+ 'task',
+ 'write',
+ 'md',
+ 'code',
+]);
+
+/**
+ * Check if a block name supports SnapshotNode insertion.
+ * SnapshotNode is used for text-based documents where content can be displayed inline.
+ */
+export function supportsSnapshotNode(
+ blockName: BlockName | BlockAlias
+): boolean {
+ return SNAPSHOT_SUPPORTED_BLOCK_NAMES.has(blockName);
+}
+
+/**
+ * Insert a SnapshotNode with document content for supported document types.
+ * Falls back to handleBasicMention for unsupported types or errors.
+ * @param item The document item to mention
+ * @param dependencies Handler dependencies
+ */
+export async function handleSnapshotMention(
+ item: Item,
+ dependencies: HandlerDependencies
+) {
+ const {
+ editor,
+ blockName: parentBlockName,
+ blockId,
+ onDocumentMention,
+ disableMentionTracking,
+ } = dependencies;
+
+ const itemEntity = entityMapper('item')(item);
+ const itemBlock = getCombinedEntityBlockName(itemEntity);
+ const itemName = getItemName(itemEntity);
+
+ // Check if this document type supports SnapshotNode
+ if (!supportsSnapshotNode(itemBlock)) {
+ return handleBasicMention(item, dependencies);
+ }
+
+ let text: string;
+ if (itemBlock === 'md' || itemBlock === 'task') {
+ const result = await fetchDocumentAsMarkdown(item.id, 'internal');
+ if (!result) {
+ console.error('failed to fetch md');
+ return;
+ } else {
+ text = result;
+ }
+ } else {
+ // Fetch document content
+ const result = await storageServiceClient.getTextDocument({
+ documentId: item.id,
+ });
+
+ if (isErr(result)) {
+ // Fall back to regular mention on error
+ console.error(
+ 'Failed to fetch document content for SnapshotNode:',
+ result
+ );
+ return;
+ }
+ text = result[1].text;
+ }
+
+ let mentionId: string | undefined;
+ if (
+ blockId &&
+ parentBlockName !== 'channel' &&
+ parentBlockName !== 'chat' &&
+ !disableMentionTracking
+ ) {
+ mentionId = await trackMention(blockId, 'document', item.id);
+ }
+
+ onDocumentMention?.(item);
+
+ editor.dispatchCommand(INSERT_SNAPSHOT_NODE_COMMAND, {
+ documentId: item.id,
+ documentName: itemName,
+ blockName: itemBlock,
+ content: text,
+ snapshotDate: new Date().toISOString(),
+ mentionUuid: mentionId,
+ });
+}
diff --git a/js/app/packages/core/constant/featureFlags.ts b/js/app/packages/core/constant/featureFlags.ts
index 91d843434f..a6fe731ae4 100644
--- a/js/app/packages/core/constant/featureFlags.ts
+++ b/js/app/packages/core/constant/featureFlags.ts
@@ -118,3 +118,8 @@ export const ENABLE_EMAIL_SHARING = true;
export const ENABLE_STATIC_DOCUMENT_CARDS = false;
export const ENABLE_MARKDOWN_AI_GENERATE = false;
+
+export const ENABLE_UNIFIED_LIST_AI_INPUT = false;
+
+// snapshot mention content inline for AI chat
+export const ENABLE_SNAPSHOT_NODE = DEV_MODE_ENV;
diff --git a/js/app/packages/lexical-core/decoratorRegistry.ts b/js/app/packages/lexical-core/decoratorRegistry.ts
index a0e5288833..186553068e 100644
--- a/js/app/packages/lexical-core/decoratorRegistry.ts
+++ b/js/app/packages/lexical-core/decoratorRegistry.ts
@@ -23,6 +23,10 @@ import type {
EquationDecoratorProps,
EquationNode,
} from './nodes/EquationNode';
+import type {
+ SnapshotDecoratorProps,
+ SnapshotNode,
+} from './nodes/SnapshotNode';
import type {
GroupMentionDecoratorProps,
GroupMentionNode,
@@ -87,6 +91,10 @@ export interface NodeDecoratorMap {
klass: typeof EquationNode;
props: EquationDecoratorProps;
};
+ SnapshotNode: {
+ klass: typeof SnapshotNode;
+ props: SnapshotDecoratorProps;
+ };
ImageNode: {
klass: typeof ImageNode;
props: ImageDecoratorProps;
diff --git a/js/app/packages/lexical-core/index.ts b/js/app/packages/lexical-core/index.ts
index 2a620d63f7..eaa17ae9d5 100644
--- a/js/app/packages/lexical-core/index.ts
+++ b/js/app/packages/lexical-core/index.ts
@@ -15,6 +15,7 @@ export * from './nodes/DiffNode';
export * from './nodes/DocumentCardNode';
export * from './nodes/DocumentMentionNode';
export * from './nodes/EquationNode';
+export * from './nodes/SnapshotNode';
export * from './nodes/GroupMentionNode';
export * from './nodes/HorizontalRuleNode';
export * from './nodes/HtmlRenderNode';
diff --git a/js/app/packages/lexical-core/node-list.ts b/js/app/packages/lexical-core/node-list.ts
index 7599df06b4..2b64a2d79b 100644
--- a/js/app/packages/lexical-core/node-list.ts
+++ b/js/app/packages/lexical-core/node-list.ts
@@ -26,6 +26,7 @@ import { DiffNode } from './nodes/DiffNode';
import { DocumentCardNode } from './nodes/DocumentCardNode';
import { DocumentMentionNode } from './nodes/DocumentMentionNode';
import { EquationNode } from './nodes/EquationNode';
+import { SnapshotNode } from './nodes/SnapshotNode';
import { HorizontalRuleNode } from './nodes/HorizontalRuleNode';
import { HtmlRenderNode } from './nodes/HtmlRenderNode';
import { ImageNode } from './nodes/ImageNode';
@@ -84,6 +85,7 @@ export const SupportedNodeTypes = [
CommentNode,
SearchMatchNode,
EquationNode,
+ SnapshotNode,
HorizontalRuleNode,
DiffNode,
DiffInsertNode,
diff --git a/js/app/packages/lexical-core/nodes/SnapshotNode.ts b/js/app/packages/lexical-core/nodes/SnapshotNode.ts
new file mode 100644
index 0000000000..edf5e14eba
--- /dev/null
+++ b/js/app/packages/lexical-core/nodes/SnapshotNode.ts
@@ -0,0 +1,295 @@
+import {
+ $applyNodeReplacement,
+ DecoratorNode,
+ type DOMConversionMap,
+ type EditorConfig,
+ type EditorThemeClasses,
+ type LexicalEditor,
+ type LexicalNode,
+ type NodeKey,
+ type SerializedLexicalNode,
+ type Spread,
+} from 'lexical';
+import { type DecoratorComponent, getDecorator } from '../decoratorRegistry';
+import { $applyIdFromSerialized } from '../plugins/nodeIdPlugin';
+
+const VERSION = 1;
+
+export type SnapshotNodeInfo = {
+ documentId: string;
+ documentName: string;
+ blockName: string;
+ content: string;
+ snapshotDate?: string;
+ mentionUuid?: string;
+};
+
+export type SerializedSnapshotNode = Spread<
+ SnapshotNodeInfo,
+ SerializedLexicalNode
+>;
+
+export type SnapshotDecoratorProps = SnapshotNodeInfo & {
+ key: NodeKey;
+ theme: EditorThemeClasses;
+};
+
+export class SnapshotNode extends DecoratorNode<
+ DecoratorComponent<SnapshotDecoratorProps> | undefined
+> {
+ __documentId: string;
+ __documentName: string;
+ __blockName: string;
+ __content: string;
+ __snapshotDate: string;
+ __mentionUuid: string | undefined;
+
+ static getType() {
+ return 'snapshot';
+ }
+
+ isInline(): boolean {
+ return true;
+ }
+
+ isKeyboardSelectable(): boolean {
+ return true;
+ }
+
+ static clone(node: SnapshotNode) {
+ return new SnapshotNode(
+ node.__documentId,
+ node.__documentName,
+ node.__blockName,
+ node.__content,
+ node.__snapshotDate,
+ node.__mentionUuid,
+ node.__key
+ );
+ }
+
+ constructor(
+ documentId: string,
+ documentName: string,
+ blockName: string,
+ content: string,
+ snapshotDate?: string,
+ mentionUuid?: string,
+ key?: NodeKey
+ ) {
+ super(key);
+ this.__documentId = documentId;
+ this.__documentName = documentName;
+ this.__blockName = blockName;
+ this.__content = content;
+ this.__snapshotDate = snapshotDate || new Date().toISOString();
+ this.__mentionUuid = mentionUuid;
+ }
+
+ static importJSON(serializedNode: SerializedSnapshotNode) {
+ const node = $createSnapshotNode({
+ documentId: serializedNode.documentId,
+ documentName: serializedNode.documentName,
+ blockName: serializedNode.blockName,
+ content: serializedNode.content,
+ snapshotDate: serializedNode.snapshotDate,
+ mentionUuid: serializedNode.mentionUuid,
+ });
+ $applyIdFromSerialized(node, serializedNode);
+ return node;
+ }
+
+ exportJSON(): SerializedSnapshotNode {
+ return {
+ ...super.exportJSON(),
+ documentId: this.__documentId,
+ documentName: this.__documentName,
+ blockName: this.__blockName,
+ content: this.__content,
+ snapshotDate: this.__snapshotDate,
+ mentionUuid: this.__mentionUuid,
+ type: SnapshotNode.getType(),
+ version: VERSION,
+ };
+ }
+
+ exportComponentProps(): SnapshotNodeInfo {
+ return {
+ documentId: this.__documentId,
+ documentName: this.__documentName,
+ blockName: this.__blockName,
+ content: this.__content,
+ snapshotDate: this.__snapshotDate,
+ mentionUuid: this.__mentionUuid,
+ };
+ }
+
+ createDOM(_config: EditorConfig): HTMLElement {
+ const span = document.createElement('span');
+ span.setAttribute('data-snapshot-node', 'true');
+ return span;
+ }
+
+ updateDOM(): boolean {
+ return false;
+ }
+
+ static importDOM(): DOMConversionMap<HTMLSpanElement> | null {
+ return {
+ span: (domNode: HTMLSpanElement) => {
+ if (!domNode.hasAttribute('data-snapshot-node')) {
+ return null;
+ }
+ return {
+ conversion: (domNode: HTMLElement) => {
+ const documentId = domNode.getAttribute('data-document-id');
+ const documentName =
+ domNode.getAttribute('data-document-name') || '';
+ const blockName = domNode.getAttribute('data-block-name') || '';
+ const content = domNode.getAttribute('data-content') || '';
+ const snapshotDate =
+ domNode.getAttribute('data-snapshot-date') ||
+ new Date().toISOString();
+ const mentionUuid =
+ domNode.getAttribute('data-mention-uuid') || undefined;
+
+ if (documentId) {
+ const node = $createSnapshotNode({
+ documentId,
+ documentName,
+ blockName,
+ content,
+ snapshotDate,
+ mentionUuid,
+ });
+ return { node };
+ }
+ return null;
+ },
+ priority: 1,
+ };
+ },
+ };
+ }
+
+ getDataAttrs(): Record<string, string> {
+ return {
+ 'data-snapshot-node': 'true',
+ 'data-document-id': this.__documentId,
+ 'data-document-name': this.__documentName,
+ 'data-block-name': this.__blockName,
+ 'data-content': this.__content,
+ 'data-snapshot-date': this.__snapshotDate,
+ 'data-mention-uuid': this.__mentionUuid || '',
+ };
+ }
+
+ exportDOM() {
+ const element = document.createElement('span');
+ const attrs = this.getDataAttrs();
+ for (const [k, v] of Object.entries(attrs)) {
+ if (v) {
+ element.setAttribute(k, v);
+ }
+ }
+ element.textContent = this.__documentName;
+ return { element };
+ }
+
+ getTextContent(): string {
+ return this.__documentName;
+ }
+
+ getSearchText(): string {
+ return this.__documentName;
+ }
+
+ getDocumentId(): string {
+ return this.__documentId;
+ }
+
+ getDocumentName(): string {
+ return this.__documentName;
+ }
+
+ getBlockName(): string {
+ return this.__blockName;
+ }
+
+ getContent(): string {
+ return this.__content;
+ }
+
+ getSnapshotDate(): string {
+ return this.__snapshotDate;
+ }
+
+ getMentionUuid(): string | undefined {
+ return this.__mentionUuid;
+ }
+
+ setDocumentId(documentId: string) {
+ const writable = this.getWritable();
+ writable.__documentId = documentId;
+ return writable;
+ }
+
+ setDocumentName(documentName: string) {
+ const writable = this.getWritable();
+ writable.__documentName = documentName;
+ return writable;
+ }
+
+ setBlockName(blockName: string) {
+ const writable = this.getWritable();
+ writable.__blockName = blockName;
+ return writable;
+ }
+
+ setContent(content: string) {
+ const writable = this.getWritable();
+ writable.__content = content;
+ return writable;
+ }
+
+ setMentionUuid(mentionUuid: string | undefined) {
+ const writable = this.getWritable();
+ writable.__mentionUuid = mentionUuid;
+ return writable;
+ }
+
+ decorate(_: LexicalEditor, config: EditorConfig) {
+ const decorator = getDecorator<SnapshotNode>(SnapshotNode);
+ if (decorator) {
+ return () =>
+ decorator({
+ documentId: this.__documentId,
+ documentName: this.__documentName,
+ blockName: this.__blockName,
+ content: this.__content,
+ snapshotDate: this.__snapshotDate,
+ mentionUuid: this.__mentionUuid,
+ key: this.getKey(),
+ theme: config.theme,
+ });
+ }
+ }
+}
+
+export function $createSnapshotNode(params: SnapshotNodeInfo): SnapshotNode {
+ const node = new SnapshotNode(
+ params.documentId,
+ params.documentName,
+ params.blockName,
+ params.content,
+ params.snapshotDate,
+ params.mentionUuid
+ );
+ return $applyNodeReplacement(node);
+}
+
+export function $isSnapshotNode(
+ node: SnapshotNode | LexicalNode | null | undefined
+): node is SnapshotNode {
+ return node instanceof SnapshotNode;
+}
diff --git a/js/app/packages/lexical-core/transformers/index.ts b/js/app/packages/lexical-core/transformers/index.ts
index 95aa9fb100..08ef80405d 100644
--- a/js/app/packages/lexical-core/transformers/index.ts
+++ b/js/app/packages/lexical-core/transformers/index.ts
@@ -1,6 +1,7 @@
import type { Transformer } from '@lexical/markdown';
import { I_MACRO_QUOTE } from './classedBlock';
import { CUSTOM_TRANSFORMERS } from './customTransformers';
+import { E_SNAPSHOT_NODE, I_SNAPSHOT_NODE } from './snapshot';
import { I_IMAGE_CONSTRAINED, IMAGE } from './image';
import {
E_BLOCK_EQUATION_NODE,
@@ -57,6 +58,7 @@ export const INTERNAL_TRANSFORMERS: Transformer[] = [
I_MACRO_QUOTE,
I_EQUATION_NODE,
I_WATERMARK,
+ I_SNAPSHOT_NODE,
...CUSTOM_TRANSFORMERS,
];
@@ -82,6 +84,7 @@ export const EXTERNAL_TRANSFORMERS: Transformer[] = [
E_BLOCK_EQUATION_NODE,
E_INLINE_EQUATION_NODE,
E_WATERMARK,
+ E_SNAPSHOT_NODE,
...HTML_ENTITY_TRANSFORMERS,
...CUSTOM_TRANSFORMERS,
];
@@ -116,6 +119,8 @@ export const ALL_TRANSFORMERS: Transformer[] = [
I_EQUATION_NODE,
I_WATERMARK,
E_WATERMARK,
+ I_SNAPSHOT_NODE,
+ E_SNAPSHOT_NODE,
// order matters
E_MULTILINE_BLOCK_EQUATION_NODE,
E_BLOCK_EQUATION_NODE,
diff --git a/js/app/packages/lexical-core/transformers/snapshot.ts b/js/app/packages/lexical-core/transformers/snapshot.ts
new file mode 100644
index 0000000000..e0e8612a03
--- /dev/null
+++ b/js/app/packages/lexical-core/transformers/snapshot.ts
@@ -0,0 +1,91 @@
+import type {
+ ElementTransformer,
+ TextMatchTransformer,
+} from '@lexical/markdown';
+import type { ElementNode, LexicalNode, TextNode } from 'lexical';
+import {
+ $createSnapshotNode,
+ $isSnapshotNode,
+ SnapshotNode,
+} from '../nodes/SnapshotNode';
+
+// Internal Snapshot Node - uses XML-based format for serialization
+export const I_SNAPSHOT_NODE: TextMatchTransformer = {
+ dependencies: [SnapshotNode],
+ type: 'text-match',
+ regExp: /<m-snapshot>(.*?)<\/m-snapshot>/,
+ importRegExp: /<m-snapshot>(.*?)<\/m-snapshot>/,
+ export: (node) => {
+ if (!$isSnapshotNode(node)) return null;
+
+ const data = JSON.stringify({
+ documentId: node.getDocumentId(),
+ documentName: node.getDocumentName(),
+ blockName: node.getBlockName(),
+ content: node.getContent(),
+ snapshotDate: node.getSnapshotDate(),
+ mentionUuid: node.getMentionUuid(),
+ });
+
+ return `<m-snapshot>${data}</m-snapshot>`;
+ },
+ replace: (node: TextNode, match: RegExpMatchArray) => {
+ try {
+ const data = JSON.parse(match[1]);
+ for (const field of [
+ 'documentId',
+ 'documentName',
+ 'blockName',
+ 'content',
+ ]) {
+ if (!(field in data)) throw new Error(`Missing field ${field}`);
+ }
+
+ const snapshotNode = $createSnapshotNode({
+ documentId: data.documentId,
+ documentName: data.documentName,
+ blockName: data.blockName,
+ content: data.content,
+ snapshotDate: data.snapshotDate || new Date().toISOString(),
+ mentionUuid: data.mentionUuid,
+ });
+ node.replace(snapshotNode);
+ } catch (e) {
+ console.error('Error in I_SNAPSHOT_NODE replace:', e);
+ }
+ },
+};
+
+// External Snapshot Node - exports to document link format
+export const E_SNAPSHOT_NODE: ElementTransformer = {
+ dependencies: [SnapshotNode],
+ type: 'element',
+ regExp: /$^/, // Never matches - no import from external format
+ export: (node) => {
+ if (!$isSnapshotNode(node)) return null;
+
+ const documentName = node.getDocumentName();
+ const documentId = node.getDocumentId();
+ const blockName = node.getBlockName();
+
+ if (!documentName || !documentId || !blockName) {
+ return null;
+ }
+
+ // Export as a document link similar to DocumentMention
+ const hostname =
+ window.location.hostname === 'localhost'
+ ? 'dev.macro.com'
+ : window.location.hostname.replace('www.', '').toLowerCase();
+ const documentUrl = `https://${hostname}/app/${blockName}/${documentId}`;
+ return `[${documentName}](${documentUrl})`;
+ },
+ replace: (
+ _parentNode: ElementNode,
+ _children: Array<LexicalNode>,
+ _match: Array<string>,
+ _isImport: boolean
+ ) => {
+ return false;
+ },
+};
diff --git a/js/app/packages/queries/storage/markdownText.ts b/js/app/packages/queries/storage/markdownText.ts
new file mode 100644
index 0000000000..3fbda8e60b
--- /dev/null
+++ b/js/app/packages/queries/storage/markdownText.ts
@@ -0,0 +1,30 @@
+import { createLexicalWrapper } from '@core/component/LexicalMarkdown/context/LexicalWrapperContext';
+import {
+ editorStateAsMarkdown,
+ initializeEditorWithState,
+} from '@core/component/LexicalMarkdown/utils';
+import { syncServiceClient } from '@service-sync/client';
+
+/**
+ * Fetches a document from the sync service and returns its content as markdown text.
+ * @param documentId The ID of the document to fetch
+ * @param target 'external' for GFM-compatible markdown, 'internal' for round-trip compatible markdown
+ * @returns The document content as a markdown string, or null if the document is empty
+ */
+export async function fetchDocumentAsMarkdown(
+ documentId: string,
+ target: 'external' | 'internal' = 'external'
+): Promise<string | null> {
+ const rawState = await syncServiceClient.getRaw({ documentId });
+ if (!rawState || !rawState.root || rawState.root.children.length === 0) {
+ return null;
+ }
+ const { editor } = createLexicalWrapper({
+ type: 'markdown',
+ namespace: 'document-markdown-extractor',
+ isInteractable: () => false,
+ });
+ initializeEditorWithState(editor, rawState);
+ const markdown = editorStateAsMarkdown(editor, target);
+ return markdown;
+}