Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Socket
Sign inDemoInstall

@atlaskit/adf-schema-generator

Package Overview
Dependencies
Maintainers
2
Versions
82
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@atlaskit/adf-schema-generator

Generates ADF and PM schemas


Version published
Weekly downloads
244
decreased by-6.87%
Maintainers
2
Weekly downloads
 
Created
Source

ADF Schema Generator

This package provides a simple DSL (Domain Specific Language) for defining the schema, that can be transformed into multiple output formats that are required to work with ADF (Atlassian Document Format):

  • ADF JSON Schema
  • ProseMirror Schema
  • Validator Specs

Usage

DSL

The package exports several functions that can be used to define the schema:

Nodes and Marks:

  • adfNode – defines a new ADF node
  • adfMark – defines a new ADF mark

Groups:

  • adfNodeGroup – defines a new ADF node group
  • adfMarkGroup – defines a new ADF mark group

Content Expressions:

  • $or - Create a content expression that allows any of the specified content items
  • $onePlus - Create a content expression that allows one or more of the specified content items
  • $zeroPlus - Create a content expression that allows zero or more of the specified content items
  • $range – Create a content expression that allows to limit number of children
Example
import {
  adfNode,
  adfMark,
  adfNodeGroup,
  $or,
  $onePlus,
  $zeroPlus,
} from '@atlaskit/adf-schema-generator';

const blockGroup = adfNodeGroup('block');

const codeMark = adfMark('code').define();

const text = adfNode('text').define({
  marks: [codeMark],
});

const paragraph = adfNode('paragraph')
  .define({
    group: blockGroup,
    content: [$zeroPlus($or(text))],
  })
  .variant('with-attrs', {
    attrs: {
      alignment: {
        type: 'enum',
        values: ['start', 'end', 'center', 'justify'],
        default: 'start',
      },
    },
  });

const doc = adfNode('doc').define({
  root: true,
  content: [$onePlus($or(blockGroup))],
});

Traverse

The schema can be traversed to generate the output formats:

Traverse accepts a root node of the ADF DSL tree and a visitor object. Visitor is a pattern that is commonly used in tree traversal algorithms. It allows to separate the traversal logic from the actual processing logic.

import { traverse } from '@atlaskit/adf-schema-generator';

traverse(doc, {
  node: (node, variant, children) => {
    return node.type;
  },
  group: (group, children) => {
    return group.name;
  },
  $or: (children) => {
    return children.join(' | ');
  },
});

Transformations

ADF JSON Schema

[] TODO

ProseMirror Schema

[] TODO

Validator Specs

[] TODO

FAQs

Package last updated on 22 May 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc