@drghaliasri/butex 7.0.3 → 7.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/dist/document2-cli.js +376 -34
- package/dist/document2-cli.js.map +1 -1
- package/dist/document2.d.mts +83 -3
- package/dist/document2.d.ts +83 -3
- package/dist/document2.js +399 -37
- package/dist/document2.js.map +1 -1
- package/dist/document2.mjs +396 -37
- package/dist/document2.mjs.map +1 -1
- package/dist/react-document2-preview.d.mts +336 -0
- package/dist/react-document2-preview.d.ts +336 -0
- package/dist/react-document2-preview.js +7767 -0
- package/dist/react-document2-preview.js.map +1 -0
- package/dist/react-document2-preview.mjs +7737 -0
- package/dist/react-document2-preview.mjs.map +1 -0
- package/dist/react-document2.d.mts +53 -14
- package/dist/react-document2.d.ts +53 -14
- package/dist/react-document2.js +284 -42
- package/dist/react-document2.js.map +1 -1
- package/dist/react-document2.mjs +281 -41
- package/dist/react-document2.mjs.map +1 -1
- package/package.json +9 -2
package/dist/react-document2.js
CHANGED
|
@@ -21,6 +21,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var react_document2_entry_exports = {};
|
|
22
22
|
__export(react_document2_entry_exports, {
|
|
23
23
|
ButexDocumentEditor2: () => ButexDocumentEditor23,
|
|
24
|
+
ButexDocumentPreview: () => ButexDocumentPreview,
|
|
24
25
|
DOCUMENT2_WIDGET_CSS: () => DOCUMENT2_WIDGET_CSS,
|
|
25
26
|
DocumentInsertToolbar: () => DocumentInsertToolbar,
|
|
26
27
|
DocumentPreview: () => DocumentPreview,
|
|
@@ -29,7 +30,8 @@ __export(react_document2_entry_exports, {
|
|
|
29
30
|
MathChip: () => MathChip,
|
|
30
31
|
MathIsland: () => MathIsland,
|
|
31
32
|
injectBuTeXDocument2Styles: () => injectBuTeXDocument2Styles,
|
|
32
|
-
resolveInitialDocument2: () => resolveInitialDocument2
|
|
33
|
+
resolveInitialDocument2: () => resolveInitialDocument2,
|
|
34
|
+
resolvePreviewDocument2: () => resolvePreviewDocument2
|
|
33
35
|
});
|
|
34
36
|
module.exports = __toCommonJS(react_document2_entry_exports);
|
|
35
37
|
|
|
@@ -827,6 +829,10 @@ function defaultFloatMeta() {
|
|
|
827
829
|
centered: true,
|
|
828
830
|
captionEnabled: false,
|
|
829
831
|
caption: "",
|
|
832
|
+
captionField: {
|
|
833
|
+
id: document2Id("field"),
|
|
834
|
+
tokens: [{ id: document2Id("text"), kind: "text", text: "" }]
|
|
835
|
+
},
|
|
830
836
|
labelEnabled: false,
|
|
831
837
|
label: ""
|
|
832
838
|
};
|
|
@@ -885,15 +891,20 @@ function collectDocument2Labels(document2) {
|
|
|
885
891
|
}
|
|
886
892
|
function walk(blocks) {
|
|
887
893
|
for (const block of blocks) {
|
|
888
|
-
if (block.kind === "image"
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
894
|
+
if (block.kind === "image") {
|
|
895
|
+
if (block.labelEnabled && block.label.trim().length > 0) {
|
|
896
|
+
counters.fig += 1;
|
|
897
|
+
entries.push({
|
|
898
|
+
key: block.label.trim(),
|
|
899
|
+
kind: "fig",
|
|
900
|
+
caption: block.captionEnabled ? block.caption : "",
|
|
901
|
+
ownerId: block.id,
|
|
902
|
+
number: counters.fig
|
|
903
|
+
});
|
|
904
|
+
}
|
|
905
|
+
if (block.captionEnabled) {
|
|
906
|
+
pushEqFromField(block.captionField.tokens);
|
|
907
|
+
}
|
|
897
908
|
}
|
|
898
909
|
if (block.kind === "table") {
|
|
899
910
|
if (block.labelEnabled && block.label.trim().length > 0) {
|
|
@@ -906,6 +917,9 @@ function collectDocument2Labels(document2) {
|
|
|
906
917
|
number: counters.tab
|
|
907
918
|
});
|
|
908
919
|
}
|
|
920
|
+
if (block.captionEnabled) {
|
|
921
|
+
pushEqFromField(block.captionField.tokens);
|
|
922
|
+
}
|
|
909
923
|
for (const row of block.rows) {
|
|
910
924
|
for (const cell of row) {
|
|
911
925
|
pushEqFromField(cell.tokens);
|
|
@@ -998,6 +1012,14 @@ function applyFloatMetaPatch(block, patch) {
|
|
|
998
1012
|
}
|
|
999
1013
|
if (typeof patch.caption === "string") {
|
|
1000
1014
|
block.caption = patch.caption;
|
|
1015
|
+
const existingText = block.captionField.tokens.find((token) => token.kind === "text");
|
|
1016
|
+
block.captionField.tokens = [
|
|
1017
|
+
{
|
|
1018
|
+
id: existingText?.id ?? document2Id("text"),
|
|
1019
|
+
kind: "text",
|
|
1020
|
+
text: patch.caption
|
|
1021
|
+
}
|
|
1022
|
+
];
|
|
1001
1023
|
}
|
|
1002
1024
|
if (typeof patch.labelEnabled === "boolean") {
|
|
1003
1025
|
block.labelEnabled = patch.labelEnabled;
|
|
@@ -1517,6 +1539,21 @@ function parseListBlock(json, options, path, diagnostics, identities) {
|
|
|
1517
1539
|
...metadataFromJson(json.metadata)
|
|
1518
1540
|
};
|
|
1519
1541
|
}
|
|
1542
|
+
function captionFieldFromJson(json, options, path, diagnostics, identities) {
|
|
1543
|
+
const caption = typeof json.caption === "string" ? json.caption : "";
|
|
1544
|
+
return applyImportedInlineIds(
|
|
1545
|
+
createInlineField2(
|
|
1546
|
+
caption,
|
|
1547
|
+
json.caption_math_objects ?? [],
|
|
1548
|
+
options,
|
|
1549
|
+
`${path}.caption`,
|
|
1550
|
+
diagnostics,
|
|
1551
|
+
json.caption_formats ?? []
|
|
1552
|
+
),
|
|
1553
|
+
json.caption_inline_ids,
|
|
1554
|
+
identities
|
|
1555
|
+
);
|
|
1556
|
+
}
|
|
1520
1557
|
function parseTableBlock(json, options, path, diagnostics, identities) {
|
|
1521
1558
|
if (!Array.isArray(json.rows)) {
|
|
1522
1559
|
throw new Error("\\begin{tabular} requires rows array");
|
|
@@ -1543,6 +1580,7 @@ function parseTableBlock(json, options, path, diagnostics, identities) {
|
|
|
1543
1580
|
if (mathObjects.length > 0 && mathObjects.length !== mathObjectIndex) {
|
|
1544
1581
|
pushDiagnostic(diagnostics, options, path, `math_objects count mismatch: detected ${String(mathObjectIndex)}, got ${String(mathObjects.length)}`);
|
|
1545
1582
|
}
|
|
1583
|
+
const floatMeta = parseFloatMetaFromJson(json);
|
|
1546
1584
|
return {
|
|
1547
1585
|
id: blockIdFromJson(json, identities),
|
|
1548
1586
|
kind: "table",
|
|
@@ -1550,13 +1588,15 @@ function parseTableBlock(json, options, path, diagnostics, identities) {
|
|
|
1550
1588
|
closing: "\\end{tabular}",
|
|
1551
1589
|
columns: typeof json.columns === "string" ? json.columns : "",
|
|
1552
1590
|
rows,
|
|
1553
|
-
...
|
|
1591
|
+
...floatMeta,
|
|
1592
|
+
captionField: captionFieldFromJson(json, options, path, diagnostics, identities),
|
|
1554
1593
|
...metadataFromJson(json.metadata)
|
|
1555
1594
|
};
|
|
1556
1595
|
}
|
|
1557
|
-
function parseImageBlock(json, identities) {
|
|
1596
|
+
function parseImageBlock(json, options, path, diagnostics, identities) {
|
|
1558
1597
|
const assetId = typeof json.asset_id === "string" && json.asset_id.length > 0 ? json.asset_id : void 0;
|
|
1559
1598
|
const value = assetId !== void 0 ? typeof json.value === "string" ? json.value : "" : requireString(json.value, "\\includegraphics requires string value");
|
|
1599
|
+
const floatMeta = parseFloatMetaFromJson(json);
|
|
1560
1600
|
return {
|
|
1561
1601
|
id: blockIdFromJson(json, identities),
|
|
1562
1602
|
kind: "image",
|
|
@@ -1564,7 +1604,8 @@ function parseImageBlock(json, identities) {
|
|
|
1564
1604
|
value,
|
|
1565
1605
|
...assetId !== void 0 ? { assetId } : {},
|
|
1566
1606
|
options: isRecordOfStrings(json.options) ? json.options : {},
|
|
1567
|
-
...
|
|
1607
|
+
...floatMeta,
|
|
1608
|
+
captionField: captionFieldFromJson(json, options, path, diagnostics, identities),
|
|
1568
1609
|
...metadataFromJson(json.metadata)
|
|
1569
1610
|
};
|
|
1570
1611
|
}
|
|
@@ -1597,7 +1638,7 @@ function parseBlock(json, options, path, diagnostics, identities) {
|
|
|
1597
1638
|
return parseTableBlock(json, options, path, diagnostics, identities);
|
|
1598
1639
|
}
|
|
1599
1640
|
if (json.command === "\\includegraphics") {
|
|
1600
|
-
return parseImageBlock(json, identities);
|
|
1641
|
+
return parseImageBlock(json, options, path, diagnostics, identities);
|
|
1601
1642
|
}
|
|
1602
1643
|
if (json.command === "\\begin{thebibliography}" || json.command === "\\bibliography") {
|
|
1603
1644
|
return parseBibliographyBlock(json, identities);
|
|
@@ -8545,6 +8586,20 @@ function cloneToken(token) {
|
|
|
8545
8586
|
function cloneField(field) {
|
|
8546
8587
|
return { id: field.id, tokens: field.tokens.map(cloneToken) };
|
|
8547
8588
|
}
|
|
8589
|
+
function inlineFieldSource(field) {
|
|
8590
|
+
return field.tokens.map((token) => {
|
|
8591
|
+
if (token.kind === "text") {
|
|
8592
|
+
return token.text;
|
|
8593
|
+
}
|
|
8594
|
+
if (token.kind === "cite") {
|
|
8595
|
+
return citeTokenLatex(token.keys);
|
|
8596
|
+
}
|
|
8597
|
+
if (token.kind === "ref") {
|
|
8598
|
+
return refTokenLatex(token.keys, token.refCommand);
|
|
8599
|
+
}
|
|
8600
|
+
return token.source;
|
|
8601
|
+
}).join("");
|
|
8602
|
+
}
|
|
8548
8603
|
function cloneBlock(block) {
|
|
8549
8604
|
const metadata = block.metadata ? { metadata: { ...block.metadata } } : {};
|
|
8550
8605
|
if (block.kind === "textBlock") {
|
|
@@ -8562,10 +8617,20 @@ function cloneBlock(block) {
|
|
|
8562
8617
|
};
|
|
8563
8618
|
}
|
|
8564
8619
|
if (block.kind === "table") {
|
|
8565
|
-
return {
|
|
8620
|
+
return {
|
|
8621
|
+
...block,
|
|
8622
|
+
...metadata,
|
|
8623
|
+
rows: block.rows.map((row) => row.map(cloneField)),
|
|
8624
|
+
captionField: cloneField(block.captionField)
|
|
8625
|
+
};
|
|
8566
8626
|
}
|
|
8567
8627
|
if (block.kind === "image") {
|
|
8568
|
-
return {
|
|
8628
|
+
return {
|
|
8629
|
+
...block,
|
|
8630
|
+
...metadata,
|
|
8631
|
+
options: { ...block.options },
|
|
8632
|
+
captionField: cloneField(block.captionField)
|
|
8633
|
+
};
|
|
8569
8634
|
}
|
|
8570
8635
|
return { ...block, ...metadata };
|
|
8571
8636
|
}
|
|
@@ -8578,6 +8643,13 @@ function cloneDocument(document2) {
|
|
|
8578
8643
|
diagnostics: document2.diagnostics.map((diagnostic) => ({ ...diagnostic }))
|
|
8579
8644
|
};
|
|
8580
8645
|
}
|
|
8646
|
+
function visitCaptionField(block, visitor) {
|
|
8647
|
+
if (!visitor(block.captionField)) {
|
|
8648
|
+
return false;
|
|
8649
|
+
}
|
|
8650
|
+
block.caption = inlineFieldSource(block.captionField);
|
|
8651
|
+
return true;
|
|
8652
|
+
}
|
|
8581
8653
|
function visitFields(blocks, visitor) {
|
|
8582
8654
|
for (const block of blocks) {
|
|
8583
8655
|
if (block.kind === "textBlock") {
|
|
@@ -8598,6 +8670,11 @@ function visitFields(blocks, visitor) {
|
|
|
8598
8670
|
}
|
|
8599
8671
|
}
|
|
8600
8672
|
}
|
|
8673
|
+
if (visitCaptionField(block, visitor)) {
|
|
8674
|
+
return true;
|
|
8675
|
+
}
|
|
8676
|
+
} else if (block.kind === "image" && visitCaptionField(block, visitor)) {
|
|
8677
|
+
return true;
|
|
8601
8678
|
}
|
|
8602
8679
|
}
|
|
8603
8680
|
return false;
|
|
@@ -9397,6 +9474,15 @@ function fieldJson(field) {
|
|
|
9397
9474
|
...serialized.hasPersistedMath ? { math_objects: serialized.mathObjects } : {}
|
|
9398
9475
|
};
|
|
9399
9476
|
}
|
|
9477
|
+
function captionJson(field) {
|
|
9478
|
+
const serialized = serializeField(field);
|
|
9479
|
+
return {
|
|
9480
|
+
caption: serialized.value,
|
|
9481
|
+
caption_inline_ids: serialized.inlineIds,
|
|
9482
|
+
...serialized.formats.length > 0 ? { caption_formats: serialized.formats } : {},
|
|
9483
|
+
...serialized.hasPersistedMath ? { caption_math_objects: serialized.mathObjects } : {}
|
|
9484
|
+
};
|
|
9485
|
+
}
|
|
9400
9486
|
function listItemJson(item) {
|
|
9401
9487
|
const field = fieldJson(item.field);
|
|
9402
9488
|
return {
|
|
@@ -9441,7 +9527,7 @@ function blockJson(block) {
|
|
|
9441
9527
|
...hasPersistedMath ? { math_objects: fields.flatMap((row) => row.flatMap((field) => field.mathObjects)) } : {},
|
|
9442
9528
|
centered: block.centered,
|
|
9443
9529
|
caption_enabled: block.captionEnabled,
|
|
9444
|
-
|
|
9530
|
+
...captionJson(block.captionField),
|
|
9445
9531
|
label_enabled: block.labelEnabled,
|
|
9446
9532
|
label: block.label,
|
|
9447
9533
|
...block.metadata ? { metadata: { ...block.metadata } } : {}
|
|
@@ -9456,7 +9542,7 @@ function blockJson(block) {
|
|
|
9456
9542
|
options: { ...block.options },
|
|
9457
9543
|
centered: block.centered,
|
|
9458
9544
|
caption_enabled: block.captionEnabled,
|
|
9459
|
-
|
|
9545
|
+
...captionJson(block.captionField),
|
|
9460
9546
|
label_enabled: block.labelEnabled,
|
|
9461
9547
|
label: block.label,
|
|
9462
9548
|
...block.metadata ? { metadata: { ...block.metadata } } : {}
|
|
@@ -9505,6 +9591,9 @@ function toDocumentJson2(document2) {
|
|
|
9505
9591
|
};
|
|
9506
9592
|
}
|
|
9507
9593
|
|
|
9594
|
+
// src/document2/diff.ts
|
|
9595
|
+
var import_diff = require("diff");
|
|
9596
|
+
|
|
9508
9597
|
// src/document2/arabicPreamble.ts
|
|
9509
9598
|
function fontOptions(digitsMapping, includeScript = true) {
|
|
9510
9599
|
const parts = [];
|
|
@@ -9872,11 +9961,12 @@ ${block.closing}`;
|
|
|
9872
9961
|
${rows.join(" \\\\\n")}
|
|
9873
9962
|
${block.closing}`;
|
|
9874
9963
|
}
|
|
9875
|
-
function floatCaptionLabelLines(block, counter) {
|
|
9964
|
+
function floatCaptionLabelLines(block, counter, labelKinds) {
|
|
9876
9965
|
const lines = [];
|
|
9877
|
-
const
|
|
9966
|
+
const caption = inlineFieldLatexWithLabelKinds(block.captionField, labelKinds).trim();
|
|
9967
|
+
const hasCaption = block.captionEnabled && caption.length > 0;
|
|
9878
9968
|
if (hasCaption) {
|
|
9879
|
-
lines.push(` \\caption{${
|
|
9969
|
+
lines.push(` \\caption{${caption}}`);
|
|
9880
9970
|
}
|
|
9881
9971
|
if (block.labelEnabled && block.label.trim().length > 0) {
|
|
9882
9972
|
if (!hasCaption) {
|
|
@@ -9892,7 +9982,7 @@ function tableBlockLatex(block, labelKinds, fixedFloats) {
|
|
|
9892
9982
|
if (block.centered) {
|
|
9893
9983
|
lines.push(" \\centering");
|
|
9894
9984
|
}
|
|
9895
|
-
lines.push(...floatCaptionLabelLines(block, "table"));
|
|
9985
|
+
lines.push(...floatCaptionLabelLines(block, "table", labelKinds));
|
|
9896
9986
|
lines.push(indent(tabularInnerLatex(block, labelKinds)));
|
|
9897
9987
|
lines.push("\\end{table}");
|
|
9898
9988
|
return lines.join("\n");
|
|
@@ -9912,14 +10002,14 @@ function imageOptionsLatex(block, constrainToColumn) {
|
|
|
9912
10002
|
}
|
|
9913
10003
|
return `[${entries.map(([key, value]) => `${key}=${value}`).join(",")}]`;
|
|
9914
10004
|
}
|
|
9915
|
-
function imageBlockLatex(block, fixedFloats) {
|
|
10005
|
+
function imageBlockLatex(block, labelKinds, fixedFloats) {
|
|
9916
10006
|
const placement = fixedFloats ? "H" : "htbp";
|
|
9917
10007
|
const lines = [`\\begin{figure}[${placement}]`];
|
|
9918
10008
|
if (block.centered) {
|
|
9919
10009
|
lines.push(" \\centering");
|
|
9920
10010
|
}
|
|
9921
10011
|
lines.push(` ${block.command}${imageOptionsLatex(block, true)}{${block.value}}`);
|
|
9922
|
-
lines.push(...floatCaptionLabelLines(block, "figure"));
|
|
10012
|
+
lines.push(...floatCaptionLabelLines(block, "figure", labelKinds));
|
|
9923
10013
|
lines.push("\\end{figure}");
|
|
9924
10014
|
return lines.join("\n");
|
|
9925
10015
|
}
|
|
@@ -9934,7 +10024,7 @@ function blockLatex(block, references, labelKinds, fixedFloats) {
|
|
|
9934
10024
|
return tableBlockLatex(block, labelKinds, fixedFloats);
|
|
9935
10025
|
}
|
|
9936
10026
|
if (block.kind === "image") {
|
|
9937
|
-
return imageBlockLatex(block, fixedFloats);
|
|
10027
|
+
return imageBlockLatex(block, labelKinds, fixedFloats);
|
|
9938
10028
|
}
|
|
9939
10029
|
if (block.kind === "bibliography") {
|
|
9940
10030
|
const width = String(Math.max(references.length, 9));
|
|
@@ -10127,7 +10217,7 @@ function validateBlock(context, block, path) {
|
|
|
10127
10217
|
);
|
|
10128
10218
|
});
|
|
10129
10219
|
});
|
|
10130
|
-
|
|
10220
|
+
validateInlineField(context, block.captionField, `${path}.caption`, block.id);
|
|
10131
10221
|
if (block.labelEnabled) {
|
|
10132
10222
|
registerKey(context, block.label, `${path}.label`, "tab", block.id);
|
|
10133
10223
|
}
|
|
@@ -10140,7 +10230,7 @@ function validateBlock(context, block, path) {
|
|
|
10140
10230
|
addIssue(context, "empty_image", path, block.id);
|
|
10141
10231
|
}
|
|
10142
10232
|
validateTextValue(context, block.value, `${path}.value`, block.id);
|
|
10143
|
-
|
|
10233
|
+
validateInlineField(context, block.captionField, `${path}.caption`, block.id);
|
|
10144
10234
|
if (block.labelEnabled) {
|
|
10145
10235
|
registerKey(context, block.label, `${path}.label`, "fig", block.id);
|
|
10146
10236
|
}
|
|
@@ -10465,6 +10555,15 @@ function floatNumberLabel(document2, key, previewOptions) {
|
|
|
10465
10555
|
digitForm: previewOptions.digitForm
|
|
10466
10556
|
});
|
|
10467
10557
|
}
|
|
10558
|
+
function captionPreview(block, islands, output, equationSide, document2, previewOptions) {
|
|
10559
|
+
if (!block.captionEnabled || block.caption.trim().length === 0) {
|
|
10560
|
+
return {};
|
|
10561
|
+
}
|
|
10562
|
+
return {
|
|
10563
|
+
caption: block.caption.trim(),
|
|
10564
|
+
captionInlines: previewInlines(block.captionField, islands, output, equationSide, document2, previewOptions)
|
|
10565
|
+
};
|
|
10566
|
+
}
|
|
10468
10567
|
function blockPreview(block, islands, output, equationSide, document2, previewOptions) {
|
|
10469
10568
|
if (block.kind === "textBlock") {
|
|
10470
10569
|
return textBlockPreview(block, islands, output, equationSide, document2, previewOptions);
|
|
@@ -10488,7 +10587,7 @@ function blockPreview(block, islands, output, equationSide, document2, previewOp
|
|
|
10488
10587
|
kind: "table",
|
|
10489
10588
|
id: block.id,
|
|
10490
10589
|
rows: block.rows.map((row) => row.map((cell) => previewInlines(cell, islands, output, equationSide, document2, previewOptions))),
|
|
10491
|
-
...block
|
|
10590
|
+
...captionPreview(block, islands, output, equationSide, document2, previewOptions),
|
|
10492
10591
|
...label.length > 0 ? { label, numberLabel: floatNumberLabel(document2, label, previewOptions) } : {},
|
|
10493
10592
|
...block.metadata ? { metadata: { ...block.metadata } } : {}
|
|
10494
10593
|
};
|
|
@@ -10502,7 +10601,7 @@ function blockPreview(block, islands, output, equationSide, document2, previewOp
|
|
|
10502
10601
|
...block.assetId !== void 0 ? { assetId: block.assetId } : {},
|
|
10503
10602
|
options: block.options,
|
|
10504
10603
|
centered: block.centered,
|
|
10505
|
-
...block
|
|
10604
|
+
...captionPreview(block, islands, output, equationSide, document2, previewOptions),
|
|
10506
10605
|
...label.length > 0 ? { label, numberLabel: floatNumberLabel(document2, label, previewOptions) } : {},
|
|
10507
10606
|
...block.metadata ? { metadata: { ...block.metadata } } : {}
|
|
10508
10607
|
};
|
|
@@ -12283,6 +12382,7 @@ function FloatMetaEditor({
|
|
|
12283
12382
|
centered,
|
|
12284
12383
|
captionEnabled,
|
|
12285
12384
|
caption,
|
|
12385
|
+
captionEditor,
|
|
12286
12386
|
labelEnabled,
|
|
12287
12387
|
label,
|
|
12288
12388
|
labelPlaceholder,
|
|
@@ -12326,9 +12426,9 @@ function FloatMetaEditor({
|
|
|
12326
12426
|
),
|
|
12327
12427
|
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { children: messages.captionToggle })
|
|
12328
12428
|
] }),
|
|
12329
|
-
captionEnabled ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("
|
|
12429
|
+
captionEnabled ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "butex-document2-widget__refs-field", children: [
|
|
12330
12430
|
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { children: messages.floatCaption }),
|
|
12331
|
-
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
12431
|
+
captionEditor ?? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
12332
12432
|
"input",
|
|
12333
12433
|
{
|
|
12334
12434
|
value: caption,
|
|
@@ -12736,9 +12836,12 @@ function BlockEditor({
|
|
|
12736
12836
|
onDeleteMath,
|
|
12737
12837
|
onOpenCite,
|
|
12738
12838
|
onDeleteCite,
|
|
12839
|
+
onOpenRef,
|
|
12840
|
+
onDeleteRef,
|
|
12739
12841
|
onFieldFocus,
|
|
12740
12842
|
onMathFocus,
|
|
12741
12843
|
onCiteFocus,
|
|
12844
|
+
onRefFocus,
|
|
12742
12845
|
onFieldBlur,
|
|
12743
12846
|
onImageSrcChange,
|
|
12744
12847
|
onImageAssetChange,
|
|
@@ -12747,6 +12850,8 @@ function BlockEditor({
|
|
|
12747
12850
|
onRequestImagePick,
|
|
12748
12851
|
listImageAssets,
|
|
12749
12852
|
renderImageBlockEditor,
|
|
12853
|
+
onFloatMetaChange,
|
|
12854
|
+
onParagraphCenteredChange,
|
|
12750
12855
|
onAddListItem,
|
|
12751
12856
|
onRemoveListItem,
|
|
12752
12857
|
onManageReferences
|
|
@@ -12771,6 +12876,7 @@ function BlockEditor({
|
|
|
12771
12876
|
{
|
|
12772
12877
|
captionEnabled: block.captionEnabled,
|
|
12773
12878
|
caption: block.caption,
|
|
12879
|
+
captionEditor: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(InlineField, { field: block.captionField, ...fieldProps }),
|
|
12774
12880
|
labelEnabled: block.labelEnabled,
|
|
12775
12881
|
label: block.label,
|
|
12776
12882
|
labelPlaceholder: messages.tableLabelPlaceholder,
|
|
@@ -12809,6 +12915,7 @@ function BlockEditor({
|
|
|
12809
12915
|
centered: block.centered,
|
|
12810
12916
|
captionEnabled: block.captionEnabled,
|
|
12811
12917
|
caption: block.caption,
|
|
12918
|
+
captionEditor: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(InlineField, { field: block.captionField, ...fieldProps }),
|
|
12812
12919
|
labelEnabled: block.labelEnabled,
|
|
12813
12920
|
label: block.label,
|
|
12814
12921
|
labelPlaceholder: messages.figureLabelPlaceholder,
|
|
@@ -13734,16 +13841,21 @@ function PreviewBlock({
|
|
|
13734
13841
|
const messages = document2Messages(uiLocale);
|
|
13735
13842
|
const floatCaptionSeparator = uiLocale === "ar" ? ": " : ". ";
|
|
13736
13843
|
const source = "metadata" in block ? block.metadata?.source : void 0;
|
|
13737
|
-
function FloatCaption({
|
|
13738
|
-
|
|
13844
|
+
function FloatCaption({
|
|
13845
|
+
numberLabel,
|
|
13846
|
+
caption,
|
|
13847
|
+
captionInlines
|
|
13848
|
+
}) {
|
|
13849
|
+
const hasCaption = Boolean(captionInlines?.length) || Boolean(caption);
|
|
13850
|
+
if (!numberLabel && !hasCaption) {
|
|
13739
13851
|
return null;
|
|
13740
13852
|
}
|
|
13741
13853
|
return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("figcaption", { dir: documentDirection, children: [
|
|
13742
13854
|
numberLabel ? /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("span", { className: "butex-document2-widget__preview-float-number", children: [
|
|
13743
13855
|
numberLabel,
|
|
13744
|
-
|
|
13856
|
+
hasCaption ? floatCaptionSeparator : ""
|
|
13745
13857
|
] }) : null,
|
|
13746
|
-
caption ?? ""
|
|
13858
|
+
captionInlines ? /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(PreviewInlines, { inlines: captionInlines, output }) : caption ?? ""
|
|
13747
13859
|
] });
|
|
13748
13860
|
}
|
|
13749
13861
|
if (block.kind === "basmala" || block.kind === "closing") {
|
|
@@ -13802,19 +13914,21 @@ function PreviewBlock({
|
|
|
13802
13914
|
if (block.kind === "table") {
|
|
13803
13915
|
return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("figure", { className: "butex-document2-widget__preview-float", "data-butex-block-source": source, children: [
|
|
13804
13916
|
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { className: "butex-document2-widget__preview-table-scroll", children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("table", { children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("tbody", { children: block.rows.map((row, rowIndex) => /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("tr", { children: row.map((cell, columnIndex) => /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("td", { children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(PreviewInlines, { inlines: cell, output }) }, columnIndex)) }, rowIndex)) }) }) }),
|
|
13805
|
-
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)(FloatCaption, { numberLabel: block.numberLabel, caption: block.caption })
|
|
13917
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)(FloatCaption, { numberLabel: block.numberLabel, caption: block.caption, captionInlines: block.captionInlines })
|
|
13806
13918
|
] });
|
|
13807
13919
|
}
|
|
13808
13920
|
if (block.kind === "image") {
|
|
13809
|
-
const
|
|
13921
|
+
const resolvedSrc = resolveImageUrl ? resolveImageUrl({ assetId: block.assetId, value: block.src }) : block.src;
|
|
13922
|
+
const src = resolvedSrc?.trim() ?? "";
|
|
13810
13923
|
return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(
|
|
13811
13924
|
"figure",
|
|
13812
13925
|
{
|
|
13813
13926
|
className: `butex-document2-widget__preview-float${block.centered === false ? " butex-document2-widget__preview-float--start" : ""}`,
|
|
13814
13927
|
"data-butex-block-source": source,
|
|
13928
|
+
"data-butex-image-pending": src.length === 0 ? "true" : void 0,
|
|
13815
13929
|
children: [
|
|
13816
|
-
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)("img", { src, alt: block.caption ?? "" }),
|
|
13817
|
-
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)(FloatCaption, { numberLabel: block.numberLabel, caption: block.caption })
|
|
13930
|
+
src.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("img", { src, alt: block.caption ?? "" }) : null,
|
|
13931
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)(FloatCaption, { numberLabel: block.numberLabel, caption: block.caption, captionInlines: block.captionInlines })
|
|
13818
13932
|
]
|
|
13819
13933
|
}
|
|
13820
13934
|
);
|
|
@@ -17881,7 +17995,7 @@ function LabelsPanel({
|
|
|
17881
17995
|
digitForm,
|
|
17882
17996
|
documentDirection
|
|
17883
17997
|
});
|
|
17884
|
-
const
|
|
17998
|
+
const captionPreview2 = entry.kind === "eq" ? title : formatFloatCaptionPreview(title, entry.caption, uiLocale);
|
|
17885
17999
|
const overrideKey = `${entry.kind}:${entry.ownerId}`;
|
|
17886
18000
|
const displayedKey = keyOverrides[overrideKey] ?? entry.key;
|
|
17887
18001
|
const entryKeyError = document2KeyError(displayedKey, {
|
|
@@ -17900,7 +18014,7 @@ function LabelsPanel({
|
|
|
17900
18014
|
className: "butex-document2-widget__modal-preview",
|
|
17901
18015
|
dir: uiLocaleDirection(uiLocale),
|
|
17902
18016
|
"aria-label": messages.captionPreview,
|
|
17903
|
-
children:
|
|
18017
|
+
children: captionPreview2
|
|
17904
18018
|
}
|
|
17905
18019
|
),
|
|
17906
18020
|
/* @__PURE__ */ (0, import_jsx_runtime16.jsxs)("div", { className: "butex-document2-widget__refs-grid", children: [
|
|
@@ -18362,6 +18476,9 @@ function findBlockIdForField(blocks, fieldId) {
|
|
|
18362
18476
|
if (block.kind === "textBlock" && block.field.id === fieldId) {
|
|
18363
18477
|
return block.id;
|
|
18364
18478
|
}
|
|
18479
|
+
if ((block.kind === "image" || block.kind === "table") && block.captionField.id === fieldId) {
|
|
18480
|
+
return block.id;
|
|
18481
|
+
}
|
|
18365
18482
|
if (block.kind === "list") {
|
|
18366
18483
|
for (const item of block.items) {
|
|
18367
18484
|
if (item.field.id === fieldId) {
|
|
@@ -20703,6 +20820,9 @@ function findInlineFieldById(document2, fieldId) {
|
|
|
20703
20820
|
if (block.kind === "textBlock" && block.field.id === fieldId) {
|
|
20704
20821
|
return block.field;
|
|
20705
20822
|
}
|
|
20823
|
+
if ((block.kind === "image" || block.kind === "table") && block.captionField.id === fieldId) {
|
|
20824
|
+
return block.captionField;
|
|
20825
|
+
}
|
|
20706
20826
|
if (block.kind === "list") {
|
|
20707
20827
|
for (const item of block.items) {
|
|
20708
20828
|
if (item.field.id === fieldId) {
|
|
@@ -20734,6 +20854,9 @@ function findInlineFieldContainingToken(document2, tokenId) {
|
|
|
20734
20854
|
if (block.kind === "textBlock" && block.field.tokens.some((token) => token.id === tokenId)) {
|
|
20735
20855
|
return block.field;
|
|
20736
20856
|
}
|
|
20857
|
+
if ((block.kind === "image" || block.kind === "table") && block.captionField.tokens.some((token) => token.id === tokenId)) {
|
|
20858
|
+
return block.captionField;
|
|
20859
|
+
}
|
|
20737
20860
|
if (block.kind === "list") {
|
|
20738
20861
|
for (const item of block.items) {
|
|
20739
20862
|
if (item.field.tokens.some((token) => token.id === tokenId)) {
|
|
@@ -20808,6 +20931,9 @@ function blockHasField(block, fieldId) {
|
|
|
20808
20931
|
if (block.kind === "textBlock") {
|
|
20809
20932
|
return block.field.id === fieldId;
|
|
20810
20933
|
}
|
|
20934
|
+
if ((block.kind === "image" || block.kind === "table") && block.captionField.id === fieldId) {
|
|
20935
|
+
return true;
|
|
20936
|
+
}
|
|
20811
20937
|
if (block.kind === "list") {
|
|
20812
20938
|
return block.items.some((item) => item.field.id === fieldId || item.blocks.some((child) => blockHasField(child, fieldId)));
|
|
20813
20939
|
}
|
|
@@ -20820,6 +20946,9 @@ function blockHasToken(block, tokenId) {
|
|
|
20820
20946
|
if (block.kind === "textBlock") {
|
|
20821
20947
|
return block.field.tokens.some((token) => token.id === tokenId);
|
|
20822
20948
|
}
|
|
20949
|
+
if ((block.kind === "image" || block.kind === "table") && block.captionField.tokens.some((token) => token.id === tokenId)) {
|
|
20950
|
+
return true;
|
|
20951
|
+
}
|
|
20823
20952
|
if (block.kind === "list") {
|
|
20824
20953
|
return block.items.some(
|
|
20825
20954
|
(item) => item.field.tokens.some((token) => token.id === tokenId) || item.blocks.some((child) => blockHasToken(child, tokenId))
|
|
@@ -20866,6 +20995,10 @@ function findFormatTextToken(document2, focus) {
|
|
|
20866
20995
|
}
|
|
20867
20996
|
}
|
|
20868
20997
|
} else if (block.kind === "table") {
|
|
20998
|
+
const captionToken = textTokenFromField(block.captionField);
|
|
20999
|
+
if (captionToken) {
|
|
21000
|
+
return captionToken;
|
|
21001
|
+
}
|
|
20869
21002
|
for (const row of block.rows) {
|
|
20870
21003
|
for (const cell of row) {
|
|
20871
21004
|
const token = textTokenFromField(cell);
|
|
@@ -20874,6 +21007,11 @@ function findFormatTextToken(document2, focus) {
|
|
|
20874
21007
|
}
|
|
20875
21008
|
}
|
|
20876
21009
|
}
|
|
21010
|
+
} else if (block.kind === "image") {
|
|
21011
|
+
const captionToken = textTokenFromField(block.captionField);
|
|
21012
|
+
if (captionToken) {
|
|
21013
|
+
return captionToken;
|
|
21014
|
+
}
|
|
20877
21015
|
}
|
|
20878
21016
|
}
|
|
20879
21017
|
return null;
|
|
@@ -22170,9 +22308,112 @@ var ButexDocumentEditor23 = (0, import_react18.forwardRef)(
|
|
|
22170
22308
|
}
|
|
22171
22309
|
);
|
|
22172
22310
|
ButexDocumentEditor23.displayName = "ButexDocumentEditor2";
|
|
22311
|
+
|
|
22312
|
+
// src/react-document2/ButexDocumentPreview.tsx
|
|
22313
|
+
var import_react19 = require("react");
|
|
22314
|
+
var import_jsx_runtime21 = require("react/jsx-runtime");
|
|
22315
|
+
function isRecord2(value) {
|
|
22316
|
+
return typeof value === "object" && value !== null;
|
|
22317
|
+
}
|
|
22318
|
+
function isDocument2Node2(value) {
|
|
22319
|
+
return isRecord2(value) && value.nodeType === "DocumentObject" && isRecord2(value.meta) && Array.isArray(value.references) && Array.isArray(value.blocks) && Array.isArray(value.diagnostics);
|
|
22320
|
+
}
|
|
22321
|
+
function hasRuntimeDocumentMarker(value) {
|
|
22322
|
+
return isRecord2(value) && value.nodeType === "DocumentObject";
|
|
22323
|
+
}
|
|
22324
|
+
function resolvePreviewDocument2(input, uiLocale = "ar") {
|
|
22325
|
+
if (isDocument2Node2(input)) {
|
|
22326
|
+
return { document: input, error: null };
|
|
22327
|
+
}
|
|
22328
|
+
const messages = document2Messages(uiLocale);
|
|
22329
|
+
if (hasRuntimeDocumentMarker(input)) {
|
|
22330
|
+
return {
|
|
22331
|
+
document: createEmptyDocument2(),
|
|
22332
|
+
error: `${messages.loadDocumentError}: ${messages.runtimePersistenceError}`
|
|
22333
|
+
};
|
|
22334
|
+
}
|
|
22335
|
+
try {
|
|
22336
|
+
return { document: fromDocumentJson2(input), error: null };
|
|
22337
|
+
} catch (error) {
|
|
22338
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
22339
|
+
return {
|
|
22340
|
+
document: createEmptyDocument2(),
|
|
22341
|
+
error: `${messages.loadDocumentError}: ${detail}`
|
|
22342
|
+
};
|
|
22343
|
+
}
|
|
22344
|
+
}
|
|
22345
|
+
function ButexDocumentPreview({
|
|
22346
|
+
document: document2,
|
|
22347
|
+
className,
|
|
22348
|
+
documentDirection = "rtl",
|
|
22349
|
+
uiLocale = "ar",
|
|
22350
|
+
digitForm,
|
|
22351
|
+
equationSide = "arabic",
|
|
22352
|
+
mathOutput = "svg",
|
|
22353
|
+
resolveImageUrl
|
|
22354
|
+
}) {
|
|
22355
|
+
const messages = document2Messages(uiLocale);
|
|
22356
|
+
const resolvedDigitForm = digitForm ?? (documentDirection === "rtl" ? "arabicIndic" : "western");
|
|
22357
|
+
const resolved = (0, import_react19.useMemo)(() => resolvePreviewDocument2(document2, uiLocale), [document2, uiLocale]);
|
|
22358
|
+
const previewState = (0, import_react19.useMemo)(() => {
|
|
22359
|
+
try {
|
|
22360
|
+
return {
|
|
22361
|
+
preview: document2Preview(resolved.document, mathOutput, equationSide, {
|
|
22362
|
+
documentDirection,
|
|
22363
|
+
digitForm: resolvedDigitForm,
|
|
22364
|
+
uiLocale
|
|
22365
|
+
}),
|
|
22366
|
+
error: resolved.error
|
|
22367
|
+
};
|
|
22368
|
+
} catch (error) {
|
|
22369
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
22370
|
+
return {
|
|
22371
|
+
preview: document2Preview(createEmptyDocument2(), mathOutput, equationSide, {
|
|
22372
|
+
documentDirection,
|
|
22373
|
+
digitForm: resolvedDigitForm,
|
|
22374
|
+
uiLocale
|
|
22375
|
+
}),
|
|
22376
|
+
error: `${messages.loadDocumentError}: ${detail}`
|
|
22377
|
+
};
|
|
22378
|
+
}
|
|
22379
|
+
}, [documentDirection, equationSide, mathOutput, messages.loadDocumentError, resolved, resolvedDigitForm, uiLocale]);
|
|
22380
|
+
(0, import_react19.useEffect)(() => {
|
|
22381
|
+
injectBuTeXDocument2Styles();
|
|
22382
|
+
}, []);
|
|
22383
|
+
return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
|
|
22384
|
+
"div",
|
|
22385
|
+
{
|
|
22386
|
+
className: ["butex-document2-widget", "butex-document2-preview", className].filter(Boolean).join(" "),
|
|
22387
|
+
dir: uiLocaleDirection(uiLocale),
|
|
22388
|
+
lang: uiLocale,
|
|
22389
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)("div", { className: "butex-document2-widget__shell", children: [
|
|
22390
|
+
previewState.error ? /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("p", { className: "butex-document2-widget__error", children: previewState.error }) : null,
|
|
22391
|
+
/* @__PURE__ */ (0, import_jsx_runtime21.jsx)("div", { className: "butex-document2-widget__layout butex-document2-widget__layout--editor-closed butex-document2-widget__layout--preview-open", children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
|
|
22392
|
+
"section",
|
|
22393
|
+
{
|
|
22394
|
+
className: "butex-document2-widget__panel butex-document2-widget__preview-panel",
|
|
22395
|
+
"aria-label": messages.documentPreview,
|
|
22396
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
|
|
22397
|
+
DocumentPreview,
|
|
22398
|
+
{
|
|
22399
|
+
blocks: previewState.preview.blocks,
|
|
22400
|
+
output: mathOutput,
|
|
22401
|
+
documentDirection,
|
|
22402
|
+
uiLocale,
|
|
22403
|
+
digitForm: resolvedDigitForm,
|
|
22404
|
+
resolveImageUrl
|
|
22405
|
+
}
|
|
22406
|
+
)
|
|
22407
|
+
}
|
|
22408
|
+
) })
|
|
22409
|
+
] })
|
|
22410
|
+
}
|
|
22411
|
+
);
|
|
22412
|
+
}
|
|
22173
22413
|
// Annotate the CommonJS export names for ESM import in node:
|
|
22174
22414
|
0 && (module.exports = {
|
|
22175
22415
|
ButexDocumentEditor2,
|
|
22416
|
+
ButexDocumentPreview,
|
|
22176
22417
|
DOCUMENT2_WIDGET_CSS,
|
|
22177
22418
|
DocumentInsertToolbar,
|
|
22178
22419
|
DocumentPreview,
|
|
@@ -22181,6 +22422,7 @@ ButexDocumentEditor23.displayName = "ButexDocumentEditor2";
|
|
|
22181
22422
|
MathChip,
|
|
22182
22423
|
MathIsland,
|
|
22183
22424
|
injectBuTeXDocument2Styles,
|
|
22184
|
-
resolveInitialDocument2
|
|
22425
|
+
resolveInitialDocument2,
|
|
22426
|
+
resolvePreviewDocument2
|
|
22185
22427
|
});
|
|
22186
22428
|
//# sourceMappingURL=react-document2.js.map
|