Editor
<astl-editor> is a ready exercise editor: the authoring kit (toolbar, inspector,
issues list, preview) around an editing surface. The surface is TipTap by default. Any other editor plugs in
through an EditorAdapter and a slot="surface" child, and then TipTap is never loaded.
import { defineEditor } from '@astl/astrolabe/editor';
defineEditor(); // every built-in component, editor descriptor, preview element and look<astl-editor locale="pl" components="astl-gap astl-choice"></astl-editor> <!-- TipTap, restricted --><astl-editor><textarea slot="surface"></textarea></astl-editor> <!-- another editor -->@astl/astrolabe/editor:defineEditor(options?)with every built-in as default,AstlEditor,createAuthoring(the kit's logic without an element, which imports no DOM: validate, outline and describe a draft on a server or in a test),createTextareaAdapter,tokensCss,DEFAULT_FEATURED(empty),TOOLBAR_ITEMSandDEFAULT_TOOLBAR_LAYOUT(the toolbar's layout),PAGE_ACTIONS(pages), the built-in lists (builtInDefinitions,builtInEditors,builtInElements,builtInStyleTemplates) and@astl/core.astrolabe-editor.js: the script-tag bundle of@astl/astrolabe/editor(indist/cdn/); it callsdefineEditor()on load and exports the same.@astl/editor-tiptap:defineEditor(options)without defaults (components,editorsandelementsare required),AstlEditorandPAGE_ACTIONS, for lean installs.@astl/editor-tiptap/tiptap:astrolabeExtensions,createTiptapAdapterandPAGE_ACTIONS, for your own TipTap editor; the only entry that imports TipTap.
None of the first three imports TipTap: <astl-editor> imports its surface, with TipTap, as a chunk of its own when it
creates it.
defineEditor
Section titled “defineEditor”defineEditor(options) registers what every <astl-editor> offers and defines <astl-editor> with the kit
elements. Nothing is defined on import. A second call adds to the first; a tag, a look or a slot kind already
registered by another object throws, as two copies would otherwise mix silently.
| Option | Type and meaning, and the default in @astl/astrolabe/editor |
|---|---|
components |
ComponentDefinition[]: the types documents may contain, as for createEngine. Default: builtInDefinitions |
editors |
EditorDescriptor[]: toolbar, insert menu and inspector entries, one per type authors can add. Default: the builtInEditors of the components types |
elements |
ElementEntry[]: player elements for the preview, eager or lazy, as for definePlayer. Default: the builtInElements (lazy) of the components types |
styleTemplates |
StyleTemplate[]: looks the inspector offers and the preview renders; []: only the default look. Default: builtInStyleTemplates (playful, notebook) |
catalogs |
MessageCatalog[]: more or overriding messages, whose keys win; English and Polish are always there. Default: none |
menuMessages |
() => Promise<MessageCatalog[]>: the insert menus' one-line descriptions, loaded when a menu first opens, so the editor's first load goes without them. Default: the built-ins' (builtInMenuMessages of @astl/components/menu-messages); without the umbrella none, and the menus show names only |
views |
{ name, label }[]: views of the host's own, after "Visual" and "HTML". Default: none |
slotKinds, profile, urlPolicy |
as for createEngine. Defaults: none, DEFAULT_PROFILE, isSafeUrl |
uploadAsset |
(file, { signal }) => Promise<{ src, width?, height?, alt? }>: your upload, for pictures (below). Its address must pass urlPolicy. Reject with UploadRefused to tell the author why. Default: none, so pictures are added by address only (or from pickPicture) |
pickPicture |
({ signal }) => Promise<{ src, width?, height?, alt? } | null>: your own picture library, for pictures (below); null when the author closes it without one. Its address must pass urlPolicy. Default: none |
fonts |
{ name, stack }[]: the fonts the toolbar and the style form offer, by name, with a CSS stack the allow-list takes. A stack it refuses throws. Default: DEFAULT_FONTS, five system stacks (Arial, Verdana, Georgia, Times New Roman, Courier New) |
styles |
{ name, style, label?, text? }[] (EditorStylePreset): the ready styles the style menu and the style form offer, in order; []: none. A name the format refuses, a declaration the allow-list refuses or a name given twice throws. Default: DEFAULT_STYLES, eight styles (below) |
featured |
string[]: the toolbar's inserts shown as buttons, in order, before "Elements": component tags, tag:template for a named starter, and text, picture, page-break. Unknown names are left out. Default: DEFAULT_FEATURED, empty (every insert is in "Elements" and "Templates") |
toolbarLayout |
ToolbarLayout: the toolbar's items and their order, as groups of item names (TOOLBAR_ITEMS), a rule between groups; an item not named is not drawn. Default: DEFAULT_TOOLBAR_LAYOUT, the toolbar as it is below |
pageActions |
PageAction[]: the buttons of each page's head, in order: add-title, check, join, delete; one not listed is not drawn. Default: PAGE_ACTIONS, all four in this order |
registry |
CustomElementRegistry: where the elements are defined. Default: the global customElements |
An option replaces its default and is never merged with it. Extend a list with the built-ins spread first, for example a component of your own:
import { builtInDefinitions, builtInEditors, builtInElements, defineEditor } from '@astl/astrolabe/editor';
defineEditor({ components: [...builtInDefinitions, yesNoDefinition], editors: [...builtInEditors, yesNoEditor], elements: [...builtInElements, yesNoElement],});To let authors use fewer types, set the components attribute: the other types stay registered, so pasted content
of those types is kept and reported. To register fewer, pass fewer components: the default editors and elements
follow them. A list you pass still replaces its default, and an editor descriptor without its component throws.
const tags = ['astl-gap', 'astl-choice'];defineEditor({ components: builtInDefinitions.filter((d) => tags.includes(d.manifest.tag)) });There is no secret: the preview compiles in the browser with a random secret and salt, so preview ids never match
published ones.
Attributes and properties
Section titled “Attributes and properties”| Name | Values | Default | Meaning |
|---|---|---|---|
locale (attribute, property) |
en, pl |
the editor's lang, else the browser languages, else en |
UI locale of the kit and the surface; also the lang of a new document |
components (attribute, property) |
space-separated tags, or string[] | null |
null: every registered type |
the types of the toolbar, the inspector, validation and the preview; other types stay in the document and show ELEMENT_UNKNOWN |
featured (attribute, property) |
space-separated names, or string[] | null |
null |
the toolbar's inserts as buttons, for this editor, in place of the featured list of defineEditor; null keeps that list |
toolbarLayout (property) |
ToolbarLayout | null |
null |
the toolbar's items and their order, for this editor, in place of the toolbarLayout of defineEditor; null keeps that layout; a change applies at once (its layout) |
page-actions (attribute; property pageActions) |
space-separated add-title, check, join, delete, or PageAction[] | null |
null |
the buttons of each page's head, in order, for this editor, in place of the pageActions of defineEditor; null keeps that list; a change redraws the heads at once (pages) |
view (attribute, property) |
visual, source, or a host view's name |
visual |
what the editor shows: the text, its HTML, or a host's view (views); an unknown name shows the text, and so does source on a surface that edits the source as text |
views (attribute, property) |
a list of { name, label }, as JSON in the attribute; or null |
null |
the host's views, for this editor, in place of the views of defineEditor; null keeps those |
panels (attribute, property) |
space-separated issues, inspector, or string[] | null |
null: issues, then inspector |
the side column's panels, in order; empty: no side column, the surface takes the width (your own layout) |
theme (attribute, property) |
light, dark, hc, auto |
auto |
written to data-theme and passed to the kit elements and the preview |
hint-position (attribute; property hintPosition) |
row, top |
row |
where the preview's player puts a question's hint, as hint-position on <astl-player> (another value is row): set it as your students' player has it; a change applies at once |
page-nav (attribute; property pageNav) |
bar, contents |
bar |
how the preview's player shows a view of several pages, as page-nav on <astl-player> (another value is bar): set it as your students' player has it; a change applies at once |
previewPolicy (property) |
AttemptPolicy | null |
null: PRACTICE_POLICY |
the policy the preview plays and grades under: the one your students get, when it offers less than practice (no hints, no check of one interaction); a change plays a shown preview again |
value (property) |
source HTML (<astl-doc>) |
an empty <astl-doc> in the UI locale's lang |
reads adapter.getSource(), writes adapter.setSource(); kept until there is an adapter |
adapter (property) |
EditorAdapter | null |
TipTap, on a surface the editor creates | setting another adapter swaps the editor; null brings the TipTap surface back, with its document, unless a slot="surface" child is there |
authoring (read-only property) |
Authoring |
the kit's logic for these registrations, locale and components: validate, describe, outline, preview and more |
|
ready (read-only property) |
Promise<void> |
resolves when the editor is first ready: its surface loaded (or your adapter set) and the value in place, so adapter, authoring and value are usable |
|
toolbar (read-only property) |
AstlToolbar | null |
the toolbar (part="toolbar") once the editor has rendered: its box, popupOpen (Escape), openMenu(menu) and openStyle(target) |
|
--astl-editor-toolbar-block-size (custom property) |
a length in px | the toolbar's block size, which the editor keeps on itself and updates when the toolbar wraps (your own layout) | |
preview() (method) |
Promise<void> |
compiles the value and plays it in the preview, as the preview's own button does; resolves when it plays or shows why it cannot | |
surface (slot) |
your editor's elements | the TipTap surface | with an adapter set (also before defineEditor runs) or a slot="surface" child when the editor first renders, TipTap is never loaded |
toolbar-start, toolbar-end (slots) |
your elements | none | at the start and at the end of the toolbar's bar, wrapping with its groups, each with a tab stop of its own (your elements in the toolbar) |
astl-editor-change (event) |
no detail | after every change of the document, the author's or value; bubbles and is composed |
|
astl-editor-ready (event) |
no detail | each time an editor becomes ready: first, and again with a new adapter (a swap, a reconnect); bubbles and is composed |
|
view-{name} (slot) |
a host view's elements | shown in the surface's place while view is {name} |
|
start (slot) |
your elements | no column | a column before the surface, in the work row (your own layout); there only while the slot has elements |
end (slot) |
your elements | no column | a column after the surface and after the side column, if there is one; there only while the slot has elements |
astl-editor-view (event) |
detail: { view } |
after each change of view, the author's or the host's; bubbles and is composed |
The TipTap schema keeps every registered type, whatever components says, so pasted content is never dropped. To
check a source as the editor does: editor.authoring.validate(editor.value).
Parts: work (the row of the columns), start and end (the host's columns), surface, toolbar (with
toolbar-bar, toolbar-button, toolbar-button-<name> for each button by its name (the buttons' parts),
toolbar-icon-button for the buttons that are an icon alone, toolbar-views for the
view switch and toolbar-view for each of its options, toolbar-separator for the rule between groups,
toolbar-icon, insert and insert-menu inside it), status-line, source, side, inspector (with
inspector-header, inspector-id, inspector-actions, inspector-issue, inspector-field and inspector-label
inside it: the inspector, and its help for students as inspector-help, inspector-help-toggle,
inspector-help-summary, inspector-help-body, inspector-help-add, inspector-help-move and
inspector-help-remove: Help for students, and inspector-check-targets and
inspector-checked-by: Check buttons), issues and preview (with its player's help parts
preview-help, preview-check, preview-check-summary, preview-help-actions, preview-check-button, preview-hint-offer, preview-hint-button, preview-hint-cost, preview-hints, preview-help-feedback, preview-help-why, preview-help-problem and preview-help-top: Help rows). The insert menus have no part of their own:
they are "Elements" and "Templates" in the toolbar (insert-menu). Tokens set on <astl-editor> reach the kit elements, the preview player and the surface; see
Looks. The surface has hooks of its own: Theming the
surface.
The kit never publishes. When the author saves, take editor.value, validate it (editor.authoring.validate) and
store it; a source with zero errors compiles, warnings are advice.
A textarea instead of TipTap
Section titled “A textarea instead of TipTap”Put the textarea (and its label) in slot="surface" and set adapter to createTextareaAdapter, which edits the
source as text and keeps your formatting:
<astl-editor> <label slot="surface" for="source">Source (HTML)</label> <textarea slot="surface" id="source"></textarea></astl-editor>import { createTextareaAdapter, defineEditor } from '@astl/astrolabe/editor';
defineEditor();const editor = document.querySelector('astl-editor');editor.adapter = createTextareaAdapter(editor.querySelector('textarea'));Until the adapter is set, the kit waits: its buttons are disabled and the issues list is empty. The toolbar shows what
the adapter can do: the textarea adapter has no formats, history or blocks, so it gets the featured inserts and the
insert menus only, and the inserts put the snippet at the caret. The textarea is the HTML already (editsSource), so
the editor offers no "HTML" view of it: no view switch, unless you add views. It runs live on the
authoring kit example page (examples/editor-textarea).
Your own editor
Section titled “Your own editor”Any editor works the same way: its element in slot="surface", and an EditorAdapter over it in adapter (source
in and out, one element by id, the selection, change events). Its optional capabilities turn on more of the toolbar:
format and formatState the format buttons, undo and redo the history buttons, wrap the types' commands,
style the style controls and the layouts. How to write one for CKEditor, Lexical or ProseMirror:
Any WYSIWYG editor.
The TipTap surface
Section titled “The TipTap surface”The surface is a TipTap editor (StarterKit restricted to the content format) in the editor's light DOM, slotted into
surface: ProseMirror selection is unreliable inside shadow roots. It is imported on demand, as its own chunk; while
it loads, the surface says "Loading the editor…" in a status message, and if the chunk cannot be loaded, "The editor
could not be loaded. Reload the page to try again." while the kit stays disabled. Its nodes come from the manifests:
inline types are atoms shown as chips, blocks with rich children are framed with their children editable, other
blocks are atoms. A chip shows its answer: an icon, the answer (a gap's, a select's correct option, a drop's word)
and "+2" when two more answers count; without one it says "No answer" with a warning icon and a dashed border, not by
colour alone. Its title names the type and the answer ("Gap: grey"). TipTap adds no <style> element: the surface stylesheet is adopted, so the editor works under
the strict policy of the security checklist.
- An option, a statement or any child with a flag (a choice's
correct) has a marker before its text: a toggle button named by the flag and the text ("Correct answers: an owl", pressed when set). Space, Enter or a click sets or clears it, one undo step. "Add option" under the last child adds an empty one with the cursor in it; a block without its prompt has "Add prompt" there too, which puts one at the block's start. In a block whose children are marked words in its text (Select words), "Add option" ends its last line with a new marked word ("word", a fresh id), selected: what the author types replaces it and stays the word, one undo step with the add. - Enter in a child adds a sibling: another option after an option, the first option after the prompt. Nothing of
the answer is copied (an option's
correct), and each child keeps a local id of its own: a new or pasted copy gets<tag>-<n>, for exampleoption-1. A child loaded without an id gets one too and keeps its answer. - Backspace or Delete in an empty prompt takes it away. Ctrl/Cmd+A in a prompt or an option selects its text; a second press selects the whole exercise.
- A pasted or dropped copy of a component or a page whose id another one has gets a fresh id, as the insert menu
makes them (
gap-2), and keeps everything else, its answer too. The ids inside it (a choice's option ids) are local to it and stay. Cut and paste is a move: the id stays. <astl-doc>keeps its attributes as written; rich text keepslanganddir, never other attributes.
The toolbar
Section titled “The toolbar”The toolbar (<astl-toolbar>) spans the editor, above the status line, the text and the side column. By default, in
order: the style menu (paragraph, heading, subheading, your own styles); font and size; bold, italic, underline, link;
text colour and highlight; alignment and spacing; the bulleted and numbered lists and clear formatting; the featured
inserts as buttons, "Elements" and "Templates"; the types' commands on the selection ("Mark word"); the view switch; undo
and redo. A host lays it out with toolbarLayout. Its groups wrap into rows when they do not fit in one
(at 624 px, with 44 px targets, they take three to five), so every button is in view. Under 30rem (a phone) the formats,
from the style menu to clear formatting, are one row that scrolls sideways, with a shade at an edge where more buttons
lie; under it the inserts, the types' commands, the view switch and undo and redo wrap, so none of them is ever out of
view.
-
"Elements" opens a popover with every component, "Picture", "Badge", the help for students, "Check button" and "Page break"; "Templates" one with every starter; "Layout" (when the adapter has
style) one with the layouts, "Frame", "Task", "Horizontal line" and "Table" (a picker beside the list, in its place on a phone). Each entry has its icon, its name and a line on what it does; the lines load when a menu first opens (menuMessages). Both search as you type (any case, accents ignored); Enter in the search inserts the first match, the arrow keys move along the entries. -
Every popup opens under its button and stays inside the viewport, the picture dialog too, also on a page that enlarges its text with
zoom: no wider or taller than the viewport (it scrolls inside), moved along to fit, and above its button where it fits only there. -
It is one tab stop: the arrow keys, Home and End move along it (the view switch included), Tab goes on to the text. Up or Down on a button with a popup (the style menu, font, size, the colours, alignment, spacing) opens it.
-
A press never moves the cursor: a pointer press leaves the focus in the text, and a key press gives it back there, the selection kept.
-
Each format button shows the state at the cursor: pressed (
aria-pressed), or unavailable (aria-disabled, dashed, still in the arrow-key order). In a component's text (an option) only the marks and text styles are available; with a component selected, none of them, and the style menu leads to its form. -
Link asks for the address in a small dialog. An address
urlPolicyrefuses is not applied, and the dialog says so; "Remove link" takes the link off. -
A featured gap on a selected word makes that word its answer: the word becomes the gap (
{{selection}}in its template). A featured block (a question) goes after the block with the cursor; "Text" adds an empty paragraph after it. -
The view switch is a radio group ("Visual", "HTML", then the host's views): the view on show is checked. Each of the two says what it shows in its tooltip, which is also its description for a screen reader: "Edit the exercise as formatted text", "Edit the exercise as HTML". Away from the text, the format and insert buttons are unavailable.
-
An adapter without a capability gets no button for it: no format buttons without
format, no undo and redo withoutundo.
<astl-editor featured="text astl-gap astl-choice picture"></astl-editor>Its layout
Section titled “Its layout”toolbarLayout, an option of defineEditor or the element's property (which wins; null keeps the option's), lays
the toolbar out: a list of groups, each a list of item names, in the order they show, with a rule between groups. A later
defineEditor call replaces it. A change applies at once, and the editor keeps its surface, its cursor and its undo
history.
| Name | Item |
|---|---|
style |
the style menu |
font, size |
font and size (with an adapter that has style) |
bold, italic, underline, link |
the marks and the link |
color, highlight |
text colour and highlight (style) |
align, spacing |
alignment and spacing (style) |
bulleted, numbered |
the lists |
clear |
clear formatting (style) |
featured |
the featured inserts, in their order |
elements, templates, layouts |
"Elements", "Templates" (while a type has starters) and "Layout" (style) |
wraps |
the types' commands on the selection ("Mark word") |
views |
the view switch (with two views or more) |
undo, redo |
undo and redo |
TOOLBAR_ITEMS lists the names. DEFAULT_TOOLBAR_LAYOUT is the toolbar above:
[ ['style'], ['font', 'size'], ['bold', 'italic', 'underline', 'link'], ['color', 'highlight'], ['align', 'spacing'], ['bulleted', 'numbered', 'clear'], ['featured', 'elements', 'templates', 'layouts'], ['wraps'], ['views'], ['undo', 'redo'],]- An item not named is not drawn, an unknown name is skipped, and a name given twice shows at its first place.
- The adapter's capabilities still apply: an item it cannot do is not drawn, whatever the layout says (no formats
without
format, no undo and redo withoutundo), and a group left with nothing goes, with its rule. - The view switch is a group of its own: named in a group with other items, it parts that group there, with no rule after it.
- Undo and redo, as the last group, go to the end of their row; anywhere else they stay where they are.
- The toolbar stays one tab stop, and the arrow keys, Home and End follow the order on show.
- Under 30rem each run of groups of formats alone (
styletoclear) is one row that scrolls sideways, and every other group wraps, button by button, so none of its buttons is ever out of view; so does a group that mixes formats with other items. All of it in the layout's order.
import { DEFAULT_TOOLBAR_LAYOUT, defineEditor } from '@astl/astrolabe/editor';
// Undo and redo first, then the default without the colours and without "Templates" (a group left empty goes).const hidden = ['undo', 'redo', 'color', 'highlight', 'templates'];defineEditor({ toolbarLayout: [['undo', 'redo'], ...DEFAULT_TOOLBAR_LAYOUT.map((group) => group.filter((name) => !hidden.includes(name)))],});The buttons' parts
Section titled “The buttons' parts”Each button is a part of its own besides button: button-<name>, its item's name (button-bold, button-elements,
button-undo). Items of several buttons name each one:
- a featured insert:
button-insert-<name>, its featured name with a starter's:as_:button-insert-astl-gap,button-insert-astl-choice_multiple-choice,button-insert-text,button-insert-picture,button-insert-page-break; - a type's command:
button-wrap-<tag>(button-wrap-astl-mark-words); - a view:
button-view-<name>(button-view-visual,button-view-source, a host view's name).
Any other character a CSS name cannot hold becomes _ too. <astl-editor> exports each as toolbar-button-<name>:
astl-editor::part(toolbar-button-elements) { border-color: var(--astl-accent);}Your elements in the toolbar
Section titled “Your elements in the toolbar”Children of <astl-editor> with slot="toolbar-start" or slot="toolbar-end" show at the start or at the end of the
toolbar's bar, in its band (toolbar-bar), and wrap with its groups. Under 30rem they wrap with the run of actions
beside them (by default the end, after undo and redo), and beside a row of formats take a row of their own (by default
the start, above the formats). A slot without elements takes no room. They are your controls in the toolbar (inside its
toolbar role): each keeps a tab stop of its own, before and after the toolbar's one, and the arrow keys pass them by.
A press on one is yours and takes the focus, where the toolbar's own buttons leave it in the text. Their looks are
yours too. <astl-toolbar> has the same slots, named start and end.
<astl-editor> <button slot="toolbar-end" type="button">Save</button></astl-editor>Escape
Section titled “Escape”Escape closes the toolbar's open popup: from inside it, and the focus goes back to its button, or from anywhere else in
the editor, as the style panel stays open while the focus is elsewhere. That Escape stops inside the editor, so a keydown
listener on <astl-editor> or above it hears only the Escapes no popup used; defaultPrevented cannot tell it, as
ProseMirror cancels every Escape in the text. The picture dialog does the same. editor.toolbar.popupOpen says whether
one of the toolbar's popups is open, for code that runs before it (a listener in the capture phase).
editor.addEventListener('keydown', (event) => { if (event.key === 'Escape') closeMyCard(); // never an Escape that closed a popup of the toolbar});Blocks
Section titled “Blocks”Each page is one flowing text, as in a word processor. A block component directly on the page (a closed question, a word bank) is framed; the content between two of them (paragraphs, headings, lists, pictures, with the gaps in their text) runs unframed. The content format has no blocks: they are a way to show and move a page's content, and the source stays as it is.
- A frame has a label tab at its top start: the type's icon, its name in bold and a summary, how many items it holds of the kinds it repeats (options, words, cards) and its points: "Closed question · 4 items · 1 pt" ("4 elementy · 1 pkt" in Polish). Never an id.
- The frame with the cursor is marked: its border in the accent colour, its tab filled. In the light DOM it carries
the attribute
data-astl-current(and the classastl-frame-current), on that one frame: a host finds it witheditor.querySelector('[data-astl-current]')to draw a line from it to its own panel. With the cursor in a layout's text and in no frame there, or the layout or one of its columns selected whole, the layout carries it instead (with the classastl-layout-current): the cases where the style targets list the layout before any other element. So does a frame (astl-box, with the classastl-box-current) with the cursor in its title, its tag or its own text, in no exercise, figure, layout, task or table there, or selected whole, a task (astl-task, with the classastl-task-current) with the cursor in its own text, and a table (its box, with the classastl-table-current) with the cursor in its caption or a cell's own text. In other text there is none. At most one element has it. - A frame (
astl-box), a task (astl-task) and a sub-task are no blocks: the blocks they hold are on the page's list, in reading order, their heads aside. A move takes a block next to one into it (its last place going up, its first going down), and its first or last block out of it; one left without content keeps an empty line. - A frame whose component has errors or warnings is dashed, in the colour of its worst issue, and says them under its tab as the issues list does, without the page ("Question 2 has no correct answer."), the severity word first for a screen reader. Nothing in the notes takes the focus. The frames follow a moment after each change.
- The inspector moves and deletes the component with the cursor.
A host reads the blocks from the outline and follows the cursor to show the page being edited:
const { pages } = editor.authoring.outline(editor.value);// pages[0].blocks: [{ kind: 'text', label: 'Gap', points: 1, errors: 0, ... }, { kind: 'component', tag: 'astl-choice', ... }]const adapter = editor.adapter;adapter?.onCursorChange?.(() => { const at = adapter.getCursor?.(); // { page: 'animals', index: 1 }, or null});adapter?.moveBlock?.({ page: 'animals', index: 1 }, 'up'); // false at the page's startadapter?.removeBlock?.({ page: 'animals', index: 0 });The inspector
Section titled “The inspector”With the cursor in a component, the inspector's header (part="header", also part="head"; <astl-editor> exports it
as inspector-header, and the other parts below as inspector-id, inspector-actions, inspector-issue,
inspector-field and inspector-label) shows its icon (the
descriptor's), its type as the heading and its id in a small monospace chip (part="id") when it has one. For a
block component the header goes on with icon buttons, in part="actions": "Move up", "Move down" and "Delete". Their
texts are their accessible names and tooltips. They act on the cursor's block through the adapter's moveBlock and
removeBlock; an adapter without one of them, or without getCursor, gets no button for it.
Under the header come the element's own issues, the sentences its frame shows, each a banner (part="issue") in its
severity's colour with an icon and the severity word for a screen reader: never colour alone. Below them, the form:
each field is a part="field" and its label a part="label". The form has one column; set the custom property
--astl-inspector-columns to 2 (on astl-editor::part(inspector), or on your own <astl-inspector>) and short fields (a
select, a number, a short text) take one column each, while checkbox groups, lists and fields with an upload span the
row. The per-element look is called "Element style" ("Styl elementu"), so it does not clash with a host's own "Look"
view.
astl-editor::part(inspector) { --astl-inspector-columns: 2;}- A move or a delete is one undo step (Ctrl+Z), and the editor's one live region says what happened ("Block moved up, now block 1", "Block 2 deleted"). Moving a question past text joins the text around it into one block.
- At the page's start or end, a move is unavailable (
aria-disabled, dashed) and keeps the focus; after a delete the focus goes back to the text.
Help for students
Section titled “Help for students”A graded element's card opens with "Help for students" ("Pomoc dla ucznia"), right under its head, before its fields,
loaded on first use. It is a disclosure, closed for each element until it is opened: its button (a chevron, the title,
aria-expanded) says what the element has while closed ("2 hints · explanation · feedback", or "none"). Open, it shows
the hints in order, each with its text, its cost, "Move hint 1 up", "Move hint 1 down" and "Remove hint 1" (icon
buttons, their names also their tooltips; a drag of its handle orders them too), then "Add a hint"; the explanation;
and the four feedback texts ("Correct", "Wrong", "Partly correct", "Skipped"). A hint's cost is a select: "Free", or
10%, 25% or 50% of the question's points, said in points from a compilation of the element alone ("-25%: -0.5 of 2
points"; the share alone while it does not compile); a cost the source has besides those stays as an option of its
own. "Add a hint" adds a draft: the source gets the hint with its first text (and the cost picked for it), and a draft
the focus leaves empty goes, so adding never leaves an empty hint behind (HELP_EMPTY). An empty explanation or
feedback text is none; while the element has one, "Remove the explanation" (an icon beside its label) takes it away.
The fields edit plain text: blank lines part paragraphs and a single line break stays one (text alone in a field in a
line of text), so a text edited there loses the formatting it had; one left alone keeps it, and a field whose text has
formatting says so under it before the first change. Parts: help (the section), help-toggle, help-summary,
help-body, help-add, help-move and help-remove, which <astl-editor> exports as inspector-help,
inspector-help-toggle and so on.
"Elements" has "Hint", "Explanation" and "Feedback": with the cursor in a graded element they open its card's help at a
new hint (a draft), at its explanation or at the next feedback text it lacks, focused and writing nothing yet;
elsewhere they go on the page. On the surface a question's help is not drawn: the editor shows the exercise as close
to the students' view as it can. Its frame's tab says what it has with tags after its summary ("Closed question · 3
items · 2 pts", then "2 hints", "Explanation", "Feedback"); a tag puts the cursor in the question and opens that part
of its help in the card, focused. The tags are out of the Tab order, as the frame's position line is: the card is the
keyboard's way. A tag fires astl-help-open (HELP_OPEN), which bubbles out of the editor (detail: { element, part }, part one of hints, explanation, feedback); unless a host cancels it, the editor's own inspector opens
the help (inspector.openHelp(part)). A host that shows its own <astl-inspector> cancels it, shows its card and
calls openHelp(part) on it (HELP_OPEN, HelpOpen and HelpPart come from @astl/astrolabe/editor, as
AstlInspector does). The help stays in the source as the question's children, so a copy or an undo keeps it;
no key selects it on the surface.
Help on the page (outside every question) is a compact labelled box in place, editable like the rest, with a select for
a feedback text's verdict and a cross that takes it away ("Remove the hint"); an empty box has a line that says what to
write there ("Write the hint...") and also goes with Backspace or Delete. A page's hints are free, so a hint on the page
has no cost to pick; one with a cost (a source written for 0.1) says so, with "Make it free". A hint or the explanation
on the page has "Move to question...": it lists the page's graded questions and moves the box into the chosen one,
after its help, in one undo step (into a field in a line of text as text, its paragraphs joined by line breaks); a
question with an explanation takes no second one, and says so in the list. The preview plays the
exercise under PRACTICE_POLICY: a Check for each question, hints, feedback and "Why?" as students get them. A host
whose students get less (an author turned hints off, say) sets that policy as previewPolicy, and the preview offers
what they get.
Check buttons
Section titled “Check buttons”"Elements" has "Check button" ("Przycisk Sprawdź"): one Check for several questions (a
Check element). It goes after the block with the cursor,
with a fresh id (check-1) and as its for the questions it takes there, the graded inline questions of the run of
text right above it; the source says them, so moving text later does not change what it checks. It stays selected.
- On the surface it is the compact button the player shows (
astl-check, its buttonastl-check-button: itslabel, else "Check") with a tag saying how many questions it checks (astl-check-tag: "3 questions"; with none, "No questions", dashed in the warning colour, anddata-emptyonastl-check). While it is selected, its questions have a dashed outline in the accent colour (astl-check-target), fields in the text and framed questions alike. It is a block of its own: the card moves and deletes it, and Backspace or Delete takes it away when it is selected. - Its card has its text ("Button text", empty for "Check") and "Questions it checks" (
part="field check-targets"): every graded question of its page in order, block questions too, each by its number among those of its type on the page ("Gap 2", "Closed question 1"), ticked when it checks them. A tick or an untick writes itsforin the page's order (none ticked: an emptyfor, and the warning that it has nothing to check). A question another check has is unavailable and says which ("Checked by Check button 2").authoring.inspectgives this model (check-targets,CheckTargetsFieldModel). - A question it checks says so in its card, under its head: "Checked by Check button 1" (
part="checked-by"), a button that selects the check (adapter.select(id));InspectorModel.checkedByhas it. - An automatic Check. Where two or more questions of a run of text have no Check element, the player gives them one
after the last of them; the surface shows it there, dashed (
astl-check astl-check-auto, its tag "automatic · 3 questions"), with "Make it a button" (astl-check-make), which writes a Check element for them in its place, selected, in one undo step. It is not in the source. - The outline lists each page's checks (
OutlinePage.checks:{ id, label, targets }) and automatic ones (OutlinePage.automatic, the questions of each), says which check has each question (OutlineComponent.check), and has the check as a block of its own (kind: 'check', labelled "Check button"). - For a host's own insert menu:
insertCheck(authoring, adapter)(from@astl/astrolabe/editor, or@astl/editor) does what the entry does, itsforfilled and, in the TipTap editor, selected in one undo step, and returns its HTML. Its label and line are the kit's messagesinsert.checkandinsert.check.description(authoring.t(EDITOR_NAMESPACE, 'insert.check')). It is no component, sobuiltInEditorsdoes not list it. - For a host's own card: the adapter reports a selected check as
{ id, tag: 'astl-check' }(getSelection), with no style targets, so a card that shows<astl-inspector>for the selection shows its model. The surface's classes are its parts: it lives in the light DOM, so a host's stylesheet reaches them; the button and the tag follow--astl-editor-control-size,--astl-editor-control-font-sizeand--astl-editor-control-icon-size.
The status line
Section titled “The status line”Under the toolbar, the status line (part="status-line") counts the document's elements and points from its outline,
then says "Ready to share" when it has no errors, or how many errors and warnings it has: "4 elements · 5 pts ·
Ready to share", "2 błędy · 0 ostrzeżeń". It follows a moment after each change. It is text to read, not a live
region: the editor's notice line stays its one live region.
view says what the editor shows; the toolbar's view switch sets it, and so may the host. Each change dispatches
astl-editor-view (detail: { view }).
visual(the default): the text, with the inspector and the issues.source: the document's HTML (content format 1) in a monospace text area, labelled "The exercise as HTML", laid out for reading: each page, block, layout, column, list and component on a line of its own, indented by its level, a paragraph's text with its elements on one line. The text area grows with the text where the browser supportsfield-sizing. Switching back tovisualapplies the edit as one change; only looking, or laying the text out another way, changes nothing, andvaluestays as compact as before. With errors it stays on the HTML and lists them under it, and the live region says how many: no text is lost.- A host view:
views(an option, an attribute or a property) adds{ name, label }entries after the two; withviewset to a name, the surface and the side column give way to theview-{name}slot. The umbrella has none. - A surface that edits the source as text (an adapter with
editsSource, such as the textarea's) is the HTML already: there is nosourceview, so without host views the toolbar has no switch, and beside them the surface's view is named "HTML".
<astl-editor views='[{"name":"lesson","label":"Lesson"}]'> <div slot="view-lesson">The host's own view of the exercise</div></astl-editor>Your own layout
Section titled “Your own layout”The work row, part="work", is one row from 48rem of the editor's width: the start column, the surface, the side
column, the end column. Below it the columns stack: start above the surface, end below it and the side column.
A host puts its own elements in the start and end slots (a page list, a card). A column is there only while its slot
has elements; an empty slot takes no room and leaves no gap. In another view (HTML, a host view) both are hidden, as the
side column is. Size the column by its content (width on your element) or by astl-editor::part(start).
<astl-editor panels="inspector"> <nav slot="start" style="inline-size: 13rem">The pages</nav></astl-editor>The side column and both host columns stay in view while the content scrolls, within the work row, and each scrolls on
its own when taller than the window. Two hooks, set on <astl-editor> or an element around it:
--astl-editor-sticky-top: where the sticky columns stop below the top of the window (--astl-space-4), e.g. under your own header.--astl-editor-layout-gap: the space between the toolbar, the status line, the work row and the preview (--astl-space-4);0pxmakes them bands that touch, which you then style with::part(toolbar),::part(status-line),::part(work)and::part(preview).
To keep the toolbar in view while the page scrolls, make its part sticky (it then travels the whole editor), above the
frames' tabs, and let the columns stop under it. The editor keeps the toolbar's block size on itself as
--astl-editor-toolbar-block-size (in px, updated when the toolbar wraps into more rows or fewer), so the columns stop
right under it, and your own elements in the editor read it too:
astl-editor::part(toolbar) { position: sticky; inset-block-start: 0; z-index: 2;}astl-editor { --astl-editor-sticky-top: calc(var(--astl-editor-toolbar-block-size, 0px) + var(--astl-space-2));}What the editor scrolls into view (the caret, an element or a page picked through the adapter's select) then stops
just below the toolbar, not under it: the editor reads the toolbar's sticky offset and height whenever its size
changes (one row or two). Outside the editor, read the property with
getComputedStyle(editor).getPropertyValue('--astl-editor-toolbar-block-size'), or the toolbar's box from
editor.toolbar.
panels decides the side column. With panels="" there is none, and the surface takes the width; put your own
<astl-inspector> (or <astl-issues>) where you want it, with the editor's authoring and adapter once it is
ready. It follows the cursor as the built-in one does.
<astl-editor panels=""></astl-editor><aside><astl-inspector></astl-inspector></aside>const editor = document.querySelector('astl-editor');const inspector = document.querySelector('astl-inspector');const wire = () => Object.assign(inspector, { authoring: editor.authoring, adapter: editor.adapter });editor.addEventListener('astl-editor-ready', wire); // again after a swap of the adapterawait editor.ready;wire();await editor.preview(); // the preview of the current value, as its own button doesA document is one page, or several that students see one at a time. In the TipTap surface each page has a head: its number of all ("Page 2 of 3"), a small "Add title" button, "Check this page", from the second page on a "Join with page 1" button and, while there are other pages, a "Delete page" button (named "Delete page Page 2 of 3"). The numbers follow every change, so every control has a name of its own that holds the text it shows.
pageActions (an option of defineEditor, or the element's property or page-actions attribute, which wins) lists
the head's buttons, in order: add-title ("Add title", with "Remove title" beside a page's title), check, join and
delete. The default, PAGE_ACTIONS, is all four in this order. A button not listed is not drawn, while a page's
title stays in its field and the adapter's addPage, mergePage, removePage and setPageCheck stay for your own
controls, such as a page list beside the text. A change applies at once: the heads are drawn again, and the surface keeps
its cursor and its undo history. With your own TipTap editor, pass it to
astrolabeExtensions.
<astl-editor page-actions="check"></astl-editor> <!-- pages added, joined and deleted from the host's own list -->Each button has data-action: add-title, check, join, delete and remove-title. The head lives in the light
DOM, and its classes are the surface's stable hooks for a host's stylesheet: astl-page-head (the head),
astl-page-number, astl-page-add-title, astl-page-check, astl-page-join, astl-page-delete,
astl-page-field (the title's row), astl-page-label (the title field) and astl-page-remove-title.
"Check this page" is pressed (aria-pressed, filled, with a tick) while the page has check: in practice students
then get a Check of the page, which checks all its questions at once and shows the page's help. A click turns it on or
off in one undo step and says so on the notice line ("Page 2 has a Check of its own now."). A page with help and
without it has the warning PAGE_HELP_UNCHECKED, which this click ends.
A title is optional: a page without a label shows no title field, and the player gives it a generated heading nobody
sees (the player). "Add title" shows the field, with the placeholder "Page title"
and the name "Title of page 2" (no visible label), and puts the cursor in it. Left empty, the field goes again when it
loses the focus, and the document is not touched. A page with a title shows the field with a "Remove title" button
beside it: it removes the label in one undo step, hides the field, moves the focus to "Add title" and says "Removed the
title of page 2" on the notice line.
- Ctrl+Enter (Cmd+Enter on macOS), or "Page break" in the toolbar's "Elements", breaks the page at the
cursor. A paragraph or a heading splits there (at its start the page breaks before it, at its end after it); in a
component or any other block, the page breaks after that block, which stays whole. The new page gets a fresh id
(
page-<n>, which no page or component uses), no title and thelanganddirof its page, and the cursor goes to its first line. A document without pages becomes two. Shift+Enter is still a line break. - Backspace at the very start of a page, Delete at the very end of the page before it, or the page's join button
joins it to the page before: its content follows that page's, which keeps its id, title,
langanddir. - The page's "Delete page" button deletes the page and everything on it; the cursor goes to the start of the page before, or of the next one when it was the first.
- Each is one undo step, and the status message says what happened ("Page 2 added", "Page 2 joined with page 1",
"Deleted page 2") until the next edit. A page left with nothing a student would see (empty paragraphs, line
breaks) gets the warning
PAGE_EMPTYin the issues list, which names the page by its number and title ("Page 3 (“Animals”) is empty"). - A component that needs another one, such as a gap for a word and its word bank, names one on its own page, or the insert adds one at the end of that page.
The host drives pages through the adapter: the TipTap adapter has the five methods, the textarea adapter all but
removePage; all are optional in EditorAdapter.
const { pages } = editor.authoring.outline(editor.value); // [{ id, label, check, errors, warnings, points, components, blocks }]const adapter = editor.adapter; // TipTap's once its surface is open, or the one you setadapter?.select('intro'); // the cursor to the start of the page "intro"adapter?.splitPage?.(); // a page break at the cursor: the new page's id, or null when there is no page thereadapter?.addPage?.('intro'); // an empty page after the page "intro" (else after the last one): its idadapter?.mergePage?.('page-2'); // joins it to the page before: false for the first page or an unknown idadapter?.removePage?.('page-2'); // deletes it and everything on it: false for the only page or an unknown idadapter?.setPageCheck?.(true, 'intro'); // "Check this page" on: one undo step; false when it was on alreadyadapter?.setPageCheck?.(false); // off on every page (a document without pages becomes a page when set on)Pictures
Section titled “Pictures”"Picture" in the toolbar's "Elements" (or a featured button) asks for a picture in a dialog: a file, which uploadAsset stores,
a picture from your own library (pickPicture, below), or its address (the only way without either, as the dialog
says); then the alt text, required unless the picture is decorative (alt=""), and an optional caption, which makes it
a <figure>. The address must pass urlPolicy, an uploaded or chosen one too, and the surface shows only pictures
whose address passes.
import { defineEditor, UploadRefused } from '@astl/astrolabe/editor';
defineEditor({ // `signal` aborts when the author cancels or picks another file. Check type and size on your server. uploadAsset: async (file, { signal }) => { const response = await fetch('/assets', { method: 'POST', body: file, signal }); // Your own words, in the editor's language, shown as they are instead of the generic failure message. if (response.status === 413) throw new UploadRefused('This file is too large: the limit is 5 MB.'); const { url, width, height } = await response.json(); return { src: url, width, height }; },});With pickPicture, the dialog offers "Choose from the library" beside the upload (alone without one), and so do the
inspector's picture fields. The dialog closes while your library is open,
keeping what the author typed, so a modal of your own takes the pointer and the keys with no top layer to fight; it
opens again when the promise settles, with the picture's address and size and the focus on the alt text. Give the
alt text your library keeps for the picture as alt: it fills in the dialog's alt text while that is empty (never
over what the author typed, never into a decorative picture), and a picture field's element its empty alt attribute;
the author may change it there, and the document keeps its own copy. Resolve with
null when the author closes the library without a picture: nothing changes. Settle once your library has closed, so
that its own focus trap is gone: the dialog and the fields then give the focus back themselves (a picture field to its
library button). signal aborts when the editor no longer waits (it asked for another picture, or left the page):
close your library then. A rejection says the library did not open, or, with UploadRefused, says your words.
defineEditor({ // `openLibrary` is your own modal: it calls back with the chosen asset, or on close without one. pickPicture: ({ signal }) => new Promise((resolve) => { const library = openLibrary({ onChoose: ({ url, width, height, alt }) => resolve({ src: url, width, height, alt }), onClose: () => resolve(null), }); signal.addEventListener('abort', () => library.close(), { once: true }); }),});- A picture file pasted or dropped into the surface goes through the same upload and dialog, where it lands. Without
uploadAssetnothing is inserted, and a status message says why until the next edit. - To change a picture's address or alt text later, select it and press Enter (in a figure: Enter in its caption, which stays one line), or press its "Edit" button. The caption is edited in place.
- Store the file where students can load it: the player shows only pictures its own URL policy allows, and your
Content Security Policy needs the asset origin in
img-src(URLs).
Styles
Section titled “Styles”With an adapter that has style (the TipTap surface has it, a textarea does not) authors style what they write. All of
it goes through the allow-list, lands in the source as style, class and <astl-style>,
keeps the cursor and undoes in one step.
- Text. Font, size, text colour and highlight go on the selected words, one span per run. With only a cursor they
apply to what is typed next. Colours offer the theme's palette first (
var(--astl-palette-N), in its soft form for a highlight or a background), then a custom colour: the native picker and a hex field. - Blocks. Alignment and spacing go on the block at the cursor and on every block of a selection. Clear formatting takes the marks and text styles of the selection, and the style of each block it covers whole.
- The style menu. "Paragraph", "Heading", "Subheading", then "My styles", the document's named styles, then "Ready styles" (below). With text selected a named style goes on a span, with only a cursor on the block. An element carries one through these controls: another replaces it, the same one again takes it away.
- The form.
<astl-style-form>edits one element: text, background and border, spacing, size and position, its named style (with the ready styles in a group of their own), "Own CSS" and "Save as a style". "Own CSS" shows each declaration the allow-list refused and why; the source never holds them. "Save as a style" turns the element's own style into a named one, and an element's own style still wins over a named one. - The rules.
<astl-style-rules>has "Text styles" (<astl-style for>rules for paragraphs, headings, subheadings, quotes, lists, captions and pictures) and "My styles" (add, rename, edit, delete). Renaming changes the label; the name elements carry stays. Deleting removes the class everywhere, in one undo step. - Pictures, figures and exercises. Selected, a picture shows its position and width, and a corner handle. So does an
exercise (a block component) while the cursor is in it: its position line at the end of its tab row, which opens its
card, and its handle halfway down the frame edge away from the float, both clear of the tab and the content; its frame
and tab go with it. Positions (
Placement) are "In the text", "On the left", "On the right", "Centred" and "Full width", written in logical forms (float: inline-start,margin-inline-end,margin-inline: auto). The width field and the handle write the same percentage, one undo step; the field is the keyboard's way. A figure takes the position and the width, its picture fills it. On a narrow page a floated picture or exercise gets a line of its own, as in the player (under 30rem), so on a phone an exercise stacks above the text that runs beside it on a wide screen. A text block has the width alone. - Layouts. The toolbar's "Layout" lists them: two columns, three columns, wide + narrow, narrow + wide, picture
beside text (which asks for the picture first). The cursor lands in the first empty column. A layout that ends its
page gets an empty paragraph after it, to go on writing in. A layout has no row of its own on the surface, so the
page keeps the place the student sees; its columns have a thin dashed edge to click into. While the cursor is in its
text (in no exercise or figure there), its columns' edges turn solid, in the accent colour, as wide as before so
nothing moves, and it carries
data-astl-current, so a host shows the layout's settings beside the page as it does an exercise's. Its style form starts with them, open, under "Columns": "Change layout" (two, three, wide + narrow, narrow + wide: the content stays, a column that goes gives its content to the last one left), "Remove layout" (the columns go, their content stays in place, one column after another) and "Delete with content", which asks first when the columns hold anything; its style sections follow, closed. A standalone page reaches the form from the toolbar's style menu or the inspector ("Layout style"). Backspace at the start of an empty layout's first column removes it. Undo takes each back. - Frames. "Frame" in the toolbar's "Layout" puts an
astl-boxafter the block with the cursor (in the place of an empty line, and never in another frame: from inside one, after it), the cursor in its title, written in place ("Frame title" while it is empty; an empty title is not written), and an empty line under it. On the surface it is drawn as the player draws it, its icon in its title, its tag on a line of its own under it ("Tag" while empty). Enter in the title goes on in the tag or the first line; Backspace at the start of the first line goes back to the end of the title, never joining them, and at the start of an empty frame takes it away; Delete at the end of the title stays there. A block inserted with the cursor in a frame goes in it (first, from its title). While the cursor is in it, a dashed line in the accent colour goes around it and its raised title, outside it, and it carriesdata-astl-current, as a layout does. Its style form starts with its settings, open, under "Frame": "Title position" (inside, on the border, in a pill, on a tab), "Look" (outline, tinted, card), "Icon", "Colour" (a theme colour, or the accent), "Tag after the title" (a tag to write in, or taken away with its text), then "Remove frame" (the frame goes, its content stays in place, its title a heading and its tag a paragraph before it) and "Delete with content", which asks first when it holds anything; its style sections follow, closed ("Frame style" in the toolbar's style menu). A frame in a column holds no layout: one inserted there goes after the layout of the column. Undo takes each back. - Tasks. "Task" in the toolbar's "Layout" puts an
astl-taskwith a fresh id (task-<n>) after the block with the cursor (never in another task: from inside one, after it), the cursor in its instruction, written in place ("Task instruction" while it is empty; an empty instruction is not written), and an empty line under it. On the surface its number and stars stand in a gutter beside it, counted as the engine counts them (the document'stask-numbering, a task's ownnumber), its tags are chips after the instruction with their icons, and its sub-tasks are lettered with their levels. The keys are a frame's. With the cursor in its own text it is the selection (getSelectiongives the task), marked with a dashed line around it, and its card in the inspector has its number (empty: the next one), its difficulty, "One Check for the whole task", the colour of its number, its tags (a list, at most 3, the first right after the instruction) and each tag's icon. The document's card (the cursor in no element) has "Task numbers" once there is a task. Blocks move into a task and its sub-tasks and out of them, and a block inserted with the cursor in a task stays in it.insertTask(adapter)does the same for a host's menu. - Badges. "Badge" in "Elements" puts a pill holding "1" at the cursor, with a fresh id (
badge-<n>), selected, so the inspector shows its card: its text (written as it is typed), its shape, its fill and its colour (a theme colour, or the accent). On the surface a badge is drawn as the player draws it; selected, it keeps its shape and takes the selection's colours, so no ring covers the words beside it.insertBadge(adapter)does the same for a host's menu. - Horizontal lines. "Horizontal line", last in the toolbar's "Layout", puts an
<hr>after the block with the cursor (in the place of an empty line), one undo step, and the cursor at the start of the line after it, a new one when the rule ends its page or its column. On the surface a rule sits in a box a pointer can take, though its line is one pixel high; a press selects it, and its style form ("Line style": the line's colour, style and thickness, its width and the space before and after it) opens in the inspector, as a picture's does. - Tables. "Table", last in the toolbar's "Layout", shows a picker beside the list: a grid of squares to point at,
or to size with the arrow keys, its size read out as it changes ("4 columns × 3 rows"), "Header row" (ticked) and
"Header column", then a click or Enter inserts an empty table after the block with the cursor (never into a table:
from a cell, after it), the cursor in its first cell. In a toolbar narrower than 30rem (a phone) the picker takes the
list's place, with a counter for the columns and one for the rows and "Insert table". Tab goes on to the next cell
(from the caption into the first), and past the last one into a new row; Shift+Tab goes back, and from the first
cell out of the editor. While the cursor is in a table, its box carries
data-astl-currentand the cell with the cursor has a dashed line in the accent colour inside its edge. Its style form starts with its commands, open, under "Table", at that cell: rows ("Insert above", "Insert below", "Delete row"), columns ("Insert left", "Insert right", "Delete column"; a merged cell across the line grows or shrinks), "Header row" and "Header column", cells ("Merge right", "Merge down": their content joined; "Split" undoes a merge), "Title above the table" (a caption) and "Delete table", which asks first when it holds anything; a command that would change nothing there is disabled. Its style sections follow, closed ("Table" in the toolbar's style menu). A gap or another inline element goes into a cell as into a paragraph; a question (a block element) goes into the empty data cell with the cursor, and from a cell with text after the table.
Ready styles
Section titled “Ready styles”Like a word processor's built-in styles, ready styles apply with one click. Picking one writes its <astl-style> rule
into the document, labelled in the editor's language at that moment, and sets the class: one undo step takes both.
From then on it is a named style of that exercise: it is listed under "My styles", editable in <astl-style-rules>,
and no longer offered under "Ready styles". A document that already has a rule of that name keeps its own, and is not
offered the ready one. The document stays self-contained: the engine and the player see an ordinary named style.
A style of boxes (no text) goes on what the cursor is in (the block, the component, the column), words selected or
not, as a paragraph style does. A style of words (text: true) goes on the selected words, and with only a cursor on
what the cursor is in. Under "My styles" a rule with the name of a ready style of boxes keeps that way of going on;
the author's own styles go on the selected words.
DEFAULT_STYLES, in order (labels are the messages style.preset.<name>):
| Name | English | Polish | Kind | Style |
|---|---|---|---|---|
note |
Note | Uwaga | boxes | background-color: #fff4d6; border-inline-start: 4px solid #b7791f; padding: 12px 16px; border-radius: 6px |
tip |
Tip | Wskazówka | boxes | background-color: #e7f6ec; border-inline-start: 4px solid #2f855a; padding: 12px 16px; border-radius: 6px |
important |
Important | Ważne | boxes | background-color: #fdecec; border-inline-start: 4px solid #c53030; padding: 12px 16px; border-radius: 6px |
definition |
Definition | Definicja | boxes | background-color: #eef1fe; border: 1px solid #5a67d8; padding: 12px 16px; border-radius: 6px |
example |
Example | Przykład | boxes | border: 2px dashed #718096; padding: 12px 16px; border-radius: 6px |
quote |
Quote | Cytat | boxes | border-inline-start: 3px solid #a0aec0; padding-inline-start: 16px; font-style: italic; color: #4a5568 |
highlight |
Highlight | Wyróżnienie | words | background-color: #fff3a3 |
small-print |
Small print | Mały druk | words | font-size: 14px; color: #4a5568 |
Their text reads at 4.5:1 or more in the light and the dark theme. Pass your own list to replace them, or extend it:
import { DEFAULT_STYLES, defineEditor } from '@astl/astrolabe/editor';
defineEditor({ styles: [ ...DEFAULT_STYLES.filter((style) => style.name !== 'small-print'), { name: 'task', label: 'Task', style: 'border: 2px solid #2f56d9; padding: 12px 16px' }, ],});A label you give is used in every language; without one the kit's message style.preset.<name> is used (add it to
catalogs for each language), else the name. Keep padding and margin out of a style of words: on a phone the player
gives whatever has a padding its own, which would pad a word inside its sentence.
An adapter of your own takes a ready style as style.setClass(where, name, rule): the rule goes in with the class in
the same undo step, unless the document has a rule of that name (EditorStyles).
Opening the form and the rules
Section titled “Opening the form and the rules”The style menu and the inspector's style section list what the cursor is in, from the inside out (the block, the
component, the column, the layout; a picture, its figure). Choosing one, or "Manage styles" for the rules, fires
astl-style-open (STYLE_OPEN), which bubbles out of the editor. detail.target is picture, figure, block,
component, column, layout or rules.
Do nothing, and it gets a default: the toolbar shows the form or the rules in a popup (part="style-panel"), the
inspector shows the form in place. Cancel the event and show them yourself, for instance in a side card:
import { loadStyleElements, STYLE_OPEN, type StyleOpen } from '@astl/astrolabe/editor';
editor.addEventListener(STYLE_OPEN, async (event) => { event.preventDefault(); const { target } = (event as CustomEvent<StyleOpen>).detail; await loadStyleElements(); // defines both elements, outside the editor's first load const element = document.createElement(target === 'rules' ? 'astl-style-rules' : 'astl-style-form'); element.authoring = editor.authoring; element.adapter = editor.adapter; if (target !== 'rules') element.target = target; // unset: whatever the cursor is in card.replaceChildren(element);});A text block has no id, so the form follows the block at the cursor. toolbar.openStyle(target) asks as the style menu
does. <astl-style-rules> has its own "Undo", as a host's view disables the toolbar's. The
TipTap example places it in a view of its own, with the editor's authoring and adapter once it
is ready:
<astl-editor views='[{"name":"styles","label":"Styles"}]'> <astl-style-rules slot="view-styles"></astl-style-rules></astl-editor>The toolbar's popups export style-menu, style-colors and style-panel, the inspector's section inspector-style.
<astl-style-form> has the parts root, section, field and label; <astl-style-rules> has root and title.
Theming the surface
Section titled “Theming the surface”The TipTap surface follows the tokens, and has hooks of its own for a
host's design: custom properties set on <astl-editor> or an element around it. Unset, each one keeps the look given
in brackets.
astl-editor { --astl-editor-frame-current-ring: 2px; --astl-editor-option-border: var(--astl-line); --astl-editor-option-gap: var(--astl-space-2);}- The sheet, the page the author writes on:
--astl-editor-sheet-radiusits corners (--astl-radius-l),--astl-editor-sheet-paddingits padding (--astl-space-4),--astl-editor-sheet-borderits border colour (--astl-outline) and--astl-editor-sheet-focus-ringits focus outline, anoutlinevalue (var(--astl-editor-focus-width) solid var(--astl-focus)). A host with a focus cue of its own, such as a ring on the selected frame, may make the outline quieter; the focus must stay visible. - The editor's focus ring, on all its controls (the toolbar and its menus, the card's fields and buttons, the sheet
and the authoring controls on it):
--astl-editor-focus-widthits width (2px) and--astl-editor-focus-offsethow far out of the control it is drawn (1px), in--astl-focus. It never reaches a field or a text beside it: the card's fields are--astl-space-1apart. The students' ring (--astl-focus-width,--astl-focus-offset) is the player's and stays as it is. - The frames:
--astl-editor-frame-radiustheir corners but the one under the tab (--astl-radius-m) and--astl-editor-frame-paddingthe space inside them (--astl-space-3). - The frame with the cursor:
--astl-editor-frame-current-ringthe width of a ring in the accent colour inside its border (0px, none). - Two states for a frame, the rest and the cursor's:
--astl-editor-frame-border-widththe border width at rest (--astl-outline-width) and--astl-editor-frame-current-border-widththe width with the cursor (the rest width; the frame keeps its size, the wider border takes from the padding); at rest the tab takes--astl-editor-frame-tab-background(--astl-surface),--astl-editor-frame-tab-ink(--astl-ink-muted, its type name--astl-ink) and--astl-editor-frame-tab-borderits border colour (the frame's). With the cursor the tab stays the accent, filled, whatever these say, and a frame with issues keeps its dashed colour on frame and tab. A soft tab with no border, in the accent:--astl-editor-frame-tab-background: var(--astl-accent-soft),--astl-editor-frame-tab-ink: var(--astl-accent),--astl-editor-frame-tab-border: transparent. - The page heads: for the number
--astl-editor-page-number-font-family(--astl-font-body),--astl-editor-page-number-size(--astl-editor-kicker-size),--astl-editor-page-number-letter-spacing(normal) and--astl-editor-page-number-text-transform(none); for the title field--astl-editor-page-title-font-family(--astl-font-display),--astl-editor-page-title-size(1.3em) and--astl-editor-page-title-weight(700). --astl-editor-column-with-component: the least width of a layout's column that holds a component (20rem, or the column's whole width when less): under it the column takes the room it needs from the others, or a line of its own, so the editing chrome leaves its text whole.--astl-editor-kicker-size: the size of the frames' tabs and the pages' numbers (--astl-size-small).- The authoring controls, so that an exercise looks as students see it: on the surface the page heads' buttons
("Add title", "Check this page", "Join with page 1", "Delete page"), a page box's select and cross, the
blocks' "Add option" and "Add prompt", a frame's position line ("In the text") and a picture's buttons; in the card
(
<astl-inspector>, its help for students and picture fields) its buttons. They are small, and each is recognisable as a button at rest, without hover: an add action ("Add option", "Add title", "Add a hint", a list's "Add") has a plus and the accent colour; any other text button a 1px line in--astl-outline(3:1 at least), and "In the text", which opens the style form, the selects' chevron too; an icon alone (move, remove) only its icon. No fill at rest, a subtle fill on hover, the focus ring; a pressed "Check this page" keeps its fill and tick, an unavailable button its dashed line. A page box's select has the same 1px line, height and corners.--astl-editor-control-sizetheir height and the least width of an icon alone (1.75rem),--astl-editor-control-font-sizetheir text (0.8125rem) and--astl-editor-control-icon-sizetheir icons (0.875rem). A target never goes under 24px (WCAG 2.5.8), whatever the size says. The card's fields and the frames' tags (24px targets) keep their sizes, and so do the markers of children with a flag, which stand for the students' radios and checkboxes. - The cards' hooks of earlier versions are renamed:
--astl-editor-card-radius,--astl-editor-card-paddingand--astl-editor-card-current-ringare the--astl-editor-frame-*hooks above;--astl-editor-card-current-kickeris gone (the tab of the frame with the cursor is filled in the accent). - The chips (a gap, a choice in the text, a drop):
--astl-editor-chip-background(--astl-accent-soft),--astl-editor-chip-borderthe border colour (--astl-accent),--astl-editor-chip-inkthe text colour (--astl-ink) and--astl-editor-chip-heightthe least height (auto). - The children with a flag (options, statements):
--astl-editor-flagthe colour of a set marker, a correct answer (--astl-success);--astl-editor-option-bordera border around each row, drawn inside it so nothing moves (transparent),--astl-editor-option-backgroundits background (transparent; a row whose flag is set keeps--astl-success-soft) and--astl-editor-option-gapthe space between rows (0px).
Your own TipTap editor
Section titled “Your own TipTap editor”Install @astl/editor-tiptap: its /tiptap entry has the same building blocks for a TipTap editor you create
yourself (@astl/astrolabe/editor does not export them, so that importing it never loads TipTap):
astrolabeExtensions(authoring, manifests?, { pictures?, pageActions? }): the extensions of the content format: StarterKit restricted to it,sub,sup,mark,span,langanddir, pictures and figures, the document, pages (with the keys and the heads of Pages) and a node per type (default: the authoring's), labelled in the authoring locale.pictures(PictureHooks) is how the surface asks about pictures:ask(request)opens a picture dialog (<astl-picture-dialog>'saskdoes) andrefuse()says that a pasted or dropped file was not inserted (no upload). Without it, picture files are left to the browser and Enter on a picture does what it does on any selection.pageActions(PageAction[], defaultPAGE_ACTIONS) are the buttons of each page's head, in order, read when the extensions are made: for others, make the editor again (<astl-editor>'s own surface takes a change at once).createTiptapAdapter(editor, manifests): theEditorAdapterover that editor, with every optional capability (format,formatState,undo,redo,moveBlock,removeBlock,getCursor,onCursorChange,selectedText,focus,splitPage,addPage,mergePage,removePageandstyle), for the kit elements or for<astl-editor>'sadapter.
import { Editor } from '@tiptap/core';import { astrolabeExtensions, createTiptapAdapter } from '@astl/editor-tiptap/tiptap';
const editor = new Editor({ element, injectCSS: false, extensions: astrolabeExtensions(authoring) });const adapter = createTiptapAdapter(editor, authoring.engine.manifests);Messages
Section titled “Messages”The surface strings (surface.label, surface.pageNumber, surface.pageTitle, surface.pageTitleOf,
surface.pageAddTitle, surface.pageRemoveTitle, surface.pageTitleRemoved, surface.pageJoin,
surface.pageDelete, surface.pageAdded, surface.pageJoined, surface.pageDeleted, surface.pageCheck*, the help
boxes' surface.hint*, surface.move*, surface.helpRemove, surface.helpPlaceholder and help.costFree, the frames'
tags surface.helpHints and surface.helpOpen, surface.loading,
surface.failed, surface.picture.*, the frames' surface.items and surface.points, surface.blockMoved*,
surface.blockRemoved, surface.addOption, the chips' surface.chip.*), the block types (block.*), the toolbar's
(toolbar.*), the insert menus' (insert.*), the style controls' (style.*, those only the form and the
rules show load with them), the inspector's actions (inspector.moveUp, inspector.moveDown,
inspector.delete), the views' (view.*), the status line's (status.*), the picture dialog's (picture.*) and
label.text, a label and its text as one name ("Gap: grey", for the chips, the markers, the issues and the insert
menu's entries) are in the kit's namespace astl.editor, in English and Polish. catalogs rewords any of them
(Internationalisation).