Skip to content
QuireKit MSFE
Developer docs
v0.0.0 · Experimental
API referenceView Markdown ↗

Command and target API

Command drafts, rejection results, external edits and captured ranges.

Signatures come from public package exports. Descriptions are checked against current JSDoc; identifiers retain their original names.

Command context

Commands are pure and synchronous. Use props.commands for nested work; see Commands.

@quirekit/msfe-core

Context of a pure author command. All nested commands share its transaction draft.

CommandPropsts

Source transactions

Each step uses the current draft coordinates, not stale initial offsets.

@quirekit/msfe-core

MSFE transaction builder; deliberately not a ProseMirror Transaction.

SourceTransactionts

Planner adapter

Adapt a pure CodeMirror planner to the same command chain.

@quirekit/msfe-core

Adapts an existing pure CodeMirror planner into the same author-command transaction. @param planner - Backend source planner. @returns Curried command body suitable for addCommands or chain.command.

sourceCommandts

Semantic format commands

toggleSourceMark({ node: 'StrongEmphasis', marker: '**', markerNode: 'EmphasisMark' }) returns a pure planner for editor.run() or sourceCommand(). Features declare grammar; Core handles paired markers, directed selections and complete shells, then verifies both the requested format and existing paired semantics. A complete body selection may expand over hidden shells. When no lossless plan is proved, the command returns null without changing source or history. Partial mark removal and crossing ranges are not automatically split. Empty selections still seed paired markers for free source input.

querySourceInline(state, range) reads endpoint ancestors without parsing, scanning the document or running a format command. Use it for structural availability. reason === null permits planning but does not guarantee a specific combination; eligible blank prose may have no node. Explicit planning is limited to one inline owner of at most 20,000 characters, with a 12ms parse-validation budget. Failure to verify in that budget also refuses. Multiple ranges are planned before one atomic commit. The low-level toggleDelimiter remains a literal source tool.

@quirekit/msfe-core

Grammar owned by a semantic paired-mark feature.

SourceMarkFormatts
@quirekit/msfe-core

One common inline owner, or an explanation of why formatting is unavailable.

SourceInlineQueryts
@quirekit/msfe-core

Reads only source endpoints and their ancestors; never starts parsing or serializes the document. @param state - Accepted source state. @param range - One intended inline range. @returns A common inline owner or a structural refusal.

querySourceInlinets
@quirekit/msfe-core

Toggles a parser-confirmed format without replacing Markdown with another document model. @param format - Owning feature's syntax and source spelling. @returns A pure atomic command; unsafe combinations leave source and history unchanged.

toggleSourceMarkts

Result branches

Named commands return booleans; inspect lastCommandResult for details.

@quirekit/msfe-core

Explicit mutation rejection instead of silently retargeting user intent.

MsfeResultts

External changes

baseRevision is the local source revision, not a server ETag.

@quirekit/msfe-core

Versioned external source mutation.

MsfeExternalChangets

Exact targets

Suitable for short menus; source changes can invalidate the target.

@quirekit/msfe-core

Captured toolbar target, valid only for its exact document revision.

MsfeTargetts

Mapped intent

See Selection and captured intent for the complete async helper.

@quirekit/msfe-core

Document-generation-scoped intent with explicit position remapping.

SourceAnchorts

Mapping policy

Choose endpoint and deletion semantics for the feature independently of presentation.

@quirekit/msfe-core

Explicit boundary affinity and deletion policy, independent of how a range is painted.

RangePolicyts

Source block commands

Resolve complete syntax blocks and run commands with a captured MsfeTarget. Planners preserve the source payload, use one undo step and reject cross-flow moves.

@quirekit/msfe-core

Exact source block and its sibling flow; never a second document model.

SourceBlockts
@quirekit/msfe-core

Source insertion side relative to a complete block.

SourceBlockSidets
@quirekit/msfe-core

Resolves only the pointer/caret ancestor chain, without scanning sibling content. @param state - Accepted source and parser snapshot. @param position - Logical position inside a block. @param scope - Optional required sibling flow, used to lift a drop target out of nested content. @returns Nearest complete block in an admitted sibling flow.

sourceBlockAtts
@quirekit/msfe-core

@param state - Accepted parser. @param block - Current complete block. @param direction - Previous or next sibling. @returns Adjacent structural block without enumerating the document.

sourceBlockSiblingts
@quirekit/msfe-core

@param a - First block. @param b - Second block. @returns Whether both belong to exactly the same source flow.

sameSourceBlockScopets
@quirekit/msfe-core

@param block - Explicit adjacent block. @param side - Source boundary. @param markdown - New complete Markdown. @returns One atomic source insertion; delimiters in the payload remain unchanged.

insertSourceBlockts

replaceSourceBlock(block, markdown) replaces a complete block atomically, preserving required sibling separators and validating enclosing container boundaries. Run it with editor.run(command, capturedTarget) to reject stale menu intents.

@quirekit/msfe-core

@param block - Complete captured source block. @param markdown - Canonical replacement. @returns One guarded replacement preserving sibling and container boundaries.

replaceSourceBlockts
@quirekit/msfe-core

An empty physical line in an admitted block flow, without a synthetic syntax node.

SourceBlankLinets
@quirekit/msfe-core

@param state - Accepted source and syntax. @param position - Pointer or caret position. @returns A blank line in an admitted flow, never whitespace owned by code or list syntax.

sourceBlankLineAtts
@quirekit/msfe-core

@param line - Captured editable blank line. @param markdown - Complete canonical payload. @returns One guarded replacement preserving sibling separators and enclosing containers.

insertAtSourceBlankLinets
@quirekit/msfe-core

@param block - Complete captured block. @returns One source deletion, validated again against the command draft.

removeSourceBlockts
@quirekit/msfe-core

Moves exact source, with one accepted transaction and one undo event through editor.run. @param block - Source block captured when the gesture began. @param target - Complete sibling at the final pointer position. @param side - Before or after that sibling. @returns A planner rejecting self/descendant/cross-flow and obsolete targets.

moveSourceBlockts

Editing boundaries

Features declare semantic ranges of hidden source through addEditingBoundaries() or the editingBoundaries descriptor field. The same option on MdEditor, createMdEditor and createMdEditorExtensions lets the host override defaults by node. See Caret and editing boundaries for integration. These declarations govern navigation, selection and native input protection. Structural actions for Enter, Shift-Enter and Mod-Enter use the addBlockInput() contract below.

Ranges and policies

All offsets belong to the current state.doc and must satisfy 0 ≤ from ≤ contentFrom ≤ contentTo ≤ to ≤ state.doc.length. Optional selectFrom/selectTo must enclose from/to within the document. An invalid range throws invalid-editing-boundary when the rule resolves. Return null when syntax cannot be confirmed.

kindMeaning and typical use
styleBold, emphasis, code, links and other inline formats with editable content inside paired shells
blockCode or containers; shell protection includes adjacent line breaks needed to retain structure
prefixHeading, list or quote prefixes; the caret enters the content after the prefix
separatorCompressed structural gaps skipped by navigation; the product permits native deletion to join text
syntaxTable pipes or alignment rows; selectFrom/selectTo can identify the complete table
atomWhole components or empty fences; the caret stays outside and deletion at an edge first selects the object

navigation: 'content' is the default inline entry policy; split keeps both inside and outside stops. Blocks can explicitly declare content to clamp native line endpoints to their content, as table rows do for outer pipes. Horizontal arrows still skip duplicate stops, and deletion protection is unchanged. Omitted block policies retain the default navigation across shells. Currently navigation: 'native' opts the entire syntax rule out of the shared runtime, including input protection. deletion: 'unwrap' removes the full style or prefix at its relevant edge; protect retains the shell; deletion: 'native' delegates editing while keeping navigation rules. Declare the deletion policy explicitly. A complete owner selection permits whole removal; partial selections retain its shell.

@quirekit/msfe-core

Current source interval and its editable interior, never a second content model.

EditingBoundaryts
@quirekit/msfe-core

Semantic ownership of hidden source, independent of DOM decoration shape.

EditingBoundaryKindts

Queries and priority

nodes names parser nodes. resolve is a pure query over current source: do not dispatch, retain old node offsets or infer positions from visible line counts. Navigation queries endpoints and ancestors, and editing queries syntax intersecting the actual changes. Custom resolvers should keep their work within those same bounds.

The first rule for each node in extension-priority order wins. Host overrides precede feature defaults. Rules replace whole declarations rather than merging fields; returning null opts that syntax rule out without falling back to the next one. Materialized block components independently contribute whole-object ranges, superseding syntax rules within them.

The default when: 'hidden' enables rules when presentation hides syntax globally. when: 'prose' also queries rules in Markdown editing. To protect unrevealed code or similar structures, first check the specific range through isSourceRevealed(state, node) and return null when revealed. Boundary normalization is disabled in source mode and during composition.

@quirekit/msfe-core

Feature-owned facts consumed by the shared navigation and editing runtime.

EditingBoundaryRulets
@quirekit/msfe-core

Pure feature query at one canonical endpoint.

EditingBoundaryContextts

Installation and lifecycle

Ordinary features install automatically through addEditingBoundaries(). Advanced CM integrations can install editingBoundaries(rules) from addCodeMirrorExtensions(); multiple installations reuse the same runtime. Empty rules returns an empty extension without uninstalling other features' rules. MD Editor's editingBoundaries: [] also retains defaults. Options are read on creation; updating Vue props does not reinstall the rules.

Input protection plans complete changes before accepting the transaction, preserving annotations and mapping effects. Moving the caret neither writes source nor adds history. Explicit structure commands, external document updates and history retain their own authority. Transactions that bypass filtering only receive selection recovery when needed, guarded by current state identity and disposal. Read-only mode does not accept text writes.

@quirekit/msfe-core

@param rules - Feature-owned syntax contracts, highest precedence first. @returns Shared navigation, input protection and endpoint recovery; duplicate installations reuse one runtime.

editingBoundariests

Block-owned Enter

Declare syntax ownership with addBlockInput(); see Commands. planBlockInput is the pure planner entry point. A null result leaves native handling to the caller.

@quirekit/msfe-core

Unique syntax ownership; omitted intents delegate, while unregistered block nodes stop routing.

BlockInputRulets
@quirekit/msfe-core

Immutable whole-selection input; handlers plan without dispatching or mutating storage.

BlockInputContextts
@quirekit/msfe-core

A selection endpoint and the current syntax owner resolved by the shared router.

BlockInputTargetts
@quirekit/msfe-core

Semantic gestures mapped from Enter, Shift-Enter and Mod-Enter.

BlockInputIntentts
@quirekit/msfe-core

One atomic source edit, delegation to an ancestor, or native keyboard fallback.

BlockInputResultts
@quirekit/msfe-core

@param context - Validated whole-selection input. @returns A pure decision for the entire gesture.

BlockInputHandlerts
@quirekit/msfe-core

A planner or a fixed ownership decision, requiring no per-key callback.

BlockInputBehaviorts
@quirekit/msfe-core

Resolves ownership without parsing, dispatching or scanning unrelated blocks. @param state - Canonical immutable source state. @param intent - Requested keyboard gesture. @returns One whole-selection edit, or native fallback with no partial mutation.

planBlockInputts
MSFE · QuireKitYour Markdown source stays yours.