sittari-studio

link field

by sittari-studio
payload-plugins
Custom fields
v4
^4.0.0-0
MIT

Overview

Summary generated from the README

Adds a reusable link field to Payload collections, with a Lexical editor feature that shares the same value shape. A plugin resolves internal document URLs through a configurable callback. It includes admin styles, HTML converters and React JSX converters for frontend rendering. Targets Payload 4.

Features

  • linkField helper with drawer appearance, relationTo collections and optional localized labels
  • Lexical LinkFieldFeature replacing Payload's native link feature
  • resolveDocumentUrl callback to build URLs for internal documents
  • HTML converters for Payload v4 Lexical-to-HTML conversion
  • React JSX converter with custom renderer support for Next.js Link
  • Lazy normalization of existing native Lexical link nodes

Use cases

  • Add internal or external link fields to pages with relationships to pages and posts
  • Replace the default Lexical link feature with document-aware links in rich text
  • Render rich text links with Next.js Link and analytics through a custom renderer

From the author

PayloadCMS link-field plugin.

Installation

npm i @sittari/payload-link-field

0

Stars

0

Forks

0

Open Issues

2 months ago

Last Updated

46

Weekly Downloads

v0.4.1

npm Version

197.3 KB

Unpacked Size

1

Dependencies

Repository stars

00 since Sep 7

Show data
Repository stars by day (UTC)
DateStars
Dec 6, 20260
Dec 5, 20260
Dec 4, 20260
Dec 3, 20260
Dec 2, 20260
Dec 1, 20260
Nov 30, 20260
Nov 29, 20260
Nov 28, 20260
Nov 27, 20260
Nov 26, 20260
Nov 25, 20260
Nov 24, 20260
Nov 23, 20260
Nov 22, 20260
Nov 21, 20260
Nov 20, 20260
Nov 19, 20260
Nov 18, 20260
Nov 17, 20260
Nov 16, 20260
Nov 15, 20260
Nov 14, 20260
Nov 13, 20260
Nov 12, 20260
Nov 11, 20260
Nov 10, 20260
Nov 9, 20260
Nov 8, 20260
Nov 7, 20260
Nov 6, 20260
Nov 5, 20260
Nov 4, 20260
Nov 3, 20260
Nov 2, 20260
Nov 1, 20260
Oct 31, 20260
Oct 30, 20260
Oct 29, 20260
Oct 28, 20260
Oct 27, 20260
Oct 26, 20260
Oct 25, 20260
Oct 24, 20260
Oct 23, 20260
Oct 22, 20260
Oct 21, 20260
Oct 20, 20260
Oct 19, 20260
Oct 18, 20260
Oct 17, 20260
Oct 16, 20260
Oct 15, 20260
Oct 14, 20260
Oct 13, 20260
Oct 12, 20260
Oct 11, 20260
Oct 10, 20260
Oct 9, 20260
Oct 8, 20260
Oct 7, 20260
Oct 6, 20260
Oct 5, 20260
Oct 4, 20260
Oct 3, 20260
Oct 2, 20260
Oct 1, 20260
Sep 30, 20260
Sep 29, 20260
Sep 28, 20260
Sep 27, 20260
Sep 26, 20260
Sep 25, 20260
Sep 24, 20260
Sep 23, 20260
Sep 22, 20260
Sep 21, 20260
Sep 20, 20260
Sep 19, 20260
Sep 18, 20260
Sep 17, 20260
Sep 16, 20260
Sep 15, 20260
Sep 14, 20260
Sep 13, 20260
Sep 12, 20260
Sep 11, 20260
Sep 10, 20260
Sep 9, 20260
Sep 8, 20260
Sep 7, 20260

Shared by 8 plugins in sittari-studio/payload-plugins.

npm weekly downloads

47−19 since Sep 7

Show data
npm weekly downloads by day (UTC)
DateWeekly downloads
Dec 6, 202647
Dec 5, 202620
Dec 4, 202620
Dec 3, 202620
Dec 2, 202617
Dec 1, 202619
Nov 30, 202619
Nov 29, 202618
Nov 28, 202617
Nov 27, 202617
Nov 26, 202617
Nov 25, 20264
Nov 24, 20263
Nov 23, 20263
Nov 22, 202617
Nov 21, 202618
Nov 20, 202631
Nov 19, 202631
Nov 18, 202645
Nov 17, 202645
Nov 16, 202646
Nov 15, 202633
Nov 14, 202633
Nov 13, 202620
Nov 12, 202620
Nov 11, 20267
Nov 10, 202620
Nov 9, 202630
Nov 8, 202629
Nov 7, 202631
Nov 6, 202630
Nov 5, 202633
Nov 4, 202638
Nov 3, 202625
Nov 2, 202614
Nov 1, 202614
Oct 31, 202612
Oct 30, 202613
Oct 29, 202610
Oct 28, 20263
Oct 27, 20263
Oct 26, 20264
Oct 25, 20265
Oct 24, 202610
Oct 23, 20269
Oct 22, 202611
Oct 21, 202612
Oct 20, 202620
Oct 19, 202620
Oct 18, 202619
Oct 17, 202616
Oct 16, 202617
Oct 15, 202624
Oct 14, 202623
Oct 13, 202616
Oct 12, 202615
Oct 11, 202617
Oct 10, 202624
Oct 9, 202644
Oct 8, 202638
Oct 7, 202640
Oct 6, 202651
Oct 5, 202651
Oct 4, 202653
Oct 3, 202653
Oct 2, 202636
Oct 1, 202635
Sep 30, 202652
Sep 29, 202640
Sep 28, 202653
Sep 27, 202652
Sep 26, 202652
Sep 25, 202653
Sep 24, 202656
Sep 23, 202650
Sep 22, 202658
Sep 21, 202695
Sep 20, 2026363
Sep 19, 2026356
Sep 18, 2026353
Sep 17, 2026354
Sep 16, 2026348
Sep 15, 2026341
Sep 14, 2026291
Sep 13, 202620
Sep 12, 202617
Sep 11, 202641
Sep 10, 202637
Sep 9, 202637
Sep 8, 202650
Sep 7, 202666

Each point is npm's rolling 7-day download count.

Health Score

63/100Good

Composite score based on GitHub activity, stars, npm downloads, publish recency, dependency count, and package size.

Badge for your README

Payload Directory health badge
Markdown
[![Payload Directory](https://payloaddirectory.dev/badge/1294311885-link-field.svg)](https://payloaddirectory.dev/plugins/1294311885-link-field)
HTML
<a href="https://payloaddirectory.dev/plugins/1294311885-link-field"><img src="https://payloaddirectory.dev/badge/1294311885-link-field.svg" alt="Payload Directory"></a>
Updated Sep 11, 2026Created Jul 8, 2026Published Sep 11, 2026

README

PayloadCMS link-field plugin.

Install

pnpm add @sittari/payload-link-field

Usage

Import the admin stylesheet from your Payload admin CSS file:

@import '@sittari/payload-link-field/admin.css';
import { buildConfig } from 'payload';
import { linkField, linkFieldPlugin } from '@sittari/payload-link-field';

export default buildConfig({
  plugins: [
    linkFieldPlugin({
      resolveDocumentUrl: ({ collectionSlug, document }) => {
        if (collectionSlug === 'pages' && typeof document?.slug === 'string') {
          return `/${document.slug}`;
        }

        return null;
      },
    }),
  ],
  collections: [
    {
      slug: 'pages',
      fields: [
        {
          name: 'title',
          type: 'text',
        },
        linkField({
          name: 'link',
          label: 'Link',
          appearance: 'drawer',
          relationTo: ['pages', 'posts'],
          localizeLabel: true,
        }),
      ],
    },
  ],
});

localizeLabel controls whether the link's nested label field is localized. It defaults to true; set it to false when link labels should use one value across all locales.

LinkFieldFeature() uses the same field schema and value shape as linkField(). It must replace Payload's native feature (both features use the link key), and linkFieldPlugin() remains required because it registers resolveDocumentUrl for reads and serialization.

import { lexicalEditor } from '@payloadcms/richtext-lexical';
import { LinkFieldFeature } from '@sittari/payload-link-field';

const editor = lexicalEditor({
  features: ({ defaultFeatures }) => [
    ...defaultFeatures.filter((feature) => feature.key !== 'link'),
    LinkFieldFeature({
      relationTo: ['pages', 'posts'],
    }),
  ],
});

The feature accepts defaultType, relationTo, showLabel, and showNewTab. When relationTo is omitted, all non-internal collections are considered and collections the current admin user cannot read are removed from the relationship selector. Collections whose slugs start with payload- are always discarded, including when explicitly provided. Existing Payload-native custom and internal link nodes are normalized lazily when read or opened in the editor; their next save writes only the plugin-owned field shape.

Payload v4 HTML conversion requires custom node converters to be passed explicitly:

import {
  convertLexicalToHTMLAsync,
  defaultHTMLConvertersAsync,
} from '@payloadcms/richtext-lexical/html-async';
import { LinkFieldHTMLConverters } from '@sittari/payload-link-field';

const html = await convertLexicalToHTMLAsync({
  converters: {
    ...defaultHTMLConvertersAsync,
    ...LinkFieldHTMLConverters,
  },
  data,
});

Frontend rendering

The React export provides JSX converters for Payload's RichText component and is safe to import from React Server Components. Spread the plugin converters after Payload's defaults:

import { RichText } from '@payloadcms/richtext-lexical/react';
import { LinkFieldJSXConverter } from '@sittari/payload-link-field/react';

export const Content = ({ data }) => (
  <RichText
    converters={({ defaultConverters }) => ({
      ...defaultConverters,
      ...LinkFieldJSXConverter(),
    })}
    data={data}
  />
);

The spread order intentionally replaces Payload's default link and autolink converters. The converter renders only a populated fields.url; unresolved links preserve their formatted children without rendering an anchor or falling back to customUrl.

Pass a renderer to integrate Next.js Link, analytics, or custom routing. The renderer receives normalized fields, rendered children, url, newTab, and the untouched serialized node:

import Link from 'next/link';
import { LinkFieldJSXConverter } from '@sittari/payload-link-field/react';

const converters = LinkFieldJSXConverter({
  renderer: ({ children, newTab, url }) => (
    <Link
      href={url}
      rel={newTab ? 'noopener noreferrer' : undefined}
      target={newTab ? '_blank' : undefined}
    >
      {children}
    </Link>
  ),
});

Similar plugins