Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const node = await api.getByID(value.id, { fetchLinks })
node.data = await normalizeBrowserFields({
...args,
value: node.data,
node: node,
})
// Now that we have this node's normallized data, place it in our cache.
store.set(value.id, node)
}
return new Proxy(
{
...value,
url: PrismicDOM.Link.url(value, linkResolver),
target: value.target || '',
raw: value,
},
{
get: (obj, prop) => {
if (obj.hasOwnProperty(prop)) return obj[prop]
if (prop === 'document') return [store.get(value.id)]
},
},
)
case 'Media':
case 'Web':
return {
...value,
target: value.target || '',
const proxyHandler = {
get: (obj, prop) => {
if (prop === 'document') {
if (value.link_type === 'Document' && value.type !== 'broken_type') return getNodeById(linkedDocId)
return null
}
return obj[prop]
},
}
return new Proxy(
{
...value,
url: PrismicDOM.Link.url(value, linkResolverForField),
raw: value,
document: null, // TODO: ???????
},
proxyHandler,
)
}
export const normalizeLinkField = async (id, value, _depth, context) => {
const { doc, createNodeId, pluginOptions } = context
const { linkResolver } = pluginOptions
const linkResolverForField = linkResolver({ key: id, value, node: doc })
let documentId = null
if (value.link_type === 'Document')
documentId = createNodeId(`${value.type} ${value.id}`)
return {
...value,
url: PrismicDOM.Link.url(value, linkResolverForField),
document: documentId,
raw: value,
}
}
export function getUrl(doc?: Document, path: string = ''): string | undefined {
const fragment = _.get(doc, path);
if (!fragment) return undefined;
return PrismicDOM.Link.url(fragment, linkResolver);
}
const normalizeLinkField = (value, linkResolver, generateNodeId) => {
switch (value.link_type) {
case 'Document':
if (!value.type || !value.id || value.isBroken) return undefined
return {
...value,
document___NODE: [generateNodeId(value.type, value.id)],
url: PrismicDOM.Link.url(value, linkResolver),
target: value.target || '',
raw: value,
}
case 'Media':
case 'Web':
return {
...value,
target: value.target || '',
raw: value,
}
default:
return undefined
}
}
);
case Elements.embed:
return (
<div data-oembed-provider="{element.oembed.provider_name}" data-oembed-type="{element.oembed.type}" data-oembed="{element.oembed.embed_url}">
{element.oembed.html}
</div>
);
case Elements.hyperlink:
const target = element.data.target || undefined;
const rel = target ? 'noopener' : undefined;
const linkUrl = PrismicDOM.Link.url(element.data, linkResolver);
const isDocument = element.data.kind === 'document';
const documentSize = isDocument
? Math.round(element.data.size / 1000)
: '';
const isInPage = linkUrl.match(/^https:\/\/(#.*)/i);
const hashLink = isInPage && isInPage[1];
const fileExtension = linkUrl.match(/\.[0-9a-z]+$/i);
const documentType =
fileExtension && fileExtension[0].substr(1).toUpperCase();
if (hashLink) {
return (
<a href="{hashLink}" rel="{rel}">
{children}</a>