Files
outline/shared/editor/lib/embeds.ts
T
Hemachandar 5584089441 feat: Figma integration (#11044)
* OAuth

* store logo

* unfurl support

* refresh token

* support for list

* embed list

* mention menu for all embeds in a list

* multi-level list

* logo

* account level connection

* tsc

* Update Icon.tsx

* coderabbit feedback

* RFC 6749 suggestion

---------

Co-authored-by: Tom Moor <tom@getoutline.com>
2026-01-15 20:27:00 -05:00

43 lines
1.1 KiB
TypeScript

import type { Node, Schema } from "prosemirror-model";
import type { EmbedDescriptor } from "../embeds";
import { isList } from "../queries/isList";
export function getMatchingEmbed(
embeds: EmbedDescriptor[],
href: string
): { embed: EmbedDescriptor; matches: RegExpMatchArray } | undefined {
for (const e of embeds) {
const matches = e.matcher(href);
if (matches) {
return { embed: e, matches };
}
}
return undefined;
}
export function transformListToEmbeds(listNode: Node, schema: Schema): Node[] {
const nodes: Node[] = [];
listNode.forEach((node) => {
nodes.push(...transformListItemToEmbeds(node, schema));
});
return nodes;
}
function transformListItemToEmbeds(listItemNode: Node, schema: Schema): Node[] {
const nodes: Node[] = [];
listItemNode.forEach((node) => {
if (node.type.name === "paragraph") {
const url = node.textContent;
nodes.push(schema.nodes.embed.create({ href: url }));
} else if (isList(node, schema)) {
nodes.push(...transformListToEmbeds(node, schema));
}
});
return nodes;
}