@sobree/core 0.1.26 → 0.1.28

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.
@@ -1,11 +1,11 @@
1
- import { AnchoredFrame, Block } from '../../doc/types';
1
+ import { AnchoredFrame, Block, SectionProperties } from '../../doc/types';
2
2
  /**
3
3
  * Splice flowable frames' content into `body` at their anchor
4
4
  * paragraph and drop them from the overlay set. Returns the rebuilt
5
5
  * body and the frames that remain overlays (with `paragraphIndex`
6
6
  * remapped to the new body positions). Pure — no mutation of inputs.
7
7
  */
8
- export declare function flowDisplacingTextboxes(body: readonly Block[], frames: readonly AnchoredFrame[]): {
8
+ export declare function flowDisplacingTextboxes(body: readonly Block[], frames: readonly AnchoredFrame[], sections: readonly SectionProperties[]): {
9
9
  body: Block[];
10
10
  frames: AnchoredFrame[];
11
11
  };
@@ -0,0 +1,27 @@
1
+ import { Block } from '../../doc/types';
2
+ /**
3
+ * Merge a freshly DOM-serialised body into the previous AST body, preserving
4
+ * everything the contentEditable DOM can't represent.
5
+ *
6
+ * The DOM is a LOSSY projection of the AST: it carries run text and inline
7
+ * marks (bold, colour, font), but NOT block-level properties — paragraph
8
+ * spacing / indent / borders, table style-id / look / cell margins,
9
+ * section-break targets. A text edit changes a block's CONTENT, never those
10
+ * properties, so re-deriving the whole AST from the DOM on every keystroke
11
+ * silently strips them — the document degrades a little with each edit and
12
+ * falls apart on the first re-render (undo / redo / remote).
13
+ *
14
+ * So we keep each previous block and overlay only the re-read content: runs
15
+ * for a paragraph, cell content for a table. Properties survive.
16
+ *
17
+ * Matching a re-read block to its previous block is by stable id (the
18
+ * renderer's `data-block-id`), resolved by the caller — so properties
19
+ * survive structural edits too (Enter / Backspace / paste / reorder), not
20
+ * just same-length typing. A re-read block with no prior match (a freshly
21
+ * inserted block) keeps the DOM block as-is. Falls back to the DOM block
22
+ * whenever kinds or nested shape diverge: structure is the one thing the
23
+ * DOM IS authoritative about.
24
+ */
25
+ export declare function mergeReadbackBlocks(next: readonly Block[], resolvePrev: (index: number) => Block | undefined): Block[];
26
+ /** Positional convenience wrapper: match each block to `prev[i]`. */
27
+ export declare function mergeReadbackPreservingProps(prev: readonly Block[], next: readonly Block[]): Block[];
@@ -10,4 +10,8 @@ import { Block, NamedStyle, NumberingDefinition, SectionProperties } from '../..
10
10
  * `rawParts` is threaded to image rendering so `<img src>` can be
11
11
  * populated from embedded bytes via a blob URL.
12
12
  */
13
- export declare function renderBlocks(blocks: readonly Block[], host: HTMLElement, numbering: readonly NumberingDefinition[], styles?: readonly NamedStyle[], rawParts?: Record<string, Uint8Array>, blockIds?: readonly string[], sections?: readonly SectionProperties[]): void;
13
+ export declare function renderBlocks(blocks: readonly Block[], host: HTMLElement, numbering: readonly NumberingDefinition[], styles?: readonly NamedStyle[], rawParts?: Record<string, Uint8Array>, blockIds?: readonly string[], sections?: readonly SectionProperties[],
14
+ /** Body block indices that carry an anchored frame. Such a block counts
15
+ * as a valid target for a deferred page break even when its body flow is
16
+ * empty — a float-only brochure panel page is still a page. */
17
+ frameAnchoredIndices?: ReadonlySet<number>): void;
@@ -10,6 +10,17 @@ export interface BlockSerializeContext {
10
10
  numId: number;
11
11
  ordered: boolean;
12
12
  } | null;
13
+ /**
14
+ * Running count of section breaks seen so far (across all hosts). The Nth
15
+ * section break transitions to section N — matching the renderer's
16
+ * order-based section assignment — so the count IS the break's
17
+ * `toSectionIndex`. Reconstructing it is load-bearing: the renderer reads
18
+ * a break's page-break-vs-continuous behaviour from `sections[toSectionIndex]`,
19
+ * so a wrong index (e.g. a hardcoded 0) makes a continuous break re-render
20
+ * as a forced page break, exploding the layout on the next re-render
21
+ * (undo/redo/remote).
22
+ */
23
+ sectionBreaks: number;
13
24
  /**
14
25
  * Capture each paragraph's effective base run style (from the rendered
15
26
  * `<p>`'s inline font) into `ParagraphProperties.runDefaults`.
@@ -25,5 +36,15 @@ export interface BlockSerializeContext {
25
36
  * styles, which must stay style-linked across edits.
26
37
  */
27
38
  captureRunDefaults?: boolean;
39
+ /**
40
+ * Optional sink for each emitted block's source DOM element (or `null`
41
+ * for a bare text node), kept strictly parallel to the returned blocks.
42
+ * The editor reads each element's stable `data-block-id` to match a
43
+ * re-read block back to its previous AST block — so block-level
44
+ * properties (spacing, table style, …) survive a read-back across plain
45
+ * typing AND structural edits, where positional matching can't. Left
46
+ * unset for callers that don't need provenance (frame read-back, tests).
47
+ */
48
+ sources?: (HTMLElement | null)[];
28
49
  }
29
50
  export declare function blocksFromNodes(nodes: readonly Node[], ctx: BlockSerializeContext): Block[];
@@ -15,3 +15,15 @@ export interface SerializeHostsOptions {
15
15
  captureRunDefaults?: boolean;
16
16
  }
17
17
  export declare function serializeHostsToDocument(hosts: readonly HTMLElement[], options?: SerializeHostsOptions): SobreeDocument;
18
+ /**
19
+ * Like {@link serializeHostsToDocument}, but also returns each block's
20
+ * source DOM element (parallel to `document.body`, `null` for bare text
21
+ * nodes). The editor reads each element's stable `data-block-id` to match a
22
+ * re-read block back to its previous AST block — so block-level properties
23
+ * the contentEditable DOM can't carry survive the read-back across plain
24
+ * typing AND structural edits (Enter / Backspace / paste / reorder).
25
+ */
26
+ export declare function serializeHostsWithSources(hosts: readonly HTMLElement[], options?: SerializeHostsOptions): {
27
+ document: SobreeDocument;
28
+ sources: (HTMLElement | null)[];
29
+ };