@sobree/core 0.1.15 → 0.1.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -23,3 +23,4 @@ export { heading, paragraph, sectionBreak } from './block';
23
23
  export { columnBreak, commentRef, emphasis, field, footnoteRef, hyperlink, image, type ImageOptions, pageBreak, softBreak, strong, tab, text, } from './inline';
24
24
  export { type CellProperties, type TableOptions, table, tableCell, tableRow } from './table';
25
25
  export { type NamedStyleOptions, namedStyle } from './style';
26
+ export { type NumberingLevelOptions, bulletDefinition, numberingDefinition, numberingLevel, orderedDefinition, } from './numbering';
@@ -0,0 +1,19 @@
1
+ import { NumberingDefinition, NumberingLevel, ParagraphIndent, RunProperties } from '../types';
2
+ export interface NumberingLevelOptions {
3
+ restart?: number;
4
+ paragraphIndent?: ParagraphIndent;
5
+ /** Run properties for the marker glyph/number itself. */
6
+ runDefaults?: RunProperties;
7
+ }
8
+ /** One indent level of a list. `format` is `bullet` / `decimal` /
9
+ * `lowerRoman` / `upperLetter` / …; `text` is the marker template
10
+ * (`%1.`, `(%1)`, or a literal bullet glyph). */
11
+ export declare function numberingLevel(level: number, format: string, text: string, options?: NumberingLevelOptions): NumberingLevel;
12
+ /** A numbering definition: a `numId` (referenced from paragraphs) plus its
13
+ * level formats. */
14
+ export declare function numberingDefinition(numId: number, levels: NumberingLevel[]): NumberingDefinition;
15
+ /** A bullet list of `levels` levels (default 3), cycling • ◦ ▪. */
16
+ export declare function bulletDefinition(numId: number, levels?: number): NumberingDefinition;
17
+ /** An ordered list of `levels` levels (default 3), each `%1.` decimal,
18
+ * restarting at the level above. */
19
+ export declare function orderedDefinition(numId: number, levels?: number): NumberingDefinition;
@@ -6,14 +6,17 @@ import { EmbedFontFaces, EmbedFontOptions } from '../fonts';
6
6
  import { History } from '../history';
7
7
  import { BlockRegistry } from './internal/blockRegistry';
8
8
  import { countBlocks } from './internal/positionMap';
9
+ import { EditorNumbering } from './numbering';
10
+ import { EditorSections } from './sections';
9
11
  import { EditorSelection } from './selection';
12
+ import { EditorStyles } from './styles';
10
13
  import { EditorTable } from './table';
11
- import { ApiRangeType, BlockInfo, ChangePayload, CommandBus, CommandDefinition, CommandSnapshot, EditorEvent, EditorEventPayload, EditorOptions, KeyDownPayload, OutlineItem, ParagraphPropertiesPatch, RevisionSpan, SelectionPayload, TrackChangesState, Unsubscribe, WrapTag } from './types';
14
+ import { ApiRangeType, BlockInfo, ChangePayload, CommandBus, CommandDefinition, CommandSnapshot, EditorEvent, EditorEventPayload, EditorOptions, KeyDownPayload, NamedStylePatch, OutlineItem, ParagraphPropertiesPatch, RevisionSpan, SectionPropertiesPatch, SelectionPayload, TrackChangesState, Unsubscribe, WrapTag } from './types';
12
15
  import * as Y from "yjs";
13
16
  export { EditorCommands } from './commands';
14
17
  export { EditorSelection } from './selection';
15
18
  export type { BlockRef, EditError, EditResult, InlinePosition, Selection };
16
- export type { ApiRangeType, BlockInfo, ChangePayload, CommandBus, CommandDefinition, CommandSnapshot, EditorEvent, EditorEventPayload, EditorOptions, KeyDownPayload, OutlineItem, ParagraphPropertiesPatch, RevisionSpan, SelectionPayload, TrackChangesState, Unsubscribe, WrapTag, };
19
+ export type { ApiRangeType, BlockInfo, ChangePayload, CommandBus, CommandDefinition, CommandSnapshot, EditorEvent, EditorEventPayload, EditorOptions, KeyDownPayload, NamedStylePatch, OutlineItem, ParagraphPropertiesPatch, RevisionSpan, SectionPropertiesPatch, SelectionPayload, TrackChangesState, Unsubscribe, WrapTag, };
17
20
  export type { CellRef, InsertAt, InsertColumnOpts, InsertRowOpts, MergeCellsOpts, } from './types';
18
21
  export { runsLength } from '../doc/runs';
19
22
  export type { RunPropertiesPatch };
@@ -42,6 +45,27 @@ export declare class Editor {
42
45
  * and inherits optimistic-lock checking via `replaceBlock`.
43
46
  */
44
47
  readonly table: EditorTable;
48
+ /**
49
+ * Section-level edit operations — page size / margins, columns,
50
+ * header/footer references, vertical alignment. Grouped here (rather
51
+ * than as flat `Editor` methods) so the facade stays thin as the
52
+ * edit-op surface grows. Every method returns an `EditResult`.
53
+ */
54
+ readonly sections: EditorSections;
55
+ /**
56
+ * Named-style edit operations — define / update / remove the style
57
+ * definitions content resolves through. Applying a `styleId` to content
58
+ * is `applyBlockProperties` / `applyRunProperties`; this manages the
59
+ * definitions themselves. Every method returns an `EditResult`.
60
+ */
61
+ readonly styles: EditorStyles;
62
+ /**
63
+ * Numbering / list-definition edit operations — define / update / remove
64
+ * the list formats paragraphs reference by `numId`. Pointing a paragraph
65
+ * at a list is `applyBlockProperties`; this manages the definitions.
66
+ * Every method returns an `EditResult`.
67
+ */
68
+ readonly numbering: EditorNumbering;
45
69
  /**
46
70
  * Named-command registry — the coordination point between plugins.
47
71
  * Plugins register commands on attach and unregister on detach;
@@ -1,6 +1,6 @@
1
1
  import { RunPropertiesPatch } from '../../doc/runs';
2
- import { Block, ParagraphProperties, RunProperties, SectionProperties, SobreeDocument } from '../../doc/types';
3
- import { ParagraphPropertiesPatch, WrapTag } from '../types';
2
+ import { Block, NamedStyle, ParagraphProperties, RunProperties, SectionProperties, SobreeDocument } from '../../doc/types';
3
+ import { NamedStylePatch, ParagraphPropertiesPatch, SectionPropertiesPatch, WrapTag } from '../types';
4
4
  /**
5
5
  * One registry-level operation produced by a mutation. The caller
6
6
  * applies these to the BlockRegistry after committing the new doc:
@@ -49,6 +49,19 @@ export declare function mergeSectionsAcross(sections: readonly SectionProperties
49
49
  * overwrites.
50
50
  */
51
51
  export declare function mergeParagraphProps(prev: ParagraphProperties, patch: ParagraphPropertiesPatch): ParagraphProperties;
52
+ /**
53
+ * Merge a {@link SectionPropertiesPatch} onto existing section properties.
54
+ * `pageSize` / `pageMargins` are FIELD-merged (a partial stays valid); the
55
+ * other fields replace wholesale. For the optional fields (`columns`,
56
+ * `titlePage`, `type`, `vAlign`) an explicit `undefined` clears them, while
57
+ * the required `headerRefs` / `footerRefs` only replace when present.
58
+ */
59
+ export declare function mergeSectionProps(prev: SectionProperties, patch: SectionPropertiesPatch): SectionProperties;
60
+ /** Merge a {@link NamedStylePatch} onto an existing style. Each present
61
+ * field replaces the style's field wholesale; an explicit `undefined`
62
+ * clears an OPTIONAL field. The required `type` / `displayName` are never
63
+ * cleared (an undefined for them is ignored). */
64
+ export declare function mergeNamedStyle(prev: NamedStyle, patch: NamedStylePatch): NamedStyle;
52
65
  /**
53
66
  * Map a semantic "wrap" tag to the run-property patch that achieves it.
54
67
  * Same mapping the browser editor uses for toolbar buttons.
@@ -0,0 +1,14 @@
1
+ import { EditResult } from '../doc/api';
2
+ import { NumberingDefinition, NumberingLevel } from '../doc/types';
3
+ import { EditorContext } from './context';
4
+ export declare class EditorNumbering {
5
+ private readonly ctx;
6
+ constructor(ctx: EditorContext);
7
+ /** Add a new numbering definition. Fails if `def.numId` already exists. */
8
+ define(def: NumberingDefinition): EditResult<void>;
9
+ /** Replace the levels of the definition with `numId`. Fails if missing. */
10
+ update(numId: number, levels: NumberingLevel[]): EditResult<void>;
11
+ /** Remove the definition with `numId`. Fails if missing. Paragraphs that
12
+ * still reference it render without a marker. */
13
+ remove(numId: number): EditResult<void>;
14
+ }
@@ -0,0 +1,15 @@
1
+ import { EditResult } from '../doc/api';
2
+ import { EditorContext } from './context';
3
+ import { SectionPropertiesPatch } from './types';
4
+ export declare class EditorSections {
5
+ private readonly ctx;
6
+ constructor(ctx: EditorContext);
7
+ /**
8
+ * Merge a patch into the section at `index`: page size / margins,
9
+ * columns, header/footer refs, vertical alignment. `pageSize` /
10
+ * `pageMargins` are field-merged (a partial stays valid); other fields
11
+ * replace wholesale, and an explicit `undefined` clears an optional one.
12
+ * Re-renders page geometry; undo-integrated.
13
+ */
14
+ setProperties(index: number, patch: SectionPropertiesPatch): EditResult<void>;
15
+ }
@@ -0,0 +1,16 @@
1
+ import { EditResult } from '../doc/api';
2
+ import { NamedStyle } from '../doc/types';
3
+ import { EditorContext } from './context';
4
+ import { NamedStylePatch } from './types';
5
+ export declare class EditorStyles {
6
+ private readonly ctx;
7
+ constructor(ctx: EditorContext);
8
+ /** Add a new style. Fails if a style with the same `id` already exists
9
+ * (use {@link update} to change one). */
10
+ define(style: NamedStyle): EditResult<void>;
11
+ /** Merge a patch into the style with `id`. Fails if no such style. */
12
+ update(id: string, patch: NamedStylePatch): EditResult<void>;
13
+ /** Remove the style with `id`. Fails if no such style. Content that
14
+ * still references it falls back to the cascade's defaults. */
15
+ remove(id: string): EditResult<void>;
16
+ }
@@ -1,7 +1,7 @@
1
1
  import { BlobStore } from '../blob';
2
2
  import { Range as ApiRange, BlockRef, EditResult, InlinePosition, Selection } from '../doc/api';
3
3
  import { RunPropertiesPatch } from '../doc/runs';
4
- import { Block, ParagraphAlignment, ParagraphProperties, SobreeDocument } from '../doc/types';
4
+ import { Block, HeaderFooterRef, NamedStyle, PageMargins, PageSize, ParagraphAlignment, ParagraphProperties, SectionColumns, SectionProperties, SobreeDocument } from '../doc/types';
5
5
  /**
6
6
  * Editor-surface types — the public type vocabulary of the `Editor`
7
7
  * façade (events, payloads, command bus, options, tracked-change spans).
@@ -121,6 +121,32 @@ export interface OutlineItem {
121
121
  export type ParagraphPropertiesPatch = {
122
122
  [K in keyof ParagraphProperties]?: ParagraphProperties[K] | undefined;
123
123
  };
124
+ /**
125
+ * Patch for a section's properties (page geometry, columns, header/footer
126
+ * refs, vertical alignment). `pageSize` / `pageMargins` are FIELD-merged
127
+ * into the existing values (so a partial — e.g. just `orientation` or
128
+ * `topTwips` — stays valid); every other field REPLACES wholesale, and an
129
+ * explicit `undefined` on an optional field clears it.
130
+ */
131
+ export interface SectionPropertiesPatch {
132
+ pageSize?: Partial<PageSize>;
133
+ pageMargins?: Partial<PageMargins>;
134
+ columns?: SectionColumns | undefined;
135
+ headerRefs?: HeaderFooterRef[];
136
+ footerRefs?: HeaderFooterRef[];
137
+ titlePage?: boolean | undefined;
138
+ type?: SectionProperties["type"];
139
+ vAlign?: SectionProperties["vAlign"];
140
+ }
141
+ /**
142
+ * Patch for an existing named style (everything except its `id`). Each
143
+ * present field replaces the style's corresponding field wholesale; an
144
+ * explicit `undefined` clears an optional one. The required `type` /
145
+ * `displayName` are never cleared.
146
+ */
147
+ export type NamedStylePatch = {
148
+ [K in keyof Omit<NamedStyle, "id">]?: NamedStyle[K] | undefined;
149
+ };
124
150
  export type WrapTag = "sup" | "sub" | "strong" | "em" | "u" | "s" | "mark";
125
151
  /** The slice of selection state plugins read (see {@link EditorLike}). */
126
152
  export interface EditorSelectionLike {
@@ -1,7 +1,7 @@
1
1
  import { BlobCache, BlobStore } from './blob';
2
2
  import { BlockRef, EditError, EditResult, Selection } from './doc/api';
3
- import { Block, ParagraphAlignment, ParagraphProperties, SobreeDocument } from './doc/types';
4
- import { ParagraphPropertiesPatch, BlockInfo, CommandBus, OutlineItem } from './editor';
3
+ import { Block, NamedStyle, NumberingDefinition, NumberingLevel, ParagraphAlignment, ParagraphProperties, SobreeDocument } from './doc/types';
4
+ import { ParagraphPropertiesPatch, BlockInfo, CommandBus, NamedStylePatch, OutlineItem, SectionPropertiesPatch } from './editor';
5
5
  import { History } from './history';
6
6
  /**
7
7
  * HeadlessSobree — a no-DOM Sobree peer for LLM agents, automation,
@@ -148,6 +148,22 @@ export declare class HeadlessSobree {
148
148
  deleteBlock(target: BlockRef): EditResult<void>;
149
149
  /** Merge a patch into each target paragraph's properties. */
150
150
  applyBlockProperties(targets: BlockRef[], patch: ParagraphPropertiesPatch): EditResult<void>;
151
+ /** Merge a patch into a section's properties (page geometry, columns,
152
+ * header/footer refs, vertical alignment). `sectionIndex` is the
153
+ * section's position in the document's `sections` array. */
154
+ applySectionProperties(sectionIndex: number, patch: SectionPropertiesPatch): EditResult<void>;
155
+ /** Add a new named style. Fails if `style.id` already exists. */
156
+ defineStyle(style: NamedStyle): EditResult<void>;
157
+ /** Merge a patch into the style with `id`. Fails if no such style. */
158
+ updateStyle(id: string, patch: NamedStylePatch): EditResult<void>;
159
+ /** Remove the style with `id`. Fails if no such style. */
160
+ removeStyle(id: string): EditResult<void>;
161
+ /** Add a new numbering definition. Fails if `def.numId` already exists. */
162
+ defineNumbering(def: NumberingDefinition): EditResult<void>;
163
+ /** Replace the levels of the definition with `numId`. Fails if missing. */
164
+ updateNumbering(numId: number, levels: NumberingLevel[]): EditResult<void>;
165
+ /** Remove the definition with `numId`. Fails if missing. */
166
+ removeNumbering(numId: number): EditResult<void>;
151
167
  on<E extends HeadlessEvent>(event: E, cb: (payload: HeadlessChangePayload) => void): HeadlessUnsubscribe;
152
168
  destroy(): void;
153
169
  private allBlockIds;