@sobree/core 0.1.0
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/LICENSE +21 -0
- package/README.md +106 -0
- package/dist/__vite-browser-external-DYxpcVy9.js +5 -0
- package/dist/__vite-browser-external-DYxpcVy9.js.map +1 -0
- package/dist/blob/cache.d.ts +69 -0
- package/dist/blob/fetch.d.ts +18 -0
- package/dist/blob/hash.d.ts +13 -0
- package/dist/blob/index.d.ts +33 -0
- package/dist/blob/memory.d.ts +2 -0
- package/dist/blob/types.d.ts +80 -0
- package/dist/createSobree.d.ts +132 -0
- package/dist/doc/api.d.ts +132 -0
- package/dist/doc/builders.d.ts +42 -0
- package/dist/doc/pageSetupBridge.d.ts +26 -0
- package/dist/doc/parts.d.ts +18 -0
- package/dist/doc/runs.d.ts +47 -0
- package/dist/doc/styles.d.ts +19 -0
- package/dist/doc/types.d.ts +800 -0
- package/dist/doc/walk.d.ts +30 -0
- package/dist/docx/export/contentTypes.d.ts +35 -0
- package/dist/docx/export/context.d.ts +59 -0
- package/dist/docx/export/document.d.ts +19 -0
- package/dist/docx/export/drawings.d.ts +10 -0
- package/dist/docx/export/headers.d.ts +19 -0
- package/dist/docx/export/index.d.ts +14 -0
- package/dist/docx/export/runs.d.ts +8 -0
- package/dist/docx/export/styles.d.ts +8 -0
- package/dist/docx/export/zip.d.ts +13 -0
- package/dist/docx/import/anchoredFrames.d.ts +34 -0
- package/dist/docx/import/comments.d.ts +3 -0
- package/dist/docx/import/document.d.ts +57 -0
- package/dist/docx/import/flowFrames.d.ts +11 -0
- package/dist/docx/import/footnotes.d.ts +3 -0
- package/dist/docx/import/headers.d.ts +50 -0
- package/dist/docx/import/index.d.ts +12 -0
- package/dist/docx/import/inlineFrames.d.ts +62 -0
- package/dist/docx/import/numbering.d.ts +2 -0
- package/dist/docx/import/paragraph.d.ts +24 -0
- package/dist/docx/import/paragraphs.d.ts +27 -0
- package/dist/docx/import/rels.d.ts +5 -0
- package/dist/docx/import/runs.d.ts +64 -0
- package/dist/docx/import/settings.d.ts +48 -0
- package/dist/docx/import/styles.d.ts +3 -0
- package/dist/docx/import/tables.d.ts +12 -0
- package/dist/docx/import/unzip.d.ts +13 -0
- package/dist/docx/shared/namespaces.d.ts +31 -0
- package/dist/docx/shared/pageSize.d.ts +27 -0
- package/dist/docx/shared/shading.d.ts +2 -0
- package/dist/docx/shared/units.d.ts +35 -0
- package/dist/docx/shared/xml.d.ts +29 -0
- package/dist/docx/types.d.ts +98 -0
- package/dist/editor/index.d.ts +1078 -0
- package/dist/editor/internal/blockRegistry.d.ts +91 -0
- package/dist/editor/internal/mutations.d.ts +63 -0
- package/dist/editor/internal/positionMap.d.ts +35 -0
- package/dist/editor/table.d.ts +96 -0
- package/dist/editor/view/docRenderer/anchorLayer.d.ts +26 -0
- package/dist/editor/view/docRenderer/block.d.ts +13 -0
- package/dist/editor/view/docRenderer/fontFallback.d.ts +28 -0
- package/dist/editor/view/docRenderer/index.d.ts +18 -0
- package/dist/editor/view/docRenderer/inline.d.ts +15 -0
- package/dist/editor/view/docRenderer/inlineFrame.d.ts +4 -0
- package/dist/editor/view/docRenderer/lists.d.ts +28 -0
- package/dist/editor/view/docRenderer/paragraph.d.ts +2 -0
- package/dist/editor/view/docRenderer/properties.d.ts +2 -0
- package/dist/editor/view/docRenderer/table.d.ts +15 -0
- package/dist/editor/view/docRenderer/units.d.ts +48 -0
- package/dist/editor/view/docSerialize/block.d.ts +14 -0
- package/dist/editor/view/docSerialize/index.d.ts +8 -0
- package/dist/editor/view/docSerialize/inline.d.ts +11 -0
- package/dist/editor/view/docSerialize/table.d.ts +12 -0
- package/dist/editor/view/imageResize.d.ts +16 -0
- package/dist/embed/floatingCorner.d.ts +44 -0
- package/dist/embed/viewport.d.ts +133 -0
- package/dist/fonts/embedAPI.d.ts +33 -0
- package/dist/fonts/emit.d.ts +24 -0
- package/dist/fonts/fontFaceRegistry.d.ts +20 -0
- package/dist/fonts/fsType.d.ts +36 -0
- package/dist/fonts/index.d.ts +19 -0
- package/dist/fonts/liveness.d.ts +2 -0
- package/dist/fonts/odttf.d.ts +33 -0
- package/dist/fonts/parse.d.ts +29 -0
- package/dist/fonts/types.d.ts +52 -0
- package/dist/headless.d.ts +168 -0
- package/dist/history/history.d.ts +100 -0
- package/dist/history/index.d.ts +4 -0
- package/dist/history/types.d.ts +54 -0
- package/dist/index.css +1 -0
- package/dist/index.d.ts +52 -0
- package/dist/index.js +10561 -0
- package/dist/index.js.map +1 -0
- package/dist/markdown/parse.d.ts +6 -0
- package/dist/pagination/cost.d.ts +32 -0
- package/dist/pagination/index.d.ts +2 -0
- package/dist/pagination/paginate.d.ts +10 -0
- package/dist/pagination/postConditions.d.ts +10 -0
- package/dist/pagination/types.d.ts +94 -0
- package/dist/paperStack/pageSetup.d.ts +42 -0
- package/dist/paperStack/paginationAdapter/buildItems.d.ts +19 -0
- package/dist/paperStack/paginationAdapter/distribute.d.ts +23 -0
- package/dist/paperStack/paginationAdapter/index.d.ts +18 -0
- package/dist/paperStack/paginationAdapter/paragraphLines.d.ts +23 -0
- package/dist/paperStack/paginationAdapter/splitList.d.ts +19 -0
- package/dist/paperStack/paginationAdapter/splitParagraph.d.ts +21 -0
- package/dist/paperStack/paginationAdapter/types.d.ts +30 -0
- package/dist/paperStack/paper.d.ts +107 -0
- package/dist/paperStack/paperStack.d.ts +245 -0
- package/dist/plugin.d.ts +24 -0
- package/dist/plugins/marks.d.ts +49 -0
- package/dist/plugins/sections.d.ts +15 -0
- package/dist/presence/attach.d.ts +48 -0
- package/dist/presence/awareness.d.ts +28 -0
- package/dist/presence/index.d.ts +19 -0
- package/dist/presence/overlay.d.ts +28 -0
- package/dist/presence/state.d.ts +36 -0
- package/dist/sobree.d.ts +211 -0
- package/dist/tokens.css +144 -0
- package/dist/util/selection.d.ts +13 -0
- package/dist/ydoc/apply.d.ts +68 -0
- package/dist/ydoc/index.d.ts +18 -0
- package/dist/ydoc/project.d.ts +41 -0
- package/dist/ydoc/runs.d.ts +51 -0
- package/dist/ydoc/schema.d.ts +123 -0
- package/dist/ydoc/seed.d.ts +45 -0
- package/dist/ydoc/textDiff.d.ts +59 -0
- package/dist/zoneEdit/index.d.ts +22 -0
- package/package.json +61 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Block, Paragraph, SobreeDocument } from '../doc/types';
|
|
2
|
+
import * as Y from "yjs";
|
|
3
|
+
/**
|
|
4
|
+
* Populate a fresh (or reset) Y.Doc with the contents of a SobreeDocument.
|
|
5
|
+
*
|
|
6
|
+
* Caller supplies the parallel `ids` array — these become the stable
|
|
7
|
+
* block ids stored in each block's Y.Map. The Editor's BlockRegistry
|
|
8
|
+
* generates them.
|
|
9
|
+
*
|
|
10
|
+
* Wraps the seed in `Y.Doc.transact` with `origin = "seed"` so a
|
|
11
|
+
* UndoManager scoped to the local origin won't push the seed onto its
|
|
12
|
+
* stack.
|
|
13
|
+
*/
|
|
14
|
+
export declare function seedYDoc(ydoc: Y.Doc, doc: SobreeDocument, ids: readonly string[]): void;
|
|
15
|
+
/**
|
|
16
|
+
* Build a *skeleton* block Y.Map — id + kind discriminator + empty
|
|
17
|
+
* containers, no content. Content lands in `populateBlockContent`
|
|
18
|
+
* after the map is integrated. Used internally by `seedYDoc` and by
|
|
19
|
+
* `applyDocumentToYDoc` (`buildBlockYMap` is a one-shot wrapper that
|
|
20
|
+
* does both phases on an orphan map; only safe for callers that will
|
|
21
|
+
* insert it inside a transact within the same call stack).
|
|
22
|
+
*/
|
|
23
|
+
export declare function buildSkeletonBlockYMap(id: string, block: Block): Y.Map<unknown>;
|
|
24
|
+
/** Populate the content of an *integrated* block Y.Map. */
|
|
25
|
+
export declare function populateBlockContent(map: Y.Map<unknown>, block: Block): void;
|
|
26
|
+
/**
|
|
27
|
+
* Populate paragraph content. Caller guarantees the map is integrated
|
|
28
|
+
* (so its child Y.Text is too).
|
|
29
|
+
*/
|
|
30
|
+
export declare function populateParagraphContent(map: Y.Map<unknown>, block: Paragraph): void;
|
|
31
|
+
/**
|
|
32
|
+
* One-shot block Y.Map builder — skeleton + content in a single call.
|
|
33
|
+
* Only safe inside a `Y.Doc.transact` block where the returned map
|
|
34
|
+
* will be inserted into an integrated parent before any read of its
|
|
35
|
+
* Y.Text. Otherwise prefer the two-phase builders above.
|
|
36
|
+
*
|
|
37
|
+
* Kept for backwards compat with callers that don't yet use the
|
|
38
|
+
* two-phase pattern.
|
|
39
|
+
*/
|
|
40
|
+
export declare function buildBlockYMap(id: string, block: Block): Y.Map<unknown>;
|
|
41
|
+
/**
|
|
42
|
+
* @deprecated Use `populateParagraphContent` (renamed for clarity).
|
|
43
|
+
* Kept as a re-export so callers don't break during migration.
|
|
44
|
+
*/
|
|
45
|
+
export declare const populateParagraphYMap: typeof populateParagraphContent;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { DeltaOp } from './runs';
|
|
2
|
+
/**
|
|
3
|
+
* Compute the minimal Y.Text mutations to bring a Y.Text in sync with
|
|
4
|
+
* a target delta.
|
|
5
|
+
*
|
|
6
|
+
* # Why minimal mutations matter
|
|
7
|
+
*
|
|
8
|
+
* Y.Text is a CRDT — every `insert` / `delete` / `format` becomes a
|
|
9
|
+
* Yjs operation broadcast to peers. The smaller and more targeted the
|
|
10
|
+
* operations, the less chance of conflicting with concurrent edits.
|
|
11
|
+
*
|
|
12
|
+
* Replacing the whole text on every change destroys CRDT semantics:
|
|
13
|
+
* one peer's "delete-all-and-reinsert" wipes whatever the other peer
|
|
14
|
+
* was simultaneously typing. The diff in this module is the
|
|
15
|
+
* difference between "two peers can type in the same paragraph" and
|
|
16
|
+
* "one peer always wins".
|
|
17
|
+
*
|
|
18
|
+
* # Algorithm
|
|
19
|
+
*
|
|
20
|
+
* Three paths in increasing generality:
|
|
21
|
+
*
|
|
22
|
+
* 1. **No-op** — current and target deltas are structurally identical.
|
|
23
|
+
* Skip entirely. Catches the (common) case where a higher-level
|
|
24
|
+
* mutation didn't actually change this paragraph.
|
|
25
|
+
*
|
|
26
|
+
* 2. **Format-only** — same length and same per-position content
|
|
27
|
+
* (chars or embeds), but at least one position has different
|
|
28
|
+
* attributes. Walk and call `format()` for each changed range.
|
|
29
|
+
* This is the case for "bold the selection" — the text content
|
|
30
|
+
* is unchanged, just the marks; using format() instead of
|
|
31
|
+
* delete+reinsert preserves CRDT for any concurrent typing
|
|
32
|
+
* inside the formatted range.
|
|
33
|
+
*
|
|
34
|
+
* 3. **Prefix/suffix replace** — find the longest common prefix and
|
|
35
|
+
* longest common suffix of cells, then `delete()` the differing
|
|
36
|
+
* middle of the old and `insert()` the differing middle of the
|
|
37
|
+
* new. This handles typing (insert at position N), deletion,
|
|
38
|
+
* paste, and any other content-changing edit. Concurrent edits
|
|
39
|
+
* OUTSIDE the changed range are preserved by Y.Text's CRDT.
|
|
40
|
+
*
|
|
41
|
+
* # Cells
|
|
42
|
+
*
|
|
43
|
+
* Both deltas are flattened to a `Cell[]` representation: one cell
|
|
44
|
+
* per character (for string inserts) or per embed (for object inserts).
|
|
45
|
+
* Cells carry the per-position attributes — Y.Text marks that
|
|
46
|
+
* surround the chunk get duplicated onto each cell.
|
|
47
|
+
*
|
|
48
|
+
* This is allocation-heavy for long paragraphs but bounded by
|
|
49
|
+
* paragraph length (rarely > 1000 chars). For Phase 1c we can switch
|
|
50
|
+
* to a streaming diff.
|
|
51
|
+
*/
|
|
52
|
+
import type * as Y from "yjs";
|
|
53
|
+
/**
|
|
54
|
+
* Apply the difference between Y.Text's current state and `targetDelta`
|
|
55
|
+
* as the minimal set of Y.Text mutations. Caller is responsible for
|
|
56
|
+
* wrapping in `Y.Doc.transact` if it wants the changes batched into
|
|
57
|
+
* one transaction with whatever else.
|
|
58
|
+
*/
|
|
59
|
+
export declare function diffApplyText(yText: Y.Text, targetDelta: readonly DeltaOp[]): void;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { PageSetup } from '../paperStack/pageSetup';
|
|
2
|
+
export type ZoneKind = "header" | "footer";
|
|
3
|
+
export interface EnterZoneEditOptions {
|
|
4
|
+
zone: HTMLElement;
|
|
5
|
+
kind: ZoneKind;
|
|
6
|
+
stackRoot: HTMLElement;
|
|
7
|
+
getSetup: () => PageSetup;
|
|
8
|
+
setSetup: (next: PageSetup) => void;
|
|
9
|
+
onExit: () => void;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Make a header or footer zone editable in place. The displayed (substituted)
|
|
13
|
+
* text is swapped for its template (e.g. "Page {page} of {pages}") so the user
|
|
14
|
+
* edits the template, not its rendered result. On commit (blur, Enter,
|
|
15
|
+
* Escape, click outside, or the caller invoking the returned `finish()`)
|
|
16
|
+
* the new template is written back to the right slot on the PageSetup.
|
|
17
|
+
*
|
|
18
|
+
* The returned function exits zone-edit programmatically — block tools call
|
|
19
|
+
* it when the user clicks the gutter indicator a second time, so the
|
|
20
|
+
* indicator works as a single toggle for entering and leaving the zone.
|
|
21
|
+
*/
|
|
22
|
+
export declare function enterZoneEdit(opts: EnterZoneEditOptions): () => void;
|
package/package.json
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sobree/core",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"publishConfig": {
|
|
5
|
+
"access": "public"
|
|
6
|
+
},
|
|
7
|
+
"description": "Embeddable, print-view-first WYSIWYG editor for .docx — framework-free core, plugin architecture, native OOXML round-trip.",
|
|
8
|
+
"keywords": [
|
|
9
|
+
"wysiwyg",
|
|
10
|
+
"editor",
|
|
11
|
+
"rich-text",
|
|
12
|
+
"docx",
|
|
13
|
+
"ooxml",
|
|
14
|
+
"framework-free",
|
|
15
|
+
"embeddable",
|
|
16
|
+
"contenteditable",
|
|
17
|
+
"pagination",
|
|
18
|
+
"sobree"
|
|
19
|
+
],
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"author": "sobree.dev",
|
|
22
|
+
"homepage": "https://docs.sobree.dev",
|
|
23
|
+
"bugs": {
|
|
24
|
+
"url": "https://github.com/khayll/sobree/issues"
|
|
25
|
+
},
|
|
26
|
+
"repository": {
|
|
27
|
+
"type": "git",
|
|
28
|
+
"url": "git+https://github.com/khayll/sobree.git",
|
|
29
|
+
"directory": "packages/core"
|
|
30
|
+
},
|
|
31
|
+
"type": "module",
|
|
32
|
+
"main": "./dist/index.js",
|
|
33
|
+
"types": "./dist/index.d.ts",
|
|
34
|
+
"exports": {
|
|
35
|
+
".": {
|
|
36
|
+
"development": "./src/index.ts",
|
|
37
|
+
"types": "./dist/index.d.ts",
|
|
38
|
+
"import": "./dist/index.js"
|
|
39
|
+
},
|
|
40
|
+
"./tokens.css": {
|
|
41
|
+
"development": "./src/styles/tokens.css",
|
|
42
|
+
"default": "./dist/tokens.css"
|
|
43
|
+
},
|
|
44
|
+
"./package.json": "./package.json"
|
|
45
|
+
},
|
|
46
|
+
"files": [
|
|
47
|
+
"dist",
|
|
48
|
+
"README.md",
|
|
49
|
+
"LICENSE"
|
|
50
|
+
],
|
|
51
|
+
"dependencies": {
|
|
52
|
+
"fflate": "^0.8.2",
|
|
53
|
+
"yjs": "^13.6.30"
|
|
54
|
+
},
|
|
55
|
+
"scripts": {
|
|
56
|
+
"typecheck": "tsc --noEmit",
|
|
57
|
+
"test": "vitest run",
|
|
58
|
+
"build": "vite build && cp src/styles/tokens.css dist/tokens.css",
|
|
59
|
+
"clean": "rm -rf dist"
|
|
60
|
+
}
|
|
61
|
+
}
|