@portone/docx-editor 0.6.2 → 0.6.3
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/CHANGELOG.md +62 -0
- package/dist/DocxEditor.js +2 -2
- package/dist/docx/headersFooters.js +4 -14
- package/dist/docx/identities.d.ts +8 -2
- package/dist/docx/identities.js +31 -11
- package/dist/docx/importPolicy.d.ts +2 -2
- package/dist/docx/importPolicy.js +12 -5
- package/dist/docx/importPreserved.d.ts +3 -3
- package/dist/docx/importSdtBlock.d.ts +24 -0
- package/dist/docx/importSdtBlock.js +42 -0
- package/dist/docx/importTable.js +35 -24
- package/dist/docx/notes/numbering.js +4 -4
- package/dist/docx/notes/references.d.ts +0 -2
- package/dist/docx/notes/references.js +2 -7
- package/dist/docx/sdt.d.ts +52 -9
- package/dist/docx/sdt.js +108 -26
- package/dist/docx/sections.d.ts +13 -13
- package/dist/docx/sections.js +34 -20
- package/dist/docx/serializeBlock.js +9 -1
- package/dist/docx/serializeSdtBlock.d.ts +24 -0
- package/dist/docx/serializeSdtBlock.js +15 -0
- package/dist/docx/serializeTable.d.ts +8 -2
- package/dist/docx/serializeTable.js +14 -20
- package/dist/docx/story.d.ts +10 -4
- package/dist/docx/story.js +25 -20
- package/dist/docx/storyBlocks.d.ts +32 -0
- package/dist/docx/storyBlocks.js +65 -0
- package/dist/docx/wrappers.d.ts +10 -7
- package/dist/docx/wrappers.js +15 -27
- package/dist/editor/blockControlEdits.d.ts +15 -0
- package/dist/editor/blockControlEdits.js +79 -0
- package/dist/editor/clipboard/normalizers.js +1 -1
- package/dist/editor/commands/lockCommands.d.ts +5 -1
- package/dist/editor/commands/lockCommands.js +27 -19
- package/dist/editor/createEditor.js +4 -0
- package/dist/editor/notes/noteSurface.js +4 -3
- package/dist/editor/plugins/controlLifecycle.d.ts +18 -0
- package/dist/editor/plugins/controlLifecycle.js +130 -0
- package/dist/editor/plugins/keymap.js +23 -5
- package/dist/editor/plugins/rowResize.js +2 -4
- package/dist/editor/stories/storyState.d.ts +2 -0
- package/dist/editor/stories/storyState.js +2 -0
- package/dist/page/blockKinds.d.ts +24 -2
- package/dist/page/blockKinds.js +6 -1
- package/dist/page/kinds/index.d.ts +5 -0
- package/dist/page/kinds/index.js +2 -0
- package/dist/page/kinds/sdtBlockKind.d.ts +14 -0
- package/dist/page/kinds/sdtBlockKind.js +143 -0
- package/dist/page/measureBlocks.js +4 -2
- package/dist/page/pageDecorations.js +3 -2
- package/dist/page/pageLayout.d.ts +16 -15
- package/dist/page/pageLayout.js +134 -67
- package/dist/page/usePageLayout.d.ts +2 -2
- package/dist/page/usePageLayout.js +5 -5
- package/dist/schema/attrRoles.js +45 -1
- package/dist/schema/clipboard.js +9 -0
- package/dist/schema/controlAttrs.d.ts +105 -0
- package/dist/schema/controlAttrs.js +129 -0
- package/dist/schema/controlEdges.d.ts +22 -0
- package/dist/schema/controlEdges.js +50 -0
- package/dist/schema/docxSchema.d.ts +1 -1
- package/dist/schema/docxSchema.js +180 -37
- package/dist/schema/editGuard.d.ts +1 -1
- package/dist/schema/guards.js +2 -0
- package/dist/schema/locks.d.ts +22 -6
- package/dist/schema/locks.js +88 -47
- package/dist/styles/classNames.d.ts +8 -0
- package/dist/styles/classNames.js +8 -0
- package/dist/styles.css +31 -2
- package/dist/table/merge.js +11 -3
- package/dist/table/rowResize.d.ts +9 -0
- package/dist/table/rowResize.js +9 -5
- package/dist/ui/TextMenu.js +2 -0
- package/package.json +3 -3
package/dist/page/pageLayout.js
CHANGED
|
@@ -23,23 +23,26 @@ function pagePixels(geometry) {
|
|
|
23
23
|
pageStep: marginTop + marginBottom + PAGE_SPLIT_PX
|
|
24
24
|
};
|
|
25
25
|
}
|
|
26
|
+
function samePaper(a, b) {
|
|
27
|
+
return a.pageWidth === b.pageWidth && a.pageHeight === b.pageHeight && a.marginTop === b.marginTop && a.marginRight === b.marginRight && a.marginBottom === b.marginBottom && a.marginLeft === b.marginLeft;
|
|
28
|
+
}
|
|
26
29
|
var A4_PAGE_PIXELS = pagePixels(A4_PORTRAIT);
|
|
27
30
|
var A4_SECTION_PIXELS = [
|
|
28
31
|
{ untilPos: Number.POSITIVE_INFINITY, pixels: A4_PAGE_PIXELS, type: null }
|
|
29
32
|
];
|
|
30
33
|
function sectionPixels(sections) {
|
|
31
|
-
return sections.map(({ anchor, props }) => ({
|
|
32
|
-
untilPos: anchor.kind === "paragraph" ?
|
|
34
|
+
return sections.map(({ anchor, to, props }) => ({
|
|
35
|
+
untilPos: anchor.kind === "paragraph" ? to : Number.POSITIVE_INFINITY,
|
|
33
36
|
pixels: pagePixels(props.geometry),
|
|
34
37
|
type: props.type
|
|
35
38
|
}));
|
|
36
39
|
}
|
|
37
40
|
function sectionIndexAt(sections, pos) {
|
|
38
41
|
const reaching = sections.findIndex((section) => pos <= section.untilPos);
|
|
39
|
-
return reaching === -1 ? sections.length - 1 : reaching;
|
|
42
|
+
return reaching === -1 ? Math.max(0, sections.length - 1) : reaching;
|
|
40
43
|
}
|
|
41
|
-
function
|
|
42
|
-
return sections[
|
|
44
|
+
function sectionPaper(sections, index) {
|
|
45
|
+
return sections[index]?.pixels ?? A4_PAGE_PIXELS;
|
|
43
46
|
}
|
|
44
47
|
function px(value) {
|
|
45
48
|
return `${Math.round(value * 100) / 100}px`;
|
|
@@ -55,6 +58,31 @@ function pageGeometryStyle(page) {
|
|
|
55
58
|
].join(";");
|
|
56
59
|
}
|
|
57
60
|
var TOLERANCE_PX = 0.5;
|
|
61
|
+
function laidOut(blocks, sections, roomy) {
|
|
62
|
+
const pieceAt = (pos) => {
|
|
63
|
+
const section = sectionIndexAt(sections, pos);
|
|
64
|
+
const pixels = sections[section]?.pixels;
|
|
65
|
+
return {
|
|
66
|
+
section,
|
|
67
|
+
paper: pixels && pixels.bodyHeight > 0 ? pixels : roomy
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
const opensPageAt = (before2, piece) => piece.section !== before2.section && (sections[piece.section]?.type !== "continuous" || !samePaper(before2.paper, piece.paper));
|
|
71
|
+
let before = null;
|
|
72
|
+
return blocks.map((block) => {
|
|
73
|
+
const first = pieceAt(block.pos);
|
|
74
|
+
let last = first;
|
|
75
|
+
const candidates = block.candidates.map((candidate) => {
|
|
76
|
+
const piece = pieceAt(candidate.at);
|
|
77
|
+
const boundary = opensPageAt(last, piece);
|
|
78
|
+
last = piece;
|
|
79
|
+
return boundary ? { ...candidate, ...piece, forced: true, kept: false } : { ...candidate, ...piece };
|
|
80
|
+
});
|
|
81
|
+
const opensPage = before !== null && opensPageAt(before, first);
|
|
82
|
+
before = last;
|
|
83
|
+
return { block, ...first, candidates, last, opensPage };
|
|
84
|
+
});
|
|
85
|
+
}
|
|
58
86
|
function round(value) {
|
|
59
87
|
return Math.round(value * 100) / 100;
|
|
60
88
|
}
|
|
@@ -112,20 +140,53 @@ function demandsInOrder(block) {
|
|
|
112
140
|
const demands = block.demands ?? NO_DEMANDS;
|
|
113
141
|
return demands.length < 2 ? demands : [...demands].sort((a, b) => a.offset - b.offset);
|
|
114
142
|
}
|
|
115
|
-
function withinSections(pages
|
|
143
|
+
function withinSections(pages) {
|
|
116
144
|
let section = null;
|
|
117
145
|
let within = 0;
|
|
118
146
|
return pages.map((page) => {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
section = index;
|
|
147
|
+
within = page.section === section ? within + 1 : 1;
|
|
148
|
+
section = page.section;
|
|
122
149
|
return { ...page, pageInSection: within };
|
|
123
150
|
});
|
|
124
151
|
}
|
|
125
|
-
function keepsWithNext(
|
|
126
|
-
return block.keepWithNext && !opensPage &&
|
|
152
|
+
function keepsWithNext(laid, next) {
|
|
153
|
+
return laid.block.keepWithNext && !next.opensPage && !laid.candidates.some((candidate) => candidate.forced) && !laid.block.breakAfter && !next.block.breakBefore;
|
|
154
|
+
}
|
|
155
|
+
function offered(laid) {
|
|
156
|
+
const { block } = laid;
|
|
157
|
+
const all = laid.candidates;
|
|
158
|
+
if (!all.some((candidate) => candidate.kept)) {
|
|
159
|
+
return { candidates: all, firstPiece: block.minFirstPiece };
|
|
160
|
+
}
|
|
161
|
+
const candidates = [];
|
|
162
|
+
let firstKeptClosed = false;
|
|
163
|
+
let runStart = 0;
|
|
164
|
+
let runPaper = laid.paper;
|
|
165
|
+
let index = 0;
|
|
166
|
+
while (index < all.length) {
|
|
167
|
+
const candidate = all[index];
|
|
168
|
+
if (!candidate) break;
|
|
169
|
+
if (!candidate.kept) {
|
|
170
|
+
candidates.push(candidate);
|
|
171
|
+
runStart = candidate.offset;
|
|
172
|
+
runPaper = candidate.paper;
|
|
173
|
+
index += 1;
|
|
174
|
+
continue;
|
|
175
|
+
}
|
|
176
|
+
let end = index;
|
|
177
|
+
while (all[end]?.kept) end += 1;
|
|
178
|
+
const runEnd = all[end]?.offset ?? block.height;
|
|
179
|
+
if (runEnd - runStart > runPaper.bodyHeight + TOLERANCE_PX) {
|
|
180
|
+
candidates.push(...all.slice(index, end));
|
|
181
|
+
} else if (index === 0) {
|
|
182
|
+
firstKeptClosed = true;
|
|
183
|
+
}
|
|
184
|
+
index = end;
|
|
185
|
+
}
|
|
186
|
+
const firstPiece = firstKeptClosed ? Math.max(block.minFirstPiece, candidates[0]?.offset ?? block.height) : block.minFirstPiece;
|
|
187
|
+
return { candidates, firstPiece };
|
|
127
188
|
}
|
|
128
|
-
function keptExtents(
|
|
189
|
+
function keptExtents(laid) {
|
|
129
190
|
const fitsPage = (extent, index) => {
|
|
130
191
|
const height = laid[index]?.paper.bodyHeight ?? 0;
|
|
131
192
|
return extent <= height + TOLERANCE_PX;
|
|
@@ -141,13 +202,12 @@ function keptExtents(blocks, laid) {
|
|
|
141
202
|
}
|
|
142
203
|
run = [];
|
|
143
204
|
};
|
|
144
|
-
for (let index =
|
|
145
|
-
const block =
|
|
146
|
-
const next =
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
run.push({ index, extent: block.height + next.gap + below });
|
|
205
|
+
for (let index = laid.length - 2; index >= 0; index -= 1) {
|
|
206
|
+
const block = laid[index];
|
|
207
|
+
const next = laid[index + 1];
|
|
208
|
+
if (block && next && keepsWithNext(block, next)) {
|
|
209
|
+
const below = run.at(-1)?.extent ?? offered(next).firstPiece;
|
|
210
|
+
run.push({ index, extent: block.block.height + next.block.gap + below });
|
|
151
211
|
} else {
|
|
152
212
|
settle();
|
|
153
213
|
}
|
|
@@ -166,10 +226,6 @@ function pageLayout({
|
|
|
166
226
|
const splits = [];
|
|
167
227
|
const reserved = [];
|
|
168
228
|
const trailing = [];
|
|
169
|
-
let blockPos = blocks[0]?.pos ?? 0;
|
|
170
|
-
const opened = [
|
|
171
|
-
{ page: 1, bodyStart: 0, pos: blockPos, crossed: false }
|
|
172
|
-
];
|
|
173
229
|
const roomy = sections.find(
|
|
174
230
|
(section) => section.pixels.bodyHeight > 0
|
|
175
231
|
)?.pixels;
|
|
@@ -178,35 +234,39 @@ function pageLayout({
|
|
|
178
234
|
pushes,
|
|
179
235
|
cuts,
|
|
180
236
|
splits,
|
|
181
|
-
pages: withinSections(
|
|
237
|
+
pages: withinSections([
|
|
238
|
+
{
|
|
239
|
+
page: 1,
|
|
240
|
+
bodyStart: 0,
|
|
241
|
+
section: sectionIndexAt(sections, blocks[0]?.pos ?? 0),
|
|
242
|
+
crossed: false
|
|
243
|
+
}
|
|
244
|
+
]),
|
|
182
245
|
bodyHeight: 0,
|
|
183
246
|
marginBottom: 0,
|
|
184
247
|
reserved,
|
|
185
248
|
trailing
|
|
186
249
|
};
|
|
187
250
|
}
|
|
188
|
-
const
|
|
189
|
-
(block) => sectionIndexAt(sections, block.pos)
|
|
190
|
-
);
|
|
191
|
-
const laid = blockSections.map((section, index) => {
|
|
192
|
-
const pixels = sections[section]?.pixels;
|
|
193
|
-
return {
|
|
194
|
-
paper: pixels && pixels.bodyHeight > 0 ? pixels : roomy,
|
|
195
|
-
opensPage: index > 0 && section !== blockSections[index - 1] && sections[section]?.type !== "continuous"
|
|
196
|
-
};
|
|
197
|
-
});
|
|
251
|
+
const laid = laidOut(blocks, sections, roomy);
|
|
198
252
|
let pageStart = 0;
|
|
199
253
|
let cursor = 0;
|
|
200
|
-
let
|
|
201
|
-
const
|
|
254
|
+
let piece = laid[0] ?? { section: 0, paper: roomy };
|
|
255
|
+
const opened = [
|
|
256
|
+
{ page: 1, bodyStart: 0, section: piece.section, crossed: false }
|
|
257
|
+
];
|
|
258
|
+
const stepTo = (opening) => piece.paper.pageStep - piece.paper.marginTop + opening.marginTop;
|
|
202
259
|
let room = emptyRoom();
|
|
203
260
|
let carried = [];
|
|
204
261
|
let reached = 0;
|
|
205
262
|
let held = 0;
|
|
206
|
-
const reservedHere = () => Math.min(
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
263
|
+
const reservedHere = () => Math.min(
|
|
264
|
+
room.height,
|
|
265
|
+
Math.max(0, pageStart + piece.paper.bodyHeight - held)
|
|
266
|
+
);
|
|
267
|
+
const bodyEnd = () => pageStart + piece.paper.bodyHeight - reservedHere();
|
|
268
|
+
const endsOnPage = (bottom) => bottom <= pageStart + piece.paper.bodyHeight + TOLERANCE_PX;
|
|
269
|
+
const settle = (floor, onPaper = piece.paper) => {
|
|
210
270
|
held = Math.max(held, floor);
|
|
211
271
|
while (held + room.height > pageStart + onPaper.bodyHeight + TOLERANCE_PX) {
|
|
212
272
|
const last = room.kept.at(-1);
|
|
@@ -235,25 +295,30 @@ function pageLayout({
|
|
|
235
295
|
top += height;
|
|
236
296
|
}
|
|
237
297
|
};
|
|
238
|
-
const split = (y, crossed, forced, opening =
|
|
298
|
+
const split = (y, crossed, forced, opening = piece) => {
|
|
239
299
|
const page = splits.length + 2;
|
|
240
300
|
recordRoom(page - 1);
|
|
241
301
|
splits.push({ y: round(y), page, forced, crossed });
|
|
242
|
-
pageStart = crossed ? y : y + stepTo(opening);
|
|
243
|
-
opened.push({
|
|
302
|
+
pageStart = crossed ? y : y + stepTo(opening.paper);
|
|
303
|
+
opened.push({
|
|
304
|
+
page,
|
|
305
|
+
bodyStart: round(pageStart),
|
|
306
|
+
section: opening.section,
|
|
307
|
+
crossed
|
|
308
|
+
});
|
|
244
309
|
room = emptyRoom();
|
|
245
310
|
held = pageStart;
|
|
246
311
|
const waiting = carried;
|
|
247
312
|
carried = [];
|
|
248
313
|
waiting.sort((a, b) => a.order - b.order);
|
|
249
314
|
for (const taken of waiting) keep(bands, room, taken);
|
|
250
|
-
settle(pageStart, opening);
|
|
315
|
+
settle(pageStart, opening.paper);
|
|
251
316
|
};
|
|
252
317
|
const crossTo = (y) => {
|
|
253
318
|
while (y > bodyEnd() + TOLERANCE_PX) {
|
|
254
319
|
const end = bodyEnd();
|
|
255
320
|
split(
|
|
256
|
-
end > pageStart + TOLERANCE_PX ? end : pageStart + paper.bodyHeight,
|
|
321
|
+
end > pageStart + TOLERANCE_PX ? end : pageStart + piece.paper.bodyHeight,
|
|
257
322
|
true,
|
|
258
323
|
false
|
|
259
324
|
);
|
|
@@ -276,24 +341,25 @@ function pageLayout({
|
|
|
276
341
|
if (endsOnPage(bottom)) settle(bottom);
|
|
277
342
|
crossTo(bottom);
|
|
278
343
|
};
|
|
279
|
-
const kept = keptExtents(
|
|
344
|
+
const kept = keptExtents(laid);
|
|
280
345
|
let breakAfterPrevious = false;
|
|
281
|
-
for (const [index,
|
|
282
|
-
|
|
283
|
-
const opening =
|
|
284
|
-
const startsSection =
|
|
285
|
-
const pageEnd = pageStart + paper.bodyHeight;
|
|
346
|
+
for (const [index, laidBlock] of laid.entries()) {
|
|
347
|
+
const { block } = laidBlock;
|
|
348
|
+
const opening = laidBlock.paper;
|
|
349
|
+
const startsSection = laidBlock.opensPage;
|
|
350
|
+
const pageEnd = pageStart + piece.paper.bodyHeight;
|
|
286
351
|
const top = cursor + block.gap;
|
|
287
352
|
const startsPage = (block.breakBefore || breakAfterPrevious || startsSection) && top > pageStart + TOLERANCE_PX;
|
|
288
|
-
const
|
|
353
|
+
const { candidates, firstPiece } = offered(laidBlock);
|
|
354
|
+
const first = kept.get(index) ?? firstPiece;
|
|
289
355
|
const overflows = top + first > pageEnd + TOLERANCE_PX;
|
|
290
356
|
const fits = first <= opening.bodyHeight + TOLERANCE_PX;
|
|
291
357
|
const demands = demandsInOrder(block);
|
|
292
358
|
const firstDemands = demands.length === 0 ? NO_DEMANDS : demands.filter((demand) => demand.offset < first);
|
|
293
359
|
const crowded = top > pageStart + TOLERANCE_PX && top + first + roomAdded(bands, room, firstDemands) > bodyEnd() + TOLERANCE_PX && first + roomAdded(bands, emptyRoom(), firstDemands) <= opening.bodyHeight + TOLERANCE_PX;
|
|
294
360
|
const push = startsPage || overflows && fits || crowded ? Math.max(0, pageEnd + stepTo(opening) - top) : 0;
|
|
295
|
-
if (push > 0 || startsPage) split(pageEnd, false, startsPage,
|
|
296
|
-
|
|
361
|
+
if (push > 0 || startsPage) split(pageEnd, false, startsPage, laidBlock);
|
|
362
|
+
piece = laidBlock;
|
|
297
363
|
if (push > 0) {
|
|
298
364
|
pushes.push({
|
|
299
365
|
pos: block.pos,
|
|
@@ -302,13 +368,12 @@ function pageLayout({
|
|
|
302
368
|
});
|
|
303
369
|
}
|
|
304
370
|
const contentTop = top + push;
|
|
305
|
-
const pageBodyHeight = paper.bodyHeight;
|
|
306
371
|
let added = 0;
|
|
307
372
|
let pieceStart = 0;
|
|
308
373
|
let untaken = 0;
|
|
309
|
-
for (let index2 = 0; index2 <=
|
|
310
|
-
const cut = index2 === 0 ? null :
|
|
311
|
-
const next =
|
|
374
|
+
for (let index2 = 0; index2 <= candidates.length; index2 += 1) {
|
|
375
|
+
const cut = index2 === 0 ? null : candidates[index2 - 1];
|
|
376
|
+
const next = candidates[index2];
|
|
312
377
|
const pieceEnd = next?.offset ?? block.height;
|
|
313
378
|
const taken = untaken;
|
|
314
379
|
while (untaken < demands.length && (next === void 0 || (demands[untaken]?.offset ?? 0) < pieceEnd)) {
|
|
@@ -319,16 +384,17 @@ function pageLayout({
|
|
|
319
384
|
let pieceBottom = contentTop + pieceEnd + added;
|
|
320
385
|
if (cut) {
|
|
321
386
|
if (cut.forced) crossTo(pieceTop);
|
|
322
|
-
const pageBottom = pageStart +
|
|
387
|
+
const pageBottom = pageStart + piece.paper.bodyHeight;
|
|
323
388
|
const size = pieceEnd - pieceStart;
|
|
324
|
-
const cutHere = cut.forced || pieceTop > pageStart + TOLERANCE_PX && (pieceBottom > pageBottom + TOLERANCE_PX && size <=
|
|
389
|
+
const cutHere = cut.forced || pieceTop > pageStart + TOLERANCE_PX && (pieceBottom > pageBottom + TOLERANCE_PX && size <= cut.paper.bodyHeight + TOLERANCE_PX || pieceBottom + roomAdded(bands, room, pieceDemands) > bodyEnd() + TOLERANCE_PX && size + roomAdded(bands, emptyRoom(), pieceDemands) <= cut.paper.bodyHeight + TOLERANCE_PX);
|
|
325
390
|
if (cutHere) {
|
|
326
|
-
split(pageBottom, false, cut.forced);
|
|
391
|
+
split(pageBottom, false, cut.forced, cut);
|
|
327
392
|
const height = Math.max(0, pageStart - pieceTop);
|
|
328
393
|
cuts.push({ at: cut.at, height: round(height) });
|
|
329
394
|
added += height + cut.repeatHeight;
|
|
330
395
|
pieceBottom += height + cut.repeatHeight;
|
|
331
396
|
}
|
|
397
|
+
piece = cut;
|
|
332
398
|
}
|
|
333
399
|
const shift = contentTop + added;
|
|
334
400
|
place(pieceBottom, pieceDemands, (demand) => shift + demand.offset);
|
|
@@ -336,10 +402,11 @@ function pageLayout({
|
|
|
336
402
|
}
|
|
337
403
|
cursor = contentTop + block.height + added;
|
|
338
404
|
breakAfterPrevious = block.breakAfter;
|
|
405
|
+
piece = laidBlock.last;
|
|
339
406
|
}
|
|
340
407
|
const drainCarried = () => {
|
|
341
408
|
while (carried.length > 0) {
|
|
342
|
-
split(pageStart + paper.bodyHeight, false, false);
|
|
409
|
+
split(pageStart + piece.paper.bodyHeight, false, false);
|
|
343
410
|
}
|
|
344
411
|
};
|
|
345
412
|
drainCarried();
|
|
@@ -350,7 +417,7 @@ function pageLayout({
|
|
|
350
417
|
const opens = below + above + row.height > bodyEnd() + TOLERANCE_PX && below > pageStart + TOLERANCE_PX;
|
|
351
418
|
if (opens) {
|
|
352
419
|
laidHere = void 0;
|
|
353
|
-
split(pageStart + paper.bodyHeight, false, false);
|
|
420
|
+
split(pageStart + piece.paper.bodyHeight, false, false);
|
|
354
421
|
below = pageStart;
|
|
355
422
|
}
|
|
356
423
|
const top = below + above;
|
|
@@ -375,10 +442,10 @@ function pageLayout({
|
|
|
375
442
|
pushes,
|
|
376
443
|
cuts,
|
|
377
444
|
splits,
|
|
378
|
-
pages: withinSections(opened
|
|
445
|
+
pages: withinSections(opened),
|
|
379
446
|
// The last page is filled out in full on the paper of the section it opens with
|
|
380
|
-
bodyHeight: round(pageStart + paper.bodyHeight),
|
|
381
|
-
marginBottom: paper.marginBottom,
|
|
447
|
+
bodyHeight: round(pageStart + piece.paper.bodyHeight),
|
|
448
|
+
marginBottom: piece.paper.marginBottom,
|
|
382
449
|
reserved,
|
|
383
450
|
trailing
|
|
384
451
|
};
|
|
@@ -390,6 +457,6 @@ export {
|
|
|
390
457
|
pageGeometryStyle,
|
|
391
458
|
pageLayout,
|
|
392
459
|
pagePixels,
|
|
393
|
-
|
|
460
|
+
sectionPaper,
|
|
394
461
|
sectionPixels
|
|
395
462
|
};
|
|
@@ -50,8 +50,8 @@ export interface TrailingRoom {
|
|
|
50
50
|
/** The paper area of one visual page, used to place its header and footer stories. */
|
|
51
51
|
export interface PageFace {
|
|
52
52
|
page: number;
|
|
53
|
-
/** The
|
|
54
|
-
|
|
53
|
+
/** The index of the section this page opens in, which its header and footer come from */
|
|
54
|
+
section: number;
|
|
55
55
|
/**
|
|
56
56
|
* The place this page takes within that section, counted from 1 again at every section, which is
|
|
57
57
|
* what its header and footer variant is chosen by (`docx/headersFooters`)
|
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
A4_SECTION_PIXELS,
|
|
13
13
|
PAGE_SPLIT_PX,
|
|
14
14
|
pageLayout,
|
|
15
|
-
|
|
15
|
+
sectionPaper
|
|
16
16
|
} from "./pageLayout.js";
|
|
17
17
|
var NO_ROOM = [];
|
|
18
18
|
function trailingOn(placement, contentTop, bodyBottom) {
|
|
@@ -88,7 +88,7 @@ function usePageLayout({
|
|
|
88
88
|
const laidOn = new Map(
|
|
89
89
|
layout.trailing.map((placement) => [placement.page, placement])
|
|
90
90
|
);
|
|
91
|
-
const paperOf = (
|
|
91
|
+
const paperOf = (section) => sectionPaper(papers, section);
|
|
92
92
|
const sheet = paperOf(0);
|
|
93
93
|
setPageMarks(view, { pushes: layout.pushes, cuts: layout.cuts });
|
|
94
94
|
const sheetHeight = measured.contentTop + layout.bodyHeight + Math.max(measured.contentBottom, layout.marginBottom);
|
|
@@ -102,18 +102,18 @@ function usePageLayout({
|
|
|
102
102
|
// the band is drawn under
|
|
103
103
|
marks: layout.splits.map((split) => ({
|
|
104
104
|
page: split.page,
|
|
105
|
-
top: measured.contentTop + split.y + (split.crossed ? 0 : paperOf(layout.pages[split.page - 2]?.
|
|
105
|
+
top: measured.contentTop + split.y + (split.crossed ? 0 : paperOf(layout.pages[split.page - 2]?.section ?? 0).marginBottom),
|
|
106
106
|
height: split.crossed ? 0 : PAGE_SPLIT_PX,
|
|
107
107
|
crossed: split.crossed
|
|
108
108
|
})),
|
|
109
109
|
// A page crossed into has no margin, so the place it was split at is its top corner
|
|
110
110
|
pages: layout.pages.map((start) => {
|
|
111
|
-
const paper = paperOf(start.
|
|
111
|
+
const paper = paperOf(start.section);
|
|
112
112
|
const paperTop = measured.contentTop + start.bodyStart - (start.crossed ? 0 : paper.marginTop);
|
|
113
113
|
const bodyBottom = measured.contentTop + start.bodyStart + paper.bodyHeight;
|
|
114
114
|
return {
|
|
115
115
|
page: start.page,
|
|
116
|
-
|
|
116
|
+
section: start.section,
|
|
117
117
|
pageInSection: start.pageInSection,
|
|
118
118
|
headerTop: paperTop + paper.marginTop / 2,
|
|
119
119
|
footerTop: paperTop + paper.pageHeight - paper.marginBottom / 2,
|
package/dist/schema/attrRoles.js
CHANGED
|
@@ -41,6 +41,14 @@ var NODE_ATTR_ROLES = {
|
|
|
41
41
|
tblPrEx: { role: "source", class: "preserved" },
|
|
42
42
|
trPr: { role: "source", class: "preserved" },
|
|
43
43
|
format: { role: "display", class: "derived" },
|
|
44
|
+
// The control a `w:sdt` under `w:tbl` put around this row, read and compared for the same
|
|
45
|
+
// reasons a wrapped cell's is
|
|
46
|
+
sdtPrefix: { role: "source", class: "preserved" },
|
|
47
|
+
sdtContentsLocked: { role: "source", class: "derived" },
|
|
48
|
+
sdtDeletionLocked: { role: "source", class: "derived" },
|
|
49
|
+
sdtGroup: { role: "source", class: "derived" },
|
|
50
|
+
sdtTemporary: { role: "source", class: "derived" },
|
|
51
|
+
sdtShowingPlaceholder: { role: "source", class: "derived" },
|
|
44
52
|
leadingXml: { role: "source", class: "preserved" },
|
|
45
53
|
trailingXml: { role: "source", class: "preserved" }
|
|
46
54
|
},
|
|
@@ -59,8 +67,41 @@ var NODE_ATTR_ROLES = {
|
|
|
59
67
|
sdtPrefix: { role: "source", class: "preserved" },
|
|
60
68
|
sdtContentsLocked: { role: "source", class: "derived" },
|
|
61
69
|
sdtDeletionLocked: { role: "source", class: "derived" },
|
|
70
|
+
sdtGroup: { role: "source", class: "derived" },
|
|
71
|
+
sdtTemporary: { role: "source", class: "derived" },
|
|
72
|
+
sdtShowingPlaceholder: { role: "source", class: "derived" },
|
|
62
73
|
trailingXml: { role: "source", class: "preserved" }
|
|
63
74
|
},
|
|
75
|
+
sdtBlock: {
|
|
76
|
+
srcId: { role: "session", class: "identity" },
|
|
77
|
+
sdtPrefix: { role: "source", class: "preserved" },
|
|
78
|
+
// Which control this is, counted as the document was opened. Export reads it to tell one
|
|
79
|
+
// control from another (`docx/identities`) and never works it out again
|
|
80
|
+
key: { role: "session", class: "identity" },
|
|
81
|
+
// Read from `sdtPrefix` rather than from the file, and compared for the same reason a cell's
|
|
82
|
+
// are: leaving a lock out would let a step that unlocks a control pass as a re-derivation
|
|
83
|
+
contentsLocked: { role: "source", class: "derived" },
|
|
84
|
+
deletionLocked: { role: "source", class: "derived" },
|
|
85
|
+
group: { role: "source", class: "derived" },
|
|
86
|
+
// What the control says about outliving an edit, read off `sdtPrefix` as the locks are.
|
|
87
|
+
// A step clears them beside the prefix they were read from, so a comparison has to see them
|
|
88
|
+
temporary: { role: "source", class: "derived" },
|
|
89
|
+
showingPlaceholder: { role: "source", class: "derived" }
|
|
90
|
+
},
|
|
91
|
+
// The same facts ride on a control holding nothing as on one holding blocks, so the rows mirror
|
|
92
|
+
// `sdtBlock`'s. Nothing ever clears `temporary` or `showingPlaceholder` here - there is nothing
|
|
93
|
+
// inside to edit, so `editor/plugins/controlLifecycle` passes the node by - and they are
|
|
94
|
+
// compared exactly as they were read.
|
|
95
|
+
sdtEmpty: {
|
|
96
|
+
srcId: { role: "session", class: "identity" },
|
|
97
|
+
sdtPrefix: { role: "source", class: "preserved" },
|
|
98
|
+
key: { role: "session", class: "identity" },
|
|
99
|
+
contentsLocked: { role: "source", class: "derived" },
|
|
100
|
+
deletionLocked: { role: "source", class: "derived" },
|
|
101
|
+
group: { role: "source", class: "derived" },
|
|
102
|
+
temporary: { role: "source", class: "derived" },
|
|
103
|
+
showingPlaceholder: { role: "source", class: "derived" }
|
|
104
|
+
},
|
|
64
105
|
rawBlock: {
|
|
65
106
|
xml: { role: "source", class: "preserved" },
|
|
66
107
|
srcId: { role: "session", class: "identity" },
|
|
@@ -141,7 +182,10 @@ var MARK_ATTR_ROLES = {
|
|
|
141
182
|
sdtPrefix: { role: "source", class: "preserved" },
|
|
142
183
|
...WRAPPER_ATTR_ROLES,
|
|
143
184
|
contentsLocked: { role: "source", class: "derived" },
|
|
144
|
-
deletionLocked: { role: "source", class: "derived" }
|
|
185
|
+
deletionLocked: { role: "source", class: "derived" },
|
|
186
|
+
group: { role: "source", class: "derived" },
|
|
187
|
+
temporary: { role: "source", class: "derived" },
|
|
188
|
+
showingPlaceholder: { role: "source", class: "derived" }
|
|
145
189
|
},
|
|
146
190
|
link: {
|
|
147
191
|
linkPrefix: { role: "source", class: "preserved" },
|
package/dist/schema/clipboard.js
CHANGED
|
@@ -128,6 +128,15 @@ var CLIPBOARD_NODES = {
|
|
|
128
128
|
// own and a nested table all say what they hold on the one line this cell stands on
|
|
129
129
|
toClipboardText: (_node, children) => oneLine(children.join(" "))
|
|
130
130
|
},
|
|
131
|
+
// A control is drawn through: what it holds is content a paste should keep, while its opening
|
|
132
|
+
// XML names a `w:id` and may name a `w:dataBinding`, neither of which may travel in a copy
|
|
133
|
+
sdtBlock: {
|
|
134
|
+
toClipboardDOM: () => ["div", 0],
|
|
135
|
+
toClipboardText: (_node, children) => children.join("\n")
|
|
136
|
+
},
|
|
137
|
+
// A control holding nothing says only that something is not there, which a copy carries by
|
|
138
|
+
// leaving it out
|
|
139
|
+
sdtEmpty: WRITES_NOTHING,
|
|
131
140
|
rawBlock: WRITES_NOTHING,
|
|
132
141
|
hardBreak: {
|
|
133
142
|
toClipboardDOM: () => ["br"],
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The attributes each carrier of a content control writes what the control states in.
|
|
3
|
+
*
|
|
4
|
+
* Five carriers state the same facts: the `sdt` mark, the `sdtBlock` container and the `sdtEmpty`
|
|
5
|
+
* node under the control's own names, and a cell or a row the file wrapped (`docx/importTable`)
|
|
6
|
+
* under `sdt`-prefixed ones, beside that node's own attributes. The names stand here once, so that
|
|
7
|
+
* a fact the editor reads off a control is declared, drawn, parsed, imported, merged and cleared
|
|
8
|
+
* from one table rather than from a list written out afresh in every module that touches one.
|
|
9
|
+
*
|
|
10
|
+
* Nothing is imported here: the schema itself reads this table (`./docxSchema`), and so does the
|
|
11
|
+
* export, which must reach no editor code at all (`core.test`).
|
|
12
|
+
*/
|
|
13
|
+
import type { Node as PMNode } from "prosemirror-model";
|
|
14
|
+
/** The node a block-level content control is read as, which `./docxSchema` declares it under */
|
|
15
|
+
export declare const SDT_BLOCK_NODE = "sdtBlock";
|
|
16
|
+
/** The node a control holding nothing at all is read as, which `./docxSchema` declares beside it */
|
|
17
|
+
export declare const SDT_EMPTY_NODE = "sdtEmpty";
|
|
18
|
+
/** Which attribute one carrier writes each fact under */
|
|
19
|
+
export interface ControlAttrNames {
|
|
20
|
+
prefix: string;
|
|
21
|
+
contentsLocked: string;
|
|
22
|
+
deletionLocked: string;
|
|
23
|
+
group: string;
|
|
24
|
+
temporary: string;
|
|
25
|
+
showingPlaceholder: string;
|
|
26
|
+
}
|
|
27
|
+
/** What a control states, in the shape every carrier reads it as (`docx/sdt`) */
|
|
28
|
+
export interface ControlFacts {
|
|
29
|
+
/** The `<w:sdt>` opening tag with everything that stood ahead of `<w:sdtContent>` */
|
|
30
|
+
prefix: string | null;
|
|
31
|
+
/** Whether its `w:lock` says the contents may not be edited */
|
|
32
|
+
contentsLocked: boolean;
|
|
33
|
+
/** Whether its `w:lock` says it may not be deleted, not even whole */
|
|
34
|
+
deletionLocked: boolean;
|
|
35
|
+
/** Whether it is a `w:group` */
|
|
36
|
+
group: boolean;
|
|
37
|
+
/** Whether `w:temporary` says the control goes once its contents are edited (§17.5.2.43) */
|
|
38
|
+
temporary: boolean;
|
|
39
|
+
/** Whether `w:showingPlcHdr` says what stands inside is placeholder text (§17.5.2.39) */
|
|
40
|
+
showingPlaceholder: boolean;
|
|
41
|
+
}
|
|
42
|
+
/** Everything a control states other than the opening XML the carrier preserves */
|
|
43
|
+
export type ControlFlags = Omit<ControlFacts, "prefix">;
|
|
44
|
+
/** The control's own names, which the mark and the block-level container both carry */
|
|
45
|
+
export declare const OWN_CONTROL_ATTRS: ControlAttrNames;
|
|
46
|
+
/**
|
|
47
|
+
* A wrapped cell or row carries the control beside its own attributes, so every name is prefixed.
|
|
48
|
+
* Both are one node the file put a `w:sdt` around, so they read it under the same names.
|
|
49
|
+
*/
|
|
50
|
+
export declare const WRAPPED_CONTROL_ATTRS: ControlAttrNames;
|
|
51
|
+
/** What a carrier no control stands around says, which is what each of them defaults to */
|
|
52
|
+
export declare const NO_CONTROL: ControlFacts;
|
|
53
|
+
/** The DOM attribute every carrier draws the control's opening XML under (`./docxSchema`) */
|
|
54
|
+
export declare const PREFIX_DOM_ATTR = "data-sdt-prefix";
|
|
55
|
+
/** These facts as the attributes of one carrier, to be spread over its own */
|
|
56
|
+
export declare function controlAttrs(names: ControlAttrNames, facts: ControlFacts): Record<string, string | boolean | null>;
|
|
57
|
+
/** What one carrier's attributes say the control standing there states */
|
|
58
|
+
export declare function controlFactsOf(names: ControlAttrNames, attrs: Record<string, unknown>): ControlFacts;
|
|
59
|
+
/** What one carrier declares for them, each defaulting to no control standing there */
|
|
60
|
+
export declare function controlAttrSpecs(names: ControlAttrNames): Record<string, {
|
|
61
|
+
default: string | boolean | null;
|
|
62
|
+
}>;
|
|
63
|
+
/**
|
|
64
|
+
* The control as a carrier draws it, beside the attributes and the class of the carrier's own.
|
|
65
|
+
* Every carrier draws it the same way, so what its node spec keeps is the class names alone.
|
|
66
|
+
*/
|
|
67
|
+
export declare function controlToDom(facts: ControlFacts): Record<string, string | undefined>;
|
|
68
|
+
/**
|
|
69
|
+
* The class the carrier wears, which is its own until the control shuts what stands inside it.
|
|
70
|
+
* A `w:group` shuts its contents as a lock does, so it is drawn as one (`./locks`).
|
|
71
|
+
*/
|
|
72
|
+
export declare function controlClassName(facts: ControlFacts, base: string, locked: string): string;
|
|
73
|
+
/**
|
|
74
|
+
* The control read back off a carrier that was drawn, as that carrier's attributes. The opening
|
|
75
|
+
* XML is handed over already validated, since what a carrier accepts there is the schema's to say.
|
|
76
|
+
*/
|
|
77
|
+
export declare function controlAttrsFromDom(names: ControlAttrNames, dom: HTMLElement, prefix: string | null): Record<string, string | boolean | null>;
|
|
78
|
+
/**
|
|
79
|
+
* Whether this node is a block-level content control (`docx/importSdtBlock`).
|
|
80
|
+
*
|
|
81
|
+
* The comparison is by type name, so a schema built beside the editor's own
|
|
82
|
+
* (`table/__testing__/tables`) is read as well.
|
|
83
|
+
*/
|
|
84
|
+
export declare function isBlockControl(node: PMNode | null | undefined): boolean;
|
|
85
|
+
/**
|
|
86
|
+
* Whether this node is a content control with nothing inside it (`docx/importSdtBlock`).
|
|
87
|
+
*
|
|
88
|
+
* Deliberately not folded into `isBlockControl`: every caller of that one asks about the blocks a
|
|
89
|
+
* control holds, and this control holds none, so it is no container and stands as an atom.
|
|
90
|
+
*/
|
|
91
|
+
export declare function isEmptyControl(node: PMNode | null | undefined): boolean;
|
|
92
|
+
/**
|
|
93
|
+
* Which attributes the control standing at this node writes what it states in, and null where no
|
|
94
|
+
* control stands there.
|
|
95
|
+
*
|
|
96
|
+
* These are the containers a control stands around whole: a cell or a row the file wrapped
|
|
97
|
+
* (`docx/importTable`), which carries the control's opening XML beside its own attributes, and a
|
|
98
|
+
* block-level control, which is the wrapper itself. A control holding nothing is a carrier as
|
|
99
|
+
* well, its extent being the node itself rather than anything standing inside it. A cell or a row
|
|
100
|
+
* no control wrapped carries none of this, and counting it as a control would end the walk out of
|
|
101
|
+
* the tree at the first one and open every lock standing around the table (`./locks`).
|
|
102
|
+
* The wrapped nodes are found by their table role, so a schema built beside the editor's own is
|
|
103
|
+
* read as well.
|
|
104
|
+
*/
|
|
105
|
+
export declare function controlAttrsOf(node: PMNode | null | undefined): ControlAttrNames | null;
|