@astrolabe/editor
The editor-agnostic authoring kit: createAuthoring, the insert menu, inspector, issues and preview elements, and the textarea adapter.
Classes
Section titled “Classes”AstlInsertMenu
Section titled “AstlInsertMenu”<astl-insert-menu>: what authors can add, in named groups: "Components" (each type with its default template),
"Exercises" (the types' named starters, when any) and "Content" ("Picture", which asks for the picture in a dialog).
Each button's name is its label and description, as shown; a press inserts at the cursor.
Extends
Section titled “Extends”AuthoringElement
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new AstlInsertMenu(): AstlInsertMenu;Returns
Section titled “Returns”Inherited from
Section titled “Inherited from”AuthoringElement.constructorProperties
Section titled “Properties”| Property | Type |
|---|---|
adapter |
EditorAdapter | null |
authoring |
Authoring | null |
Methods
Section titled “Methods”insert()
Section titled “insert()”insert( tag, template?, picture?): string | null;Inserts a new element of tag at the cursor: its default template, or the named starter template; with
picture, the element takes it (a type whose zones or pins sit on a picture: its picture field's address, its
alt text and size). An element whose companion the document lacks brings it at the end (the word bank of a first
gap); the cursor stays on the new element. Returns its source HTML, or null without authoring or adapter.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
tag |
string |
template? |
string |
picture? |
PictureFields |
Returns
Section titled “Returns”string | null
insertPicture()
Section titled “insertPicture()”insertPicture(): Promise<string | null>;Asks for a picture in the dialog and inserts it at the cursor. Resolves with its HTML, or null when cancelled.
Returns
Section titled “Returns”Promise<string | null>
AstlInspector
Section titled “AstlInspector”<astl-inspector>: a form for the component at the cursor (answers, alternatives, correct options, whether each
statement is true, the category of each card, scoring, points, variant, look), or, with the cursor outside every
component, the document's own settings (its look). Every edit goes through authoring.update and the adapter
(replaceElement, or setSource for the document), so the editor stays the source of truth.
Extends
Section titled “Extends”AuthoringElement
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new AstlInspector(): AstlInspector;Returns
Section titled “Returns”Inherited from
Section titled “Inherited from”AuthoringElement.constructorProperties
Section titled “Properties”| Property | Type |
|---|---|
adapter |
EditorAdapter | null |
authoring |
Authoring | null |
Accessors
Section titled “Accessors”Get Signature
Section titled “Get Signature”get model(): | InspectorModel | null;The inspector model on screen (a component's, or the document's), or null.
Returns
Section titled “Returns”| InspectorModel
| null
AstlIssues
Section titled “AstlIssues”<astl-issues>: live validation of the whole document in the UI locale, errors first. Selecting an issue moves the
editor's cursor to its element (adapter.select).
Extends
Section titled “Extends”AuthoringElement
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new AstlIssues(): AstlIssues;Returns
Section titled “Returns”Inherited from
Section titled “Inherited from”AuthoringElement.constructorProperties
Section titled “Properties”| Property | Type |
|---|---|
adapter |
EditorAdapter | null |
authoring |
Authoring | null |
Accessors
Section titled “Accessors”issues
Section titled “issues”Get Signature
Section titled “Get Signature”get issues(): readonly Issue[] | null;The issues on screen (null before the first validation).
Returns
Section titled “Returns”readonly Issue[] | null
Methods
Section titled “Methods”validate()
Section titled “validate()”validate(): void;Validates now instead of waiting for the debounce.
Returns
Section titled “Returns”void
AstlPictureDialog
Section titled “AstlPictureDialog”<astl-picture-dialog>: asks for a picture in a modal dialog: a file, uploaded with the host's uploadAsset, or
an address (the only way without one, as it says); the alt text, required unless the picture is decorative
(alt=""); and, for a new picture, an optional caption. The address must pass the authoring's URL policy, an
uploaded one too. ask resolves with the fields, or null when the author cancels.
Extends
Section titled “Extends”AuthoringElement
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new AstlPictureDialog(): AstlPictureDialog;Returns
Section titled “Returns”Inherited from
Section titled “Inherited from”AuthoringElement.constructorProperties
Section titled “Properties”| Property | Type |
|---|---|
adapter |
EditorAdapter | null |
authoring |
Authoring | null |
Methods
Section titled “Methods”ask(request?): Promise< | PictureFields| null>;Opens the dialog. Resolves with the picture's fields, or null when the author cancels.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
request? |
PictureRequest |
Returns
Section titled “Returns”Promise<
| PictureFields
| null>
AstlPictureField
Section titled “AstlPictureField”<astl-picture-field>: the inspector's picture-regions and picture-points fields. The picture (by address,
or uploaded with the host's uploadAsset) with its zones or pins drawn on it in palette colours and numbered;
drag on it to draw a zone, click to place a pin; and every value in number fields, so nothing needs a pointer.
Changes go to the inspector as astl-field-change events.
Extends
Section titled “Extends”LitElement
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new AstlPictureField(): AstlPictureField;Returns
Section titled “Returns”Overrides
Section titled “Overrides”LitElement.constructorProperties
Section titled “Properties”| Property | Type | Description |
|---|---|---|
authoring |
Authoring | null |
- |
element |
string | null |
The source id of the element the field belongs to (the inspector sets it). |
field |
Field | null |
- |
AstlPreview
Section titled “AstlPreview”<astl-preview>: a button that compiles the current source with a throw-away salt and plays it in <astl-player>
with local grading and the authoring's style templates, the way a student sees it. Invalid sources show their
errors instead. Tokens set on the preview reach the player; the player's events stay inside.
Extends
Section titled “Extends”AuthoringElement
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new AstlPreview(): AstlPreview;Returns
Section titled “Returns”Inherited from
Section titled “Inherited from”AuthoringElement.constructorProperties
Section titled “Properties”| Property | Type |
|---|---|
adapter |
EditorAdapter | null |
authoring |
Authoring | null |
Accessors
Section titled “Accessors”player
Section titled “player”Get Signature
Section titled “Get Signature”get player(): AstlPlayer | null;The player, once the first preview started.
Returns
Section titled “Returns”AstlPlayer | null
Get Signature
Section titled “Get Signature”get state(): PreviewState;idle, loading, ready, invalid (errors shown) or failed.
Returns
Section titled “Returns”PreviewState
Methods
Section titled “Methods”refresh()
Section titled “refresh()”refresh(): Promise<void>;Compiles the current source and plays it. Resolves when the player is ready or the errors are shown.
Returns
Section titled “Returns”Promise<void>
Interfaces
Section titled “Interfaces”Authoring
Section titled “Authoring”Properties
Section titled “Properties”| Property | Modifier | Type | Description |
|---|---|---|---|
descriptors |
readonly |
readonly EditorDescriptor[] |
- |
elements |
readonly |
readonly ElementEntry[] |
- |
engine |
readonly |
Engine |
- |
locale |
readonly |
string |
- |
styleTemplates |
readonly |
readonly StyleTemplate[] |
- |
uploadAsset |
readonly |
UploadAsset | null |
The host's upload, or null: pictures are added by address only. |
urlPolicy |
readonly |
UrlPolicy |
- |
Methods
Section titled “Methods”assignIds()
Section titled “assignIds()”assignIds(source): string;source with fresh ids on pages and components that lack one (or have an empty one).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
source |
string |
Returns
Section titled “Returns”string
describe()
Section titled “describe()”describe(issue): string;An issue as a sentence in the authoring locale.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
issue |
Issue |
Returns
Section titled “Returns”string
descriptor()
Section titled “descriptor()”descriptor(tag): | EditorDescriptor | null;The descriptor of a component tag, or null.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
tag |
string |
Returns
Section titled “Returns”| EditorDescriptor
| null
inspect()
Section titled “inspect()”inspect(elementHtml, source?): | InspectorModel | null;The inspector model of one component element (source HTML), or null for elements it does not know. With the
whole document (source), fields offer what other elements hold (the words of the bank a drop takes its words
from); without it they show the attribute's own control.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
elementHtml |
string |
source? |
string |
Returns
Section titled “Returns”| InspectorModel
| null
inspectDocument()
Section titled “inspectDocument()”inspectDocument(source): | InspectorModel | null;The document's own settings (its style template) as an inspector model for <astl-doc>, or null when the source
has no <astl-doc> root or there is nothing to set. Apply its changes with update(source, change): the first
element of the source is the document, so only its start tag changes.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
source |
string |
Returns
Section titled “Returns”| InspectorModel
| null
instantiate()
Section titled “instantiate()”instantiate( tag, source, templateId?): string;The descriptor's template, or its named starter templateId, ready to insert into source: {{id}} becomes
<idPrefix>-<n> with the smallest n whose id source does not use, {{t:key}} an escaped message of the
manifest namespace, and other components written without an id get fresh ones too. An element of a type with a
companion and an empty attribute names the first such element of the template, else of source, else the one
withCompanion adds. Throws for a tag without a descriptor or an unknown starter.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
tag |
string |
source |
string |
templateId? |
string |
Returns
Section titled “Returns”string
outline()
Section titled “outline()”outline(source): Outline;Pages, their components and issue counts.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
source |
string |
Returns
Section titled “Returns”preview()
Section titled “preview()”preview(source): Promise<PreviewResult>;Compiles with a random per-session salt and grades locally. The source is not stored anywhere.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
source |
string |
Returns
Section titled “Returns”Promise<PreviewResult>
t( namespace, key, params?): string;A message in the authoring locale: kit (astl.editor), descriptor, engine and extra catalogs.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
namespace |
string |
key |
string |
params? |
Readonly<Record<string, string | number>> |
Returns
Section titled “Returns”string
templates()
Section titled “templates()”templates(tag): readonly EditorTemplate[];The named starters of a component tag (EditorDescriptor.templates); none without a descriptor.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
tag |
string |
Returns
Section titled “Returns”readonly EditorTemplate[]
update()
Section titled “update()”update(elementHtml, change): string;The element HTML with one inspector change applied; everything else stays byte-identical.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
elementHtml |
string |
change |
InspectorChange |
Returns
Section titled “Returns”string
validate()
Section titled “validate()”validate(source): ValidationReport;Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
source |
string |
Returns
Section titled “Returns”withCompanion()
Section titled “withCompanion()”withCompanion(tag, source): string | null;source (with an inserted tag element) and the template of the descriptor's companion at the end of the
document (in the last page), when it has no such element yet; else null.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
tag |
string |
source |
string |
Returns
Section titled “Returns”string | null
AuthoringOptions
Section titled “AuthoringOptions”Properties
Section titled “Properties”| Property | Modifier | Type | Description |
|---|---|---|---|
catalogs? |
readonly |
readonly MessageCatalog[] |
More or overriding catalogs (any namespace), e.g. another UI locale. |
descriptors |
readonly |
readonly EditorDescriptor[] |
One per component type authors can insert and inspect. Each tag must be registered in the engine. |
elements? |
readonly |
readonly ElementEntry[] |
Player elements for <astl-preview>, eager or lazy. |
engine |
readonly |
Engine |
- |
locale |
readonly |
string |
The author's UI locale: labels, issues, template texts. |
styleTemplates? |
readonly |
readonly StyleTemplate[] |
Style templates authors can pick (register the same ones with the engine and the player): the inspector offers them per component and for the whole document, labelled from their catalogs; <astl-preview> renders them. |
uploadAsset? |
readonly |
UploadAsset |
Stores a picture file and returns its address (and size): the host's upload, used by the picture dialog, by pictures pasted or dropped into the editor and by picture fields; also by url fields with accept (a video, its captions). The address must pass urlPolicy. Without it, pictures and files are added by address only. signal aborts when the author cancels or picks another file. The file's type is the browser's guess: check type and size on the server, and serve SVG with nosniff. |
urlPolicy? |
readonly |
UrlPolicy |
The engine's URL policy (createEngine({ urlPolicy })): the preview's player cleans with it and editors check picture addresses with it before they show them. Default isSafeUrl. |
CheckboxFieldModel
Section titled “CheckboxFieldModel”Extends
Section titled “Extends”FieldTexts
Properties
Section titled “Properties”ChildChoiceFieldModel
Section titled “ChildChoiceFieldModel”Extends
Section titled “Extends”FieldTexts
Properties
Section titled “Properties”| Property | Modifier | Type | Description |
|---|---|---|---|
attribute |
readonly |
string |
- |
children |
readonly |
readonly ChildChoiceModel[] |
- |
control |
readonly |
"select" | "radios" |
Radios for the enum values of the attribute, a select for the ids of other children (options). |
help |
readonly |
string | null |
Translated help text, or null. |
kind |
readonly |
"child-choice" |
- |
label |
readonly |
string |
Translated label. |
tag |
readonly |
string |
- |
ChildChoiceModel
Section titled “ChildChoiceModel”Properties
Section titled “Properties”| Property | Modifier | Type | Description |
|---|---|---|---|
id |
readonly |
string | null |
- |
index |
readonly |
number |
Position among the children with this tag, from 0 (what child-choice changes use). |
label |
readonly |
string |
The child's text, or a placeholder when it is empty. |
options |
readonly |
readonly InspectorOption[] |
The choices of this child. Enum source: the attribute's values, the same for every child (an absent or unknown value matches none). Child source: each option child's id with its text, plus the "not set" option when the value is absent and the written value itself when it names no option (so the control shows what the source says). |
value |
readonly |
string |
The written value; '' when absent. |
ChildFlagFieldModel
Section titled “ChildFlagFieldModel”Extends
Section titled “Extends”FieldTexts
Properties
Section titled “Properties”| Property | Modifier | Type | Description |
|---|---|---|---|
attribute |
readonly |
string |
- |
children |
readonly |
readonly ChildFlagModel[] |
- |
help |
readonly |
string | null |
Translated help text, or null. |
kind |
readonly |
"child-flag" |
- |
label |
readonly |
string |
Translated label. |
tag |
readonly |
string |
- |
ChildFlagModel
Section titled “ChildFlagModel”Properties
Section titled “Properties”ChildTextFieldModel
Section titled “ChildTextFieldModel”Extends
Section titled “Extends”FieldTexts
Properties
Section titled “Properties”| Property | Modifier | Type | Description |
|---|---|---|---|
attribute |
readonly |
string |
- |
children |
readonly |
readonly ChildTextModel[] |
- |
help |
readonly |
string | null |
Translated help text, or null. |
kind |
readonly |
"child-text" |
- |
label |
readonly |
string |
Translated label. |
tag |
readonly |
string |
- |
ChildTextModel
Section titled “ChildTextModel”Properties
Section titled “Properties”FieldChange
Section titled “FieldChange”A change of the field, and the source id of the element it is for (an upload may end after the cursor moved).
Properties
Section titled “Properties”| Property | Modifier | Type |
|---|---|---|
change |
readonly |
InspectorChange |
element |
readonly |
string | null |
InspectorModel
Section titled “InspectorModel”Properties
Section titled “Properties”| Property | Modifier | Type | Description |
|---|---|---|---|
fields |
readonly |
readonly InspectorFieldModel[] |
- |
icon |
readonly |
string | null |
Icon name from the descriptor. |
id |
readonly |
string | null |
- |
label |
readonly |
string |
Translated menu label of the type (the tag when there is no descriptor). |
tag |
readonly |
string |
- |
InspectorOption
Section titled “InspectorOption”Properties
Section titled “Properties”| Property | Modifier | Type |
|---|---|---|
label |
readonly |
string |
value |
readonly |
string |
NumberFieldModel
Section titled “NumberFieldModel”Extends
Section titled “Extends”FieldTexts
Properties
Section titled “Properties”Outline
Section titled “Outline”Properties
Section titled “Properties”| Property | Modifier | Type | Description |
|---|---|---|---|
errors |
readonly |
number |
Every issue of the document. |
pages |
readonly |
readonly OutlinePage[] |
- |
warnings |
readonly |
number |
- |
OutlineComponent
Section titled “OutlineComponent”Properties
Section titled “Properties”OutlinePage
Section titled “OutlinePage”Properties
Section titled “Properties”| Property | Modifier | Type | Description |
|---|---|---|---|
components |
readonly |
readonly OutlineComponent[] |
- |
errors |
readonly |
number |
Issues located on the page, its content and its components. |
id |
readonly |
string | null |
null for the implicit page of a document without pages. |
label |
readonly |
string | null |
- |
warnings |
readonly |
number |
- |
PictureFields
Section titled “PictureFields”A picture as the picture dialog asks for it: alt is '' for a decorative picture.
Properties
Section titled “Properties”| Property | Modifier | Type | Description |
|---|---|---|---|
alt |
readonly |
string |
- |
caption? |
readonly |
string |
A caption makes the picture a figure. |
height? |
readonly |
number |
- |
src |
readonly |
string |
- |
width? |
readonly |
number |
- |
PicturePointModel
Section titled “PicturePointModel”One pin of a picture-points field, in percent of the picture.
Properties
Section titled “Properties”| Property | Modifier | Type |
|---|---|---|
id |
readonly |
string |
index |
readonly |
number |
label |
readonly |
string |
x |
readonly |
number |
y |
readonly |
number |
PicturePointsFieldModel
Section titled “PicturePointsFieldModel”Extends
Section titled “Extends”PictureFieldBase
Properties
Section titled “Properties”| Property | Modifier | Type | Description |
|---|---|---|---|
elementTag |
readonly |
string |
The tag of the element with the picture: the URL policy is asked for its srcAttribute, as the engine does. |
help |
readonly |
string | null |
Translated help text, or null. |
kind |
readonly |
"picture-points" |
- |
label |
readonly |
string |
Translated label. |
points |
readonly |
readonly PicturePointModel[] |
- |
src |
readonly |
string |
- |
srcAttribute |
readonly |
string |
The element's attribute with the picture's address, and its value ('' when absent). |
tag |
readonly |
string |
- |
PictureRegionModel
Section titled “PictureRegionModel”One zone of a picture-regions field, in percent of the picture (absent or invalid numbers read as 0).
Properties
Section titled “Properties”| Property | Modifier | Type | Description |
|---|---|---|---|
flagged |
readonly |
boolean |
Whether the zone has the field's flag (a right place): drawn solid, the others dashed. |
height |
readonly |
number |
- |
id |
readonly |
string |
- |
index |
readonly |
number |
Position among the children with the field's tag, from 0 (what child-* changes use). |
label |
readonly |
string |
- |
points |
readonly |
readonly (readonly [number, number])[] |
- |
r |
readonly |
number |
- |
shape |
readonly |
PictureShape |
- |
width |
readonly |
number |
- |
x |
readonly |
number |
- |
y |
readonly |
number |
- |
PictureRegionsFieldModel
Section titled “PictureRegionsFieldModel”Extends
Section titled “Extends”PictureFieldBase
Properties
Section titled “Properties”| Property | Modifier | Type | Description |
|---|---|---|---|
elementTag |
readonly |
string |
The tag of the element with the picture: the URL policy is asked for its srcAttribute, as the engine does. |
flag |
readonly |
string | null |
The boolean attribute of a child-flag field on the same child tag (a hotspot's right places), whose zones are drawn solid and the others dashed; null without one (every zone solid). |
help |
readonly |
string | null |
Translated help text, or null. |
kind |
readonly |
"picture-regions" |
- |
label |
readonly |
string |
Translated label. |
regions |
readonly |
readonly PictureRegionModel[] |
- |
shapes |
readonly |
readonly PictureShape[] |
The shapes a zone may take: the values of the child's shape enum, or rectangles only when it has no shape (then no shape is written). |
src |
readonly |
string |
- |
srcAttribute |
readonly |
string |
The element's attribute with the picture's address, and its value ('' when absent). |
tag |
readonly |
string |
- |
PictureRequest
Section titled “PictureRequest”What ask opens the dialog with.
Properties
Section titled “Properties”| Property | Modifier | Type | Description |
|---|---|---|---|
altRequired? |
readonly |
boolean |
The picture carries the task (a component's): its alt text is required, with no decorative choice. |
caption? |
readonly |
boolean |
Whether to ask for a caption (a new picture). Default: true for a new picture, false for an edit. |
current? |
readonly |
PictureFields |
A picture to edit: its address, alt text and size. Absent: a new picture. |
decorative? |
readonly |
boolean |
Whether current is decorative; default: when its alt text is empty. |
file? |
readonly |
File |
A file to upload first (pasted or dropped), through the authoring's uploadAsset. |
target? |
readonly |
object |
The element and attribute the address is for, as the URL policy is asked; default img and src. |
target.attribute |
readonly |
string |
- |
target.tag |
readonly |
string |
- |
ScannedElement
Section titled “ScannedElement”A page or a component found by scanElements. Offsets index into the scanned string.
Properties
Section titled “Properties”| Property | Modifier | Type | Description |
|---|---|---|---|
end |
readonly |
number |
- |
id |
readonly |
string | null |
The id attribute (entities decoded), or null when absent. |
start |
readonly |
number |
- |
tag |
readonly |
string |
- |
SelectFieldModel
Section titled “SelectFieldModel”Extends
Section titled “Extends”FieldTexts
Properties
Section titled “Properties”| Property | Modifier | Type | Description |
|---|---|---|---|
control |
readonly |
"select" |
- |
help |
readonly |
string | null |
Translated help text, or null. |
kind |
readonly |
"attribute" |
- |
label |
readonly |
string |
Translated label. |
name |
readonly |
string |
- |
options |
readonly |
readonly InspectorOption[] |
- |
value |
readonly |
string |
The written value, else the default; '' (the "not set" option) when neither. |
TextareaAdapter
Section titled “TextareaAdapter”What a WYSIWYG integration must provide so the authoring kit can drive it. Everything is in source HTML
(the <astl-doc> format), so an adapter is free to use any internal model.
Extends
Section titled “Extends”Methods
Section titled “Methods”destroy()
Section titled “destroy()”destroy(): void;Removes the textarea listeners and every subscription.
Returns
Section titled “Returns”void
getElement()
Section titled “getElement()”getElement(id): string | null;Source HTML of one component element, or null when the id is not in the document.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
id |
string |
Returns
Section titled “Returns”string | null
Inherited from
Section titled “Inherited from”getSelection()
Section titled “getSelection()”getSelection(): | EditorSelection | null;The component at the cursor, or null.
Returns
Section titled “Returns”| EditorSelection
| null
Inherited from
Section titled “Inherited from”getSource()
Section titled “getSource()”getSource(): string;The whole document as source HTML.
Returns
Section titled “Returns”string
Inherited from
Section titled “Inherited from”insert()
Section titled “insert()”insert(html): void;Inserts a source snippet (an instantiated template) at the cursor.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
html |
string |
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”onChange()
Section titled “onChange()”onChange(listener): () => void;Subscribe to document changes. Returns an unsubscribe function.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
listener |
() => void |
Returns
Section titled “Returns”() => void
Inherited from
Section titled “Inherited from”onSelectionChange()
Section titled “onSelectionChange()”onSelectionChange(listener): () => void;Subscribe to selection changes. Returns an unsubscribe function.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
listener |
(selection) => void |
Returns
Section titled “Returns”() => void
Inherited from
Section titled “Inherited from”EditorAdapter.onSelectionChange
replaceElement()
Section titled “replaceElement()”replaceElement(id, html): void;Replaces one component element in place (inspector edits); the rest of the document is untouched.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
id |
string |
html |
string |
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”select()
Section titled “select()”select(id): void;Moves the cursor to an element by source id (a component or a page) and focuses the editor.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
id |
string |
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”setSource()
Section titled “setSource()”setSource(source): void;Replaces the whole document.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
source |
string |
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”wrap()?
Section titled “wrap()?”optional wrap(tag): boolean;Runs the wrap command of the type tag (EditorDescriptor.wrap) on the selection and focuses the editor;
returns whether the document changed. Absent: the editor offers no such command.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
tag |
string |
Returns
Section titled “Returns”boolean
Inherited from
Section titled “Inherited from”TextFieldModel
Section titled “TextFieldModel”Extends
Section titled “Extends”FieldTexts
Properties
Section titled “Properties”TextListFieldModel
Section titled “TextListFieldModel”Extends
Section titled “Extends”FieldTexts
Properties
Section titled “Properties”UploadedAsset
Section titled “UploadedAsset”A stored picture, as uploadAsset returns it: its address, and its size in pixels when known.
Properties
Section titled “Properties”| Property | Modifier | Type |
|---|---|---|
height? |
readonly |
number |
src |
readonly |
string |
width? |
readonly |
number |
Type Aliases
Section titled “Type Aliases”InspectorChange
Section titled “InspectorChange”type InspectorChange = | { kind: "attribute"; name: string; value: string | boolean | null;} | { kind: "text-list"; tag: string; values: readonly string[];} | { attribute: string; index: number; kind: "child-flag"; tag: string; value: boolean;} | { attribute: string; index: number; kind: "child-choice"; tag: string; value: string | null;} | { attributes: Readonly<Record<string, string | null>>; index: number; kind: "child-attributes"; tag: string;} | { attributes: Readonly<Record<string, string>>; kind: "child-add"; tag: string;} | { index: number; kind: "child-remove"; tag: string;};What an inspector control changes. Indexes count children with the same tag, from 0.
Union Members
Section titled “Union Members”Type Literal
Section titled “Type Literal”{ kind: "attribute"; name: string; value: string | boolean | null;}| Name | Type | Description |
|---|---|---|
kind |
"attribute" |
- |
name |
string |
- |
value |
string | boolean | null |
A string sets the value, true writes a bare boolean attribute, false or null removes it. |
Type Literal
Section titled “Type Literal”{ kind: "text-list"; tag: string; values: readonly string[];}Type Literal
Section titled “Type Literal”{ attribute: string; index: number; kind: "child-flag"; tag: string; value: boolean;}Type Literal
Section titled “Type Literal”{ attribute: string; index: number; kind: "child-choice"; tag: string; value: string | null;}| Name | Type | Description |
|---|---|---|
attribute |
string |
- |
index |
number |
- |
kind |
"child-choice" |
- |
tag |
string |
- |
value |
string | null |
The value to write; null removes the attribute. |
Type Literal
Section titled “Type Literal”{ attributes: Readonly<Record<string, string | null>>; index: number; kind: "child-attributes"; tag: string;}| Name | Type | Description |
|---|---|---|
attributes |
Readonly<Record<string, string | null>> |
- |
index |
number |
- |
kind |
"child-attributes" |
Several attributes of one child (a zone's shape and coordinates): a string sets one, null removes it. |
tag |
string |
- |
Type Literal
Section titled “Type Literal”{ attributes: Readonly<Record<string, string>>; kind: "child-add"; tag: string;}A new empty child with these attributes, after the last child of its tag (or at the end).
Type Literal
Section titled “Type Literal”{ index: number; kind: "child-remove"; tag: string;}Removes one child, its content included.
InspectorFieldModel
Section titled “InspectorFieldModel”type InspectorFieldModel = | TextFieldModel | NumberFieldModel | CheckboxFieldModel | SelectFieldModel | TextListFieldModel | ChildFlagFieldModel | ChildTextFieldModel | ChildChoiceFieldModel | ChildTableFieldModel | PictureRegionsFieldModel | PicturePointsFieldModel;PictureShape
Section titled “PictureShape”type PictureShape = "rect" | "circle" | "polygon";PreviewResult
Section titled “PreviewResult”type PreviewResult = | { checker: LocalChecker; issues: readonly Issue[]; ok: true; view: string;} | { issues: readonly Issue[]; ok: false;};A playable preview, or the issues that block compiling.
Union Members
Section titled “Union Members”Type Literal
Section titled “Type Literal”{ checker: LocalChecker; issues: readonly Issue[]; ok: true; view: string;}| Name | Type | Description |
|---|---|---|
checker |
LocalChecker |
Local grading for this preview (practice policy). |
issues |
readonly Issue[] |
Warnings. |
ok |
true |
- |
view |
string |
- |
Type Literal
Section titled “Type Literal”{ issues: readonly Issue[]; ok: false;}UploadAsset
Section titled “UploadAsset”type UploadAsset = (file, options) => Promise<UploadedAsset>;Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
file |
File |
options |
{ signal: AbortSignal; } |
options.signal |
AbortSignal |
Returns
Section titled “Returns”Promise<UploadedAsset>
Variables
Section titled “Variables”EDITOR_NAMESPACE
Section titled “EDITOR_NAMESPACE”const EDITOR_NAMESPACE: "astl.editor" = 'astl.editor';i18n namespace of the authoring kit's own UI (insert menu, inspector, issues, preview).
editorMessages
Section titled “editorMessages”const editorMessages: readonly MessageCatalog[];FIELD_CHANGE
Section titled “FIELD_CHANGE”const FIELD_CHANGE: "astl-field-change" = 'astl-field-change';Fired with a FieldChange for the inspector to apply.
Functions
Section titled “Functions”createAuthoring()
Section titled “createAuthoring()”function createAuthoring(options): Authoring;Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
options |
AuthoringOptions |
Returns
Section titled “Returns”createTextareaAdapter()
Section titled “createTextareaAdapter()”function createTextareaAdapter(textarea): TextareaAdapter;Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
textarea |
HTMLTextAreaElement |
Returns
Section titled “Returns”defineAuthoringElements()
Section titled “defineAuthoringElements()”function defineAuthoringElements(registry?): void;Defines <astl-insert-menu>, <astl-inspector>, <astl-issues> and <astl-preview>, and the two they use for
pictures, <astl-picture-dialog> and <astl-picture-field> (nothing is defined on import). Safe to call again; a
tag already defined by another class throws, as two copies of the kit would otherwise mix silently.
Parameters
Section titled “Parameters”| Parameter | Type | Default value |
|---|---|---|
registry? |
CustomElementRegistry |
customElements |
Returns
Section titled “Returns”void
pictureHtml()
Section titled “pictureHtml()”function pictureHtml(picture): string;The source HTML of a picture: an <img> that sits in text, or with a caption a <figure> that stands on its own.
Every value is read once and escaped, and only the attributes of the content format are written.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
picture |
PictureFields |
Returns
Section titled “Returns”string
pictureSize()
Section titled “pictureSize()”function pictureSize(value): number | undefined;A picture's width or height as the content format takes it: a positive whole number of pixels (a safe integer), from a number or its written form; anything else is no size.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
value |
unknown |
Returns
Section titled “Returns”number | undefined
scanElements()
Section titled “scanElements()”function scanElements(source): ScannedElement[];Pages (astl-page) and components in document order, with offsets into source, for text-based adapters. An
component is any custom element outside another component (so a misspelt tag is found too); custom elements
inside a component are its children. Tolerant of messy input: comments, quoted > in attributes, any case,
unclosed or self-closed elements.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
source |
string |