Skip to content

@astl/editor-tiptap

<astl-editor>, the authoring kit around a TipTap surface, and defineEditor. This entry never imports TipTap: the surface is a dynamic import, made only when no other editor is plugged in.

  • LitElement
new AstlEditor(): AstlEditor;

AstlEditor

LitElement.constructor
Property Type Description
adapter EditorAdapter | null The editor the kit drives. Default: TipTap, on a surface this element creates when it first renders without an adapter and without a slot="surface" child. Setting another adapter swaps the editor; null brings the TipTap surface back (with its document), unless a slot="surface" child is there.
components readonly string[] | null The component types authors can use (space-separated tags in the attribute); null: every registered type. Others stay in the document, reported as unknown elements.
featured readonly string[] | null The toolbar's featured inserts, as buttons before "More" (space-separated in the attribute): component tags, tag:template for a named starter, and text, picture, page-break. Null: the list defineEditor got.
hintPosition HintPosition Where the preview's player puts a question's hint (hint-position), as on <astl-player>: row, in its help row after its Check (the default), or top, at the top of the question; another value is row. Set it as your students' player has it. A change applies at once.
locale string | null UI locale (en, pl); default: the lang attribute, else the browser languages, else en.
pageActions | readonly PageAction[] | null The buttons of each page's head on the TipTap surface, in order (space-separated in the attribute): add-title, check, join, delete; one not listed is not drawn, and a change redraws the heads at once. Null: the list defineEditor got. The adapter's addPage, mergePage, removePage and setPageCheck stay for a host's own controls.
pageNav PageNav How the preview's player shows a view of several pages (page-nav), as on <astl-player>: bar (the default) or contents, a table of contents. Set it as your students' player has it. A change applies at once.
panels readonly string[] | null The side column's panels, in order (space-separated in the attribute): issues and inspector. Null: both, issues first. Empty: no side column, the surface takes the width; a host then shows its own <astl-inspector> or <astl-issues>, wired with authoring and adapter once the editor is ready.
previewPolicy AttemptPolicy | null The policy the preview plays under: the one the host's students get, when it offers less than practice (no hints, no check of one interaction). Null: PRACTICE_POLICY. A change plays a shown preview again.
theme ThemeSetting | null light, dark, hc or auto (the system's light or dark), passed on as data-theme.
toolbarLayout ToolbarLayout | null The toolbar's items and their order, for this editor, in place of the toolbarLayout of defineEditor: groups of item names (TOOLBAR_ITEMS), a rule between groups; an item not named is not drawn. Null: the registered layout.
view string What the editor shows: visual (default) the surface; source the document's HTML in a text area, which leaving applies (with errors the editor stays there and lists them, so no text is lost); or the name of one of views. The toolbar's view switch sets it; each change fires astl-editor-view (bubbles, composed; detail.view).
views | readonly EditorHostView[] | null The host's views, after "Visual" and "HTML" in the view switch: { name, label } each (the attribute: a JSON list). One shows the host's slot="view-<name>" children in place of the editor. Null: the list defineEditor got.
get authoring(): Authoring;

The kit's logic, built from the registrations, the UI locale and components.

Authoring

get ready(): Promise<void>;

Resolves when the editor is first ready: its surface loaded (or the host's adapter set) and the value in place, so adapter, authoring and value are usable. Each time an editor becomes ready (again after a swap or a reconnect, with a new adapter), astl-editor-ready fires (bubbles, composed).

Promise<void>

get toolbar(): AstlToolbar | null;

The toolbar (<astl-toolbar>, part="toolbar") once the editor has rendered, else null: for its box, its popupOpen and its openMenu and openStyle.

AstlToolbar | null

get value(): string;

The source HTML (<astl-doc>): the adapter's, or a value waiting for it, or an empty document.

string

set value(source): void;
Parameter Type
source string

void

preview(): Promise<void>;

Compiles the current value and plays it in the preview, as the preview's own button does. Resolves when it plays, or shows why it cannot.

Promise<void>

The same option names, types and meanings as createEngine and definePlayer; the editor makes its own secret.

Property Modifier Type Description
catalogs? readonly readonly MessageCatalog[] Extra or replacement message catalogs (e.g. more locales) for describe.
components readonly readonly ComponentDefinition[] -
editors readonly readonly EditorDescriptor[] Insert menu and inspector entries: one per type authors can add.
elements readonly readonly ElementEntry[] Player elements for the preview, eager or lazy.
featured? readonly readonly string[] The toolbar's featured inserts, as buttons before "Elements": component tags, tag:template for a named starter, and text, picture, page-break. A later call's list replaces it; an element's featured overrides it. Default: none.
fonts? readonly readonly EditorFont[] The fonts the toolbar and the style form offer, in order: a name and a CSS stack the style allow-list keeps (any other throws). A later call's list replaces it. Default: DEFAULT_FONTS, stacks every system has.
groundColors? readonly GroundColors The colours a page shows text on (hex), for the warning STYLE_LOW_CONTRAST: a colour declared in a style is compared with these where nothing else is declared around it. Without them, only colours both declared are compared.
menuMessages? readonly () => Promise<readonly MessageCatalog[]> Catalogs only the insert menus show (their one-line descriptions), loaded when a menu first opens; @astl/astrolabe passes the built-in ones. Default: none (the menus show the names alone).
pageActions? readonly readonly PageAction[] The buttons of each page's head on the TipTap surface, in order: add-title, check, join, delete; one not listed is not drawn. A later call's list replaces it; an element's pageActions overrides it. Default: PAGE_ACTIONS, all four.
pickPicture? readonly PickPicture Opens the host's own picture library and gives the chosen picture (its address must pass urlPolicy), or null: the picture dialog and picture fields offer it beside the upload. The picture dialog closes while the library is open, keeping what the author typed, so a modal of the host's own takes the pointer and the keys.
profile? readonly Partial<NormalisationProfile> Overrides of the default text comparison profile.
registry? readonly CustomElementRegistry Default: the global customElements.
slotKinds? readonly readonly SlotKind<JsonObject>[] Added to the built-in slot kinds (text, number, choice, flag). Same kind twice = error.
styles? readonly readonly EditorStylePreset[] The ready styles the style menu and the style form offer, in order; []: none. A name isStyleName refuses, a declaration the style allow-list refuses or a name given twice throws. A later call's list replaces it. Default: DEFAULT_STYLES.
styleTemplates? readonly readonly StyleTemplate[] Style templates the hosts' players register, so style-template values can be checked: a name that is not registered, or not allowed at its scope or for its tag, gives the warning STYLE_TEMPLATE_UNKNOWN (the attribute stays in the view). Same name twice = error.
toolbarLayout? readonly ToolbarLayout The toolbar's items and their order: groups of item names (TOOLBAR_ITEMS), a rule between groups; an item not named is not drawn. A later call's layout replaces it; an element's toolbarLayout overrides it. Default: DEFAULT_TOOLBAR_LAYOUT.
uploadAsset? readonly UploadAsset Stores a picture file and returns its address (it must pass urlPolicy): the picture dialog, pasted and dropped pictures and picture fields use it. Without it, pictures are added by address only (or from pickPicture). Reject with UploadRefused to tell the author why.
urlPolicy? readonly UrlPolicy Which URLs stay in sources and views (UrlPolicy). Default isSafeUrl.
views? readonly readonly EditorHostView[] The host's views, after "Visual" and "HTML" in the view switch: each shows the host's content in the slot view-<name> in place of the editor. A later call's list replaces it; an element's views overrides it. Default: none.

A host view of <astl-editor>: its name (lower-case letters, digits and dashes) and its label in the switch.

Property Modifier Type
label readonly string
name readonly string
type PageAction = "add-title" | "check" | "join" | "delete";

A button of a page's head on the TipTap surface, for pageActions.

const PAGE_ACTIONS: readonly PageAction[];

Every button of a page's head, in their default order: "Add title" (with "Remove title" beside a page's title), "Check this page", "Join with page N" and "Delete page".

function defineEditor(options): void;

Registers components, editor descriptors, preview elements and looks for every <astl-editor>, and defines <astl-editor> and the kit elements (nothing is defined on import). A second call adds to the first; a tag or a look name already registered by another object throws, as two copies would otherwise mix silently.

Parameter Type
options DefineEditorOptions

void