Editor API
Look up the current public creation options, instance methods, and incremental events.
Type signatures are extracted from the current MSFE public exports. Initial configuration applies only at mount time; use instance methods for subsequent state changes.
Creation function
@quirekit/msfe-coreValidates and acquires the source before mounting, rolling back every partial installation on failure. @param options - Editor mount and extension configuration. @returns Independent disposable editor.
function createMsfeEditor(options: MsfeEditorOptions): MsfeEditorCreation options
Provide a browser mount element as parent. Set markdown, extensions, mode, and host callbacks as needed.
@quirekit/msfe-coreBrowser editor creation options; the host owns storage and file decoding.
export interface MsfeEditorOptions {
readonly parent: HTMLElement;
readonly markdown?: string;
readonly documentId?: string;
readonly mode?: MsfeMode;
readonly readOnly?: boolean;
readonly theme?: "light" | "dark";
readonly extensions?: readonly AnyExtension[];
readonly icons?: MsfeIconFactory;
readonly codeLanguages?: readonly CodeLanguage[];
readonly searchPanel?: ComponentViewRenderer<SearchPanelProps>;
readonly componentHost?: MsfeComponentHost;
readonly label?: string;
readonly onChange?: (event: MsfeChangeEvent) => void;
readonly onError?: (error: unknown) => void;
}Editor instance
commands runs commands, can() checks applicability, and chain() combines operations into one dispatch. If a command is unavailable, inspect its return value and lastCommandResult.
@quirekit/msfe-coreFramework-neutral experimental MSFE public surface.
export interface MsfeEditor {
readonly history: MsfeHistory;
readonly scope: TaskScope;
readonly documentScope: TaskScope;
captureAnchor(range: MsfeSourceRange, policy?: RangePolicy): SourceAnchor;
querySource(name: string, range?: MsfeSourceRange): SourceQuery;
isActive(name: string, attrs?: Readonly<Record<string, unknown>>): boolean;
getAttributes(name: string): Readonly<Record<string, unknown>> | null;
getState<T>(slot: StateSlot<T>): T;
subscribeState<T>(subscription: StateSubscription<T>): () => void;
readonly commands: SingleCommands;
readonly lastCommandResult: MsfeResult | undefined;
readonly storage: Readonly<Record<string, unknown>>;
readonly element: HTMLElement;
readonly state: EditorState;
readonly documentId: string;
readonly revision: number;
readonly mode: MsfeMode;
readonly work: Readonly<MsfeWorkCounters>;
getMarkdown(): string;
captureTarget(): MsfeTarget;
run(command: MsfeCommand, target?: MsfeTarget): MsfeResult;
chain(target?: MsfeTarget): MsfeCommandChain;
chain(commands: readonly MsfeCommand[], target?: MsfeTarget): MsfeResult;
can(): CanCommands;
can(command: MsfeCommand, target?: MsfeTarget): boolean;
applyChanges(change: MsfeExternalChange): MsfeResult;
replaceDocument(markdown: string, documentId: string): MsfeResult;
setMode(mode: MsfeMode): void;
setReadOnly(readOnly: boolean): void;
setTheme(theme: "light" | "dark"): void;
setSelection(selection: EditorSelection): void;
updateViewState(update: MsfeViewStateUpdate): MsfeResult;
scrollTo(position: number): void;
focus(): void;
undo(): boolean;
redo(): boolean;
onChange(listener: (event: MsfeChangeEvent) => void): () => void;
destroy(): void;
}Document changes
Events preserve incremental edits and origin information without serializing the entire document by default. Observer errors are reported through the host error callback.
@quirekit/msfe-coreAn accepted source change, without an eagerly serialized document.
export interface MsfeChangeEvent {
readonly documentId: string;
readonly revision: number;
readonly changes: ChangeSet;
readonly selection: EditorSelection;
readonly origin: string;
}Find methods by task
| Task | Combination | Guide |
|---|---|---|
| Save | getMarkdown + onChange | Serialized saving |
| External same-document edits | applyChanges + identity/revision | External updates |
| Switch files | replaceDocument + fresh resources | Lifecycle |
| Format toolbar | can / isActive / getAttributes / subscribeState | Toolbars |
| Compound action | chain(...).run() | Commands |
| Write after a dialog | captureTarget or captureAnchor | Captured intent |
| Reading preferences | defineState + updateViewState | State |
| Diagnose behavior | onError / lastCommandResult / work | Diagnostics |
Read the minimum necessary source in selectors and queries. Do not keep invoking disposed instances or pass their old state to another editor.