Extensions

uniqueId

Behaviour takes options 0.18 kB gzipped

Declare the attribute so the schema keeps it.

Without this the id is dropped on the way in: undeclared attributes do not survive, which is a security property rather than an oversight. The id is written to the element as `data-<attribute>` and read back from there, so it survives HTML as well as JSON.

1 · Install

One package for every extension · there is no @matrajs/uniqueId to install.

npm i @matrajs/core

2 · Add it to the editor

Import it and put it in the extensions array. That array is the whole feature list: what is not in it is not in your bundle and not in the document's schema.

import { createEditor, document, paragraph, text, uniqueId } from '@matrajs/core'

const editor = createEditor({
  extensions: [document, paragraph, text, uniqueId({ … })],
  element: document.querySelector('#editor'),
})

3 · Use it

Nothing to call · this one works once it is in the array. Declare the attribute so the schema keeps it.

Options

uniqueId is a function · call it with an options object.

Option Type What it does
types string[] Which node types get an id. Defaults to the blocks in the box.
attribute string The attribute the id is written to.
generate () => string Supply your own, when the ids have to match something outside the editor.

← All 83 extensions

Edit this page on GitHub