mirror of
https://github.com/docmost/docmost.git
synced 2025-11-13 16:02:35 +10:00
feat: internal page links and mentions (#604)
* Work on mentions * fix: properly parse page slug * fix editor suggestion bugs * mentions must start with whitespace * add icon to page mention render * feat: backlinks - WIP * UI - WIP * permissions check * use FTS for page suggestion * cleanup * WIP * page title fallback * feat: handle internal link paste * link styling * WIP * Switch back to LIKE operator for search suggestion * WIP * scope to workspaceId * still create link for pages not found * select necessary columns * cleanups
This commit is contained in:
58
apps/server/src/common/helpers/prosemirror/utils.ts
Normal file
58
apps/server/src/common/helpers/prosemirror/utils.ts
Normal file
@ -0,0 +1,58 @@
|
||||
import { Node } from '@tiptap/pm/model';
|
||||
import { jsonToNode } from '../../../collaboration/collaboration.util';
|
||||
|
||||
export interface MentionNode {
|
||||
id: string;
|
||||
label: string;
|
||||
entityType: 'user' | 'page';
|
||||
entityId: string;
|
||||
creatorId: string;
|
||||
}
|
||||
|
||||
export function extractMentions(prosemirrorJson: any) {
|
||||
const mentionList: MentionNode[] = [];
|
||||
const doc = jsonToNode(prosemirrorJson);
|
||||
|
||||
doc.descendants((node: Node) => {
|
||||
if (node.type.name === 'mention') {
|
||||
if (
|
||||
node.attrs.id &&
|
||||
!mentionList.some((mention) => mention.id === node.attrs.id)
|
||||
) {
|
||||
mentionList.push({
|
||||
id: node.attrs.id,
|
||||
label: node.attrs.label,
|
||||
entityType: node.attrs.entityType,
|
||||
entityId: node.attrs.entityId,
|
||||
creatorId: node.attrs.creatorId,
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
return mentionList;
|
||||
}
|
||||
|
||||
export function extractUserMentions(mentionList: MentionNode[]): MentionNode[] {
|
||||
const userList = [];
|
||||
for (const mention of mentionList) {
|
||||
if (mention.entityType === 'user') {
|
||||
userList.push(mention);
|
||||
}
|
||||
}
|
||||
return userList as MentionNode[];
|
||||
}
|
||||
|
||||
export function extractPageMentions(mentionList: MentionNode[]): MentionNode[] {
|
||||
const pageMentionList = [];
|
||||
for (const mention of mentionList) {
|
||||
if (
|
||||
mention.entityType === 'page' &&
|
||||
!pageMentionList.some(
|
||||
(pageMention) => pageMention.entityId === mention.entityId,
|
||||
)
|
||||
) {
|
||||
pageMentionList.push(mention);
|
||||
}
|
||||
}
|
||||
return pageMentionList as MentionNode[];
|
||||
}
|
||||
Reference in New Issue
Block a user