* Share - WIP * - public attachment links - WIP * WIP * WIP * Share - WIP * WIP * WIP * include userRole in space object * WIP * Server render shared page meta tags * disable user select * Close Navbar on outside click on mobile * update shared page spaceId * WIP * fix * close sidebar on click * close sidebar * defaults * update copy * Store share key in lowercase * refactor page breadcrumbs * Change copy * add link ref * open link button * add meta og:title * add twitter tags * WIP * make shares/info endpoint public * fix * * add /p/ segment to share urls * minore fixes * change mobile breadcrumb icon
97 lines
No EOL
2.4 KiB
TypeScript
97 lines
No EOL
2.4 KiB
TypeScript
import { Node } from '@tiptap/pm/model';
|
|
import { jsonToNode } from '../../../collaboration/collaboration.util';
|
|
import { validate as isValidUUID } from 'uuid';
|
|
|
|
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[];
|
|
}
|
|
|
|
|
|
export function getProsemirrorContent(content: any) {
|
|
return (
|
|
content ?? {
|
|
type: 'doc',
|
|
content: [{ type: 'paragraph', attrs: { textAlign: 'left' } }],
|
|
}
|
|
);
|
|
}
|
|
|
|
export function isAttachmentNode(nodeType: string) {
|
|
const attachmentNodeTypes = [
|
|
'attachment',
|
|
'image',
|
|
'video',
|
|
'excalidraw',
|
|
'drawio',
|
|
];
|
|
return attachmentNodeTypes.includes(nodeType);
|
|
}
|
|
|
|
export function getAttachmentIds(prosemirrorJson: any) {
|
|
const doc = jsonToNode(prosemirrorJson);
|
|
const attachmentIds = [];
|
|
|
|
doc?.descendants((node: Node) => {
|
|
if (isAttachmentNode(node.type.name)) {
|
|
if (node.attrs.attachmentId && isValidUUID(node.attrs.attachmentId)) {
|
|
if (!attachmentIds.includes(node.attrs.attachmentId)) {
|
|
attachmentIds.push(node.attrs.attachmentId);
|
|
}
|
|
}
|
|
}
|
|
});
|
|
|
|
return attachmentIds;
|
|
} |