Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@keystonejs/fields-content

keystonejs1.2kMIT9.1.2

A block-based content field for KeystoneJS

readme

Content

This is the last active development release of this package as Keystone 5 is now in a 6 to 12 month active maintenance phase. For more information please read our Keystone 5 and beyond post.

A Block-based Content Field for composing rich text such as blog posts, wikis, and even complete pages.

The Content field type can accept an optional array of Blocks which enhance the editing experience of that field in various ways. Built on top of Slate.js, Blocks are a powerful tool for creating structured and unstructured content editing flows.

Usage

This package isn't included with the keystone fields package and needs to be installed with yarn add @keystonejs/fields-content or npm install @keystonejs/fields-content.

const { Content } = require('@keystonejs/fields-content');

keystone.createList('Post', {
  fields: {
    body: {
      type: Content,
      blocks: [
        Content.blocks.blockquote,
        Content.blocks.image,
        Content.blocks.link,
        Content.blocks.orderedList,
        Content.blocks.unorderedList,
        Content.blocks.heading,
      ],
    },
  },
});

API

Each block is defined by the following API:

{
  // (required)
  // A globally unique name for this block. Alpha-num characters only.
  // NOTE: This must match the value exported from `getAdminViews()#type`.
  type: 'MyBlock',

  // (required)
  // The views this block will provide.
  // See below for the expected exports.
  // Blocks can insert/render other blocks (eg; an image gallery can insert
  // an image block). These other block views should also be included here.
  getAdminViews: () => ['/absolute/path/to/built/view/file'],

  // (optional)
  // The server-side serialization implementation logic.
  // If not provided, any data included in the block will be serialised and
  // stored as a string in the database, and passed directly back to the
  // slate.js editor client side.
  // NOTE: See getAdminViews()#serialiser for complimentary client-side logic
  implementation: SingleImageBlock,

  // TODO: The client-side serialization implementation logic.
}

The view files referenced from the getAdminViews() option can have the following exports:

// (required)
// A globally unique name for this block. Alpha-num characters only.
// NOTE: This must match the value exported from the Block config .type
export const type = 'MyBlock';

// (required)
// The element rendered into the slate.js editor.
// Is passed all the props a slate.js `renderNode()` receives.
export const Node = /* ... */;

// (optional)
// A button / element to insert into the side bar when it's opened.
// Will be passed a single prop; `editor` which is an instance of the Slate.js
// editor.
export const Sidebar = /* ... */;

// (optional)
// The individual button which shows in the toolbar
export const ToolbarElement = /* ... */;

// (optional)
// Toolbar overwrite. Useful if clicking the button needs to show more info.
// Will be rendered within the toolbar, and passed {children} which is the
// regular toolbar. It can opt to not render the {children} so the entire
// toolbar is replaced with this element.
export const Toolbar = /* ... */;

// (optional)
// Wraps the entire Content Editor. The value is the options object passed to
// the block from the field config.
// TODO: Can we skip this and instead pass the options into each of the above
// views directly?
export const Provider = /* ... */;

// (optional)
// slate.js schema object, injected into the slate.js schema as:
// {
//   document: { /* .. */ },
//   blocks: {
//     [type]: <here>,
//   },
// }
export const schema = /* ... */;

// (optional)
// slate.js plugins array.
export const plugins = /* ... */;

// (optional)
//
export function processNodeForConnectQuery({ id, node }) { return { node, query } };

Custom blocks

In addition to the standard set of blocks exposed by the Content field, you can create custom blocks using the above API. Some other field types also expose custom blocks that can be used in the Content field. You can find examples of custom blocks in the following fields:

changelog

@keystonejs/fields-content

9.1.2

Patch Changes

9.1.1

Patch Changes

9.1.0

Minor Changes

Patch Changes

9.0.7

Patch Changes

9.0.6

Patch Changes

9.0.5

Patch Changes

9.0.4

Patch Changes

9.0.3

Patch Changes

9.0.2

Patch Changes

9.0.1

Patch Changes

9.0.0

Major Changes

Patch Changes

8.0.5

Patch Changes

8.0.4

Patch Changes

8.0.3

Patch Changes

8.0.2

Patch Changes

8.0.1

Patch Changes

8.0.0

Major Changes

  • 149d6fd6f #3304 Thanks @MadeByMike! - Renamed @keystonejs/field-content to @keystonejs/fields-content. Please install @keystonejs/fields-content and update your imports from @keystonejs/field-content to @keystonejs/fields-content.

Patch Changes

7.0.3

Patch Changes

7.0.2

Patch Changes

7.0.1

Patch Changes

7.0.0

Major Changes

  • ea9608342 #2976 Thanks @Vultraz! - Refactored how list and item queries and generated. Field controllers' getFilterGraphQL method now returns an object in the format { filter: value } rather than a GraphQL string. Additionally, getFilterValue should now return undefined instead of null if the filter should not be submitted.

Minor Changes

  • c2ebb51c7 #2258 Thanks @gautamsi! - * Added isReadOnly option on field's adminConfig. Fields with this option set will be excluded from the create form, and set as disabled in the update form in the Admin UI.

    • Updated the item detail page to include fields with access { update: false } in a disabled state, rather than excluded the form.
    • Updated all Field Views to accept isDisabled prop. When set to true this will disable the field input.

    Example:

    keystone.createList('Todo', {
      fields: {
        name: { type: Text, isRequired: true },
        someReadOnlyField: {
          type: Text,
          adminConfig: {
            isReadOnly: true,
          },
          defaultValue: 'Some default value',
        },
      },
    });

Patch Changes

6.0.1

Patch Changes

6.0.0

Major Changes

  • d8584765 #2906 Thanks @timleslie! - Removed Controller.adminMeta in favour of explicit values for .readViews, .preloadViews, .getListByKey, .adminPath, and .authStrategy.

Patch Changes

5.4.8

Patch Changes

5.4.7

Patch Changes

5.4.6

Patch Changes

5.4.5

Patch Changes

5.4.4

Patch Changes

5.4.3

Patch Changes

5.4.2

Patch Changes

5.4.1

Patch Changes

5.4.0

Minor Changes

Patch Changes

5.3.0

Minor Changes

  • 220d3a4b #2005 - The presentation and usability of the content blocks editor was improved.

Patch Changes

5.2.2

Patch Changes

5.2.1

Patch Changes

5.2.0

Minor Changes

  • 129b0f6 #2092 - A fix to correctly serialize slate content in the list view of the Admin UI.

Patch Changes

5.1.0

Minor Changes

Patch Changes

5.0.1

Patch Changes

5.0.0

Major Changes

  • 7b4ed362 #1821 Thanks @jesstelford! - Release @keystonejs/* packages (つ^ ◡ ^)つ

    • This is the first release of @keystonejs/* packages (previously @keystone-alpha/*).
    • All packages in the @keystone-alpha namespace are now available in the @keystonejs namespace, starting at version 5.0.0.
    • To upgrade your project you must update any @keystone-alpha/* dependencies in package.json to point to "@keystonejs/*": "^5.0.0" and update any require/import statements in your code.

Patch Changes

@keystone-alpha/field-content

3.1.4

Patch Changes

3.1.3

Patch Changes

3.1.2

3.1.1

Patch Changes

  • 04aa6a08: Fix regression when parent list of a Content field had a where clause as its access control.

3.1.0

Minor Changes

  • f56ffdfd: Apply access control to auxiliary lists

3.0.1

3.0.0

Major Changes

  • 89c0d7e9: The .access property of Fields is now keyed by schemaName. As such, a number of getters have been replaced with methods which take { schemaName }.

    • get gqlOutputFields() -> gqlOutputFields({ schemaName })
    • get gqlOutputFieldResolvers() -> gqlOutputFieldResolvers({ schemaName })
    • get gqlAuxFieldResolvers() -> gqlAuxFieldResolvers({ schemaName })
    • get gqlAuxQueryResolvers() -> gqlAuxQueryResolvers({ schemaName })
    • get gqlAuxMutationResolvers() -> gqlAuxMutationResolvers({ schemaName })
    • get gqlQueryInputFields() -> gqlQueryInputFields({ schemaName })
  • Updated dependencies a8e9378d:

2.1.0

Minor Changes

  • e049cfcb: Support defaultValue as a function in view Controllers

2.0.2

Patch Changes

2.0.1

2.0.0

Major Changes

  • ac7934fe:

    Update Slate 0.44.12 -> 0.47.4 & slate-rect 0.21.18 -> 0.22.4

Patch Changes

  • ac7934fe:

    Ensure all plugins for default Blocks are added to Slate correctly

1.0.0

Major Changes

  • b6a9f6b9:

    Extract Content field into its own package: @keystone-alpha/field-content.