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(md): add unknown md-parser for hiding nasty json when new nodes (#1327)

Seamus31fa833cfa45
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 a87039b373..68a4f805a4 100644
--- a/js/app/packages/core/component/LexicalMarkdown/component/core/StaticMarkdown.tsx
+++ b/js/app/packages/core/component/LexicalMarkdown/component/core/StaticMarkdown.tsx
@@ -23,6 +23,7 @@ import {
type HorizontalRuleNode,
type ImageNode,
type ThemeMentionNode,
+ type UnknownMentionNode,
isSupportedLanguage,
normalizedLanguage,
SupportedNodeTypes,
@@ -77,6 +78,7 @@ import { MarkdownImage as ImageDecorator } from '../decorator/MarkdownImage';
import { MarkdownVideo as VideoDecorator } from '../decorator/MarkdownVideo';
import { UserMention as UserMentionDecorator } from '../decorator/UserMention';
import { ThemeMention as ThemeMentionDecorator } from '../decorator/ThemeMention';
+import { UnknownMention as UnknownMentionDecorator } from '../decorator/UnknownMention';
import { Watermark as WatermarkDecorator } from '../decorator/Watermark';
import { LinkWithPreview } from './LinkWithPreview';
@@ -362,6 +364,20 @@ const Snapshot: RenderableEntity<SnapshotNode> = {
),
};
+const UnknownMention: RenderableEntity<UnknownMentionNode> = {
+ guard: (node: LexicalNode): node is UnknownMentionNode =>
+ node.__type === 'unknown-mention',
+ render: (props) => (
+ <span>
+ {UnknownMentionDecorator({
+ ...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()),
@@ -675,6 +691,7 @@ const InlineEntities: Array<RenderableEntity> = [
HorizontalRule,
Equation,
ThemeMention,
+ UnknownMention,
Watermark,
] as const;
diff --git a/js/app/packages/core/component/LexicalMarkdown/component/decorator/UnknownMention.tsx b/js/app/packages/core/component/LexicalMarkdown/component/decorator/UnknownMention.tsx
new file mode 100644
index 0000000000..db63594bad
--- /dev/null
+++ b/js/app/packages/core/component/LexicalMarkdown/component/decorator/UnknownMention.tsx
@@ -0,0 +1,29 @@
+import type { UnknownMentionDecoratorProps } from '@lexical-core';
+import { useContext } from 'solid-js';
+import Fallback from '@icon/regular/placeholder.svg';
+import { LexicalWrapperContext } from '../../context/LexicalWrapperContext';
+
+export function UnknownMention(props: UnknownMentionDecoratorProps) {
+ const lexicalWrapper = useContext(LexicalWrapperContext);
+ const selection = () => lexicalWrapper?.selection;
+
+ const isSelectedAsNode = () => {
+ const sel = selection();
+ if (!sel) return false;
+ return sel.type === 'node' && sel.nodeKeys.has(props.key);
+ };
+
+ return (
+ <span
+ class="relative py-0.5 px-0.5 cursor-default text-ink-muted/50"
+ classList={{
+ 'bracket-offset-2': isSelectedAsNode(),
+ }}
+ >
+ <span class="relative top-[0.125em] size-[1em] inline-flex mx-1 opacity-50">
+ <Fallback />
+ </span>
+ <span>{props.name || 'Unknown'}</span>
+ </span>
+ );
+}
diff --git a/js/app/packages/core/component/LexicalMarkdown/init.ts b/js/app/packages/core/component/LexicalMarkdown/init.ts
index 0002c624aa..5a70c3c922 100644
--- a/js/app/packages/core/component/LexicalMarkdown/init.ts
+++ b/js/app/packages/core/component/LexicalMarkdown/init.ts
@@ -11,6 +11,7 @@ import {
HtmlRenderNode,
ImageNode,
ThemeMentionNode,
+ UnknownMentionNode,
UserMentionNode,
VideoNode,
WatermarkNode,
@@ -30,6 +31,7 @@ import { MarkdownImage } from './component/decorator/MarkdownImage';
import { MarkdownVideo } from './component/decorator/MarkdownVideo';
import { UserMention } from './component/decorator/UserMention';
import { ThemeMention } from './component/decorator/ThemeMention';
+import { UnknownMention } from './component/decorator/UnknownMention';
import { Watermark } from './component/decorator/Watermark';
import { registerDiffNodeFactory } from './component/dom-factory/diff-factory';
@@ -52,6 +54,7 @@ export function initializeLexical() {
setDecorator(SnapshotNode, Snapshot);
setDecorator(HtmlRenderNode, HtmlRender);
setDecorator(ThemeMentionNode, ThemeMention);
+ setDecorator(UnknownMentionNode, UnknownMention);
setDecorator(WatermarkNode, Watermark);
registerDiffNodeFactory();
}
diff --git a/js/app/packages/core/component/LexicalMarkdown/version.ts b/js/app/packages/core/component/LexicalMarkdown/version.ts
index 7ae1a0551d..ade00c8872 100644
--- a/js/app/packages/core/component/LexicalMarkdown/version.ts
+++ b/js/app/packages/core/component/LexicalMarkdown/version.ts
@@ -7,7 +7,8 @@
* Version 1.0 - July 18, 2025
* Version 1.1 - August 7, 2025. Added scale support to media nodes.
* Version 1.2 - Feb 3, 2026. Added theme-mention-node.
+ * Version 1.21 - Feb 4, 2026. Added fallback-xml tag node.
*/
-export const MARKDOWN_VERSION_COUNTER = 1.2;
+export const MARKDOWN_VERSION_COUNTER = 1.21;
export const STAGING_TAG = 'staging';
diff --git a/js/app/packages/lexical-core/decoratorRegistry.ts b/js/app/packages/lexical-core/decoratorRegistry.ts
index 98d61d8bd6..32c2e7b8ee 100644
--- a/js/app/packages/lexical-core/decoratorRegistry.ts
+++ b/js/app/packages/lexical-core/decoratorRegistry.ts
@@ -53,11 +53,17 @@ import type {
WatermarkDecoratorProps,
WatermarkNode,
} from './nodes/WatermarkNode';
+import type {
+ UnknownMentionNode,
+ UnknownMentionDecoratorProps,
+} from './nodes/UnknownMentionNode';
// Generic component type to be overridden by solid-js on the front end
// and nothing on the backend.
export type DecoratorComponent<P extends {}> = (props: P) => any;
+// Maps node type names to their class and props types
+// This provides compile-time type safety for decorator registration
export interface NodeDecoratorMap {
DiffInsertNode: {
klass: typeof DiffInsertNode;
@@ -119,33 +125,32 @@ export interface NodeDecoratorMap {
klass: typeof WatermarkNode;
props: WatermarkDecoratorProps;
};
+ UnknownMentionNode: {
+ klass: typeof UnknownMentionNode;
+ props: UnknownMentionDecoratorProps;
+ };
}
-export type NodeClassToProps<T extends LexicalNode> = T extends InstanceType<
- NodeDecoratorMap[keyof NodeDecoratorMap]['klass']
->
- ? Extract<
- NodeDecoratorMap[keyof NodeDecoratorMap],
- { klass: new (...args: any) => T }
- >['props']
- : never;
-
const decoratorRegistry = new Map<
Klass<LexicalNode>,
DecoratorComponent<any>
>();
-export function setDecorator<T extends LexicalNode>(
- klass: Klass<T>,
- component: DecoratorComponent<NodeClassToProps<T>>
+// Type-safe registration: caller specifies both the node class and props type explicitly
+export function setDecorator<TProps extends {}>(
+ klass: Klass<LexicalNode>,
+ component: DecoratorComponent<TProps>
): void {
decoratorRegistry.set(klass, component);
}
-export function getDecorator<T extends LexicalNode>(
- klass: Klass<T>
-): DecoratorComponent<NodeClassToProps<T>> | undefined {
- return decoratorRegistry.get(klass);
+// Simple retrieval: caller specifies the props type they expect
+// This avoids complex conditional type inference that can fail
+export function getDecorator<TProps extends {}>(
+ klass: Klass<LexicalNode>
+): DecoratorComponent<TProps> | undefined {
+ const decorator = decoratorRegistry.get(klass);
+ return decorator as DecoratorComponent<TProps> | undefined;
}
export function clearDecorators() {
diff --git a/js/app/packages/lexical-core/index.ts b/js/app/packages/lexical-core/index.ts
index f6b8592f2e..eff582688b 100644
--- a/js/app/packages/lexical-core/index.ts
+++ b/js/app/packages/lexical-core/index.ts
@@ -23,6 +23,7 @@ export * from './nodes/ImageNode';
export * from './nodes/InlineSearchNode';
export * from './nodes/MediaNode';
export * from './nodes/UnlinkedTextNode';
+export * from './nodes/UnknownMentionNode';
export * from './nodes/UserMentionNode';
export * from './nodes/VideoNode';
export * from './nodes/ThemeMentionNode';
diff --git a/js/app/packages/lexical-core/node-list.ts b/js/app/packages/lexical-core/node-list.ts
index 595b281001..744583024e 100644
--- a/js/app/packages/lexical-core/node-list.ts
+++ b/js/app/packages/lexical-core/node-list.ts
@@ -36,6 +36,7 @@ import { UnlinkedTextNode } from './nodes/UnlinkedTextNode';
import { UserMentionNode } from './nodes/UserMentionNode';
import { VideoNode } from './nodes/VideoNode';
import { ThemeMentionNode } from './nodes/ThemeMentionNode';
+import { UnknownMentionNode } from './nodes/UnknownMentionNode';
import { WatermarkNode } from './nodes/WatermarkNode';
/**
@@ -95,6 +96,7 @@ export const SupportedNodeTypes = [
ClassedBlockNode,
WatermarkNode,
ThemeMentionNode,
+ UnknownMentionNode,
] as const;
export const NodeReplacements: LexicalNodeReplacement[] = [
diff --git a/js/app/packages/lexical-core/nodes/ContactMentionNode.ts b/js/app/packages/lexical-core/nodes/ContactMentionNode.ts
index fde564a621..360b8166ad 100644
--- a/js/app/packages/lexical-core/nodes/ContactMentionNode.ts
+++ b/js/app/packages/lexical-core/nodes/ContactMentionNode.ts
@@ -273,7 +273,8 @@ export class ContactMentionNode extends DecoratorNode<
}
decorate(_: LexicalEditor, config: EditorConfig) {
- const decorator = getDecorator<ContactMentionNode>(ContactMentionNode);
+ const decorator =
+ getDecorator<ContactMentionDecoratorProps>(ContactMentionNode);
if (decorator) {
return () =>
decorator({
diff --git a/js/app/packages/lexical-core/nodes/CustomCodeNode.ts b/js/app/packages/lexical-core/nodes/CustomCodeNode.ts
index b5c240a617..1b3c3ab86a 100644
--- a/js/app/packages/lexical-core/nodes/CustomCodeNode.ts
+++ b/js/app/packages/lexical-core/nodes/CustomCodeNode.ts
@@ -3,7 +3,6 @@
* synced via a single LoroText item
*/
-import { ENABLE_SVG_PREVIEW } from '@core/constant/featureFlags';
import {
$isCodeNode,
CodeNode,
@@ -22,6 +21,8 @@ import {
import { $applyIdFromSerialized } from '../plugins/nodeIdPlugin';
import { $applyPeerIdFromSerialized } from '../plugins/peerIdPlugin';
+const ENABLE_SVG_PREVIEW = true;
+
/**
* Lexical default imported prism languages.
* 'prismjs/components/prism-clike';
@@ -53,7 +54,7 @@ import {
normalizedLanguage,
type SupportedLanguage,
SupportedLanguages,
-} from '@lexical-core/utils/languageSupport';
+} from '../utils/languageSupport';
const VERSION = 2;
diff --git a/js/app/packages/lexical-core/nodes/DateMentionNode.ts b/js/app/packages/lexical-core/nodes/DateMentionNode.ts
index d90d094a81..17ff853043 100644
--- a/js/app/packages/lexical-core/nodes/DateMentionNode.ts
+++ b/js/app/packages/lexical-core/nodes/DateMentionNode.ts
@@ -200,7 +200,7 @@ export class DateMentionNode extends DecoratorNode<
}
decorate(_: LexicalEditor, config: EditorConfig) {
- const decorator = getDecorator<DateMentionNode>(DateMentionNode);
+ const decorator = getDecorator<DateMentionDecoratorProps>(DateMentionNode);
if (decorator) {
return () =>
decorator({
diff --git a/js/app/packages/lexical-core/nodes/DiffInsertNode.ts b/js/app/packages/lexical-core/nodes/DiffInsertNode.ts
index 8a4361de78..a92fd974f6 100644
--- a/js/app/packages/lexical-core/nodes/DiffInsertNode.ts
+++ b/js/app/packages/lexical-core/nodes/DiffInsertNode.ts
@@ -98,7 +98,7 @@ export class DiffInsertNode extends DecoratorNode<
}
decorate(_: LexicalEditor, config: EditorConfig) {
- const decorator = getDecorator<DiffInsertNode>(DiffInsertNode);
+ const decorator = getDecorator<DiffInsertDecoratorProps>(DiffInsertNode);
if (decorator) {
return () =>
decorator({
diff --git a/js/app/packages/lexical-core/nodes/DocumentCardNode.ts b/js/app/packages/lexical-core/nodes/DocumentCardNode.ts
index 4220e8fa3f..8a397d6001 100644
--- a/js/app/packages/lexical-core/nodes/DocumentCardNode.ts
+++ b/js/app/packages/lexical-core/nodes/DocumentCardNode.ts
@@ -325,7 +325,8 @@ export class DocumentCardNode extends DecoratorBlockNode<
? documentCardNodeKeyToPreviewComponent.get(key)?.component
: undefined;
- const decorator = getDecorator<DocumentCardNode>(DocumentCardNode);
+ const decorator =
+ getDecorator<DocumentCardDecoratorProps>(DocumentCardNode);
if (decorator) {
return () =>
decorator({
diff --git a/js/app/packages/lexical-core/nodes/DocumentMentionNode.ts b/js/app/packages/lexical-core/nodes/DocumentMentionNode.ts
index 7ee808b3b2..72dbc5206b 100644
--- a/js/app/packages/lexical-core/nodes/DocumentMentionNode.ts
+++ b/js/app/packages/lexical-core/nodes/DocumentMentionNode.ts
@@ -288,7 +288,8 @@ export class DocumentMentionNode extends DecoratorNode<
}
decorate(_: LexicalEditor, config: EditorConfig) {
- const decorator = getDecorator<DocumentMentionNode>(DocumentMentionNode);
+ const decorator =
+ getDecorator<DocumentMentionDecoratorProps>(DocumentMentionNode);
if (decorator) {
return () =>
decorator({
diff --git a/js/app/packages/lexical-core/nodes/EquationNode.ts b/js/app/packages/lexical-core/nodes/EquationNode.ts
index b6904f79b1..c1bb6560f5 100644
--- a/js/app/packages/lexical-core/nodes/EquationNode.ts
+++ b/js/app/packages/lexical-core/nodes/EquationNode.ts
@@ -139,7 +139,7 @@ export class EquationNode extends DecoratorNode<
}
decorate(__: LexicalEditor, _: EditorConfig) {
- const decorator = getDecorator<EquationNode>(EquationNode);
+ const decorator = getDecorator<EquationDecoratorProps>(EquationNode);
if (decorator) {
return () =>
decorator({
diff --git a/js/app/packages/lexical-core/nodes/GroupMentionNode.ts b/js/app/packages/lexical-core/nodes/GroupMentionNode.ts
index aa519333a5..5e6f90b0bd 100644
--- a/js/app/packages/lexical-core/nodes/GroupMentionNode.ts
+++ b/js/app/packages/lexical-core/nodes/GroupMentionNode.ts
@@ -142,7 +142,8 @@ export class GroupMentionNode extends DecoratorNode<
}
decorate(_: LexicalEditor, config: EditorConfig) {
- const decorator = getDecorator<GroupMentionNode>(GroupMentionNode);
+ const decorator =
+ getDecorator<GroupMentionDecoratorProps>(GroupMentionNode);
if (decorator) {
return () =>
decorator({
diff --git a/js/app/packages/lexical-core/nodes/HorizontalRuleNode.ts b/js/app/packages/lexical-core/nodes/HorizontalRuleNode.ts
index bb41fc9bf0..5f6b63d312 100644
--- a/js/app/packages/lexical-core/nodes/HorizontalRuleNode.ts
+++ b/js/app/packages/lexical-core/nodes/HorizontalRuleNode.ts
@@ -69,7 +69,7 @@ export class HorizontalRuleNode extends DecoratorBlockNode<
}
decorate() {
- const dec = getDecorator<HorizontalRuleNode>(HorizontalRuleNode);
+ const dec = getDecorator<HorizontalRuleDecoratorProps>(HorizontalRuleNode);
if (dec) {
return () =>
dec({
diff --git a/js/app/packages/lexical-core/nodes/HtmlRenderNode.ts b/js/app/packages/lexical-core/nodes/HtmlRenderNode.ts
index d5ed31a8c9..849e42854a 100644
--- a/js/app/packages/lexical-core/nodes/HtmlRenderNode.ts
+++ b/js/app/packages/lexical-core/nodes/HtmlRenderNode.ts
@@ -130,7 +130,7 @@ export class HtmlRenderNode extends DecoratorBlockNode<
}
decorate(_: LexicalEditor, config: EditorConfig) {
- const decorator = getDecorator<HtmlRenderNode>(HtmlRenderNode);
+ const decorator = getDecorator<HtmlRenderDecoratorProps>(HtmlRenderNode);
if (decorator) {
return () =>
decorator({
diff --git a/js/app/packages/lexical-core/nodes/ImageNode.ts b/js/app/packages/lexical-core/nodes/ImageNode.ts
index e4a85c8cd7..73471558f0 100644
--- a/js/app/packages/lexical-core/nodes/ImageNode.ts
+++ b/js/app/packages/lexical-core/nodes/ImageNode.ts
@@ -222,7 +222,7 @@ export class ImageNode extends MediaNode<{ alt: string }> {
if (!this.__componentDirty && this.__cachedDecoratorComponent) {
return this.__cachedDecoratorComponent;
}
- const decorator = getDecorator<ImageNode>(ImageNode);
+ const decorator = getDecorator<ImageDecoratorProps>(ImageNode);
if (decorator) {
const comp = () => decorator(this.exportComponentProps());
this.__cachedDecoratorComponent = comp;
diff --git a/js/app/packages/lexical-core/nodes/SnapshotNode.ts b/js/app/packages/lexical-core/nodes/SnapshotNode.ts
index edf5e14eba..1686d76f91 100644
--- a/js/app/packages/lexical-core/nodes/SnapshotNode.ts
+++ b/js/app/packages/lexical-core/nodes/SnapshotNode.ts
@@ -259,7 +259,7 @@ export class SnapshotNode extends DecoratorNode<
}
decorate(_: LexicalEditor, config: EditorConfig) {
- const decorator = getDecorator<SnapshotNode>(SnapshotNode);
+ const decorator = getDecorator<SnapshotDecoratorProps>(SnapshotNode);
if (decorator) {
return () =>
decorator({
diff --git a/js/app/packages/lexical-core/nodes/ThemeMentionNode.ts b/js/app/packages/lexical-core/nodes/ThemeMentionNode.ts
index 34e12508a4..c94813d8cd 100644
--- a/js/app/packages/lexical-core/nodes/ThemeMentionNode.ts
+++ b/js/app/packages/lexical-core/nodes/ThemeMentionNode.ts
@@ -147,7 +147,8 @@ export class ThemeMentionNode extends DecoratorNode<
}
decorate(_: LexicalEditor, config: EditorConfig) {
- const decorator = getDecorator<ThemeMentionNode>(ThemeMentionNode);
+ const decorator =
+ getDecorator<ThemeMentionDecoratorProps>(ThemeMentionNode);
if (decorator) {
return () =>
decorator({
diff --git a/js/app/packages/lexical-core/nodes/UnknownMentionNode.ts b/js/app/packages/lexical-core/nodes/UnknownMentionNode.ts
new file mode 100644
index 0000000000..7ed8eac001
--- /dev/null
+++ b/js/app/packages/lexical-core/nodes/UnknownMentionNode.ts
@@ -0,0 +1,152 @@
+import {
+ $applyNodeReplacement,
+ DecoratorNode,
+ type DOMConversionMap,
+ type DOMConversionOutput,
+ type DOMExportOutput,
+ 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';
+
+export type UnknownMentionData = {
+ name: string;
+};
+
+export type SerializedUnknownMentionNode = Spread<
+ UnknownMentionData,
+ SerializedLexicalNode
+>;
+
+export type UnknownMentionDecoratorProps = {
+ name: string;
+ key: NodeKey;
+ theme: EditorThemeClasses;
+};
+
+export class UnknownMentionNode extends DecoratorNode<
+ DecoratorComponent<UnknownMentionDecoratorProps> | undefined
+> {
+ __name: string;
+
+ static getType() {
+ return 'unknown-mention';
+ }
+
+ isInline(): boolean {
+ return true;
+ }
+
+ isKeyboardSelectable(): boolean {
+ return true;
+ }
+
+ static clone(node: UnknownMentionNode) {
+ return new UnknownMentionNode(node.__name, node.__key);
+ }
+
+ constructor(name: string, key?: NodeKey) {
+ super(key);
+ this.__name = name;
+ }
+
+ static importJSON(serializedNode: SerializedUnknownMentionNode) {
+ const node = $createUnknownMentionNode({
+ name: serializedNode.name,
+ });
+ $applyIdFromSerialized(node, serializedNode);
+ return node;
+ }
+
+ exportJSON(): SerializedUnknownMentionNode {
+ return {
+ ...super.exportJSON(),
+ name: this.__name,
+ type: UnknownMentionNode.getType(),
+ version: 1,
+ };
+ }
+
+ exportComponentProps(): UnknownMentionData {
+ return {
+ name: this.__name,
+ };
+ }
+
+ createDOM(_config: EditorConfig): HTMLElement {
+ const container = document.createElement('span');
+ return container;
+ }
+
+ updateDOM(): boolean {
+ return false;
+ }
+
+ static importDOM(): DOMConversionMap<HTMLDivElement> | null {
+ const convert = (domNode: HTMLElement): DOMConversionOutput | null => {
+ if (!domNode.hasAttribute('data-unknown-mention')) {
+ return null;
+ }
+
+ const name = domNode.getAttribute('data-name') || 'unknown';
+ const node = $createUnknownMentionNode({ name });
+ return { node };
+ };
+
+ return {
+ div: () => ({ conversion: convert, priority: 1 }),
+ };
+ }
+
+ exportDOM(): DOMExportOutput {
+ const element = document.createElement('div');
+ element.setAttribute('data-unknown-mention', 'true');
+ element.setAttribute('data-name', this.__name);
+ return { element };
+ }
+
+ getTextContent(): string {
+ return '';
+ }
+
+ getName(): string {
+ return this.__name;
+ }
+
+ setName(name: string): void {
+ const writable = this.getWritable();
+ writable.__name = name;
+ }
+
+ decorate(_: LexicalEditor, config: EditorConfig) {
+ const decorator =
+ getDecorator<UnknownMentionDecoratorProps>(UnknownMentionNode);
+ if (!decorator) return;
+
+ return () =>
+ decorator({
+ name: this.__name,
+ key: this.getKey(),
+ theme: config.theme,
+ });
+ }
+}
+
+export function $createUnknownMentionNode(
+ params: UnknownMentionData
+): UnknownMentionNode {
+ const node = new UnknownMentionNode(params.name);
+ return $applyNodeReplacement(node);
+}
+
+export function $isUnknownMentionNode(
+ node: LexicalNode | null | undefined
+): node is UnknownMentionNode {
+ return node instanceof UnknownMentionNode;
+}
diff --git a/js/app/packages/lexical-core/nodes/UserMentionNode.ts b/js/app/packages/lexical-core/nodes/UserMentionNode.ts
index e1f6f795fe..94a7c53406 100644
--- a/js/app/packages/lexical-core/nodes/UserMentionNode.ts
+++ b/js/app/packages/lexical-core/nodes/UserMentionNode.ts
@@ -189,7 +189,7 @@ export class UserMentionNode extends DecoratorNode<
}
decorate(_: LexicalEditor, config: EditorConfig) {
- const decorator = getDecorator<UserMentionNode>(UserMentionNode);
+ const decorator = getDecorator<UserMentionDecoratorProps>(UserMentionNode);
if (decorator) {
return () =>
decorator({
diff --git a/js/app/packages/lexical-core/nodes/VideoNode.ts b/js/app/packages/lexical-core/nodes/VideoNode.ts
index 9e7cae48ff..d4d36a4291 100644
--- a/js/app/packages/lexical-core/nodes/VideoNode.ts
+++ b/js/app/packages/lexical-core/nodes/VideoNode.ts
@@ -228,7 +228,7 @@ export class VideoNode extends MediaNode<{ controls: boolean }> {
return this.__cachedDecoratorComponent;
}
- const decorator = getDecorator<VideoNode>(VideoNode);
+ const decorator = getDecorator<VideoDecoratorProps>(VideoNode);
if (decorator) {
const comp = () => decorator(this.exportComponentProps());
this.__cachedDecoratorComponent = comp;
diff --git a/js/app/packages/lexical-core/nodes/WatermarkNode.ts b/js/app/packages/lexical-core/nodes/WatermarkNode.ts
index 960916c4e9..26d6602876 100644
--- a/js/app/packages/lexical-core/nodes/WatermarkNode.ts
+++ b/js/app/packages/lexical-core/nodes/WatermarkNode.ts
@@ -151,7 +151,7 @@ export class WatermarkNode extends DecoratorNode<
}
decorate(_: LexicalEditor, config: EditorConfig) {
- const decorator = getDecorator<WatermarkNode>(WatermarkNode);
+ const decorator = getDecorator<WatermarkDecoratorProps>(WatermarkNode);
if (decorator) {
return () =>
decorator({
diff --git a/js/app/packages/lexical-core/transformers/index.ts b/js/app/packages/lexical-core/transformers/index.ts
index 9969781219..3f2947761c 100644
--- a/js/app/packages/lexical-core/transformers/index.ts
+++ b/js/app/packages/lexical-core/transformers/index.ts
@@ -34,6 +34,7 @@ import {
PRESERVE_LINES,
SEARCH_MATCH,
} from './transformers';
+import { UNKNOWN_MENTION } from './unknownMention';
import { E_WATERMARK, I_WATERMARK } from './watermark';
/**
@@ -62,6 +63,7 @@ export const INTERNAL_TRANSFORMERS: Transformer[] = [
I_WATERMARK,
I_SNAPSHOT_NODE,
...CUSTOM_TRANSFORMERS,
+ UNKNOWN_MENTION, // Must be last to act as fallback for unrecognized XML tags
];
/**
@@ -89,6 +91,7 @@ export const EXTERNAL_TRANSFORMERS: Transformer[] = [
E_SNAPSHOT_NODE,
...HTML_ENTITY_TRANSFORMERS,
...CUSTOM_TRANSFORMERS,
+ UNKNOWN_MENTION, // Must be last to act as fallback for unrecognized XML tags
];
/**
@@ -130,4 +133,5 @@ export const ALL_TRANSFORMERS: Transformer[] = [
E_INLINE_EQUATION_NODE,
...HTML_ENTITY_TRANSFORMERS,
...CUSTOM_TRANSFORMERS,
+ UNKNOWN_MENTION, // Must be last to act as fallback for unrecognized XML tags
];
diff --git a/js/app/packages/lexical-core/transformers/unknownMention.ts b/js/app/packages/lexical-core/transformers/unknownMention.ts
new file mode 100644
index 0000000000..069800b660
--- /dev/null
+++ b/js/app/packages/lexical-core/transformers/unknownMention.ts
@@ -0,0 +1,36 @@
+import type { TextMatchTransformer } from '@lexical/markdown';
+import type { LexicalNode, TextNode } from 'lexical';
+import {
+ $createUnknownMentionNode,
+ $isUnknownMentionNode,
+ UnknownMentionNode,
+} from '../nodes/UnknownMentionNode';
+
+// Transformer for unknown/unrecognized XML tags
+// This acts as a fallback to capture any XML-like tags that don't have specific handlers
+export const UNKNOWN_MENTION: TextMatchTransformer = {
+ dependencies: [UnknownMentionNode],
+ type: 'text-match',
+ // Match any XML tag that starts with 'm-' or other prefixes we don't recognize
+ // This should be registered AFTER all known transformers to act as a fallback
+ regExp: /<([a-zA-Z0-9_-]+)>(.*?)<\/\1>/s,
+ importRegExp: /<([a-zA-Z0-9_-]+)>(.*?)<\/\1>/s,
+
+ export: (node: LexicalNode) => {
+ if (!$isUnknownMentionNode(node)) return null;
+
+ const tagName = node.getName();
+
+ return `<${tagName}></${tagName}>`;
+ },
+
+ replace: (textNode: TextNode, match: RegExpMatchArray) => {
+ try {
+ const name = match[1];
+ const unknownMentionNode = $createUnknownMentionNode({ name });
+ textNode.replace(unknownMentionNode);
+ } catch (e) {
+ console.error('Error in UNKNOWN_MENTION replace:', e);
+ }
+ },
+};