@atlaskit/adf-utils
Version:
Set of utilities to traverse, modify and create ADF documents.
75 lines • 2.41 kB
JavaScript
import { scrubAttrs } from './scrub-content';
const card = (node, {
valueReplacements
}) => {
var _node$attrs;
return {
type: node.type,
attrs: {
...(node.attrs || {}),
url: valueReplacements.href((_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.url)
}
};
};
const mediaParent = node => {
var _node$content;
return {
type: node.type,
// Ignored via go/ees005
// eslint-disable-next-line @typescript-eslint/no-explicit-any
attrs: node.attrs ? scrubAttrs(node.type, node.attrs) : undefined,
content: (_node$content = node.content) === null || _node$content === void 0 ? void 0 : _node$content.filter(c => (c === null || c === void 0 ? void 0 : c.type) === 'media')
};
};
export const defaultNodeReplacements = {
emoji: () => ({
type: 'emoji',
attrs: {
shortName: ':blue_star:',
id: 'atlassian-blue_star',
text: ':blue_star:'
}
}),
date: () => ({
type: 'date',
attrs: {
timestamp: new Date('2020-01-01').getTime()
}
}),
mention: () => ({
type: 'mention',
attrs: {
id: 'error:NotFound',
text: '@Nemo',
accessLevel: 'CONTAINER'
}
}),
inlineCard: card,
blockCard: card,
mediaSingle: mediaParent,
mediaGroup: mediaParent,
media: (node, {
parent
}) => {
var _parent$node, _node$attrs$width, _node$attrs2, _node$attrs$height, _node$attrs3;
const defaults = ((_parent$node = parent.node) === null || _parent$node === void 0 ? void 0 : _parent$node.type) === 'mediaSingle' ? {
width: 600,
height: 400
} : {
width: 150,
height: 125
};
const width = (_node$attrs$width = (_node$attrs2 = node.attrs) === null || _node$attrs2 === void 0 ? void 0 : _node$attrs2.width) !== null && _node$attrs$width !== void 0 ? _node$attrs$width : defaults.width;
const height = (_node$attrs$height = (_node$attrs3 = node.attrs) === null || _node$attrs3 === void 0 ? void 0 : _node$attrs3.height) !== null && _node$attrs$height !== void 0 ? _node$attrs$height : defaults.height;
return {
type: 'media',
attrs: {
// Ignored via go/ees005
// eslint-disable-next-line @typescript-eslint/no-explicit-any
...scrubAttrs('media', node.attrs),
type: 'external',
url: `https://dummyimage.com/${width}x${height}/f4f5f7/a5adba`
}
};
}
};