@drghaliasri/butex 8.0.3 → 8.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -7
- package/dist/document-cli.js +158 -86
- package/dist/document-cli.js.map +1 -1
- package/dist/document.d.mts +35 -2
- package/dist/document.d.ts +35 -2
- package/dist/document.js +181 -98
- package/dist/document.js.map +1 -1
- package/dist/document.mjs +176 -98
- package/dist/document.mjs.map +1 -1
- package/dist/react-document-preview.d.mts +4 -0
- package/dist/react-document-preview.d.ts +4 -0
- package/dist/react-document-preview.js +78 -71
- package/dist/react-document-preview.js.map +1 -1
- package/dist/react-document-preview.mjs +78 -71
- package/dist/react-document-preview.mjs.map +1 -1
- package/dist/react-document.d.mts +8 -1
- package/dist/react-document.d.ts +8 -1
- package/dist/react-document.js +171 -113
- package/dist/react-document.js.map +1 -1
- package/dist/react-document.mjs +171 -113
- package/dist/react-document.mjs.map +1 -1
- package/package.json +1 -1
package/dist/react-document.mjs
CHANGED
|
@@ -838,82 +838,79 @@ function refTokenLatex(keys, refCommand) {
|
|
|
838
838
|
const command = refCommand === "eqref" ? "\\eqref" : "\\ref";
|
|
839
839
|
return `${command}{${keys.join(",")}}`;
|
|
840
840
|
}
|
|
841
|
-
function
|
|
842
|
-
const
|
|
841
|
+
function implicitReferenceKey(kind, ownerId, unitId) {
|
|
842
|
+
const hex = (value) => Array.from(new TextEncoder().encode(value), (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
843
|
+
const scope = unitId === void 0 ? "a" : "u" + hex(unitId);
|
|
844
|
+
return kind + ":butex-auto-" + scope + "-" + hex(ownerId);
|
|
845
|
+
}
|
|
846
|
+
function supportsSingleEquationNumbering(token) {
|
|
847
|
+
return token.display && (token.opening === "\\[" || token.opening === String.fromCharCode(36, 36) || token.opening === "\\begin{equation}" || token.opening === "\\begin{equation*}");
|
|
848
|
+
}
|
|
849
|
+
function isNumberedEquation(token) {
|
|
850
|
+
if (!supportsSingleEquationNumbering(token)) return false;
|
|
851
|
+
if (typeof token.numbered === "boolean") return token.numbered;
|
|
852
|
+
return token.opening === "\\begin{equation}" || Boolean(token.labelEnabled) && Boolean(token.label?.trim());
|
|
853
|
+
}
|
|
854
|
+
function isNumberedFloat(block) {
|
|
855
|
+
return block.captionEnabled && block.caption.trim().length > 0 || block.labelEnabled && block.label.trim().length > 0;
|
|
856
|
+
}
|
|
857
|
+
function collectDocumentReferenceTargets(document2) {
|
|
858
|
+
const targets = [];
|
|
843
859
|
const counters = { fig: 0, tab: 0, eq: 0 };
|
|
844
|
-
function
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
860
|
+
function append(kind, ownerId, caption, numbered, manualKey = "") {
|
|
861
|
+
if (numbered) counters[kind] += 1;
|
|
862
|
+
targets.push({
|
|
863
|
+
key: implicitReferenceKey(kind, ownerId),
|
|
864
|
+
kind,
|
|
865
|
+
ownerId,
|
|
866
|
+
caption,
|
|
867
|
+
number: numbered ? counters[kind] : null,
|
|
868
|
+
...manualKey.trim() ? { manualKey: manualKey.trim() } : {}
|
|
869
|
+
});
|
|
870
|
+
}
|
|
871
|
+
function visitField(field) {
|
|
872
|
+
for (const token of field.tokens) {
|
|
873
|
+
if (token.kind === "math" && supportsSingleEquationNumbering(token)) {
|
|
874
|
+
append("eq", token.id, "", isNumberedEquation(token), token.labelEnabled ? token.label ?? "" : "");
|
|
858
875
|
}
|
|
859
876
|
}
|
|
860
877
|
}
|
|
861
878
|
function walk(blocks) {
|
|
862
879
|
for (const block of blocks) {
|
|
863
|
-
if (block.kind === "image") {
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
if (block.captionEnabled) {
|
|
875
|
-
pushEqFromField(block.captionField.tokens);
|
|
876
|
-
}
|
|
877
|
-
}
|
|
878
|
-
if (block.kind === "table") {
|
|
879
|
-
if (block.labelEnabled && block.label.trim().length > 0) {
|
|
880
|
-
counters.tab += 1;
|
|
881
|
-
entries.push({
|
|
882
|
-
key: block.label.trim(),
|
|
883
|
-
kind: "tab",
|
|
884
|
-
caption: block.captionEnabled ? block.caption : "",
|
|
885
|
-
ownerId: block.id,
|
|
886
|
-
number: counters.tab
|
|
887
|
-
});
|
|
888
|
-
}
|
|
889
|
-
if (block.captionEnabled) {
|
|
890
|
-
pushEqFromField(block.captionField.tokens);
|
|
891
|
-
}
|
|
892
|
-
for (const row of block.rows) {
|
|
893
|
-
for (const cell of row) {
|
|
894
|
-
pushEqFromField(cell.tokens);
|
|
895
|
-
}
|
|
880
|
+
if (block.kind === "image" || block.kind === "table") {
|
|
881
|
+
append(
|
|
882
|
+
block.kind === "image" ? "fig" : "tab",
|
|
883
|
+
block.id,
|
|
884
|
+
block.captionEnabled ? block.caption : "",
|
|
885
|
+
isNumberedFloat(block),
|
|
886
|
+
block.labelEnabled ? block.label : ""
|
|
887
|
+
);
|
|
888
|
+
if (block.captionEnabled) visitField(block.captionField);
|
|
889
|
+
if (block.kind === "table") {
|
|
890
|
+
for (const row of block.rows) for (const cell of row) visitField(cell);
|
|
896
891
|
}
|
|
897
|
-
}
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
}
|
|
901
|
-
if (block.kind === "list") {
|
|
892
|
+
} else if (block.kind === "textBlock") {
|
|
893
|
+
visitField(block.field);
|
|
894
|
+
} else if (block.kind === "list") {
|
|
902
895
|
for (const item of block.items) {
|
|
903
|
-
|
|
896
|
+
visitField(item.field);
|
|
904
897
|
walk(item.blocks);
|
|
905
898
|
}
|
|
906
899
|
}
|
|
907
900
|
}
|
|
908
901
|
}
|
|
909
902
|
walk(document2.blocks);
|
|
910
|
-
return
|
|
903
|
+
return targets;
|
|
904
|
+
}
|
|
905
|
+
function collectDocumentLabels(document2) {
|
|
906
|
+
return collectDocumentReferenceTargets(document2).filter((target) => target.number !== null && Boolean(target.manualKey)).map(({ manualKey, kind, caption, ownerId, number }) => ({ key: manualKey, kind, caption, ownerId, number }));
|
|
911
907
|
}
|
|
912
908
|
function labelNumberMap(document2) {
|
|
913
909
|
const map = /* @__PURE__ */ new Map();
|
|
914
|
-
for (const
|
|
915
|
-
if (
|
|
916
|
-
|
|
910
|
+
for (const target of collectDocumentReferenceTargets(document2)) {
|
|
911
|
+
if (target.number === null) continue;
|
|
912
|
+
for (const key of [target.key, target.manualKey]) {
|
|
913
|
+
if (key && !map.has(key)) map.set(key, { kind: target.kind, number: target.number });
|
|
917
914
|
}
|
|
918
915
|
}
|
|
919
916
|
return map;
|
|
@@ -967,8 +964,12 @@ function stripDisplayMathDelimiters(source) {
|
|
|
967
964
|
if (trimmed.startsWith("$$") && trimmed.endsWith("$$")) {
|
|
968
965
|
return trimmed.slice(2, -2).trim();
|
|
969
966
|
}
|
|
970
|
-
|
|
971
|
-
|
|
967
|
+
for (const environment of ["equation", "equation*"]) {
|
|
968
|
+
const opening = `\\begin{${environment}}`;
|
|
969
|
+
const closing = `\\end{${environment}}`;
|
|
970
|
+
if (trimmed.startsWith(opening) && trimmed.endsWith(closing)) {
|
|
971
|
+
return trimmed.slice(opening.length, -closing.length).trim();
|
|
972
|
+
}
|
|
972
973
|
}
|
|
973
974
|
return trimmed;
|
|
974
975
|
}
|
|
@@ -1361,7 +1362,8 @@ function createInlineField(value = "", mathObjects = [], options = {}, path = "$
|
|
|
1361
1362
|
editable: true,
|
|
1362
1363
|
sourceOwner: structuredMathJson.source_owner === "editor" ? "editor" : "imported-structured",
|
|
1363
1364
|
...typeof structuredMathJson.label_enabled === "boolean" ? { labelEnabled: structuredMathJson.label_enabled } : {},
|
|
1364
|
-
...typeof structuredMathJson.label === "string" ? { label: structuredMathJson.label } : {}
|
|
1365
|
+
...typeof structuredMathJson.label === "string" ? { label: structuredMathJson.label } : {},
|
|
1366
|
+
...typeof structuredMathJson.numbered === "boolean" ? { numbered: structuredMathJson.numbered } : {}
|
|
1365
1367
|
});
|
|
1366
1368
|
} else {
|
|
1367
1369
|
tokens.push({
|
|
@@ -1376,7 +1378,8 @@ function createInlineField(value = "", mathObjects = [], options = {}, path = "$
|
|
|
1376
1378
|
reason: "\u0647\u0630\u0647 \u0627\u0644\u0645\u0639\u0627\u062F\u0644\u0629 \u0645\u062D\u0641\u0648\u0638\u0629 \u0643\u0646\u0635 \u062E\u0627\u0645 \u0641\u0642\u0637 \u062D\u0627\u0644\u064A\u0627",
|
|
1377
1379
|
sourceOwner: "raw",
|
|
1378
1380
|
...mathJson?.node_type === "RawMathObject" && typeof mathJson.label_enabled === "boolean" ? { labelEnabled: mathJson.label_enabled } : {},
|
|
1379
|
-
...mathJson?.node_type === "RawMathObject" && typeof mathJson.label === "string" ? { label: mathJson.label } : {}
|
|
1381
|
+
...mathJson?.node_type === "RawMathObject" && typeof mathJson.label === "string" ? { label: mathJson.label } : {},
|
|
1382
|
+
...mathJson?.node_type === "RawMathObject" && typeof mathJson.numbered === "boolean" ? { numbered: mathJson.numbered } : {}
|
|
1380
1383
|
});
|
|
1381
1384
|
}
|
|
1382
1385
|
index = span.end;
|
|
@@ -9452,6 +9455,9 @@ function replaceMathTokenFromSession(document2, tokenId, session, opening, closi
|
|
|
9452
9455
|
if (current.label !== void 0) {
|
|
9453
9456
|
replaced.label = current.label;
|
|
9454
9457
|
}
|
|
9458
|
+
if (current.numbered !== void 0) {
|
|
9459
|
+
replaced.numbered = current.numbered;
|
|
9460
|
+
}
|
|
9455
9461
|
field.tokens[index] = replaced;
|
|
9456
9462
|
return true;
|
|
9457
9463
|
});
|
|
@@ -9671,6 +9677,9 @@ function updateMathTokenLabel(document2, tokenId, patch) {
|
|
|
9671
9677
|
if (typeof patch.label === "string") {
|
|
9672
9678
|
token.label = patch.label;
|
|
9673
9679
|
}
|
|
9680
|
+
if (typeof patch.numbered === "boolean") {
|
|
9681
|
+
token.numbered = patch.numbered;
|
|
9682
|
+
}
|
|
9674
9683
|
return true;
|
|
9675
9684
|
});
|
|
9676
9685
|
return next;
|
|
@@ -9988,12 +9997,13 @@ function serializeField(field) {
|
|
|
9988
9997
|
}
|
|
9989
9998
|
value += token.source;
|
|
9990
9999
|
if (!token.math || token.sourceOwner === "raw") {
|
|
9991
|
-
if (token.labelEnabled !== void 0 || token.label !== void 0) {
|
|
10000
|
+
if (token.labelEnabled !== void 0 || token.label !== void 0 || token.numbered !== void 0) {
|
|
9992
10001
|
hasPersistedMath = true;
|
|
9993
10002
|
mathObjects.push({
|
|
9994
10003
|
node_type: "RawMathObject",
|
|
9995
10004
|
...token.labelEnabled !== void 0 ? { label_enabled: token.labelEnabled } : {},
|
|
9996
|
-
...token.label !== void 0 ? { label: token.label } : {}
|
|
10005
|
+
...token.label !== void 0 ? { label: token.label } : {},
|
|
10006
|
+
...token.numbered !== void 0 ? { numbered: token.numbered } : {}
|
|
9997
10007
|
});
|
|
9998
10008
|
} else {
|
|
9999
10009
|
mathObjects.push(null);
|
|
@@ -10006,7 +10016,8 @@ function serializeField(field) {
|
|
|
10006
10016
|
...token.sourceSide ? { source_side: token.sourceSide } : {},
|
|
10007
10017
|
source_owner: token.sourceOwner,
|
|
10008
10018
|
...token.labelEnabled !== void 0 ? { label_enabled: token.labelEnabled } : {},
|
|
10009
|
-
...token.label !== void 0 ? { label: token.label } : {}
|
|
10019
|
+
...token.label !== void 0 ? { label: token.label } : {},
|
|
10020
|
+
...token.numbered !== void 0 ? { numbered: token.numbered } : {}
|
|
10010
10021
|
});
|
|
10011
10022
|
}
|
|
10012
10023
|
return { value, formats, mathObjects, hasPersistedMath, inlineIds: inlineIdsFromField(field) };
|
|
@@ -10447,12 +10458,15 @@ function tokenLatex(token, labelKinds, previousToken) {
|
|
|
10447
10458
|
if (token.kind === "ref") {
|
|
10448
10459
|
return refTokenLatexForDocument(token, labelKinds, previousToken);
|
|
10449
10460
|
}
|
|
10450
|
-
if (token
|
|
10461
|
+
if (isNumberedEquation(token)) {
|
|
10451
10462
|
const body = mathBodyLatex(token);
|
|
10452
|
-
|
|
10453
|
-
|
|
10454
|
-
|
|
10455
|
-
\\end{equation}
|
|
10463
|
+
const autoKey = implicitReferenceKey("eq", token.id);
|
|
10464
|
+
const aliases = [autoKey];
|
|
10465
|
+
if (token.labelEnabled && token.label?.trim() && token.label.trim() !== autoKey) aliases.push(token.label.trim());
|
|
10466
|
+
return "\\begin{equation}\n" + body + "\n" + aliases.map((key) => "\\label{" + key + "}").join("\n") + "\n\\end{equation}";
|
|
10467
|
+
}
|
|
10468
|
+
if (token.display && token.numbered === false && token.opening === "\\begin{equation}") {
|
|
10469
|
+
return "\\[" + mathBodyLatex(token) + "\\]";
|
|
10456
10470
|
}
|
|
10457
10471
|
if (token.sourceOwner === "editor") {
|
|
10458
10472
|
return editorMathLatexForCompile(token);
|
|
@@ -10519,11 +10533,12 @@ function floatCaptionLabelLines(block, counter, labelKinds) {
|
|
|
10519
10533
|
if (hasCaption) {
|
|
10520
10534
|
lines.push(` \\caption{${caption}}`);
|
|
10521
10535
|
}
|
|
10522
|
-
|
|
10523
|
-
|
|
10524
|
-
|
|
10525
|
-
|
|
10526
|
-
lines.push(
|
|
10536
|
+
const hasManualLabel = block.labelEnabled && block.label.trim().length > 0;
|
|
10537
|
+
if (hasCaption || hasManualLabel) {
|
|
10538
|
+
if (!hasCaption) lines.push(" \\refstepcounter{" + counter + "}");
|
|
10539
|
+
const autoKey = implicitReferenceKey(counter === "figure" ? "fig" : "tab", block.id);
|
|
10540
|
+
lines.push(" \\label{" + autoKey + "}");
|
|
10541
|
+
if (hasManualLabel && block.label.trim() !== autoKey) lines.push(" \\label{" + block.label.trim() + "}");
|
|
10527
10542
|
}
|
|
10528
10543
|
return lines;
|
|
10529
10544
|
}
|
|
@@ -10619,10 +10634,8 @@ ${meta.abstract.trim()}
|
|
|
10619
10634
|
}
|
|
10620
10635
|
function documentLabelKindMap(document2) {
|
|
10621
10636
|
const map = /* @__PURE__ */ new Map();
|
|
10622
|
-
for (const entry of
|
|
10623
|
-
|
|
10624
|
-
map.set(entry.key, entry.kind);
|
|
10625
|
-
}
|
|
10637
|
+
for (const [key, entry] of labelNumberMap(document2)) {
|
|
10638
|
+
map.set(key, entry.kind);
|
|
10626
10639
|
}
|
|
10627
10640
|
return map;
|
|
10628
10641
|
}
|
|
@@ -10721,10 +10734,17 @@ function validateToken(context, token, path, blockId) {
|
|
|
10721
10734
|
return;
|
|
10722
10735
|
}
|
|
10723
10736
|
validateTextValue(context, token.source, `${path}.source`, blockId, token.id);
|
|
10737
|
+
if (token.numbered === true && !supportsSingleEquationNumbering(token)) {
|
|
10738
|
+
addIssue(context, "invalid_equation_label", `${path}.numbered`, blockId, token.id);
|
|
10739
|
+
}
|
|
10724
10740
|
if (!token.labelEnabled) {
|
|
10725
10741
|
return;
|
|
10726
10742
|
}
|
|
10727
|
-
if (!token
|
|
10743
|
+
if (!supportsSingleEquationNumbering(token)) {
|
|
10744
|
+
addIssue(context, "invalid_equation_label", `${path}.label`, blockId, token.id);
|
|
10745
|
+
return;
|
|
10746
|
+
}
|
|
10747
|
+
if (!isNumberedEquation(token)) {
|
|
10728
10748
|
addIssue(context, "invalid_equation_label", `${path}.label`, blockId, token.id);
|
|
10729
10749
|
return;
|
|
10730
10750
|
}
|
|
@@ -10822,7 +10842,7 @@ function validatePendingReferences(context) {
|
|
|
10822
10842
|
for (const pending of context.pendingReferences) {
|
|
10823
10843
|
for (const key of pending.token.keys) {
|
|
10824
10844
|
const normalized = normalizeDocumentKey(key);
|
|
10825
|
-
if (!isValidDocumentKey(normalized)) {
|
|
10845
|
+
if (!isValidDocumentKey(normalized) || !context.labelKinds.has(normalized)) {
|
|
10826
10846
|
addIssue(
|
|
10827
10847
|
context,
|
|
10828
10848
|
"missing_reference",
|
|
@@ -10921,6 +10941,18 @@ function validateDocument(document2) {
|
|
|
10921
10941
|
resolved.blocks.forEach((block, index) => {
|
|
10922
10942
|
validateBlock(context, block, `$.blocks[${String(index)}]`);
|
|
10923
10943
|
});
|
|
10944
|
+
for (const target of collectDocumentReferenceTargets(resolved)) {
|
|
10945
|
+
if (target.number !== null && target.manualKey !== target.key) {
|
|
10946
|
+
registerKey(
|
|
10947
|
+
context,
|
|
10948
|
+
target.key,
|
|
10949
|
+
"$.automatic_labels",
|
|
10950
|
+
target.kind,
|
|
10951
|
+
target.kind === "eq" ? void 0 : target.ownerId,
|
|
10952
|
+
target.kind === "eq" ? target.ownerId : void 0
|
|
10953
|
+
);
|
|
10954
|
+
}
|
|
10955
|
+
}
|
|
10924
10956
|
for (const diagnostic of resolved.diagnostics) {
|
|
10925
10957
|
addIssue(context, "parser_diagnostic", diagnostic.path);
|
|
10926
10958
|
}
|
|
@@ -11061,6 +11093,7 @@ function previewInlines(field, islands, output, equationSide, document2, preview
|
|
|
11061
11093
|
})
|
|
11062
11094
|
};
|
|
11063
11095
|
}
|
|
11096
|
+
const number = collectDocumentReferenceTargets(document2).find((target) => target.kind === "eq" && target.ownerId === token.id)?.number;
|
|
11064
11097
|
const island = {
|
|
11065
11098
|
id: token.id,
|
|
11066
11099
|
tex: mathTex(token, equationSide, previewOptions.digitForm),
|
|
@@ -11068,8 +11101,12 @@ function previewInlines(field, islands, output, equationSide, document2, preview
|
|
|
11068
11101
|
output,
|
|
11069
11102
|
editable: token.editable
|
|
11070
11103
|
};
|
|
11104
|
+
const numberLabel = number == null ? void 0 : formatBibliographyNumber(number, {
|
|
11105
|
+
documentDirection: previewOptions.documentDirection,
|
|
11106
|
+
digitForm: previewOptions.digitForm
|
|
11107
|
+
});
|
|
11071
11108
|
islands.push(island);
|
|
11072
|
-
return { kind: "math", ...island };
|
|
11109
|
+
return { kind: "math", ...island, ...numberLabel ? { numberLabel } : {} };
|
|
11073
11110
|
});
|
|
11074
11111
|
}
|
|
11075
11112
|
function textBlockPreview(block, islands, output, equationSide, document2, previewOptions) {
|
|
@@ -11092,12 +11129,9 @@ function textBlockPreview(block, islands, output, equationSide, document2, previ
|
|
|
11092
11129
|
...block.centered ? { centered: true } : {}
|
|
11093
11130
|
};
|
|
11094
11131
|
}
|
|
11095
|
-
function floatNumberLabel(document2,
|
|
11096
|
-
|
|
11097
|
-
|
|
11098
|
-
}
|
|
11099
|
-
const hit = labelNumberMap(document2).get(key.trim());
|
|
11100
|
-
if (!hit || hit.kind !== "fig" && hit.kind !== "tab") {
|
|
11132
|
+
function floatNumberLabel(document2, ownerId, previewOptions) {
|
|
11133
|
+
const hit = collectDocumentReferenceTargets(document2).find((target) => target.ownerId === ownerId);
|
|
11134
|
+
if (!hit || hit.number === null || hit.kind !== "fig" && hit.kind !== "tab") {
|
|
11101
11135
|
return void 0;
|
|
11102
11136
|
}
|
|
11103
11137
|
return formatFloatCaptionTitle(hit.kind, hit.number, {
|
|
@@ -11139,7 +11173,8 @@ function blockPreview(block, islands, output, equationSide, document2, previewOp
|
|
|
11139
11173
|
id: block.id,
|
|
11140
11174
|
rows: block.rows.map((row) => row.map((cell) => previewInlines(cell, islands, output, equationSide, document2, previewOptions))),
|
|
11141
11175
|
...captionPreview(block, islands, output, equationSide, document2, previewOptions),
|
|
11142
|
-
...label.length > 0 ? { label
|
|
11176
|
+
...label.length > 0 ? { label } : {},
|
|
11177
|
+
...floatNumberLabel(document2, block.id, previewOptions) ? { numberLabel: floatNumberLabel(document2, block.id, previewOptions) } : {},
|
|
11143
11178
|
...block.metadata ? { metadata: { ...block.metadata } } : {}
|
|
11144
11179
|
};
|
|
11145
11180
|
}
|
|
@@ -11153,7 +11188,8 @@ function blockPreview(block, islands, output, equationSide, document2, previewOp
|
|
|
11153
11188
|
options: block.options,
|
|
11154
11189
|
centered: block.centered,
|
|
11155
11190
|
...captionPreview(block, islands, output, equationSide, document2, previewOptions),
|
|
11156
|
-
...label.length > 0 ? { label
|
|
11191
|
+
...label.length > 0 ? { label } : {},
|
|
11192
|
+
...floatNumberLabel(document2, block.id, previewOptions) ? { numberLabel: floatNumberLabel(document2, block.id, previewOptions) } : {},
|
|
11157
11193
|
...block.metadata ? { metadata: { ...block.metadata } } : {}
|
|
11158
11194
|
};
|
|
11159
11195
|
}
|
|
@@ -14375,7 +14411,14 @@ function PreviewInlines({ inlines, output }) {
|
|
|
14375
14411
|
if (inline.kind === "ref") {
|
|
14376
14412
|
return /* @__PURE__ */ jsx12("span", { className: "butex-document-widget__preview-cite butex-document-widget__preview-ref", children: contextualRefLabel(inlines, index, inline.label) }, inline.id);
|
|
14377
14413
|
}
|
|
14378
|
-
return /* @__PURE__ */
|
|
14414
|
+
return /* @__PURE__ */ jsxs11("span", { className: "butex-document-widget__preview-math-numbered", children: [
|
|
14415
|
+
/* @__PURE__ */ jsx12(MathIsland, { id: inline.id, tex: inline.tex, display: inline.display, output }),
|
|
14416
|
+
inline.numberLabel ? /* @__PURE__ */ jsxs11("span", { className: "butex-document-widget__preview-equation-number", children: [
|
|
14417
|
+
"(",
|
|
14418
|
+
inline.numberLabel,
|
|
14419
|
+
")"
|
|
14420
|
+
] }) : null
|
|
14421
|
+
] }, inline.id);
|
|
14379
14422
|
}) });
|
|
14380
14423
|
}
|
|
14381
14424
|
function isBodyPreviewBlock(block) {
|
|
@@ -18439,6 +18482,8 @@ function EquationDrawer({
|
|
|
18439
18482
|
responsiveMode = "auto",
|
|
18440
18483
|
labelEnabled = false,
|
|
18441
18484
|
label = "",
|
|
18485
|
+
numbered = false,
|
|
18486
|
+
onNumberedChange,
|
|
18442
18487
|
labels = [],
|
|
18443
18488
|
references = [],
|
|
18444
18489
|
ownerId = "",
|
|
@@ -18528,6 +18573,10 @@ function EquationDrawer({
|
|
|
18528
18573
|
] })
|
|
18529
18574
|
] }),
|
|
18530
18575
|
mathMode === "display" ? /* @__PURE__ */ jsxs14("div", { className: "butex-document-widget__float-meta", children: [
|
|
18576
|
+
/* @__PURE__ */ jsxs14("label", { className: "butex-document-widget__float-meta-toggle", children: [
|
|
18577
|
+
/* @__PURE__ */ jsx15("input", { type: "checkbox", checked: numbered, onChange: (event) => onNumberedChange?.(event.currentTarget.checked) }),
|
|
18578
|
+
/* @__PURE__ */ jsx15("span", { children: uiLocale === "ar" ? "\u062A\u0631\u0642\u064A\u0645 \u0627\u0644\u0645\u0639\u0627\u062F\u0644\u0629" : "Number equation" })
|
|
18579
|
+
] }),
|
|
18531
18580
|
/* @__PURE__ */ jsxs14("label", { className: "butex-document-widget__float-meta-toggle", children: [
|
|
18532
18581
|
/* @__PURE__ */ jsx15(
|
|
18533
18582
|
"input",
|
|
@@ -19051,13 +19100,14 @@ import { useEffect as useEffect12, useRef as useRef14, useState as useState13 }
|
|
|
19051
19100
|
import { jsx as jsx18, jsxs as jsxs17 } from "react/jsx-runtime";
|
|
19052
19101
|
function RefPickerPopover({
|
|
19053
19102
|
open,
|
|
19054
|
-
|
|
19103
|
+
targets,
|
|
19055
19104
|
initialKeys = [],
|
|
19056
19105
|
initialRefCommand = "ref",
|
|
19057
19106
|
uiLocale = "ar",
|
|
19058
19107
|
digitForm = "arabicIndic",
|
|
19059
19108
|
onClose,
|
|
19060
19109
|
onConfirm,
|
|
19110
|
+
onNumberEquation,
|
|
19061
19111
|
onManageLabels
|
|
19062
19112
|
}) {
|
|
19063
19113
|
const messages = documentMessages(uiLocale);
|
|
@@ -19094,22 +19144,19 @@ function RefPickerPopover({
|
|
|
19094
19144
|
/* @__PURE__ */ jsx18("strong", { children: messages.refPickerTitle }),
|
|
19095
19145
|
/* @__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" })
|
|
19096
19146
|
] }),
|
|
19097
|
-
/* @__PURE__ */ jsx18("div", { className: "butex-document-widget__dialog-body", children:
|
|
19098
|
-
const checked = selected.includes(entry.key);
|
|
19099
|
-
const title = formatFloatCaptionTitle(entry.kind, entry.number, {
|
|
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) => {
|
|
19148
|
+
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, {
|
|
19100
19150
|
uiLocale,
|
|
19101
19151
|
digitForm,
|
|
19102
19152
|
documentDirection
|
|
19103
19153
|
});
|
|
19104
19154
|
return /* @__PURE__ */ jsx18("li", { children: /* @__PURE__ */ jsxs17("label", { className: "butex-document-widget__cite-picker-item", children: [
|
|
19105
|
-
/* @__PURE__ */ jsx18("input", { type: "radio", name: "butex-ref-key", checked, onChange: () => selectKey(entry.key, entry.kind) }),
|
|
19155
|
+
/* @__PURE__ */ jsx18("input", { type: "radio", name: "butex-ref-key", checked, disabled: entry.number === null, onChange: () => selectKey(entry.key, entry.kind) }),
|
|
19106
19156
|
/* @__PURE__ */ jsxs17("span", { children: [
|
|
19107
|
-
/* @__PURE__ */
|
|
19108
|
-
|
|
19109
|
-
|
|
19110
|
-
/* @__PURE__ */ jsx18("span", { className: "butex-document-widget__refs-item-key", children: entry.key })
|
|
19111
|
-
] }),
|
|
19112
|
-
entry.caption ? /* @__PURE__ */ jsx18("span", { className: "butex-document-widget__cite-picker-meta", children: entry.caption }) : null
|
|
19157
|
+
/* @__PURE__ */ jsx18("strong", { children: entry.kind === "eq" && entry.number !== null ? title.replace(/(\d+|[٠-٩]+)$/, "($1)") : title }),
|
|
19158
|
+
entry.caption ? /* @__PURE__ */ jsx18("span", { className: "butex-document-widget__cite-picker-meta", children: entry.caption }) : null,
|
|
19159
|
+
entry.kind === "eq" && entry.number === null && onNumberEquation ? /* @__PURE__ */ jsx18("button", { type: "button", onClick: () => onNumberEquation(entry.ownerId), children: uiLocale === "ar" ? "\u0631\u0642\u0651\u0645 \u0627\u0644\u0645\u0639\u0627\u062F\u0644\u0629 \u0623\u0648\u0644\u0627\u064B" : "Number equation first" }) : null
|
|
19113
19160
|
] })
|
|
19114
19161
|
] }) }, `${entry.kind}:${entry.ownerId}`);
|
|
19115
19162
|
}) }) }),
|
|
@@ -21829,6 +21876,7 @@ var ButexDocumentEditor = forwardRef2(
|
|
|
21829
21876
|
const latex = documentLatex(documentNode, { digitForm });
|
|
21830
21877
|
const documentJson = useMemo2(() => toDocumentJson(documentNode), [documentNode]);
|
|
21831
21878
|
const documentLabels = useMemo2(() => collectDocumentLabels(documentNode), [documentNode]);
|
|
21879
|
+
const referenceTargets = useMemo2(() => collectDocumentReferenceTargets(documentNode), [documentNode]);
|
|
21832
21880
|
const preview = useMemo2(
|
|
21833
21881
|
() => documentPreview(documentNode, mathOutput, equationSide, {
|
|
21834
21882
|
documentDirection,
|
|
@@ -22164,7 +22212,8 @@ var ButexDocumentEditor = forwardRef2(
|
|
|
22164
22212
|
session: equationSessionWithDocumentDigits(createEmptyEquationSession(equationSide)),
|
|
22165
22213
|
reason: null,
|
|
22166
22214
|
labelEnabled: false,
|
|
22167
|
-
label: ""
|
|
22215
|
+
label: "",
|
|
22216
|
+
numbered: false
|
|
22168
22217
|
});
|
|
22169
22218
|
}
|
|
22170
22219
|
function openMath(token, origin) {
|
|
@@ -22189,7 +22238,8 @@ var ButexDocumentEditor = forwardRef2(
|
|
|
22189
22238
|
session: equationSessionWithDocumentDigits(createEmptyEquationSession(equationSide)),
|
|
22190
22239
|
reason: result.reason,
|
|
22191
22240
|
labelEnabled: Boolean(token.labelEnabled),
|
|
22192
|
-
label: token.label ?? ""
|
|
22241
|
+
label: token.label ?? "",
|
|
22242
|
+
numbered: isNumberedEquation(token)
|
|
22193
22243
|
});
|
|
22194
22244
|
return;
|
|
22195
22245
|
}
|
|
@@ -22202,7 +22252,8 @@ var ButexDocumentEditor = forwardRef2(
|
|
|
22202
22252
|
session: equationSessionWithDocumentDigits(result.session),
|
|
22203
22253
|
reason: null,
|
|
22204
22254
|
labelEnabled: Boolean(token.labelEnabled),
|
|
22205
|
-
label: token.label ?? ""
|
|
22255
|
+
label: token.label ?? "",
|
|
22256
|
+
numbered: isNumberedEquation(token)
|
|
22206
22257
|
});
|
|
22207
22258
|
}
|
|
22208
22259
|
function selectMobileView(view) {
|
|
@@ -22293,10 +22344,11 @@ var ButexDocumentEditor = forwardRef2(
|
|
|
22293
22344
|
if (selectedMath.mathMode === "display") {
|
|
22294
22345
|
next2 = updateMathTokenLabel(next2, selectedMath.tokenId, {
|
|
22295
22346
|
labelEnabled: selectedMath.labelEnabled,
|
|
22296
|
-
label: selectedMath.label
|
|
22347
|
+
label: selectedMath.label,
|
|
22348
|
+
numbered: selectedMath.numbered
|
|
22297
22349
|
});
|
|
22298
22350
|
} else {
|
|
22299
|
-
next2 = updateMathTokenLabel(next2, selectedMath.tokenId, { labelEnabled: false, label: "" });
|
|
22351
|
+
next2 = updateMathTokenLabel(next2, selectedMath.tokenId, { labelEnabled: false, label: "", numbered: false });
|
|
22300
22352
|
}
|
|
22301
22353
|
pendingFocusRef.current = { kind: "math", tokenId: selectedMath.tokenId };
|
|
22302
22354
|
applyDocument(next2, "immediate");
|
|
@@ -22341,10 +22393,11 @@ var ButexDocumentEditor = forwardRef2(
|
|
|
22341
22393
|
0,
|
|
22342
22394
|
fieldAfter.tokens.findIndex((token) => token.id === trailingTextTokenId) - 1
|
|
22343
22395
|
)]?.id : null : fieldAfter?.tokens.filter((token) => token.kind === "math").at(-1)?.id ?? null;
|
|
22344
|
-
if (insertedMathId && selectedMath.mathMode === "display"
|
|
22396
|
+
if (insertedMathId && selectedMath.mathMode === "display") {
|
|
22345
22397
|
next = updateMathTokenLabel(next, insertedMathId, {
|
|
22346
|
-
labelEnabled:
|
|
22347
|
-
label: selectedMath.label
|
|
22398
|
+
labelEnabled: selectedMath.labelEnabled,
|
|
22399
|
+
label: selectedMath.label,
|
|
22400
|
+
numbered: selectedMath.numbered
|
|
22348
22401
|
});
|
|
22349
22402
|
}
|
|
22350
22403
|
if (insertedMathId) {
|
|
@@ -22796,10 +22849,12 @@ var ButexDocumentEditor = forwardRef2(
|
|
|
22796
22849
|
responsiveMode,
|
|
22797
22850
|
labelEnabled: selectedMath.labelEnabled,
|
|
22798
22851
|
label: selectedMath.label,
|
|
22852
|
+
numbered: selectedMath.numbered,
|
|
22853
|
+
onNumberedChange: (numbered) => setSelectedMath((current) => current ? { ...current, numbered } : current),
|
|
22799
22854
|
labels: documentLabels,
|
|
22800
22855
|
references: documentNode.references,
|
|
22801
22856
|
ownerId: selectedMath.tokenId ?? void 0,
|
|
22802
|
-
onLabelEnabledChange: (enabled) => setSelectedMath((current) => current ? { ...current, labelEnabled: enabled } : current),
|
|
22857
|
+
onLabelEnabledChange: (enabled) => setSelectedMath((current) => current ? { ...current, labelEnabled: enabled, numbered: enabled || current.numbered } : current),
|
|
22803
22858
|
onLabelChange: (nextLabel) => setSelectedMath((current) => current ? { ...current, label: nextLabel } : current),
|
|
22804
22859
|
onMathModeChange: (mode) => setSelectedMath((current) => current ? { ...current, mathMode: mode } : current),
|
|
22805
22860
|
onClose: closeEquationAndRestoreOrigin,
|
|
@@ -22827,13 +22882,16 @@ var ButexDocumentEditor = forwardRef2(
|
|
|
22827
22882
|
RefPickerPopover,
|
|
22828
22883
|
{
|
|
22829
22884
|
open: refPicker !== null,
|
|
22830
|
-
|
|
22885
|
+
targets: referenceTargets,
|
|
22831
22886
|
initialKeys: refPicker?.keys ?? [],
|
|
22832
22887
|
initialRefCommand: refPicker?.refCommand ?? "ref",
|
|
22833
22888
|
uiLocale,
|
|
22834
22889
|
digitForm,
|
|
22835
22890
|
onClose: () => setRefPicker(null),
|
|
22836
22891
|
onConfirm: confirmRefKeys,
|
|
22892
|
+
onNumberEquation: (tokenId) => {
|
|
22893
|
+
applyDocument(updateMathTokenLabel(documentRef.current, tokenId, { numbered: true }), "immediate");
|
|
22894
|
+
},
|
|
22837
22895
|
onManageLabels: () => {
|
|
22838
22896
|
setRefPicker(null);
|
|
22839
22897
|
openLabelsManager();
|