@drghaliasri/butex 8.1.0 → 8.1.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/dist/document-cli.js +125 -32
- package/dist/document-cli.js.map +1 -1
- package/dist/document.d.mts +47 -4
- package/dist/document.d.ts +47 -4
- package/dist/document.js +204 -36
- package/dist/document.js.map +1 -1
- package/dist/document.mjs +198 -36
- package/dist/document.mjs.map +1 -1
- package/dist/react-document-preview.d.mts +28 -5
- package/dist/react-document-preview.d.ts +28 -5
- package/dist/react-document-preview.js +55 -10
- package/dist/react-document-preview.js.map +1 -1
- package/dist/react-document-preview.mjs +55 -10
- package/dist/react-document-preview.mjs.map +1 -1
- package/dist/react-document.d.mts +32 -3
- package/dist/react-document.d.ts +32 -3
- package/dist/react-document.js +282 -83
- package/dist/react-document.js.map +1 -1
- package/dist/react-document.mjs +282 -83
- package/dist/react-document.mjs.map +1 -1
- package/package.json +1 -1
package/dist/react-document.mjs
CHANGED
|
@@ -838,11 +838,17 @@ function refTokenLatex(keys, refCommand) {
|
|
|
838
838
|
const command = refCommand === "eqref" ? "\\eqref" : "\\ref";
|
|
839
839
|
return `${command}{${keys.join(",")}}`;
|
|
840
840
|
}
|
|
841
|
-
function
|
|
841
|
+
function implicitObjectKey(kind, ownerId, unitId) {
|
|
842
842
|
const hex = (value) => Array.from(new TextEncoder().encode(value), (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
843
843
|
const scope = unitId === void 0 ? "a" : "u" + hex(unitId);
|
|
844
844
|
return kind + ":butex-auto-" + scope + "-" + hex(ownerId);
|
|
845
845
|
}
|
|
846
|
+
function implicitReferenceKey(kind, ownerId, unitId) {
|
|
847
|
+
return implicitObjectKey(kind, ownerId, unitId);
|
|
848
|
+
}
|
|
849
|
+
function implicitHeadingReferenceKey(kind, ownerId, unitId) {
|
|
850
|
+
return implicitObjectKey(kind, ownerId, unitId);
|
|
851
|
+
}
|
|
846
852
|
function supportsSingleEquationNumbering(token) {
|
|
847
853
|
return token.display && (token.opening === "\\[" || token.opening === String.fromCharCode(36, 36) || token.opening === "\\begin{equation}" || token.opening === "\\begin{equation*}");
|
|
848
854
|
}
|
|
@@ -1476,6 +1482,7 @@ function parseTextBlock(json, options, path, diagnostics, identities) {
|
|
|
1476
1482
|
identities
|
|
1477
1483
|
),
|
|
1478
1484
|
...metadataFromJson(json.metadata),
|
|
1485
|
+
...typeof json.label === "string" && json.command !== "\\paragraph" ? { label: json.label } : {},
|
|
1479
1486
|
...json.centered === true ? { centered: true } : {}
|
|
1480
1487
|
};
|
|
1481
1488
|
}
|
|
@@ -9494,6 +9501,24 @@ function updateDocumentTextBlockCentered(document2, blockId, centered) {
|
|
|
9494
9501
|
visit(next.blocks);
|
|
9495
9502
|
return next;
|
|
9496
9503
|
}
|
|
9504
|
+
function updateDocumentHeadingLabel(document2, blockId, label) {
|
|
9505
|
+
const next = cloneDocument(document2);
|
|
9506
|
+
function visit(blocks) {
|
|
9507
|
+
for (const block of blocks) {
|
|
9508
|
+
if (block.id === blockId && block.kind === "textBlock" && block.command !== "\\paragraph") {
|
|
9509
|
+
if (label.trim()) block.label = label.trim();
|
|
9510
|
+
else delete block.label;
|
|
9511
|
+
return true;
|
|
9512
|
+
}
|
|
9513
|
+
if (block.kind === "list") {
|
|
9514
|
+
for (const item of block.items) if (visit(item.blocks)) return true;
|
|
9515
|
+
}
|
|
9516
|
+
}
|
|
9517
|
+
return false;
|
|
9518
|
+
}
|
|
9519
|
+
visit(next.blocks);
|
|
9520
|
+
return next;
|
|
9521
|
+
}
|
|
9497
9522
|
function newListBlock(ordered) {
|
|
9498
9523
|
const command = ordered ? "\\begin{enumerate}" : "\\begin{itemize}";
|
|
9499
9524
|
const closing = ordered ? "\\end{enumerate}" : "\\end{itemize}";
|
|
@@ -10057,6 +10082,7 @@ function blockJson(block) {
|
|
|
10057
10082
|
id: block.id,
|
|
10058
10083
|
command: block.command,
|
|
10059
10084
|
...fieldJson(block.field),
|
|
10085
|
+
...block.command !== "\\paragraph" && block.label ? { label: block.label } : {},
|
|
10060
10086
|
...block.metadata ? { metadata: { ...block.metadata } } : {},
|
|
10061
10087
|
...block.command === "\\paragraph" ? { centered: block.centered === true } : {}
|
|
10062
10088
|
};
|
|
@@ -10448,7 +10474,7 @@ function refTokenLatexForDocument(token, labelKinds, previousToken) {
|
|
|
10448
10474
|
}
|
|
10449
10475
|
return `${semanticRefPrefix(kind)}~${reference}`;
|
|
10450
10476
|
}
|
|
10451
|
-
function tokenLatex(token, labelKinds, previousToken) {
|
|
10477
|
+
function tokenLatex(token, labelKinds, previousToken, unitId) {
|
|
10452
10478
|
if (token.kind === "text") {
|
|
10453
10479
|
return styledTextLatex(token.text, token.style);
|
|
10454
10480
|
}
|
|
@@ -10460,7 +10486,7 @@ function tokenLatex(token, labelKinds, previousToken) {
|
|
|
10460
10486
|
}
|
|
10461
10487
|
if (isNumberedEquation(token)) {
|
|
10462
10488
|
const body = mathBodyLatex(token);
|
|
10463
|
-
const autoKey = implicitReferenceKey("eq", token.id);
|
|
10489
|
+
const autoKey = implicitReferenceKey("eq", token.id, unitId);
|
|
10464
10490
|
const aliases = [autoKey];
|
|
10465
10491
|
if (token.labelEnabled && token.label?.trim() && token.label.trim() !== autoKey) aliases.push(token.label.trim());
|
|
10466
10492
|
return "\\begin{equation}\n" + body + "\n" + aliases.map((key) => "\\label{" + key + "}").join("\n") + "\n\\end{equation}";
|
|
@@ -10476,13 +10502,18 @@ function tokenLatex(token, labelKinds, previousToken) {
|
|
|
10476
10502
|
}
|
|
10477
10503
|
return renderMathNodeLatex(token.math);
|
|
10478
10504
|
}
|
|
10479
|
-
function inlineFieldLatexWithLabelKinds(field, labelKinds) {
|
|
10480
|
-
return field.tokens.map((token, index) => tokenLatex(token, labelKinds, field.tokens[index - 1])).join("");
|
|
10505
|
+
function inlineFieldLatexWithLabelKinds(field, labelKinds, unitId) {
|
|
10506
|
+
return field.tokens.map((token, index) => tokenLatex(token, labelKinds, field.tokens[index - 1], unitId)).join("");
|
|
10481
10507
|
}
|
|
10482
|
-
function textBlockLatex(block, labelKinds) {
|
|
10483
|
-
const content = inlineFieldLatexWithLabelKinds(block.field, labelKinds);
|
|
10508
|
+
function textBlockLatex(block, labelKinds, unitId) {
|
|
10509
|
+
const content = inlineFieldLatexWithLabelKinds(block.field, labelKinds, unitId);
|
|
10484
10510
|
const body = block.command === "\\paragraph" ? `\\par
|
|
10485
10511
|
${content}` : `${block.command}{${content}}`;
|
|
10512
|
+
if (block.command !== "\\paragraph") {
|
|
10513
|
+
const keys = unitId ? [implicitHeadingReferenceKey(block.command.slice(1), block.id, unitId)] : [];
|
|
10514
|
+
if (block.label?.trim() && !keys.includes(block.label.trim())) keys.push(block.label.trim());
|
|
10515
|
+
return [body, ...keys.map((key) => `\\label{${key}}`)].join("\n");
|
|
10516
|
+
}
|
|
10486
10517
|
if (block.command === "\\paragraph" && block.centered) {
|
|
10487
10518
|
return `\\begin{center}
|
|
10488
10519
|
${body}
|
|
@@ -10493,10 +10524,10 @@ ${body}
|
|
|
10493
10524
|
function indent(value) {
|
|
10494
10525
|
return value.split("\n").map((line) => ` ${line}`).join("\n");
|
|
10495
10526
|
}
|
|
10496
|
-
function listBlockLatex(block, references, labelKinds, fixedFloats) {
|
|
10527
|
+
function listBlockLatex(block, references, labelKinds, fixedFloats, unitId) {
|
|
10497
10528
|
const items = block.items.map((item) => {
|
|
10498
|
-
const nested = item.blocks.map((child) => "\n" + indent(blockLatex(child, references, labelKinds, fixedFloats))).join("");
|
|
10499
|
-
return ` \\item ${inlineFieldLatexWithLabelKinds(item.field, labelKinds)}${nested}`;
|
|
10529
|
+
const nested = item.blocks.map((child) => "\n" + indent(blockLatex(child, references, labelKinds, fixedFloats, unitId))).join("");
|
|
10530
|
+
return ` \\item ${inlineFieldLatexWithLabelKinds(item.field, labelKinds, unitId)}${nested}`;
|
|
10500
10531
|
}).join("\n");
|
|
10501
10532
|
return `${block.command}
|
|
10502
10533
|
${items}
|
|
@@ -10510,9 +10541,9 @@ function defaultGridColumnSpec(block) {
|
|
|
10510
10541
|
}
|
|
10511
10542
|
return `|${compact.split("").join("|")}|`;
|
|
10512
10543
|
}
|
|
10513
|
-
function tabularInnerLatex(block, labelKinds) {
|
|
10544
|
+
function tabularInnerLatex(block, labelKinds, unitId) {
|
|
10514
10545
|
const rows = block.rows.map(
|
|
10515
|
-
(row) => ` ${row.map((cell) => inlineFieldLatexWithLabelKinds(cell, labelKinds)).join(" & ")}`
|
|
10546
|
+
(row) => ` ${row.map((cell) => inlineFieldLatexWithLabelKinds(cell, labelKinds, unitId)).join(" & ")}`
|
|
10516
10547
|
);
|
|
10517
10548
|
const gridColumns = defaultGridColumnSpec(block);
|
|
10518
10549
|
if (gridColumns) {
|
|
@@ -10526,9 +10557,9 @@ ${block.closing}`;
|
|
|
10526
10557
|
${rows.join(" \\\\\n")}
|
|
10527
10558
|
${block.closing}`;
|
|
10528
10559
|
}
|
|
10529
|
-
function floatCaptionLabelLines(block, counter, labelKinds) {
|
|
10560
|
+
function floatCaptionLabelLines(block, counter, labelKinds, unitId) {
|
|
10530
10561
|
const lines = [];
|
|
10531
|
-
const caption = inlineFieldLatexWithLabelKinds(block.captionField, labelKinds).trim();
|
|
10562
|
+
const caption = inlineFieldLatexWithLabelKinds(block.captionField, labelKinds, unitId).trim();
|
|
10532
10563
|
const hasCaption = block.captionEnabled && caption.length > 0;
|
|
10533
10564
|
if (hasCaption) {
|
|
10534
10565
|
lines.push(` \\caption{${caption}}`);
|
|
@@ -10536,20 +10567,20 @@ function floatCaptionLabelLines(block, counter, labelKinds) {
|
|
|
10536
10567
|
const hasManualLabel = block.labelEnabled && block.label.trim().length > 0;
|
|
10537
10568
|
if (hasCaption || hasManualLabel) {
|
|
10538
10569
|
if (!hasCaption) lines.push(" \\refstepcounter{" + counter + "}");
|
|
10539
|
-
const autoKey = implicitReferenceKey(counter === "figure" ? "fig" : "tab", block.id);
|
|
10570
|
+
const autoKey = implicitReferenceKey(counter === "figure" ? "fig" : "tab", block.id, unitId);
|
|
10540
10571
|
lines.push(" \\label{" + autoKey + "}");
|
|
10541
10572
|
if (hasManualLabel && block.label.trim() !== autoKey) lines.push(" \\label{" + block.label.trim() + "}");
|
|
10542
10573
|
}
|
|
10543
10574
|
return lines;
|
|
10544
10575
|
}
|
|
10545
|
-
function tableBlockLatex(block, labelKinds, fixedFloats) {
|
|
10576
|
+
function tableBlockLatex(block, labelKinds, fixedFloats, unitId) {
|
|
10546
10577
|
const placement = fixedFloats ? "H" : "htbp";
|
|
10547
10578
|
const lines = [`\\begin{table}[${placement}]`];
|
|
10548
10579
|
if (block.centered) {
|
|
10549
10580
|
lines.push(" \\centering");
|
|
10550
10581
|
}
|
|
10551
|
-
lines.push(...floatCaptionLabelLines(block, "table", labelKinds));
|
|
10552
|
-
lines.push(indent(tabularInnerLatex(block, labelKinds)));
|
|
10582
|
+
lines.push(...floatCaptionLabelLines(block, "table", labelKinds, unitId));
|
|
10583
|
+
lines.push(indent(tabularInnerLatex(block, labelKinds, unitId)));
|
|
10553
10584
|
lines.push("\\end{table}");
|
|
10554
10585
|
return lines.join("\n");
|
|
10555
10586
|
}
|
|
@@ -10568,29 +10599,29 @@ function imageOptionsLatex(block, constrainToColumn) {
|
|
|
10568
10599
|
}
|
|
10569
10600
|
return `[${entries.map(([key, value]) => `${key}=${value}`).join(",")}]`;
|
|
10570
10601
|
}
|
|
10571
|
-
function imageBlockLatex(block, labelKinds, fixedFloats) {
|
|
10602
|
+
function imageBlockLatex(block, labelKinds, fixedFloats, unitId) {
|
|
10572
10603
|
const placement = fixedFloats ? "H" : "htbp";
|
|
10573
10604
|
const lines = [`\\begin{figure}[${placement}]`];
|
|
10574
10605
|
if (block.centered) {
|
|
10575
10606
|
lines.push(" \\centering");
|
|
10576
10607
|
}
|
|
10577
10608
|
lines.push(` ${block.command}${imageOptionsLatex(block, true)}{${block.value}}`);
|
|
10578
|
-
lines.push(...floatCaptionLabelLines(block, "figure", labelKinds));
|
|
10609
|
+
lines.push(...floatCaptionLabelLines(block, "figure", labelKinds, unitId));
|
|
10579
10610
|
lines.push("\\end{figure}");
|
|
10580
10611
|
return lines.join("\n");
|
|
10581
10612
|
}
|
|
10582
|
-
function blockLatex(block, references, labelKinds, fixedFloats) {
|
|
10613
|
+
function blockLatex(block, references, labelKinds, fixedFloats, unitId) {
|
|
10583
10614
|
if (block.kind === "textBlock") {
|
|
10584
|
-
return textBlockLatex(block, labelKinds);
|
|
10615
|
+
return textBlockLatex(block, labelKinds, unitId);
|
|
10585
10616
|
}
|
|
10586
10617
|
if (block.kind === "list") {
|
|
10587
|
-
return listBlockLatex(block, references, labelKinds, fixedFloats);
|
|
10618
|
+
return listBlockLatex(block, references, labelKinds, fixedFloats, unitId);
|
|
10588
10619
|
}
|
|
10589
10620
|
if (block.kind === "table") {
|
|
10590
|
-
return tableBlockLatex(block, labelKinds, fixedFloats);
|
|
10621
|
+
return tableBlockLatex(block, labelKinds, fixedFloats, unitId);
|
|
10591
10622
|
}
|
|
10592
10623
|
if (block.kind === "image") {
|
|
10593
|
-
return imageBlockLatex(block, labelKinds, fixedFloats);
|
|
10624
|
+
return imageBlockLatex(block, labelKinds, fixedFloats, unitId);
|
|
10594
10625
|
}
|
|
10595
10626
|
if (block.kind === "bibliography") {
|
|
10596
10627
|
const width = String(Math.max(references.length, 9));
|
|
@@ -10644,6 +10675,17 @@ function closingHamdalaLatex() {
|
|
|
10644
10675
|
\\maghribi{${BUTEX_CLOSING_HAMDALA}}
|
|
10645
10676
|
\\end{center}`;
|
|
10646
10677
|
}
|
|
10678
|
+
function documentContentLatex(document2, context) {
|
|
10679
|
+
if (!context?.unitId?.trim()) throw new Error("book-content export requires a stable unitId");
|
|
10680
|
+
const labelKinds = documentLabelKindMap(document2);
|
|
10681
|
+
for (const target of context?.targets ?? []) {
|
|
10682
|
+
if (target.kind === "fig" || target.kind === "tab" || target.kind === "eq") {
|
|
10683
|
+
labelKinds.set(target.key, target.kind);
|
|
10684
|
+
if (target.manualKey) labelKinds.set(target.manualKey, target.kind);
|
|
10685
|
+
}
|
|
10686
|
+
}
|
|
10687
|
+
return document2.blocks.filter((block) => block.kind !== "bibliography").map((block) => blockLatex(block, document2.references, labelKinds, false, context?.unitId)).filter((part) => part.length > 0).join("\n\n");
|
|
10688
|
+
}
|
|
10647
10689
|
function documentLatex(document2, options = {}) {
|
|
10648
10690
|
const meta = document2.meta ?? emptyDocumentMeta();
|
|
10649
10691
|
const twocolumn = options.twocolumn === true;
|
|
@@ -10675,6 +10717,65 @@ ${body}
|
|
|
10675
10717
|
`;
|
|
10676
10718
|
}
|
|
10677
10719
|
|
|
10720
|
+
// src/document/bookContent.ts
|
|
10721
|
+
function bookContextReferences(context) {
|
|
10722
|
+
return (context?.references ?? []).map((entry, index) => ({
|
|
10723
|
+
...referenceFromJson(entry),
|
|
10724
|
+
id: "book-ref-" + String(index)
|
|
10725
|
+
}));
|
|
10726
|
+
}
|
|
10727
|
+
function bookContentTargets(document2, context) {
|
|
10728
|
+
const local = collectDocumentReferenceTargets(document2).map((target) => {
|
|
10729
|
+
const key = implicitReferenceKey(target.kind, target.ownerId, context.unitId);
|
|
10730
|
+
const projection = context.targets?.find((entry) => entry.unitId === context.unitId && (entry.ownerId === target.ownerId || entry.key === key));
|
|
10731
|
+
return {
|
|
10732
|
+
...target,
|
|
10733
|
+
key,
|
|
10734
|
+
...projection?.displayLabel ? { displayLabel: projection.displayLabel } : {}
|
|
10735
|
+
};
|
|
10736
|
+
});
|
|
10737
|
+
const headings = document2.blocks.flatMap((block) => {
|
|
10738
|
+
if (block.kind !== "textBlock" || block.command === "\\paragraph") return [];
|
|
10739
|
+
const kind = block.command.slice(1);
|
|
10740
|
+
const caption = block.field.tokens.filter((token) => token.kind === "text").map((token) => token.text).join("");
|
|
10741
|
+
return [{
|
|
10742
|
+
unitId: context.unitId,
|
|
10743
|
+
ownerId: block.id,
|
|
10744
|
+
kind,
|
|
10745
|
+
key: implicitHeadingReferenceKey(kind, block.id, context.unitId),
|
|
10746
|
+
caption,
|
|
10747
|
+
number: null,
|
|
10748
|
+
displayLabel: context.targets?.find((target) => target.unitId === context.unitId && target.ownerId === block.id)?.displayLabel ?? (caption || kind),
|
|
10749
|
+
...block.label ? { manualKey: block.label } : {}
|
|
10750
|
+
}];
|
|
10751
|
+
});
|
|
10752
|
+
const external = (context.targets ?? []).filter((target) => target.unitId !== context.unitId).map((target) => ({
|
|
10753
|
+
...target,
|
|
10754
|
+
caption: target.caption ?? "",
|
|
10755
|
+
number: null
|
|
10756
|
+
}));
|
|
10757
|
+
return [...local, ...headings, ...external];
|
|
10758
|
+
}
|
|
10759
|
+
function formatBookReferenceLabel(keys, document2, command, context, options = {}) {
|
|
10760
|
+
const targets = context.targets ?? [];
|
|
10761
|
+
return keys.map((key) => {
|
|
10762
|
+
const target = targets.find((entry) => entry.key === key || entry.manualKey === key);
|
|
10763
|
+
if (target?.displayLabel) return target.displayLabel;
|
|
10764
|
+
const local = collectDocumentReferenceTargets(document2).find((entry) => entry.manualKey === key || implicitReferenceKey(entry.kind, entry.ownerId, context.unitId) === key);
|
|
10765
|
+
if (local) return formatRefLabel([local.manualKey || local.key], document2, command, options);
|
|
10766
|
+
const heading = document2.blocks.find((block) => block.kind === "textBlock" && block.command !== "\\paragraph" && (block.label === key || implicitHeadingReferenceKey(
|
|
10767
|
+
block.command.slice(1),
|
|
10768
|
+
block.id,
|
|
10769
|
+
context.unitId
|
|
10770
|
+
) === key));
|
|
10771
|
+
if (heading?.kind === "textBlock") {
|
|
10772
|
+
const caption = heading.field.tokens.filter((token) => token.kind === "text").map((token) => token.text).join("").trim();
|
|
10773
|
+
return caption || heading.command.slice(1);
|
|
10774
|
+
}
|
|
10775
|
+
return command === "eqref" ? "(?)" : "?";
|
|
10776
|
+
}).join(options.documentDirection === "ltr" ? ", " : "\u060C");
|
|
10777
|
+
}
|
|
10778
|
+
|
|
10678
10779
|
// src/document/validation.ts
|
|
10679
10780
|
var XELATEX_UNSUPPORTED_EMOJI_PATTERN = /[\p{Emoji_Presentation}\p{Emoji_Modifier}\p{Regional_Indicator}\uFE0F\u20E3]/u;
|
|
10680
10781
|
function hasXeLatexUnsupportedEmoji(value) {
|
|
@@ -10758,6 +10859,13 @@ function validateInlineField(context, field, path, blockId) {
|
|
|
10758
10859
|
function validateBlock(context, block, path) {
|
|
10759
10860
|
if (block.kind === "textBlock") {
|
|
10760
10861
|
validateInlineField(context, block.field, `${path}.field`, block.id);
|
|
10862
|
+
if (block.command !== "\\paragraph") {
|
|
10863
|
+
const kind = block.command.slice(1);
|
|
10864
|
+
if (block.label) registerKey(context, block.label, `${path}.label`, kind, block.id);
|
|
10865
|
+
if (context.bookMode && context.bookContext) {
|
|
10866
|
+
context.labelKinds.set(implicitHeadingReferenceKey(kind, block.id, context.bookContext.unitId), kind);
|
|
10867
|
+
}
|
|
10868
|
+
}
|
|
10761
10869
|
return;
|
|
10762
10870
|
}
|
|
10763
10871
|
if (block.kind === "list") {
|
|
@@ -10807,6 +10915,10 @@ function validateBlock(context, block, path) {
|
|
|
10807
10915
|
}
|
|
10808
10916
|
return;
|
|
10809
10917
|
}
|
|
10918
|
+
if (block.kind === "bibliography" && context.bookMode) {
|
|
10919
|
+
addIssue(context, "book_local_bibliography", path, block.id);
|
|
10920
|
+
return;
|
|
10921
|
+
}
|
|
10810
10922
|
if (block.kind === "raw") {
|
|
10811
10923
|
validateTextValue(context, block.value, `${path}.value`, block.id);
|
|
10812
10924
|
}
|
|
@@ -10829,7 +10941,7 @@ function validateDuplicateKeys(context) {
|
|
|
10829
10941
|
}
|
|
10830
10942
|
function validatePendingReferences(context) {
|
|
10831
10943
|
for (const pending of context.pendingCitations) {
|
|
10832
|
-
if (pending.token.keys.some((key) => !isValidDocumentKey(normalizeDocumentKey(key)))) {
|
|
10944
|
+
if (pending.token.keys.some((key) => !isValidDocumentKey(normalizeDocumentKey(key)) || context.citationKeys !== void 0 && !context.citationKeys.has(normalizeDocumentKey(key)))) {
|
|
10833
10945
|
addIssue(
|
|
10834
10946
|
context,
|
|
10835
10947
|
"missing_citation",
|
|
@@ -10911,7 +11023,7 @@ function resolveDocument(document2) {
|
|
|
10911
11023
|
return null;
|
|
10912
11024
|
}
|
|
10913
11025
|
}
|
|
10914
|
-
function validateDocument(document2) {
|
|
11026
|
+
function validateDocument(document2, options = {}) {
|
|
10915
11027
|
const resolved = resolveDocument(document2);
|
|
10916
11028
|
if (!resolved) {
|
|
10917
11029
|
return {
|
|
@@ -10923,6 +11035,9 @@ function validateDocument(document2) {
|
|
|
10923
11035
|
issues: [],
|
|
10924
11036
|
keyOwners: [],
|
|
10925
11037
|
labelKinds: /* @__PURE__ */ new Map(),
|
|
11038
|
+
bookMode: options.mode === "book-content",
|
|
11039
|
+
bookContext: options.bookContext,
|
|
11040
|
+
...options.mode === "book-content" && options.bookContext?.references ? { citationKeys: new Set(options.bookContext.references.map((entry) => normalizeDocumentKey(entry.key))) } : {},
|
|
10926
11041
|
pendingCitations: [],
|
|
10927
11042
|
pendingReferences: []
|
|
10928
11043
|
};
|
|
@@ -10942,10 +11057,11 @@ function validateDocument(document2) {
|
|
|
10942
11057
|
validateBlock(context, block, `$.blocks[${String(index)}]`);
|
|
10943
11058
|
});
|
|
10944
11059
|
for (const target of collectDocumentReferenceTargets(resolved)) {
|
|
10945
|
-
|
|
11060
|
+
const autoKey = context.bookMode && context.bookContext ? implicitReferenceKey(target.kind, target.ownerId, context.bookContext.unitId) : target.key;
|
|
11061
|
+
if (target.number !== null && target.manualKey !== autoKey) {
|
|
10946
11062
|
registerKey(
|
|
10947
11063
|
context,
|
|
10948
|
-
|
|
11064
|
+
autoKey,
|
|
10949
11065
|
"$.automatic_labels",
|
|
10950
11066
|
target.kind,
|
|
10951
11067
|
target.kind === "eq" ? void 0 : target.ownerId,
|
|
@@ -10953,6 +11069,15 @@ function validateDocument(document2) {
|
|
|
10953
11069
|
);
|
|
10954
11070
|
}
|
|
10955
11071
|
}
|
|
11072
|
+
if (context.bookMode) {
|
|
11073
|
+
for (const target of context.bookContext?.targets ?? []) {
|
|
11074
|
+
context.labelKinds.set(normalizeDocumentKey(target.key), target.kind);
|
|
11075
|
+
if (target.manualKey) context.labelKinds.set(normalizeDocumentKey(target.manualKey), target.kind);
|
|
11076
|
+
}
|
|
11077
|
+
}
|
|
11078
|
+
if (context.bookMode && !context.bookContext?.unitId?.trim()) {
|
|
11079
|
+
addIssue(context, "book_context_required", "$.book_context");
|
|
11080
|
+
}
|
|
10956
11081
|
for (const diagnostic of resolved.diagnostics) {
|
|
10957
11082
|
addIssue(context, "parser_diagnostic", diagnostic.path);
|
|
10958
11083
|
}
|
|
@@ -10963,9 +11088,6 @@ function validateDocument(document2) {
|
|
|
10963
11088
|
issues: context.issues
|
|
10964
11089
|
};
|
|
10965
11090
|
}
|
|
10966
|
-
function isDocumentValid(document2) {
|
|
10967
|
-
return validateDocument(document2).valid;
|
|
10968
|
-
}
|
|
10969
11091
|
|
|
10970
11092
|
// src/document/history.ts
|
|
10971
11093
|
var DEFAULT_DOCUMENT_HISTORY_MAX_DEPTH = 100;
|
|
@@ -11075,7 +11197,7 @@ function previewInlines(field, islands, output, equationSide, document2, preview
|
|
|
11075
11197
|
kind: "cite",
|
|
11076
11198
|
id: token.id,
|
|
11077
11199
|
keys: [...token.keys],
|
|
11078
|
-
label: formatCiteLabel(token.keys, document2.references, {
|
|
11200
|
+
label: formatCiteLabel(token.keys, previewOptions.mode === "book-content" ? bookContextReferences(previewOptions.bookContext) : document2.references, {
|
|
11079
11201
|
documentDirection: previewOptions.documentDirection,
|
|
11080
11202
|
digitForm: previewOptions.digitForm
|
|
11081
11203
|
})
|
|
@@ -11087,7 +11209,10 @@ function previewInlines(field, islands, output, equationSide, document2, preview
|
|
|
11087
11209
|
id: token.id,
|
|
11088
11210
|
keys: [...token.keys],
|
|
11089
11211
|
refCommand: token.refCommand,
|
|
11090
|
-
label:
|
|
11212
|
+
label: previewOptions.mode === "book-content" && previewOptions.bookContext ? formatBookReferenceLabel(token.keys, document2, token.refCommand, previewOptions.bookContext, {
|
|
11213
|
+
documentDirection: previewOptions.documentDirection,
|
|
11214
|
+
digitForm: previewOptions.digitForm
|
|
11215
|
+
}) : formatRefLabel(token.keys, document2, token.refCommand, {
|
|
11091
11216
|
documentDirection: previewOptions.documentDirection,
|
|
11092
11217
|
digitForm: previewOptions.digitForm
|
|
11093
11218
|
})
|
|
@@ -11243,14 +11368,16 @@ function documentPreview(document2, output = "svg", equationSide = "arabic", pre
|
|
|
11243
11368
|
const options = {
|
|
11244
11369
|
documentDirection: previewOptions.documentDirection ?? "rtl",
|
|
11245
11370
|
digitForm: previewOptions.digitForm ?? (previewOptions.documentDirection === "ltr" ? "western" : "arabicIndic"),
|
|
11246
|
-
uiLocale: previewOptions.uiLocale ?? "ar"
|
|
11371
|
+
uiLocale: previewOptions.uiLocale ?? "ar",
|
|
11372
|
+
mode: previewOptions.mode ?? "article",
|
|
11373
|
+
bookContext: previewOptions.bookContext
|
|
11247
11374
|
};
|
|
11248
|
-
const body = document2.blocks.map((block) => blockPreview(block, mathIslands, output, equationSide, document2, options));
|
|
11375
|
+
const body = document2.blocks.filter((block) => options.mode !== "book-content" || block.kind !== "bibliography").map((block) => blockPreview(block, mathIslands, output, equationSide, document2, options));
|
|
11249
11376
|
return {
|
|
11250
11377
|
blocks: [
|
|
11251
|
-
...articleChromePreview(document2, options.uiLocale ?? "ar", options),
|
|
11378
|
+
...options.mode === "book-content" ? [] : articleChromePreview(document2, options.uiLocale ?? "ar", options),
|
|
11252
11379
|
...body,
|
|
11253
|
-
{ kind: "closing", id: "article-closing", text: BUTEX_CLOSING_HAMDALA, tex: butexMaghribiDisplayTex(BUTEX_CLOSING_HAMDALA) }
|
|
11380
|
+
...options.mode === "book-content" ? [] : [{ kind: "closing", id: "article-closing", text: BUTEX_CLOSING_HAMDALA, tex: butexMaghribiDisplayTex(BUTEX_CLOSING_HAMDALA) }]
|
|
11254
11381
|
],
|
|
11255
11382
|
mathIslands
|
|
11256
11383
|
};
|
|
@@ -12483,6 +12610,7 @@ import { jsx as jsx5, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
|
12483
12610
|
function RefChip({
|
|
12484
12611
|
token,
|
|
12485
12612
|
document: document2,
|
|
12613
|
+
bookContext,
|
|
12486
12614
|
documentDirection = "rtl",
|
|
12487
12615
|
digitForm,
|
|
12488
12616
|
editable = true,
|
|
@@ -12494,7 +12622,7 @@ function RefChip({
|
|
|
12494
12622
|
onRequestTextFocus
|
|
12495
12623
|
}) {
|
|
12496
12624
|
const messages = documentMessages(uiLocale);
|
|
12497
|
-
const label = formatRefLabel(token.keys, document2, token.refCommand, { documentDirection, digitForm });
|
|
12625
|
+
const label = bookContext ? formatBookReferenceLabel(token.keys, document2, token.refCommand, bookContext, { documentDirection, digitForm }) : formatRefLabel(token.keys, document2, token.refCommand, { documentDirection, digitForm });
|
|
12498
12626
|
const forwardArrowKey = documentDirection === "rtl" ? "ArrowLeft" : "ArrowRight";
|
|
12499
12627
|
const backwardArrowKey = documentDirection === "rtl" ? "ArrowRight" : "ArrowLeft";
|
|
12500
12628
|
if (!editable) {
|
|
@@ -12572,6 +12700,7 @@ function InlineField({
|
|
|
12572
12700
|
blockId,
|
|
12573
12701
|
references = [],
|
|
12574
12702
|
documentNode,
|
|
12703
|
+
bookContext,
|
|
12575
12704
|
documentDirection = "rtl",
|
|
12576
12705
|
digitForm,
|
|
12577
12706
|
mathOutput = "svg",
|
|
@@ -12808,6 +12937,7 @@ function InlineField({
|
|
|
12808
12937
|
return /* @__PURE__ */ jsx6(
|
|
12809
12938
|
RefChip,
|
|
12810
12939
|
{
|
|
12940
|
+
bookContext,
|
|
12811
12941
|
token,
|
|
12812
12942
|
document: documentNode,
|
|
12813
12943
|
documentDirection,
|
|
@@ -13290,7 +13420,9 @@ function BlockEditor({
|
|
|
13290
13420
|
onParagraphCenteredChange,
|
|
13291
13421
|
onAddListItem,
|
|
13292
13422
|
onRemoveListItem,
|
|
13293
|
-
onManageReferences
|
|
13423
|
+
onManageReferences,
|
|
13424
|
+
bookContext,
|
|
13425
|
+
onHeadingLabelChange
|
|
13294
13426
|
}) {
|
|
13295
13427
|
const messages = documentMessages(uiLocale);
|
|
13296
13428
|
const labels = documentNode ? collectDocumentLabels(documentNode) : [];
|
|
@@ -13305,6 +13437,7 @@ function BlockEditor({
|
|
|
13305
13437
|
blockId: block.id,
|
|
13306
13438
|
references,
|
|
13307
13439
|
documentNode,
|
|
13440
|
+
bookContext,
|
|
13308
13441
|
documentDirection,
|
|
13309
13442
|
digitForm,
|
|
13310
13443
|
mathOutput,
|
|
@@ -13382,6 +13515,18 @@ function BlockEditor({
|
|
|
13382
13515
|
return /* @__PURE__ */ jsxs6("section", { className: chromeClass, "data-butex-block-source": block.metadata?.source, children: [
|
|
13383
13516
|
header,
|
|
13384
13517
|
/* @__PURE__ */ jsx7(InlineField, { field: block.field, ...fieldProps }),
|
|
13518
|
+
bookContext && block.command !== "\\paragraph" ? /* @__PURE__ */ jsxs6("label", { className: "butex-document-widget__refs-field", children: [
|
|
13519
|
+
/* @__PURE__ */ jsx7("span", { children: messages.floatLabel }),
|
|
13520
|
+
/* @__PURE__ */ jsx7(
|
|
13521
|
+
"input",
|
|
13522
|
+
{
|
|
13523
|
+
type: "text",
|
|
13524
|
+
dir: "ltr",
|
|
13525
|
+
value: block.label ?? "",
|
|
13526
|
+
onChange: (event) => onHeadingLabelChange?.(block.id, event.currentTarget.value)
|
|
13527
|
+
}
|
|
13528
|
+
)
|
|
13529
|
+
] }) : null,
|
|
13385
13530
|
block.command === "\\paragraph" ? /* @__PURE__ */ jsx7("div", { className: "butex-document-widget__float-meta butex-document-widget__float-meta--compact", children: /* @__PURE__ */ jsxs6("label", { className: "butex-document-widget__float-meta-toggle", children: [
|
|
13386
13531
|
/* @__PURE__ */ jsx7(
|
|
13387
13532
|
"input",
|
|
@@ -13441,7 +13586,9 @@ function BlockEditor({
|
|
|
13441
13586
|
onParagraphCenteredChange,
|
|
13442
13587
|
onAddListItem,
|
|
13443
13588
|
onRemoveListItem,
|
|
13444
|
-
onManageReferences
|
|
13589
|
+
onManageReferences,
|
|
13590
|
+
bookContext,
|
|
13591
|
+
onHeadingLabelChange
|
|
13445
13592
|
},
|
|
13446
13593
|
child.id
|
|
13447
13594
|
))
|
|
@@ -13801,6 +13948,7 @@ function digitFormLabel(digitForm) {
|
|
|
13801
13948
|
return "456";
|
|
13802
13949
|
}
|
|
13803
13950
|
function DocumentInsertToolbar({
|
|
13951
|
+
mode = "article",
|
|
13804
13952
|
canUndo,
|
|
13805
13953
|
canRedo,
|
|
13806
13954
|
editableEquations = true,
|
|
@@ -13990,7 +14138,7 @@ function DocumentInsertToolbar({
|
|
|
13990
14138
|
)
|
|
13991
14139
|
] }),
|
|
13992
14140
|
/* @__PURE__ */ jsxs9("div", { className: "butex-document-widget__toolbar-group", role: "group", "aria-label": messages.structure, children: [
|
|
13993
|
-
/* @__PURE__ */ jsx10(
|
|
14141
|
+
mode === "article" ? /* @__PURE__ */ jsx10(
|
|
13994
14142
|
"button",
|
|
13995
14143
|
{
|
|
13996
14144
|
type: "button",
|
|
@@ -14000,7 +14148,7 @@ function DocumentInsertToolbar({
|
|
|
14000
14148
|
onClick: onOpenArticleMeta,
|
|
14001
14149
|
children: "\u2726"
|
|
14002
14150
|
}
|
|
14003
|
-
),
|
|
14151
|
+
) : null,
|
|
14004
14152
|
/* @__PURE__ */ jsx10("button", { type: "button", className: "butex-document-widget__icon-btn butex-document-widget__icon-btn--h1", title: messages.addSection, "aria-label": messages.addSection, onClick: onAddSection, children: messages.sectionGlyph }),
|
|
14005
14153
|
/* @__PURE__ */ jsx10("button", { type: "button", className: "butex-document-widget__icon-btn butex-document-widget__icon-btn--h2", title: messages.addSubsection, "aria-label": messages.addSubsection, onClick: onAddSubsection, children: messages.subsectionGlyph }),
|
|
14006
14154
|
/* @__PURE__ */ jsx10("button", { type: "button", className: "butex-document-widget__icon-btn butex-document-widget__icon-btn--h3", title: messages.addSubsubsection, "aria-label": messages.addSubsubsection, onClick: onAddSubsubsection, children: messages.subsubsectionGlyph }),
|
|
@@ -14075,14 +14223,14 @@ function DocumentInsertToolbar({
|
|
|
14075
14223
|
/* @__PURE__ */ jsx10("span", { "aria-hidden": "true", children: "\xA7" }),
|
|
14076
14224
|
/* @__PURE__ */ jsx10("span", { children: messages.insertInternalRef })
|
|
14077
14225
|
] }),
|
|
14078
|
-
/* @__PURE__ */ jsxs9("button", { type: "button", role: "menuitem", title: messages.insertBibliography, onClick: () => runReferenceAction(onInsertBibliography), children: [
|
|
14226
|
+
mode === "article" ? /* @__PURE__ */ jsxs9("button", { type: "button", role: "menuitem", title: messages.insertBibliography, onClick: () => runReferenceAction(onInsertBibliography), children: [
|
|
14079
14227
|
/* @__PURE__ */ jsx10("span", { className: "butex-document-widget__icon-bibliography", "aria-hidden": "true", children: /* @__PURE__ */ jsx10("svg", { viewBox: "0 0 16 16", width: "14", height: "14", focusable: "false", children: /* @__PURE__ */ jsx10("path", { fill: "currentColor", d: "M2.2 2.4h7.2c.9 0 1.6.7 1.6 1.6v9.2c0 .5-.6.8-1 .5l-2.2-1.6H2.2c-.9 0-1.6-.7-1.6-1.6V4c0-.9.7-1.6 1.6-1.6zm0 1.2c-.2 0-.4.2-.4.4v6.5c0 .2.2.4.4.4h6.1l1.5 1.1V4c0-.2-.2-.4-.4-.4H2.2zM3.4 5.2h5.2v1H3.4zm0 2.1h4.2v1H3.4zm0 2.1h3.4v1H3.4zM11.4 4.1h2.2c.8 0 1.4.6 1.4 1.4v7.1c0 .4-.5.7-.8.4l-1.7-1.3h-1.1V4.1zm1.2 1.2v5.4l.7.5V5.5c0-.1-.1-.2-.2-.2h-.5z" }) }) }),
|
|
14080
14228
|
/* @__PURE__ */ jsx10("span", { children: messages.insertBibliography })
|
|
14081
|
-
] }),
|
|
14082
|
-
/* @__PURE__ */ jsxs9("button", { type: "button", role: "menuitem", title: messages.manageReferences, onClick: () => runReferenceAction(onManageReferences), children: [
|
|
14229
|
+
] }) : null,
|
|
14230
|
+
mode === "article" ? /* @__PURE__ */ jsxs9("button", { type: "button", role: "menuitem", title: messages.manageReferences, onClick: () => runReferenceAction(onManageReferences), children: [
|
|
14083
14231
|
/* @__PURE__ */ jsx10("span", { "aria-hidden": "true", children: "\u2630" }),
|
|
14084
14232
|
/* @__PURE__ */ jsx10("span", { children: messages.manageReferences })
|
|
14085
|
-
] }),
|
|
14233
|
+
] }) : null,
|
|
14086
14234
|
/* @__PURE__ */ jsxs9("button", { type: "button", role: "menuitem", title: messages.manageLabels, onClick: () => runReferenceAction(onManageLabels), children: [
|
|
14087
14235
|
/* @__PURE__ */ jsx10("span", { "aria-hidden": "true", children: "\u2317" }),
|
|
14088
14236
|
/* @__PURE__ */ jsx10("span", { children: messages.manageLabels })
|
|
@@ -14114,6 +14262,7 @@ function digitFormLabel2(digitForm) {
|
|
|
14114
14262
|
return "456";
|
|
14115
14263
|
}
|
|
14116
14264
|
function DocumentMobileToolbar({
|
|
14265
|
+
mode = "article",
|
|
14117
14266
|
mobileView,
|
|
14118
14267
|
canUndo,
|
|
14119
14268
|
canRedo,
|
|
@@ -14298,7 +14447,7 @@ function DocumentMobileToolbar({
|
|
|
14298
14447
|
/* @__PURE__ */ jsxs10("section", { className: "butex-document-widget__command-group", "aria-labelledby": `${titleId}-structure`, children: [
|
|
14299
14448
|
/* @__PURE__ */ jsx11("h3", { id: `${titleId}-structure`, children: messages.structure }),
|
|
14300
14449
|
/* @__PURE__ */ jsxs10("div", { className: "butex-document-widget__command-grid", children: [
|
|
14301
|
-
/* @__PURE__ */ jsx11("button", { type: "button", onClick: () => runAction(onOpenArticleMeta), children: messages.articleMetaTitle }),
|
|
14450
|
+
mode === "article" ? /* @__PURE__ */ jsx11("button", { type: "button", onClick: () => runAction(onOpenArticleMeta), children: messages.articleMetaTitle }) : null,
|
|
14302
14451
|
/* @__PURE__ */ jsx11("button", { type: "button", onClick: () => runAction(onAddSection), children: messages.addSection }),
|
|
14303
14452
|
/* @__PURE__ */ jsx11("button", { type: "button", onClick: () => runAction(onAddSubsection), children: messages.addSubsection }),
|
|
14304
14453
|
/* @__PURE__ */ jsx11("button", { type: "button", onClick: () => runAction(onAddSubsubsection), children: messages.addSubsubsection }),
|
|
@@ -14339,8 +14488,8 @@ function DocumentMobileToolbar({
|
|
|
14339
14488
|
/* @__PURE__ */ jsxs10("div", { className: "butex-document-widget__command-grid", children: [
|
|
14340
14489
|
/* @__PURE__ */ jsx11("button", { type: "button", onClick: () => runAction(onInsertCitation, false), children: messages.insertCitation }),
|
|
14341
14490
|
/* @__PURE__ */ jsx11("button", { type: "button", onClick: () => runAction(onInsertInternalRef, false), children: messages.insertInternalRef }),
|
|
14342
|
-
/* @__PURE__ */ jsx11("button", { type: "button", onClick: () => runAction(onInsertBibliography), children: messages.insertBibliography }),
|
|
14343
|
-
/* @__PURE__ */ jsx11("button", { type: "button", onClick: () => runAction(() => onManageReferences(triggerRef.current), false), children: messages.manageReferences }),
|
|
14491
|
+
mode === "article" ? /* @__PURE__ */ jsx11("button", { type: "button", onClick: () => runAction(onInsertBibliography), children: messages.insertBibliography }) : null,
|
|
14492
|
+
mode === "article" ? /* @__PURE__ */ jsx11("button", { type: "button", onClick: () => runAction(() => onManageReferences(triggerRef.current), false), children: messages.manageReferences }) : null,
|
|
14344
14493
|
/* @__PURE__ */ jsx11("button", { type: "button", onClick: () => runAction(() => onManageLabels(triggerRef.current), false), children: messages.manageLabels })
|
|
14345
14494
|
] })
|
|
14346
14495
|
] }),
|
|
@@ -19144,15 +19293,15 @@ function RefPickerPopover({
|
|
|
19144
19293
|
/* @__PURE__ */ jsx18("strong", { children: messages.refPickerTitle }),
|
|
19145
19294
|
/* @__PURE__ */ jsx18("button", { type: "button", "data-dialog-initial-focus": true, className: "butex-document-widget__icon-btn", title: messages.close, "aria-label": messages.close, onClick: onClose, children: "\xD7" })
|
|
19146
19295
|
] }),
|
|
19147
|
-
/* @__PURE__ */ jsx18("div", { className: "butex-document-widget__dialog-body", children: targets.length === 0 ? /* @__PURE__ */ jsx18("p", { className: "butex-document-widget__cite-picker-empty", children: messages.noLabelsYet }) : /* @__PURE__ */ jsx18("ul", { className: "butex-document-widget__cite-picker-list", children: targets.filter((entry) => entry.number !== null || entry.kind === "eq").map((entry) => {
|
|
19296
|
+
/* @__PURE__ */ jsx18("div", { className: "butex-document-widget__dialog-body", children: targets.length === 0 ? /* @__PURE__ */ jsx18("p", { className: "butex-document-widget__cite-picker-empty", children: messages.noLabelsYet }) : /* @__PURE__ */ jsx18("ul", { className: "butex-document-widget__cite-picker-list", children: targets.filter((entry) => entry.number !== null || Boolean(entry.displayLabel) || entry.kind === "eq").map((entry) => {
|
|
19148
19297
|
const checked = selected.includes(entry.key) || Boolean(entry.manualKey && selected.includes(entry.manualKey));
|
|
19149
|
-
const title = entry.number === null ? uiLocale === "ar" ? "\u0645\u0639\u0627\u062F\u0644\u0629 \u063A\u064A\u0631 \u0645\u0631\u0642\u0645\u0629" : "Unnumbered equation" : formatFloatCaptionTitle(entry.kind, entry.number, {
|
|
19298
|
+
const title = entry.displayLabel ?? (entry.number === null ? uiLocale === "ar" ? "\u0645\u0639\u0627\u062F\u0644\u0629 \u063A\u064A\u0631 \u0645\u0631\u0642\u0645\u0629" : "Unnumbered equation" : formatFloatCaptionTitle(entry.kind, entry.number, {
|
|
19150
19299
|
uiLocale,
|
|
19151
19300
|
digitForm,
|
|
19152
19301
|
documentDirection
|
|
19153
|
-
});
|
|
19302
|
+
}));
|
|
19154
19303
|
return /* @__PURE__ */ jsx18("li", { children: /* @__PURE__ */ jsxs17("label", { className: "butex-document-widget__cite-picker-item", children: [
|
|
19155
|
-
/* @__PURE__ */ jsx18("input", { type: "radio", name: "butex-ref-key", checked, disabled: entry.number === null, onChange: () => selectKey(entry.key, entry.kind) }),
|
|
19304
|
+
/* @__PURE__ */ jsx18("input", { type: "radio", name: "butex-ref-key", checked, disabled: entry.number === null && !entry.displayLabel, onChange: () => selectKey(entry.key, entry.kind) }),
|
|
19156
19305
|
/* @__PURE__ */ jsxs17("span", { children: [
|
|
19157
19306
|
/* @__PURE__ */ jsx18("strong", { children: entry.kind === "eq" && entry.number !== null ? title.replace(/(\d+|[٠-٩]+)$/, "($1)") : title }),
|
|
19158
19307
|
entry.caption ? /* @__PURE__ */ jsx18("span", { className: "butex-document-widget__cite-picker-meta", children: entry.caption }) : null,
|
|
@@ -21801,6 +21950,8 @@ var ButexDocumentEditor = forwardRef2(
|
|
|
21801
21950
|
function ButexDocumentEditor2({
|
|
21802
21951
|
initialDocument,
|
|
21803
21952
|
documentMeta,
|
|
21953
|
+
mode = "article",
|
|
21954
|
+
bookContext,
|
|
21804
21955
|
className,
|
|
21805
21956
|
debug = false,
|
|
21806
21957
|
documentDirection = "rtl",
|
|
@@ -21849,6 +22000,27 @@ var ButexDocumentEditor = forwardRef2(
|
|
|
21849
22000
|
return setCurrentDigitForm(session, digitForm);
|
|
21850
22001
|
}
|
|
21851
22002
|
const historyRef = useRef15(createDocumentHistory());
|
|
22003
|
+
const selectedMathRef = useRef15(selectedMath);
|
|
22004
|
+
selectedMathRef.current = selectedMath;
|
|
22005
|
+
const imagePickCountRef = useRef15(0);
|
|
22006
|
+
const documentGenerationRef = useRef15(0);
|
|
22007
|
+
useEffect13(() => {
|
|
22008
|
+
documentGenerationRef.current += 1;
|
|
22009
|
+
return () => {
|
|
22010
|
+
documentGenerationRef.current += 1;
|
|
22011
|
+
};
|
|
22012
|
+
}, [initialDocument]);
|
|
22013
|
+
const safeRequestImagePick = useCallback2(async (ctx) => {
|
|
22014
|
+
if (!onRequestImagePick) return null;
|
|
22015
|
+
const generation = documentGenerationRef.current;
|
|
22016
|
+
imagePickCountRef.current += 1;
|
|
22017
|
+
try {
|
|
22018
|
+
const picked = await onRequestImagePick(ctx);
|
|
22019
|
+
return generation === documentGenerationRef.current ? picked : null;
|
|
22020
|
+
} finally {
|
|
22021
|
+
imagePickCountRef.current -= 1;
|
|
22022
|
+
}
|
|
22023
|
+
}, [onRequestImagePick]);
|
|
21852
22024
|
const documentRef = useRef15(documentNode);
|
|
21853
22025
|
const editorFocusRef = useRef15(editorFocus);
|
|
21854
22026
|
const textSnapshotArmedRef = useRef15(false);
|
|
@@ -21873,17 +22045,26 @@ var ButexDocumentEditor = forwardRef2(
|
|
|
21873
22045
|
}
|
|
21874
22046
|
documentRef.current = documentNode;
|
|
21875
22047
|
editorFocusRef.current = editorFocus;
|
|
21876
|
-
const latex = documentLatex(documentNode, { digitForm });
|
|
22048
|
+
const latex = mode === "book-content" ? documentContentLatex(documentNode, bookContext) : documentLatex(documentNode, { digitForm });
|
|
21877
22049
|
const documentJson = useMemo2(() => toDocumentJson(documentNode), [documentNode]);
|
|
21878
22050
|
const documentLabels = useMemo2(() => collectDocumentLabels(documentNode), [documentNode]);
|
|
21879
|
-
const
|
|
22051
|
+
const displayReferences = useMemo2(
|
|
22052
|
+
() => mode === "book-content" ? bookContextReferences(bookContext) : documentNode.references,
|
|
22053
|
+
[mode, bookContext, documentNode]
|
|
22054
|
+
);
|
|
22055
|
+
const referenceTargets = useMemo2(
|
|
22056
|
+
() => mode === "book-content" && bookContext ? bookContentTargets(documentNode, bookContext) : collectDocumentReferenceTargets(documentNode),
|
|
22057
|
+
[mode, bookContext, documentNode]
|
|
22058
|
+
);
|
|
21880
22059
|
const preview = useMemo2(
|
|
21881
22060
|
() => documentPreview(documentNode, mathOutput, equationSide, {
|
|
21882
22061
|
documentDirection,
|
|
21883
22062
|
digitForm,
|
|
21884
|
-
uiLocale
|
|
22063
|
+
uiLocale,
|
|
22064
|
+
mode,
|
|
22065
|
+
bookContext
|
|
21885
22066
|
}),
|
|
21886
|
-
[documentNode, documentDirection, digitForm, equationSide, mathOutput, uiLocale]
|
|
22067
|
+
[documentNode, documentDirection, digitForm, equationSide, mathOutput, uiLocale, mode, bookContext]
|
|
21887
22068
|
);
|
|
21888
22069
|
const debugEnabled = useMemo2(() => {
|
|
21889
22070
|
if (debug) {
|
|
@@ -22010,11 +22191,11 @@ var ButexDocumentEditor = forwardRef2(
|
|
|
22010
22191
|
setHistoryTick((tick) => tick + 1);
|
|
22011
22192
|
}, []);
|
|
22012
22193
|
const applyDocument = useCallback2(
|
|
22013
|
-
(next,
|
|
22014
|
-
if (
|
|
22194
|
+
(next, mode2 = "immediate") => {
|
|
22195
|
+
if (mode2 === "immediate") {
|
|
22015
22196
|
pushDocumentSnapshot(historyRef.current, documentRef.current);
|
|
22016
22197
|
bumpHistoryUi();
|
|
22017
|
-
} else if (
|
|
22198
|
+
} else if (mode2 === "text") {
|
|
22018
22199
|
if (!textSnapshotArmedRef.current) {
|
|
22019
22200
|
pushDocumentSnapshot(historyRef.current, documentRef.current);
|
|
22020
22201
|
textSnapshotArmedRef.current = true;
|
|
@@ -22053,6 +22234,9 @@ var ButexDocumentEditor = forwardRef2(
|
|
|
22053
22234
|
},
|
|
22054
22235
|
getDocumentJson() {
|
|
22055
22236
|
return toDocumentJson(documentRef.current);
|
|
22237
|
+
},
|
|
22238
|
+
hasPendingChildTransaction() {
|
|
22239
|
+
return selectedMathRef.current !== null || imagePickCountRef.current > 0;
|
|
22056
22240
|
}
|
|
22057
22241
|
}),
|
|
22058
22242
|
[applyDocument, insertImageBlock]
|
|
@@ -22190,7 +22374,7 @@ var ButexDocumentEditor = forwardRef2(
|
|
|
22190
22374
|
function onFieldBlur() {
|
|
22191
22375
|
textSnapshotArmedRef.current = false;
|
|
22192
22376
|
}
|
|
22193
|
-
function openNewEquation(
|
|
22377
|
+
function openNewEquation(mode2) {
|
|
22194
22378
|
if (!editableEquations) {
|
|
22195
22379
|
return;
|
|
22196
22380
|
}
|
|
@@ -22208,7 +22392,7 @@ var ButexDocumentEditor = forwardRef2(
|
|
|
22208
22392
|
fieldId: target?.fieldId ?? null,
|
|
22209
22393
|
textTokenId: target?.textTokenId ?? null,
|
|
22210
22394
|
insertAt: target?.caretOffset ?? 0,
|
|
22211
|
-
mathMode:
|
|
22395
|
+
mathMode: mode2,
|
|
22212
22396
|
session: equationSessionWithDocumentDigits(createEmptyEquationSession(equationSide)),
|
|
22213
22397
|
reason: null,
|
|
22214
22398
|
labelEnabled: false,
|
|
@@ -22227,14 +22411,14 @@ var ButexDocumentEditor = forwardRef2(
|
|
|
22227
22411
|
editorFocus: { ...editorFocusRef.current }
|
|
22228
22412
|
};
|
|
22229
22413
|
const result = mathTokenToEditorSession(token.math, equationSide);
|
|
22230
|
-
const
|
|
22414
|
+
const mode2 = token.display ? "display" : "inline";
|
|
22231
22415
|
if (!result.editable) {
|
|
22232
22416
|
setSelectedMath({
|
|
22233
22417
|
tokenId: token.id,
|
|
22234
22418
|
fieldId: null,
|
|
22235
22419
|
insertAt: 0,
|
|
22236
22420
|
textTokenId: null,
|
|
22237
|
-
mathMode:
|
|
22421
|
+
mathMode: mode2,
|
|
22238
22422
|
session: equationSessionWithDocumentDigits(createEmptyEquationSession(equationSide)),
|
|
22239
22423
|
reason: result.reason,
|
|
22240
22424
|
labelEnabled: Boolean(token.labelEnabled),
|
|
@@ -22248,7 +22432,7 @@ var ButexDocumentEditor = forwardRef2(
|
|
|
22248
22432
|
fieldId: null,
|
|
22249
22433
|
insertAt: 0,
|
|
22250
22434
|
textTokenId: null,
|
|
22251
|
-
mathMode:
|
|
22435
|
+
mathMode: mode2,
|
|
22252
22436
|
session: equationSessionWithDocumentDigits(result.session),
|
|
22253
22437
|
reason: null,
|
|
22254
22438
|
labelEnabled: Boolean(token.labelEnabled),
|
|
@@ -22573,6 +22757,7 @@ var ButexDocumentEditor = forwardRef2(
|
|
|
22573
22757
|
/* @__PURE__ */ jsx19(
|
|
22574
22758
|
DocumentInsertToolbar,
|
|
22575
22759
|
{
|
|
22760
|
+
mode,
|
|
22576
22761
|
canUndo,
|
|
22577
22762
|
canRedo,
|
|
22578
22763
|
editableEquations,
|
|
@@ -22611,6 +22796,7 @@ var ButexDocumentEditor = forwardRef2(
|
|
|
22611
22796
|
/* @__PURE__ */ jsx19(
|
|
22612
22797
|
DocumentMobileToolbar,
|
|
22613
22798
|
{
|
|
22799
|
+
mode,
|
|
22614
22800
|
mobileView,
|
|
22615
22801
|
canUndo,
|
|
22616
22802
|
canRedo,
|
|
@@ -22682,7 +22868,7 @@ var ButexDocumentEditor = forwardRef2(
|
|
|
22682
22868
|
"aria-label": messages.documentEditor,
|
|
22683
22869
|
"aria-hidden": !showEditorPanel,
|
|
22684
22870
|
children: /* @__PURE__ */ jsxs18("div", { className: "butex-document-widget__blocks", children: [
|
|
22685
|
-
/* @__PURE__ */ jsx19(
|
|
22871
|
+
mode === "article" ? /* @__PURE__ */ jsx19(
|
|
22686
22872
|
ArticleMetaPanel,
|
|
22687
22873
|
{
|
|
22688
22874
|
meta: documentNode.meta ?? emptyDocumentMeta(),
|
|
@@ -22694,13 +22880,16 @@ var ButexDocumentEditor = forwardRef2(
|
|
|
22694
22880
|
applyDocument(updateDocumentMeta(documentRef.current, patch), "text");
|
|
22695
22881
|
}
|
|
22696
22882
|
}
|
|
22697
|
-
),
|
|
22883
|
+
) : null,
|
|
22884
|
+
mode === "book-content" && documentNode.blocks.some((block) => block.kind === "bibliography") ? /* @__PURE__ */ jsx19("p", { role: "alert", className: "butex-document-widget__error", children: uiLocale === "ar" ? "\u062A\u0633\u062A\u062E\u062F\u0645 \u0641\u0635\u0648\u0644 \u0627\u0644\u0643\u062A\u0627\u0628 \u0642\u0627\u0626\u0645\u0629 \u0645\u0631\u0627\u062C\u0639 \u0645\u0634\u062A\u0631\u0643\u0629\u061B \u0623\u0632\u0644 \u0642\u0627\u0626\u0645\u0629 \u0627\u0644\u0645\u0631\u0627\u062C\u0639 \u0627\u0644\u0645\u062D\u0644\u064A\u0629 \u0645\u0646 \u0627\u0644\u0641\u0635\u0644." : "Book chapters use the shared bibliography. Remove the local bibliography block." }) : null,
|
|
22698
22885
|
documentNode.blocks.map((block, blockIndex) => /* @__PURE__ */ jsx19(
|
|
22699
22886
|
BlockEditor,
|
|
22700
22887
|
{
|
|
22701
22888
|
block,
|
|
22702
|
-
references:
|
|
22889
|
+
references: displayReferences,
|
|
22703
22890
|
documentNode,
|
|
22891
|
+
bookContext: mode === "book-content" ? bookContext : void 0,
|
|
22892
|
+
onHeadingLabelChange: (blockId, label) => applyDocument(updateDocumentHeadingLabel(documentRef.current, blockId, label), "text"),
|
|
22704
22893
|
documentDirection,
|
|
22705
22894
|
digitForm,
|
|
22706
22895
|
mathOutput,
|
|
@@ -22739,7 +22928,7 @@ var ButexDocumentEditor = forwardRef2(
|
|
|
22739
22928
|
applyDocument(clearDocumentImageAsset(documentRef.current, blockId), "immediate");
|
|
22740
22929
|
},
|
|
22741
22930
|
resolveImageUrl,
|
|
22742
|
-
onRequestImagePick,
|
|
22931
|
+
onRequestImagePick: onRequestImagePick ? safeRequestImagePick : void 0,
|
|
22743
22932
|
listImageAssets,
|
|
22744
22933
|
renderImageBlockEditor,
|
|
22745
22934
|
onFloatMetaChange: (blockId, kind, patch) => {
|
|
@@ -22761,7 +22950,7 @@ var ButexDocumentEditor = forwardRef2(
|
|
|
22761
22950
|
clearBlockSelection();
|
|
22762
22951
|
applyDocument(removeDocumentListItem(documentRef.current, listBlockId, itemId), "immediate");
|
|
22763
22952
|
},
|
|
22764
|
-
onManageReferences: () => openReferencesManager()
|
|
22953
|
+
onManageReferences: mode === "article" ? () => openReferencesManager() : void 0
|
|
22765
22954
|
},
|
|
22766
22955
|
block.id
|
|
22767
22956
|
))
|
|
@@ -22852,11 +23041,11 @@ var ButexDocumentEditor = forwardRef2(
|
|
|
22852
23041
|
numbered: selectedMath.numbered,
|
|
22853
23042
|
onNumberedChange: (numbered) => setSelectedMath((current) => current ? { ...current, numbered } : current),
|
|
22854
23043
|
labels: documentLabels,
|
|
22855
|
-
references:
|
|
23044
|
+
references: displayReferences,
|
|
22856
23045
|
ownerId: selectedMath.tokenId ?? void 0,
|
|
22857
23046
|
onLabelEnabledChange: (enabled) => setSelectedMath((current) => current ? { ...current, labelEnabled: enabled, numbered: enabled || current.numbered } : current),
|
|
22858
23047
|
onLabelChange: (nextLabel) => setSelectedMath((current) => current ? { ...current, label: nextLabel } : current),
|
|
22859
|
-
onMathModeChange: (
|
|
23048
|
+
onMathModeChange: (mode2) => setSelectedMath((current) => current ? { ...current, mathMode: mode2 } : current),
|
|
22860
23049
|
onClose: closeEquationAndRestoreOrigin,
|
|
22861
23050
|
onSave: saveEquation,
|
|
22862
23051
|
onDelete: deleteSelectedEquation
|
|
@@ -22866,16 +23055,16 @@ var ButexDocumentEditor = forwardRef2(
|
|
|
22866
23055
|
CitePickerPopover,
|
|
22867
23056
|
{
|
|
22868
23057
|
open: citePicker !== null,
|
|
22869
|
-
references:
|
|
23058
|
+
references: displayReferences,
|
|
22870
23059
|
initialKeys: citePicker?.keys ?? [],
|
|
22871
23060
|
uiLocale,
|
|
22872
23061
|
digitForm,
|
|
22873
23062
|
onClose: () => setCitePicker(null),
|
|
22874
23063
|
onConfirm: confirmCiteKeys,
|
|
22875
|
-
onManageReferences: () => {
|
|
23064
|
+
onManageReferences: mode === "article" ? () => {
|
|
22876
23065
|
setCitePicker(null);
|
|
22877
23066
|
openReferencesManager();
|
|
22878
|
-
}
|
|
23067
|
+
} : void 0
|
|
22879
23068
|
}
|
|
22880
23069
|
) : null,
|
|
22881
23070
|
!previewOnly ? /* @__PURE__ */ jsx19(
|
|
@@ -22898,7 +23087,7 @@ var ButexDocumentEditor = forwardRef2(
|
|
|
22898
23087
|
}
|
|
22899
23088
|
}
|
|
22900
23089
|
) : null,
|
|
22901
|
-
!previewOnly ? /* @__PURE__ */ jsx19(
|
|
23090
|
+
!previewOnly && mode === "article" ? /* @__PURE__ */ jsx19(
|
|
22902
23091
|
ReferencesPanel,
|
|
22903
23092
|
{
|
|
22904
23093
|
open: referencesOpen,
|
|
@@ -22919,7 +23108,7 @@ var ButexDocumentEditor = forwardRef2(
|
|
|
22919
23108
|
{
|
|
22920
23109
|
open: labelsOpen,
|
|
22921
23110
|
labels: documentLabels,
|
|
22922
|
-
references:
|
|
23111
|
+
references: displayReferences,
|
|
22923
23112
|
uiLocale,
|
|
22924
23113
|
digitForm,
|
|
22925
23114
|
returnFocusRef: managerFocusOriginRef,
|
|
@@ -22956,6 +23145,8 @@ var ButexDocumentEditor3 = forwardRef3(
|
|
|
22956
23145
|
function ValidatedButexDocumentEditor({
|
|
22957
23146
|
initialDocument,
|
|
22958
23147
|
uiLocale = "ar",
|
|
23148
|
+
mode = "article",
|
|
23149
|
+
bookContext,
|
|
22959
23150
|
onDocumentChange,
|
|
22960
23151
|
onValidityChange,
|
|
22961
23152
|
renderImageBlockEditor,
|
|
@@ -22984,10 +23175,10 @@ var ButexDocumentEditor3 = forwardRef3(
|
|
|
22984
23175
|
(document2) => {
|
|
22985
23176
|
const validationTarget = initialDocument !== void 0 && (malformedInitialDocument || awaitingInitialResolutionRef.current) ? initialDocument : document2;
|
|
22986
23177
|
awaitingInitialResolutionRef.current = false;
|
|
22987
|
-
emitValidity(
|
|
23178
|
+
emitValidity(validateDocument(validationTarget, { mode, bookContext }).valid);
|
|
22988
23179
|
onDocumentChange?.(document2);
|
|
22989
23180
|
},
|
|
22990
|
-
[emitValidity, initialDocument, malformedInitialDocument, onDocumentChange]
|
|
23181
|
+
[emitValidity, initialDocument, malformedInitialDocument, onDocumentChange, mode, bookContext]
|
|
22991
23182
|
);
|
|
22992
23183
|
const handleImageBlockEditor = useCallback3(
|
|
22993
23184
|
(ctx) => {
|
|
@@ -23024,6 +23215,8 @@ var ButexDocumentEditor3 = forwardRef3(
|
|
|
23024
23215
|
...rest,
|
|
23025
23216
|
initialDocument,
|
|
23026
23217
|
uiLocale,
|
|
23218
|
+
mode,
|
|
23219
|
+
bookContext,
|
|
23027
23220
|
onDocumentChange: handleDocumentChange,
|
|
23028
23221
|
renderImageBlockEditor: handleImageBlockEditor
|
|
23029
23222
|
}
|
|
@@ -23066,6 +23259,8 @@ function resolvePreviewDocument(input, uiLocale = "ar") {
|
|
|
23066
23259
|
}
|
|
23067
23260
|
}
|
|
23068
23261
|
function ButexDocumentPreview({
|
|
23262
|
+
mode = "article",
|
|
23263
|
+
bookContext,
|
|
23069
23264
|
document: document2,
|
|
23070
23265
|
className,
|
|
23071
23266
|
documentDirection = "rtl",
|
|
@@ -23084,7 +23279,9 @@ function ButexDocumentPreview({
|
|
|
23084
23279
|
preview: documentPreview(resolved.document, mathOutput, equationSide, {
|
|
23085
23280
|
documentDirection,
|
|
23086
23281
|
digitForm: resolvedDigitForm,
|
|
23087
|
-
uiLocale
|
|
23282
|
+
uiLocale,
|
|
23283
|
+
mode,
|
|
23284
|
+
bookContext
|
|
23088
23285
|
}),
|
|
23089
23286
|
error: resolved.error
|
|
23090
23287
|
};
|
|
@@ -23094,12 +23291,14 @@ function ButexDocumentPreview({
|
|
|
23094
23291
|
preview: documentPreview(createEmptyDocument(), mathOutput, equationSide, {
|
|
23095
23292
|
documentDirection,
|
|
23096
23293
|
digitForm: resolvedDigitForm,
|
|
23097
|
-
uiLocale
|
|
23294
|
+
uiLocale,
|
|
23295
|
+
mode,
|
|
23296
|
+
bookContext
|
|
23098
23297
|
}),
|
|
23099
23298
|
error: `${messages.loadDocumentError}: ${detail}`
|
|
23100
23299
|
};
|
|
23101
23300
|
}
|
|
23102
|
-
}, [documentDirection, equationSide, mathOutput, messages.loadDocumentError, resolved, resolvedDigitForm, uiLocale]);
|
|
23301
|
+
}, [bookContext, mode, documentDirection, equationSide, mathOutput, messages.loadDocumentError, resolved, resolvedDigitForm, uiLocale]);
|
|
23103
23302
|
useEffect14(() => {
|
|
23104
23303
|
injectBuTeXDocumentStyles();
|
|
23105
23304
|
}, []);
|