js.documents 7.17.5 → 7.18.1
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/README.md +1 -1
- package/dist/edit/docx/content.cjs +4 -0
- package/dist/edit/docx/content.js +4 -0
- package/dist/edit/docx/editor.cjs +46 -5
- package/dist/edit/docx/editor.d.cts +2 -1
- package/dist/edit/docx/editor.d.ts +2 -1
- package/dist/edit/docx/editor.js +46 -5
- package/dist/edit/odt/content.cjs +6 -0
- package/dist/edit/odt/content.js +6 -0
- package/dist/edit/odt/editor.cjs +42 -6
- package/dist/edit/odt/editor.d.cts +2 -1
- package/dist/edit/odt/editor.d.ts +2 -1
- package/dist/edit/odt/editor.js +43 -7
- package/package.json +13 -13
package/README.md
CHANGED
|
@@ -270,7 +270,7 @@ const pdfBytes = docxToPdf(docxBytes, {
|
|
|
270
270
|
|
|
271
271
|
The tree and the flat `ContentDocument` are one format in two encodings, related by three laws (stated on [document-schema.js#20](https://github.com/ExaDev/document-schema.js/issues/20), proven over this package's real corpus by the bijection suite in `src/convert/bijection.test.ts`): (i) `flattenTree(assembleTree(c))` reproduces `c` exactly, up to one declared normalisation (a present-but-empty sheet `embeddedObjects` array normalises to the field absent); (ii) effective-property equality holds universally — a factored and an unfactored serialisation of one document resolve to the same properties; (iii) minting is idempotent — factoring a second time produces the identical styles table.
|
|
272
272
|
|
|
273
|
-
Three flat-form signals drive the grouping, and all three are reproduced exactly on the way back: `headingLevel`, `list.level`, and — since document-schema.js 4.2.0 — the `constructStart`/`constructEnd` block pair that delimits a fidelity construct (a docx SDT, an ODF field, a tracked-change span, a bookmark, a hyperlink region, a division). `decompose` promotes each marker pair to a construct group carrying the `ConstructDescriptor` and holding the delimited region as its children, decomposed on its own; `flattenTree` writes the pair back around that region. A construct is a semantic wrapper rather than a container, so it neither disturbs the enclosing heading/list nesting it sits inside nor resets the style chain resolving onto it — content inside a construct still inherits the ambient heading's or section's factored properties, exactly as if the construct were not there. Markers must pair up within one container's block flow: an unmatched `constructEnd`, or a `constructStart` a container never closes, throws document-schema.js's `ConstructMarkerImbalanceError` (carrying its `ConstructMarkerImbalance` payload, so the offending block index is available without parsing the message) rather than being repaired into a plausible tree. The format codecs emit and consume these markers on both sides today — ooxml.js's docx pair (SDTs, bookmarks, tracked changes, block-scoped fields), odf.js's odt reader for divisions, index wrappers, and cross-paragraph bookmarks with its writer covering the construct kinds it models and refusing the rest by name, markdown-codec, rtf-codec, and epub-codec in both directions, and this package's own PDF reconstruction emitting division and anchor pairs — so the marker machinery has real producers and consumers, not just the boundary transform. Reaching further than the codecs is still a mixed picture, not a blanket guarantee: `buildMarkdownText` passes markers through to markdown-codec's own bracket-resolving writer, which renders each construct it has a markdown spelling for (a footnote definition, a blockquote division, a titled image's link wrapper) and renders the rest transparently with a diagnostic — markdown-codec's own read side emits those pairs, so this package's editor and conversion round trips depend on it; building docx bytes from marker-carrying flat content writes a bookmark anchor's pair as real `w:bookmarkStart`/`w:bookmarkEnd` around the blocks it spans
|
|
273
|
+
Three flat-form signals drive the grouping, and all three are reproduced exactly on the way back: `headingLevel`, `list.level`, and — since document-schema.js 4.2.0 — the `constructStart`/`constructEnd` block pair that delimits a fidelity construct (a docx SDT, an ODF field, a tracked-change span, a bookmark, a hyperlink region, a division). `decompose` promotes each marker pair to a construct group carrying the `ConstructDescriptor` and holding the delimited region as its children, decomposed on its own; `flattenTree` writes the pair back around that region. A construct is a semantic wrapper rather than a container, so it neither disturbs the enclosing heading/list nesting it sits inside nor resets the style chain resolving onto it — content inside a construct still inherits the ambient heading's or section's factored properties, exactly as if the construct were not there. Markers must pair up within one container's block flow: an unmatched `constructEnd`, or a `constructStart` a container never closes, throws document-schema.js's `ConstructMarkerImbalanceError` (carrying its `ConstructMarkerImbalance` payload, so the offending block index is available without parsing the message) rather than being repaired into a plausible tree. The format codecs emit and consume these markers on both sides today — ooxml.js's docx pair (SDTs, bookmarks, tracked changes, block-scoped fields), odf.js's odt reader for divisions, index wrappers, and cross-paragraph bookmarks with its writer covering the construct kinds it models and refusing the rest by name, markdown-codec, rtf-codec, and epub-codec in both directions, and this package's own PDF reconstruction emitting division and anchor pairs — so the marker machinery has real producers and consumers, not just the boundary transform. Reaching further than the codecs is still a mixed picture, not a blanket guarantee: `buildMarkdownText` passes markers through to markdown-codec's own bracket-resolving writer, which renders each construct it has a markdown spelling for (a footnote definition, a blockquote division, a titled image's link wrapper) and renders the rest transparently with a diagnostic — markdown-codec's own read side emits those pairs, so this package's editor and conversion round trips depend on it; building docx bytes from marker-carrying flat content writes a bookmark anchor's pair as real `w:bookmarkStart`/`w:bookmarkEnd` around the blocks it spans, a content control's pair as a real `w:sdt` region (the descriptor driving `w:sdtPr`, the blocks between the markers landing inside its own `w:sdtContent`), and a tracked change's pair as a real `w:ins`/`w:del`/`w:moveFrom`/`w:moveTo` region whose author and date ride the element and whose deletion interiors spell their runs `w:delText` — and the odt builder does the bookmark pair through `text:bookmark-start`/`-end`, a division's pair as a real `text:section` region the between-blocks land inside, and an index contentControl's pair as a real index wrapper region (`text:table-of-content` or one of its six siblings, named by the descriptor's `*-source` residue) whose cached blocks land inside its own `text:index-body` — so every wrapper kind each format natively spells at body scope survives the build, round-tripping through its own reader as the identical construct pair. A `formatChange` pair stays dropped on the docx side (its Word spellings are property-layer, with no block-level element to open) and a residue-less index descriptor stays dropped on the odt side (nothing names which of the seven wrappers to write); and the layout engines (`convertWordprocessingToLayout`, `convertShape`) silently skip a marker block during pagination — harmless there, since a marker carries no content of its own to render.
|
|
274
274
|
|
|
275
275
|
`assembleTree` is the one constructor behind every construction site — decompose, then `factorStyles`, the minting pass that hoists property tuples occurring two or more times onto a group-wrapper ref plus a `styles` table entry (deterministic order; `frames`/`sourcePath`/`styleId` are per-node facts and never factor). The transform belongs to `document-schema.js`, which owns both encodings and publishes `assembleTree`, `decompose`, `flattenTree`, `factorStyles`, `ConstructMarkerImbalanceError`, and the `TreeChildren` type for any caller composing its own boundary — import them from there, not from this package. documents.js consumes that transform at its own boundary and re-exports none of it; the readers, builders, layout engines, and editors here keep producing and consuming the flat form, so the tree exists only where a `DocumentTree` is constructed or consumed:
|
|
276
276
|
|
|
@@ -33,6 +33,10 @@ var ConstructMarkerState = class {
|
|
|
33
33
|
body.openContentControlRegion(detail);
|
|
34
34
|
return;
|
|
35
35
|
}
|
|
36
|
+
if (detail.kind === "provenance" && body.openProvenanceRegion(detail)) {
|
|
37
|
+
this.open.push({ kind: "region" });
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
36
40
|
this.open.push({ kind: "dropped" });
|
|
37
41
|
}
|
|
38
42
|
closeConstruct(body) {
|
|
@@ -32,6 +32,10 @@ var ConstructMarkerState = class {
|
|
|
32
32
|
body.openContentControlRegion(detail);
|
|
33
33
|
return;
|
|
34
34
|
}
|
|
35
|
+
if (detail.kind === "provenance" && body.openProvenanceRegion(detail)) {
|
|
36
|
+
this.open.push({ kind: "region" });
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
35
39
|
this.open.push({ kind: "dropped" });
|
|
36
40
|
}
|
|
37
41
|
closeConstruct(body) {
|
|
@@ -37,6 +37,7 @@ var DocxBodyImpl = class {
|
|
|
37
37
|
pkg;
|
|
38
38
|
openRegions = [];
|
|
39
39
|
nextSdtId = 1;
|
|
40
|
+
nextProvenanceId = 1;
|
|
40
41
|
constructor(body, imageContext, pkg) {
|
|
41
42
|
this.body = body;
|
|
42
43
|
this.imageContext = imageContext;
|
|
@@ -45,7 +46,7 @@ var DocxBodyImpl = class {
|
|
|
45
46
|
appendToBody(element) {
|
|
46
47
|
const region = this.openRegions.at(-1);
|
|
47
48
|
if (region !== void 0) {
|
|
48
|
-
region.children.push(element);
|
|
49
|
+
region.container.children.push(element);
|
|
49
50
|
return;
|
|
50
51
|
}
|
|
51
52
|
this.body.children.splice(bodyInsertionPoint(this.body), 0, element);
|
|
@@ -53,7 +54,7 @@ var DocxBodyImpl = class {
|
|
|
53
54
|
appendParagraph(init) {
|
|
54
55
|
const paragraphElement = require_edit_docx_paragraph.buildParagraph(init);
|
|
55
56
|
this.appendToBody(paragraphElement);
|
|
56
|
-
const container = this.openRegions.at(-1)?.children ?? this.body.children;
|
|
57
|
+
const container = this.openRegions.at(-1)?.container.children ?? this.body.children;
|
|
57
58
|
return new require_edit_docx_paragraph.DocxParagraph(container, paragraphElement, this.imageContext, this.pkg);
|
|
58
59
|
}
|
|
59
60
|
insertParagraphAt(index, init) {
|
|
@@ -66,7 +67,7 @@ var DocxBodyImpl = class {
|
|
|
66
67
|
appendTable(init) {
|
|
67
68
|
const tableElement = require_edit_docx_table.buildTable(init);
|
|
68
69
|
this.appendToBody(tableElement);
|
|
69
|
-
const container = this.openRegions.at(-1)?.children ?? this.body.children;
|
|
70
|
+
const container = this.openRegions.at(-1)?.container.children ?? this.body.children;
|
|
70
71
|
return new require_edit_docx_table.DocxTable(container, tableElement);
|
|
71
72
|
}
|
|
72
73
|
appendPageBreak() {
|
|
@@ -120,12 +121,52 @@ var DocxBodyImpl = class {
|
|
|
120
121
|
}
|
|
121
122
|
const sdtContent = require_xml_fragment.el("w:sdtContent", {}, []);
|
|
122
123
|
this.appendToBody(require_xml_fragment.el("w:sdt", {}, [require_xml_fragment.el("w:sdtPr", {}, sdtPr), sdtContent]));
|
|
123
|
-
this.openRegions.push(
|
|
124
|
+
this.openRegions.push({
|
|
125
|
+
container: sdtContent,
|
|
126
|
+
deletion: false
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
openProvenanceRegion(descriptor) {
|
|
130
|
+
const tag = descriptor.change === "insertion" ? "w:ins" : descriptor.change === "deletion" ? "w:del" : descriptor.change === "moveFrom" ? "w:moveFrom" : descriptor.change === "moveTo" ? "w:moveTo" : void 0;
|
|
131
|
+
if (tag === void 0) return false;
|
|
132
|
+
const attributes = [{
|
|
133
|
+
name: "w:id",
|
|
134
|
+
value: String(this.nextProvenanceId)
|
|
135
|
+
}];
|
|
136
|
+
this.nextProvenanceId += 1;
|
|
137
|
+
if (descriptor.author !== void 0) attributes.push({
|
|
138
|
+
name: "w:author",
|
|
139
|
+
value: require_xml_entities.encodeXmlText(descriptor.author)
|
|
140
|
+
});
|
|
141
|
+
if (descriptor.dateIso !== void 0) attributes.push({
|
|
142
|
+
name: "w:date",
|
|
143
|
+
value: require_xml_entities.encodeXmlText(descriptor.dateIso)
|
|
144
|
+
});
|
|
145
|
+
const region = {
|
|
146
|
+
type: "element",
|
|
147
|
+
tag,
|
|
148
|
+
attributes,
|
|
149
|
+
children: []
|
|
150
|
+
};
|
|
151
|
+
this.appendToBody(region);
|
|
152
|
+
this.openRegions.push({
|
|
153
|
+
container: region,
|
|
154
|
+
deletion: descriptor.change === "deletion" || descriptor.change === "moveFrom"
|
|
155
|
+
});
|
|
156
|
+
return true;
|
|
124
157
|
}
|
|
125
158
|
closeRegion() {
|
|
126
|
-
this.openRegions.pop();
|
|
159
|
+
const entry = this.openRegions.pop();
|
|
160
|
+
if (entry?.deletion === true) spellDeletedText(entry.container);
|
|
127
161
|
}
|
|
128
162
|
};
|
|
163
|
+
function spellDeletedText(element) {
|
|
164
|
+
for (const child of element.children) {
|
|
165
|
+
if (child.type !== "element") continue;
|
|
166
|
+
if (child.tag === "w:t") child.tag = "w:delText";
|
|
167
|
+
spellDeletedText(child);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
129
170
|
var DocxEditor = class {
|
|
130
171
|
body;
|
|
131
172
|
pkg;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { t as ClockPort } from "../../clock-C7SUuYN0.cjs";
|
|
2
2
|
import { DocxParagraph, ParagraphInit } from "./paragraph.cjs";
|
|
3
3
|
import { DocxTable, TableInit } from "./table.cjs";
|
|
4
|
-
import { ContentControlDescriptor, LayoutMetadata } from "document-schema.js";
|
|
4
|
+
import { ContentControlDescriptor, LayoutMetadata, ProvenanceDescriptor } from "document-schema.js";
|
|
5
5
|
import { Package } from "ooxml.js";
|
|
6
6
|
//#region src/edit/docx/editor.d.ts
|
|
7
7
|
interface DocxBody {
|
|
@@ -12,6 +12,7 @@ interface DocxBody {
|
|
|
12
12
|
appendBookmarkStart(id: number, name: string): void;
|
|
13
13
|
appendBookmarkEnd(id: number): void;
|
|
14
14
|
openContentControlRegion(descriptor: ContentControlDescriptor): void;
|
|
15
|
+
openProvenanceRegion(descriptor: ProvenanceDescriptor): boolean;
|
|
15
16
|
closeRegion(): void;
|
|
16
17
|
}
|
|
17
18
|
declare class DocxEditor {
|
|
@@ -2,7 +2,7 @@ import { t as ClockPort } from "../../clock-C7SUuYN0.js";
|
|
|
2
2
|
import { DocxParagraph, ParagraphInit } from "./paragraph.js";
|
|
3
3
|
import { DocxTable, TableInit } from "./table.js";
|
|
4
4
|
import { Package } from "ooxml.js";
|
|
5
|
-
import { ContentControlDescriptor, LayoutMetadata } from "document-schema.js";
|
|
5
|
+
import { ContentControlDescriptor, LayoutMetadata, ProvenanceDescriptor } from "document-schema.js";
|
|
6
6
|
//#region src/edit/docx/editor.d.ts
|
|
7
7
|
interface DocxBody {
|
|
8
8
|
insertParagraphAt(index: number, init?: ParagraphInit): DocxParagraph;
|
|
@@ -12,6 +12,7 @@ interface DocxBody {
|
|
|
12
12
|
appendBookmarkStart(id: number, name: string): void;
|
|
13
13
|
appendBookmarkEnd(id: number): void;
|
|
14
14
|
openContentControlRegion(descriptor: ContentControlDescriptor): void;
|
|
15
|
+
openProvenanceRegion(descriptor: ProvenanceDescriptor): boolean;
|
|
15
16
|
closeRegion(): void;
|
|
16
17
|
}
|
|
17
18
|
declare class DocxEditor {
|
package/dist/edit/docx/editor.js
CHANGED
|
@@ -36,6 +36,7 @@ var DocxBodyImpl = class {
|
|
|
36
36
|
pkg;
|
|
37
37
|
openRegions = [];
|
|
38
38
|
nextSdtId = 1;
|
|
39
|
+
nextProvenanceId = 1;
|
|
39
40
|
constructor(body, imageContext, pkg) {
|
|
40
41
|
this.body = body;
|
|
41
42
|
this.imageContext = imageContext;
|
|
@@ -44,7 +45,7 @@ var DocxBodyImpl = class {
|
|
|
44
45
|
appendToBody(element) {
|
|
45
46
|
const region = this.openRegions.at(-1);
|
|
46
47
|
if (region !== void 0) {
|
|
47
|
-
region.children.push(element);
|
|
48
|
+
region.container.children.push(element);
|
|
48
49
|
return;
|
|
49
50
|
}
|
|
50
51
|
this.body.children.splice(bodyInsertionPoint(this.body), 0, element);
|
|
@@ -52,7 +53,7 @@ var DocxBodyImpl = class {
|
|
|
52
53
|
appendParagraph(init) {
|
|
53
54
|
const paragraphElement = buildParagraph(init);
|
|
54
55
|
this.appendToBody(paragraphElement);
|
|
55
|
-
const container = this.openRegions.at(-1)?.children ?? this.body.children;
|
|
56
|
+
const container = this.openRegions.at(-1)?.container.children ?? this.body.children;
|
|
56
57
|
return new DocxParagraph(container, paragraphElement, this.imageContext, this.pkg);
|
|
57
58
|
}
|
|
58
59
|
insertParagraphAt(index, init) {
|
|
@@ -65,7 +66,7 @@ var DocxBodyImpl = class {
|
|
|
65
66
|
appendTable(init) {
|
|
66
67
|
const tableElement = buildTable(init);
|
|
67
68
|
this.appendToBody(tableElement);
|
|
68
|
-
const container = this.openRegions.at(-1)?.children ?? this.body.children;
|
|
69
|
+
const container = this.openRegions.at(-1)?.container.children ?? this.body.children;
|
|
69
70
|
return new DocxTable(container, tableElement);
|
|
70
71
|
}
|
|
71
72
|
appendPageBreak() {
|
|
@@ -119,12 +120,52 @@ var DocxBodyImpl = class {
|
|
|
119
120
|
}
|
|
120
121
|
const sdtContent = el("w:sdtContent", {}, []);
|
|
121
122
|
this.appendToBody(el("w:sdt", {}, [el("w:sdtPr", {}, sdtPr), sdtContent]));
|
|
122
|
-
this.openRegions.push(
|
|
123
|
+
this.openRegions.push({
|
|
124
|
+
container: sdtContent,
|
|
125
|
+
deletion: false
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
openProvenanceRegion(descriptor) {
|
|
129
|
+
const tag = descriptor.change === "insertion" ? "w:ins" : descriptor.change === "deletion" ? "w:del" : descriptor.change === "moveFrom" ? "w:moveFrom" : descriptor.change === "moveTo" ? "w:moveTo" : void 0;
|
|
130
|
+
if (tag === void 0) return false;
|
|
131
|
+
const attributes = [{
|
|
132
|
+
name: "w:id",
|
|
133
|
+
value: String(this.nextProvenanceId)
|
|
134
|
+
}];
|
|
135
|
+
this.nextProvenanceId += 1;
|
|
136
|
+
if (descriptor.author !== void 0) attributes.push({
|
|
137
|
+
name: "w:author",
|
|
138
|
+
value: encodeXmlText(descriptor.author)
|
|
139
|
+
});
|
|
140
|
+
if (descriptor.dateIso !== void 0) attributes.push({
|
|
141
|
+
name: "w:date",
|
|
142
|
+
value: encodeXmlText(descriptor.dateIso)
|
|
143
|
+
});
|
|
144
|
+
const region = {
|
|
145
|
+
type: "element",
|
|
146
|
+
tag,
|
|
147
|
+
attributes,
|
|
148
|
+
children: []
|
|
149
|
+
};
|
|
150
|
+
this.appendToBody(region);
|
|
151
|
+
this.openRegions.push({
|
|
152
|
+
container: region,
|
|
153
|
+
deletion: descriptor.change === "deletion" || descriptor.change === "moveFrom"
|
|
154
|
+
});
|
|
155
|
+
return true;
|
|
123
156
|
}
|
|
124
157
|
closeRegion() {
|
|
125
|
-
this.openRegions.pop();
|
|
158
|
+
const entry = this.openRegions.pop();
|
|
159
|
+
if (entry?.deletion === true) spellDeletedText(entry.container);
|
|
126
160
|
}
|
|
127
161
|
};
|
|
162
|
+
function spellDeletedText(element) {
|
|
163
|
+
for (const child of element.children) {
|
|
164
|
+
if (child.type !== "element") continue;
|
|
165
|
+
if (child.tag === "w:t") child.tag = "w:delText";
|
|
166
|
+
spellDeletedText(child);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
128
169
|
var DocxEditor = class {
|
|
129
170
|
body;
|
|
130
171
|
pkg;
|
|
@@ -205,6 +205,12 @@ var ConstructMarkerState = class {
|
|
|
205
205
|
body.openDivisionRegion(detail);
|
|
206
206
|
return;
|
|
207
207
|
}
|
|
208
|
+
if (detail.kind === "contentControl" && detail.controlType === "index") {
|
|
209
|
+
if (body.openIndexRegion(detail)) {
|
|
210
|
+
this.open.push({ kind: "region" });
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
208
214
|
this.open.push({ kind: "dropped" });
|
|
209
215
|
}
|
|
210
216
|
closeConstruct(body) {
|
package/dist/edit/odt/content.js
CHANGED
|
@@ -204,6 +204,12 @@ var ConstructMarkerState = class {
|
|
|
204
204
|
body.openDivisionRegion(detail);
|
|
205
205
|
return;
|
|
206
206
|
}
|
|
207
|
+
if (detail.kind === "contentControl" && detail.controlType === "index") {
|
|
208
|
+
if (body.openIndexRegion(detail)) {
|
|
209
|
+
this.open.push({ kind: "region" });
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
207
213
|
this.open.push({ kind: "dropped" });
|
|
208
214
|
}
|
|
209
215
|
closeConstruct(body) {
|
package/dist/edit/odt/editor.cjs
CHANGED
|
@@ -31,13 +31,13 @@ function findOfficeText(contentRoot) {
|
|
|
31
31
|
var OdtBodyImpl = class {
|
|
32
32
|
officeText;
|
|
33
33
|
pkg;
|
|
34
|
-
|
|
34
|
+
openRegions = [];
|
|
35
35
|
constructor(officeText, pkg) {
|
|
36
36
|
this.officeText = officeText;
|
|
37
37
|
this.pkg = pkg;
|
|
38
38
|
}
|
|
39
39
|
containerChildren() {
|
|
40
|
-
return this.
|
|
40
|
+
return this.openRegions.at(-1)?.container.children ?? this.officeText.children;
|
|
41
41
|
}
|
|
42
42
|
appendParagraph(init) {
|
|
43
43
|
const paragraphElement = require_edit_odt_paragraph.buildParagraph(this.pkg, init);
|
|
@@ -125,13 +125,49 @@ var OdtBodyImpl = class {
|
|
|
125
125
|
children: []
|
|
126
126
|
};
|
|
127
127
|
this.containerChildren().push(section);
|
|
128
|
-
this.
|
|
129
|
-
section,
|
|
128
|
+
this.openRegions.push({
|
|
129
|
+
container: section,
|
|
130
130
|
linked: descriptor.linked
|
|
131
131
|
});
|
|
132
132
|
}
|
|
133
|
+
openIndexRegion(descriptor) {
|
|
134
|
+
let tag;
|
|
135
|
+
try {
|
|
136
|
+
tag = (0, odf_js.odfIndexWrapperTag)(descriptor);
|
|
137
|
+
} catch {
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
140
|
+
const attributes = [];
|
|
141
|
+
if (descriptor.tag !== void 0) attributes.push({
|
|
142
|
+
name: "text:name",
|
|
143
|
+
value: require_xml_entities.encodeXmlText(descriptor.tag)
|
|
144
|
+
});
|
|
145
|
+
const indexBody = {
|
|
146
|
+
type: "element",
|
|
147
|
+
tag: "text:index-body",
|
|
148
|
+
attributes: [],
|
|
149
|
+
children: []
|
|
150
|
+
};
|
|
151
|
+
const wrapper = {
|
|
152
|
+
type: "element",
|
|
153
|
+
tag,
|
|
154
|
+
attributes,
|
|
155
|
+
children: [{
|
|
156
|
+
type: "element",
|
|
157
|
+
tag: `${tag}-source`,
|
|
158
|
+
attributes: [],
|
|
159
|
+
children: []
|
|
160
|
+
}, indexBody]
|
|
161
|
+
};
|
|
162
|
+
this.containerChildren().push(wrapper);
|
|
163
|
+
this.openRegions.push({
|
|
164
|
+
container: indexBody,
|
|
165
|
+
linked: void 0
|
|
166
|
+
});
|
|
167
|
+
return true;
|
|
168
|
+
}
|
|
133
169
|
closeRegion() {
|
|
134
|
-
const entry = this.
|
|
170
|
+
const entry = this.openRegions.pop();
|
|
135
171
|
if (entry === void 0) return;
|
|
136
172
|
if (entry.linked !== void 0) {
|
|
137
173
|
const sourceAttributes = [{
|
|
@@ -145,7 +181,7 @@ var OdtBodyImpl = class {
|
|
|
145
181
|
name: "text:section-name",
|
|
146
182
|
value: require_xml_entities.encodeXmlText(entry.linked.sectionName)
|
|
147
183
|
});
|
|
148
|
-
entry.
|
|
184
|
+
entry.container.children.push({
|
|
149
185
|
type: "element",
|
|
150
186
|
tag: "text:section-source",
|
|
151
187
|
attributes: sourceAttributes,
|
|
@@ -2,7 +2,7 @@ import { t as ClockPort } from "../../clock-C7SUuYN0.cjs";
|
|
|
2
2
|
import { n as ParagraphInit, t as OdtParagraph } from "../../paragraph-CRaLSzWz.cjs";
|
|
3
3
|
import { t as OdtList } from "../../list-C_UPIZWM.cjs";
|
|
4
4
|
import { a as TableInit, n as OdtTable } from "../../table-COmzfIOe.cjs";
|
|
5
|
-
import { Box, ContentFormula, ContentVector, DivisionDescriptor, LayoutMetadata } from "document-schema.js";
|
|
5
|
+
import { Box, ContentControlDescriptor, ContentFormula, ContentVector, DivisionDescriptor, LayoutMetadata } from "document-schema.js";
|
|
6
6
|
import { Package } from "odf.js";
|
|
7
7
|
//#region src/edit/odt/editor.d.ts
|
|
8
8
|
interface OdtBody {
|
|
@@ -15,6 +15,7 @@ interface OdtBody {
|
|
|
15
15
|
appendBookmarkStart(name: string): void;
|
|
16
16
|
appendBookmarkEnd(name: string): void;
|
|
17
17
|
openDivisionRegion(descriptor: DivisionDescriptor): void;
|
|
18
|
+
openIndexRegion(descriptor: ContentControlDescriptor): boolean;
|
|
18
19
|
closeRegion(): void;
|
|
19
20
|
}
|
|
20
21
|
declare class OdtEditor {
|
|
@@ -2,7 +2,7 @@ import { t as ClockPort } from "../../clock-C7SUuYN0.js";
|
|
|
2
2
|
import { n as ParagraphInit, t as OdtParagraph } from "../../paragraph-D4f705GG.js";
|
|
3
3
|
import { t as OdtList } from "../../list-C2GWIe6E.js";
|
|
4
4
|
import { a as TableInit, n as OdtTable } from "../../table-BmMyqRML.js";
|
|
5
|
-
import { Box, ContentFormula, ContentVector, DivisionDescriptor, LayoutMetadata } from "document-schema.js";
|
|
5
|
+
import { Box, ContentControlDescriptor, ContentFormula, ContentVector, DivisionDescriptor, LayoutMetadata } from "document-schema.js";
|
|
6
6
|
import { Package } from "odf.js";
|
|
7
7
|
//#region src/edit/odt/editor.d.ts
|
|
8
8
|
interface OdtBody {
|
|
@@ -15,6 +15,7 @@ interface OdtBody {
|
|
|
15
15
|
appendBookmarkStart(name: string): void;
|
|
16
16
|
appendBookmarkEnd(name: string): void;
|
|
17
17
|
openDivisionRegion(descriptor: DivisionDescriptor): void;
|
|
18
|
+
openIndexRegion(descriptor: ContentControlDescriptor): boolean;
|
|
18
19
|
closeRegion(): void;
|
|
19
20
|
}
|
|
20
21
|
declare class OdtEditor {
|
package/dist/edit/odt/editor.js
CHANGED
|
@@ -9,7 +9,7 @@ import { OdtParagraph, buildParagraph } from "./paragraph.js";
|
|
|
9
9
|
import { OdtList, buildList } from "./list.js";
|
|
10
10
|
import { createEmptyOdtPackage } from "./scaffold.js";
|
|
11
11
|
import { OdtTable, buildTable } from "./table.js";
|
|
12
|
-
import { decodePackage, encodePackage, readOdfMetadata, writeEmbeddedObject } from "odf.js";
|
|
12
|
+
import { decodePackage, encodePackage, odfIndexWrapperTag, readOdfMetadata, writeEmbeddedObject } from "odf.js";
|
|
13
13
|
//#region src/edit/odt/editor.ts
|
|
14
14
|
const CONTENT_PART_PATH = "content.xml";
|
|
15
15
|
function findContentRoot(pkg) {
|
|
@@ -30,13 +30,13 @@ function findOfficeText(contentRoot) {
|
|
|
30
30
|
var OdtBodyImpl = class {
|
|
31
31
|
officeText;
|
|
32
32
|
pkg;
|
|
33
|
-
|
|
33
|
+
openRegions = [];
|
|
34
34
|
constructor(officeText, pkg) {
|
|
35
35
|
this.officeText = officeText;
|
|
36
36
|
this.pkg = pkg;
|
|
37
37
|
}
|
|
38
38
|
containerChildren() {
|
|
39
|
-
return this.
|
|
39
|
+
return this.openRegions.at(-1)?.container.children ?? this.officeText.children;
|
|
40
40
|
}
|
|
41
41
|
appendParagraph(init) {
|
|
42
42
|
const paragraphElement = buildParagraph(this.pkg, init);
|
|
@@ -124,13 +124,49 @@ var OdtBodyImpl = class {
|
|
|
124
124
|
children: []
|
|
125
125
|
};
|
|
126
126
|
this.containerChildren().push(section);
|
|
127
|
-
this.
|
|
128
|
-
section,
|
|
127
|
+
this.openRegions.push({
|
|
128
|
+
container: section,
|
|
129
129
|
linked: descriptor.linked
|
|
130
130
|
});
|
|
131
131
|
}
|
|
132
|
+
openIndexRegion(descriptor) {
|
|
133
|
+
let tag;
|
|
134
|
+
try {
|
|
135
|
+
tag = odfIndexWrapperTag(descriptor);
|
|
136
|
+
} catch {
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
const attributes = [];
|
|
140
|
+
if (descriptor.tag !== void 0) attributes.push({
|
|
141
|
+
name: "text:name",
|
|
142
|
+
value: encodeXmlText$1(descriptor.tag)
|
|
143
|
+
});
|
|
144
|
+
const indexBody = {
|
|
145
|
+
type: "element",
|
|
146
|
+
tag: "text:index-body",
|
|
147
|
+
attributes: [],
|
|
148
|
+
children: []
|
|
149
|
+
};
|
|
150
|
+
const wrapper = {
|
|
151
|
+
type: "element",
|
|
152
|
+
tag,
|
|
153
|
+
attributes,
|
|
154
|
+
children: [{
|
|
155
|
+
type: "element",
|
|
156
|
+
tag: `${tag}-source`,
|
|
157
|
+
attributes: [],
|
|
158
|
+
children: []
|
|
159
|
+
}, indexBody]
|
|
160
|
+
};
|
|
161
|
+
this.containerChildren().push(wrapper);
|
|
162
|
+
this.openRegions.push({
|
|
163
|
+
container: indexBody,
|
|
164
|
+
linked: void 0
|
|
165
|
+
});
|
|
166
|
+
return true;
|
|
167
|
+
}
|
|
132
168
|
closeRegion() {
|
|
133
|
-
const entry = this.
|
|
169
|
+
const entry = this.openRegions.pop();
|
|
134
170
|
if (entry === void 0) return;
|
|
135
171
|
if (entry.linked !== void 0) {
|
|
136
172
|
const sourceAttributes = [{
|
|
@@ -144,7 +180,7 @@ var OdtBodyImpl = class {
|
|
|
144
180
|
name: "text:section-name",
|
|
145
181
|
value: encodeXmlText$1(entry.linked.sectionName)
|
|
146
182
|
});
|
|
147
|
-
entry.
|
|
183
|
+
entry.container.children.push({
|
|
148
184
|
type: "element",
|
|
149
185
|
tag: "text:section-source",
|
|
150
186
|
attributes: sourceAttributes,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "js.documents",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.18.1",
|
|
4
4
|
"description": "Bidirectional docx/pptx <-> PDF conversion and a read+write editable OOXML document model, built on ooxml.js and Zod 4 codecs.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -77,21 +77,21 @@
|
|
|
77
77
|
],
|
|
78
78
|
"license": "MIT",
|
|
79
79
|
"dependencies": {
|
|
80
|
-
"archive-codec": "1.10.
|
|
80
|
+
"archive-codec": "1.10.4",
|
|
81
81
|
"byte-codec": "1.4.2",
|
|
82
|
-
"doc-codec": "2.8.
|
|
83
|
-
"document-schema.js": "7.
|
|
84
|
-
"epub-codec": "1.3.
|
|
82
|
+
"doc-codec": "2.8.2",
|
|
83
|
+
"document-schema.js": "7.7.0",
|
|
84
|
+
"epub-codec": "1.3.6",
|
|
85
85
|
"fflate": "0.8.3",
|
|
86
|
-
"markdown-codec": "6.6.
|
|
87
|
-
"odf.js": "7.
|
|
88
|
-
"ooxml.js": "8.10.
|
|
89
|
-
"pdf-codec": "4.5.
|
|
90
|
-
"ppt-codec": "1.4.
|
|
91
|
-
"rtf-codec": "4.2.
|
|
86
|
+
"markdown-codec": "6.6.3",
|
|
87
|
+
"odf.js": "7.24.1",
|
|
88
|
+
"ooxml.js": "8.10.2",
|
|
89
|
+
"pdf-codec": "4.5.3",
|
|
90
|
+
"ppt-codec": "1.4.7",
|
|
91
|
+
"rtf-codec": "4.2.2",
|
|
92
92
|
"temml": "0.13.4",
|
|
93
|
-
"wpd-codec": "3.4.
|
|
94
|
-
"xls-codec": "4.12.
|
|
93
|
+
"wpd-codec": "3.4.2",
|
|
94
|
+
"xls-codec": "4.12.3",
|
|
95
95
|
"zod": "4.4.3"
|
|
96
96
|
},
|
|
97
97
|
"devDependencies": {
|