@stesura/core/stores
Per-editor nanostores atoms, the registry that finds them, and the global user preferences.
createEditorStores({ defaults, extensionStores }) builds one FullEditorStores per editor scope: atoms for the editor mode, TOC, pagination output (page counts, page numbering, the first-layout gate), stylesheet, list configs and block handle. extensionStores is spread into the result; type it by augmenting EditorStoreExtensions. The root editor’s configPlugin (part of basePlugins / stesuraPlugins) creates and registers them with addEditorStoresToMap when its view mounts and removes them on unmount, so integrators never call these; commands and plugins reach the stores through getEditorStores(idOrState) instead of taking a stores parameter. A sub-editor’s state falls through to its parent’s stores. In React, read and write them with useEditorStoreValue / useEditorStore from @stesura/editor-react.
userPreferences holds global atoms shared by every editor. Seed their defaults with initUserPreferences before the first mount.
Functions & values
activeFloatingBoxAtom
The text box being edited in editorId, or null. Created on first use, stable per editor.
| Name | Type | Default |
|---|---|---|
editorId | string |
addEditorStoresToMap
Registers an editor’s stores under its id and bumps registryVersion.
A duplicate id keeps the FIRST registration — the second editor then reads and writes the first’s stores, which is never what the caller wants, so it is reported rather than silently accepted.
Returns whether THIS call created the entry. Callers must only unregister on teardown when it did: a refused duplicate’s destroy would otherwise take the surviving editor’s stores with it (CORE-132).
| Name | Type | Default |
|---|---|---|
id | string | |
atoms | FullEditorStores |
addMountConfigToMap
Registers a root mount’s config. Mirrors addEditorStoresToMap’s
first-wins rule so a refused duplicate id can’t hijack the entry.
| Name | Type | Default |
|---|---|---|
id | string | |
state | ConfigPluginState |
closeFloatingBox
Unmounts editorId’s box sub-editor, if any.
| Name | Type | Default |
|---|---|---|
editorId | string |
createEditorStores
Creates the reactive stores for one editor scope. User preferences are not
here: they are global singletons in userPreferences (./user-preferences.ts),
a few of which are also spread into the result for compatibility.
| Name | Type | Default |
|---|---|---|
props | { defaults: Partial<EditorStoreDefaults>; extensionStores: Record<string, PreinitializedWritableAtom<unknown>>; } |
disarmAll
Disarms every mode armed in editorId, except except.
except is how an arming control interacts with itself without cancelling
the mode it just armed — its own button, and its own menu opening.
| Name | Type | Default |
|---|---|---|
editorId | string | |
except | "highlight" | "formatPainter" |
disposeFloatingBoxState
Resets editorId’s atom and evicts it once nothing listens, so apps minting
an editor id per document don’t leak. Deferred a microtask: StrictMode
re-subscribes within the unmounting commit (as disposeNotePanelState).
| Name | Type | Default |
|---|---|---|
editorId | string |
floatingBoxEditorRegistry
Mounted text box sub-editors; one at most per main editor.
getEditorStores
The stores for an editor id or state. A state whose editor has no stores of
its own (a sub-editor) falls through to its parentEditorId’s; a raw id
does not.
| Name | Type | Default |
|---|---|---|
idOrState | string | EditorState |
getFirstLayoutReady
Reads the first-layout gate; null when the editor has no stores.
| Name | Type | Default |
|---|---|---|
idOrState | string | EditorState |
getFirstLayoutReadyAtom
The editor’s first-layout gate atom.
null — nobody claims it (unpaginated mount, or pagination not loaded).
false — pagination’s first pass is outstanding; the canvas holds.
true — every section has a layout, or the hold timed out.
| Name | Type | Default |
|---|---|---|
idOrState | string | EditorState |
getMountConfig
The configPlugin state a root mount was created with, if it is still mounted.
| Name | Type | Default |
|---|---|---|
id | string |
getNodePageNumbersStore
Page label per block id (“iv”, “12”), as the TOC renders it.
| Name | Type | Default |
|---|---|---|
idOrState | string | EditorState |
getPageCountsStore
Pages per section, in document order. Sum it for the document’s page count; sum the entries ahead of a section for that section’s page offset.
| Name | Type | Default |
|---|---|---|
idOrState | string | EditorState |
getPageNumberingStore
Sections’ own pageNumbering, keyed by section id — see the store’s docs.
| Name | Type | Default |
|---|---|---|
idOrState | string | EditorState |
getProofReadApiFailedFor
Parameters:| Name | Type | Default |
|---|---|---|
editorId | string |
getProofReadLoadingFor
Parameters:| Name | Type | Default |
|---|---|---|
editorId | string |
getRootEditorView
The main editor view registered under id, or undefined.
| Name | Type | Default |
|---|---|---|
id | string |
getTocBreaksStore
Where the TOC’s rows split across pages, as measured by pagination.
| Name | Type | Default |
|---|---|---|
idOrState | string | EditorState |
getTOCstore
The editor’s TOC state (its anchor registry and rendered entries).
| Name | Type | Default |
|---|---|---|
idOrState | string | EditorState |
headerFooterEditorRegistry
Mounted header/footer sub-editors. Unlike notes, a header and a footer
editor can be open at once for the same section and variant. Entries are
registered by SubEditorRegister (editor-react); the binding plugin pushes
main-editor changes into each.
initUserPreferences
Applies default preferences for keys with no localStorage entry yet, so persisted user choices win. Call once at startup, before mounting an editor.
| Name | Type | Default |
|---|---|---|
defaults | Partial<UserPreferences> |
openFloatingBox
Mounts the sub-editor of box boxId in editorId; one box is active at a time.
| Name | Type | Default |
|---|---|---|
editorId | string | |
boxId | string | |
options | { at?: { left: number; top: number; }; focus?: boolean; } |
proofReadApiFailedByEditor
proofReadLoadingByEditor
Per-root-editor proofread flags, keyed like the proofread cache. Write through the setters below, which keep the global aggregates in step.
registerArmedMode
Records that key is armed in editorId, together with the callback that
disarms it.
Register when the mode arms and call the returned release when it disarms —
an entry that outlives its view would disarm through a dead EditorView.
| Name | Type | Default |
|---|---|---|
editorId | string | |
key | "highlight" | "formatPainter" | |
disarm | () => void |
registerRootEditorView
Records a main editor’s view under its id. Called on mount.
| Name | Type | Default |
|---|---|---|
id | string | |
view | EditorView |
registryVersion
Bumped on every registry change so hooks re-render when stores appear or go. Store consumers can mount before the editor registers its stores, and the plain map isn’t reactive, so without this they never saw the stores.
removeEditorStoresFromMap
Unregisters an editor’s stores on unmount and bumps registryVersion.
| Name | Type | Default |
|---|---|---|
id | string |
removeMountConfigFromMap
Unregisters a root mount’s config on unmount.
| Name | Type | Default |
|---|---|---|
id | string |
resolveEditorId
The id as given, or read from the state’s config plugin (undefined without one).
| Name | Type | Default |
|---|---|---|
idOrState | string | EditorState |
setFirstLayoutReady
Sets the first-layout gate: false claims the hold, true releases it,
null disclaims it (pagination off or unmounted). No-op when unchanged.
| Name | Type | Default |
|---|---|---|
idOrState | string | EditorState | |
ready | boolean |
setNodePageNumbersStore
Replaces the block-id to page-number map.
| Name | Type | Default |
|---|---|---|
idOrState | string | EditorState | |
pageNumbers | Map<string, string> |
setPageCountsStore
Replaces the section-id to page-count map. undefined when pagination is off.
| Name | Type | Default |
|---|---|---|
idOrState | string | EditorState | |
pageCounts | Map<string, number> |
setPageNumberingStore
Replaces the section-id to page-numbering map.
| Name | Type | Default |
|---|---|---|
idOrState | string | EditorState | |
pageNumbering | Map<string, PageNumberingAttrs> |
setProofReadApiFailedFor
Raises or clears editorId’s proofread api-failure flag, and the global aggregate.
| Name | Type | Default |
|---|---|---|
editorId | string | |
value | boolean |
setProofReadLoadingFor
Raises or clears editorId’s proofread loading flag, and the global aggregate.
| Name | Type | Default |
|---|---|---|
editorId | string | |
value | boolean |
setTocBreaksStore
Replaces the TOC row-break map.
| Name | Type | Default |
|---|---|---|
idOrState | string | EditorState | |
breaks | Map<string, TOCbreakEntry[]> |
setTOCstore
Replaces the editor’s TOC state.
| Name | Type | Default |
|---|---|---|
idOrState | string | EditorState | |
toc | TOCstate |
unregisterRootEditorView
Drops a main editor’s view. Called on unmount.
| Name | Type | Default |
|---|---|---|
id | string |
userPreferences
Global user-preference atoms, shared by every editor. All but the proofread
status flags persist to localStorage. Set startup defaults with
initUserPreferences().
Types
ActiveFloatingBox
The text box being edited in one main editor. at is the viewport point to
put the caret at (a double-click), null for the start of the box. focus
false leaves focus where it is (search navigation).
| Name | Type | Default |
|---|---|---|
boxId | string | |
at | { left: number; top: number; } | null | |
focus | boolean |
FloatingBoxEditorKey
Identifies the text box a sub-editor is bound to, and the main editor it belongs to.
| Name | Type | Default |
|---|---|---|
boxId | string | |
mainEditorId | string |
HeaderFooterEditorKey
Identifies which header/footer content a sub-editor is bound to.
| Name | Type | Default |
|---|---|---|
sectionId | string | |
target | "header" | "footer" | |
variant | HeaderFooterVariant |
Other exports
| Export | Type | Description |
|---|---|---|
ARMED_MODE_KEYS | readonly ["formatPainter", "highlight"] | The modes that can be armed. ArmedModeKey is its element type. |
ArmedModeKey | "formatPainter" | "highlight" | |
UserPreferenceKey | "showOutline" | "showRuler" | "showComments" | "displayUnits" | "proofReadEnabled" | "zoomLevel" | "trackChanges" | "proofReadLoading" | "proofReadApiFailed" |