@sobree/core 0.1.27 → 0.1.29
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.
- package/dist/doc/mutations/blocks.d.ts +14 -0
- package/dist/doc/mutations/index.d.ts +38 -0
- package/dist/doc/mutations/numbering.d.ts +8 -0
- package/dist/doc/mutations/paragraphs.d.ts +13 -0
- package/dist/doc/mutations/sections.d.ts +40 -0
- package/dist/doc/mutations/styles.d.ts +14 -0
- package/dist/doc/mutations/types.d.ts +57 -0
- package/dist/doc/types/block.d.ts +182 -0
- package/dist/doc/types/document.d.ts +122 -0
- package/dist/doc/types/drawing.d.ts +141 -0
- package/dist/doc/types/headersFooters.d.ts +7 -0
- package/dist/doc/types/index.d.ts +34 -0
- package/dist/doc/types/numbering.d.ts +25 -0
- package/dist/doc/types/paragraph.d.ts +82 -0
- package/dist/doc/types/parts.d.ts +18 -0
- package/dist/doc/types/revisions.d.ts +8 -0
- package/dist/doc/types/runs.d.ts +178 -0
- package/dist/doc/types/sections.d.ts +67 -0
- package/dist/doc/types/styles.d.ts +32 -0
- package/dist/doc/types.d.ts +7 -842
- package/dist/editor/internal/applyMutation.d.ts +9 -0
- package/dist/editor/internal/mutations.d.ts +4 -64
- package/dist/editor/internal/readbackMerge.d.ts +27 -0
- package/dist/editor/ops/blocks.d.ts +5 -4
- package/dist/editor/view/docSerialize/block.d.ts +21 -0
- package/dist/editor/view/docSerialize/index.d.ts +12 -0
- package/dist/headless.d.ts +10 -4
- package/dist/index.js +4721 -4664
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { EditResult } from '../../doc/api';
|
|
2
|
+
import { DocumentMutationResult, MutationInput } from '../../doc/mutations';
|
|
3
|
+
import { EditorContext } from '../context';
|
|
4
|
+
/** Build the engine input from the live editor context. The `BlockRegistry`
|
|
5
|
+
* satisfies `BlockRegistryView` directly. */
|
|
6
|
+
export declare function mutationInput(ctx: EditorContext): MutationInput;
|
|
7
|
+
/** Apply a mutation result through `ctx.commit`, or pass the failure
|
|
8
|
+
* through unchanged. */
|
|
9
|
+
export declare function applyMutation<T>(ctx: EditorContext, result: DocumentMutationResult<T>): EditResult<T>;
|
|
@@ -1,67 +1,8 @@
|
|
|
1
1
|
import { RunPropertiesPatch } from '../../doc/runs';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
* applies these to the BlockRegistry after committing the new doc:
|
|
7
|
-
* `insert` adds an id, `remove` drops one, `bump` keeps the same id
|
|
8
|
-
* but increments its version.
|
|
9
|
-
*/
|
|
10
|
-
export type Mutation = {
|
|
11
|
-
type: "bump";
|
|
12
|
-
index: number;
|
|
13
|
-
} | {
|
|
14
|
-
type: "insert";
|
|
15
|
-
index: number;
|
|
16
|
-
} | {
|
|
17
|
-
type: "remove";
|
|
18
|
-
index: number;
|
|
19
|
-
};
|
|
20
|
-
/**
|
|
21
|
-
* Index in `sections` of the section that ENDS at the section_break at
|
|
22
|
-
* `breakIndex`. Sections are 1:1 with section_breaks; the first
|
|
23
|
-
* section ends at the first break (or at the end of `body` if there's
|
|
24
|
-
* no break).
|
|
25
|
-
*
|
|
26
|
-
* body = [p, p, break, p, break, p]
|
|
27
|
-
* sections = [s0, s1, s2]
|
|
28
|
-
*
|
|
29
|
-
* breakIndex = 2 → 0 (the first break ends section 0)
|
|
30
|
-
* breakIndex = 4 → 1 (the second break ends section 1)
|
|
31
|
-
*/
|
|
32
|
-
export declare function removedSectionIndex(body: readonly Block[], breakIndex: number): number;
|
|
33
|
-
/**
|
|
34
|
-
* Drop the section at `endingIndex + 1` from `sections` — that's the
|
|
35
|
-
* section the now-removed break STARTED. The section ENDED by the
|
|
36
|
-
* removed break (at `endingIndex`) absorbs whatever content used to
|
|
37
|
-
* belong to its successor. Properties of the surviving section are
|
|
38
|
-
* preserved verbatim; nothing about the removed section's settings is
|
|
39
|
-
* carried over.
|
|
40
|
-
*
|
|
41
|
-
* If `sections` doesn't have a successor (the removed break was the
|
|
42
|
-
* last one and there's only one section), the array is returned
|
|
43
|
-
* unchanged.
|
|
44
|
-
*/
|
|
45
|
-
export declare function mergeSectionsAcross(sections: readonly SectionProperties[], endingIndex: number): SectionProperties[];
|
|
46
|
-
/**
|
|
47
|
-
* Merge a `ParagraphPropertiesPatch` into existing properties.
|
|
48
|
-
* `undefined` in the patch removes a field; everything else
|
|
49
|
-
* overwrites.
|
|
50
|
-
*/
|
|
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;
|
|
2
|
+
import { SobreeDocument } from '../../doc/types';
|
|
3
|
+
import { WrapTag } from '../types';
|
|
4
|
+
export type { Mutation } from '../../doc/mutations';
|
|
5
|
+
export { mergeNamedStyle, mergeParagraphProps, mergeSectionProps, mergeSectionsAcross, removedSectionIndex, } from '../../doc/mutations';
|
|
65
6
|
/**
|
|
66
7
|
* Map a semantic "wrap" tag to the run-property patch that achieves it.
|
|
67
8
|
* Same mapping the browser editor uses for toolbar buttons.
|
|
@@ -73,4 +14,3 @@ export declare function mimeToExtension(mime: string): string;
|
|
|
73
14
|
export declare function allocateMediaPath(doc: SobreeDocument, ext: string): string;
|
|
74
15
|
/** Convert pixels (CSS @ 96 dpi) to OOXML's EMU (914400 per inch). */
|
|
75
16
|
export declare function pxToEmu(px: number): number;
|
|
76
|
-
export type { RunProperties };
|
|
@@ -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[];
|
|
@@ -4,9 +4,10 @@ import { EditorContext } from '../context';
|
|
|
4
4
|
import { ParagraphPropertiesPatch } from '../types';
|
|
5
5
|
/**
|
|
6
6
|
* Block-level mutations: replace / insert / delete whole blocks and
|
|
7
|
-
* patch paragraph properties.
|
|
8
|
-
* `
|
|
9
|
-
*
|
|
7
|
+
* patch paragraph properties. The plain document transform lives in the
|
|
8
|
+
* shared `doc/mutations` engine (lock check + body splice + section-break
|
|
9
|
+
* merge); these wrappers add the browser-only track-changes behaviour and
|
|
10
|
+
* apply the engine's patch through `ctx.commit`. Track-changes mode stamps
|
|
10
11
|
* paragraph insert/delete markers instead of moving content outright.
|
|
11
12
|
*/
|
|
12
13
|
/** Replace the block at `target`'s index with `block`. */
|
|
@@ -35,7 +36,7 @@ export declare function insertBlockAfter(ctx: EditorContext, target: BlockRef, b
|
|
|
35
36
|
* `ins` marker (a paragraph the user themselves just created), the block
|
|
36
37
|
* is removed outright — cancelling an un-committed insert, matching the
|
|
37
38
|
* inline `deleteRange` semantics. Non-paragraph blocks (tables, section
|
|
38
|
-
* breaks) bypass tracking in v1 — they remove plainly.
|
|
39
|
+
* breaks) bypass tracking in v1 — they remove plainly via the engine.
|
|
39
40
|
*/
|
|
40
41
|
export declare function deleteBlock(ctx: EditorContext, target: BlockRef): EditResult<void>;
|
|
41
42
|
/** Merge a patch into each target paragraph's properties. */
|
|
@@ -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
|
+
};
|
package/dist/headless.d.ts
CHANGED
|
@@ -43,9 +43,10 @@ import { History } from './history';
|
|
|
43
43
|
* parsing, etc. HeadlessSobree skips all that — if you need
|
|
44
44
|
* them, mount a real Editor.
|
|
45
45
|
* - A *table editor*. The browser `Editor` has a rich table API
|
|
46
|
-
* (`editor.table.insertRow`, etc.). HeadlessSobree
|
|
47
|
-
*
|
|
48
|
-
* `replaceBlock`
|
|
46
|
+
* (`editor.table.insertRow`, etc.). HeadlessSobree keeps table
|
|
47
|
+
* edits at the block boundary today — operate on `Table` blocks
|
|
48
|
+
* directly via `replaceBlock` unless a dedicated headless table
|
|
49
|
+
* API is added.
|
|
49
50
|
*
|
|
50
51
|
* # Origin tagging
|
|
51
52
|
*
|
|
@@ -176,7 +177,12 @@ export declare class HeadlessSobree {
|
|
|
176
177
|
* in the local cache. No-op when no `blobStore` is configured.
|
|
177
178
|
*/
|
|
178
179
|
ensurePartsLoaded(): Promise<void>;
|
|
179
|
-
|
|
180
|
+
/** Build the engine input from this peer's live state. The
|
|
181
|
+
* `BlockRegistry` satisfies `BlockRegistryView` directly. */
|
|
182
|
+
private mutationInput;
|
|
183
|
+
/** Apply a mutation engine result through `commit`, or pass the failure
|
|
184
|
+
* through unchanged. */
|
|
185
|
+
private applyPatch;
|
|
180
186
|
private commit;
|
|
181
187
|
private fireChange;
|
|
182
188
|
private summariseBlock;
|