@drghaliasri/butex 6.1.4 → 6.1.5
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.map +1 -1
- package/dist/document2.d.mts +33 -2
- package/dist/document2.d.ts +33 -2
- package/dist/document2.js +321 -16
- package/dist/document2.js.map +1 -1
- package/dist/document2.mjs +312 -11
- package/dist/document2.mjs.map +1 -1
- package/dist/react-document2.d.mts +10 -2
- package/dist/react-document2.d.ts +10 -2
- package/dist/react-document2.js +414 -15
- package/dist/react-document2.js.map +1 -1
- package/dist/react-document2.mjs +414 -15
- package/dist/react-document2.mjs.map +1 -1
- package/package.json +1 -1
package/dist/react-document2.mjs
CHANGED
|
@@ -920,14 +920,22 @@ function labelNumberMap(document2) {
|
|
|
920
920
|
}
|
|
921
921
|
return map;
|
|
922
922
|
}
|
|
923
|
+
function labelKindWord(kind, uiLocale) {
|
|
924
|
+
if (kind === "fig") {
|
|
925
|
+
return uiLocale === "ar" ? "\u0627\u0644\u0634\u0643\u0644" : "Figure";
|
|
926
|
+
}
|
|
927
|
+
if (kind === "tab") {
|
|
928
|
+
return uiLocale === "ar" ? "\u0627\u0644\u062C\u062F\u0648\u0644" : "Table";
|
|
929
|
+
}
|
|
930
|
+
return uiLocale === "ar" ? "\u0627\u0644\u0645\u0639\u0627\u062F\u0644\u0629" : "Equation";
|
|
931
|
+
}
|
|
923
932
|
function formatFloatCaptionTitle(kind, number, options = {}) {
|
|
924
933
|
const locale = options.uiLocale ?? "ar";
|
|
925
|
-
const kindWord = kind === "fig" ? locale === "ar" ? "\u0627\u0644\u0634\u0643\u0644" : "Figure" : kind === "tab" ? locale === "ar" ? "\u0627\u0644\u062C\u062F\u0648\u0644" : "Table" : locale === "ar" ? "\u0627\u0644\u0645\u0639\u0627\u062F\u0644\u0629" : "Equation";
|
|
926
934
|
const digits = formatBibliographyNumber(number, {
|
|
927
935
|
documentDirection: options.documentDirection ?? (locale === "ar" ? "rtl" : "ltr"),
|
|
928
936
|
digitForm: options.digitForm ?? (locale === "ar" ? "arabicIndic" : "western")
|
|
929
937
|
});
|
|
930
|
-
return `${
|
|
938
|
+
return `${labelKindWord(kind, locale)} ${digits}`;
|
|
931
939
|
}
|
|
932
940
|
function formatFloatCaptionPreview(title, caption, uiLocale = "ar") {
|
|
933
941
|
const trimmed = caption?.trim() ?? "";
|
|
@@ -940,19 +948,18 @@ function formatFloatCaptionPreview(title, caption, uiLocale = "ar") {
|
|
|
940
948
|
function formatRefLabel(keys, document2, refCommand, options = {}) {
|
|
941
949
|
const documentDirection = options.documentDirection ?? "rtl";
|
|
942
950
|
const digitForm = options.digitForm ?? (documentDirection === "rtl" ? "arabicIndic" : "western");
|
|
951
|
+
const uiLocale = documentDirection === "rtl" ? "ar" : "en";
|
|
943
952
|
const map = labelNumberMap(document2);
|
|
944
953
|
const parts = keys.map((key) => {
|
|
945
954
|
const hit = map.get(key);
|
|
946
955
|
if (!hit) {
|
|
947
|
-
return "?";
|
|
956
|
+
return refCommand === "eqref" ? "(?)" : "?";
|
|
948
957
|
}
|
|
949
|
-
|
|
958
|
+
const digits = formatDigits(String(hit.number), digitForm);
|
|
959
|
+
const numberLabel = refCommand === "eqref" ? `(${digits})` : digits;
|
|
960
|
+
return `${labelKindWord(hit.kind, uiLocale)} ${numberLabel}`;
|
|
950
961
|
});
|
|
951
|
-
|
|
952
|
-
if (refCommand === "eqref") {
|
|
953
|
-
return `(${body})`;
|
|
954
|
-
}
|
|
955
|
-
return body;
|
|
962
|
+
return parts.join(documentDirection === "rtl" ? "\u060C" : ", ");
|
|
956
963
|
}
|
|
957
964
|
function stripDisplayMathDelimiters(source) {
|
|
958
965
|
const trimmed = source.trim();
|
|
@@ -9344,6 +9351,10 @@ var DOCUMENT2_KEY_PATTERN = /^[\p{L}\p{M}\p{Nd}:._-]+$/u;
|
|
|
9344
9351
|
function normalizeDocument2Key(key) {
|
|
9345
9352
|
return key.normalize("NFC").trim();
|
|
9346
9353
|
}
|
|
9354
|
+
function isValidDocument2Key(key) {
|
|
9355
|
+
const normalized = normalizeDocument2Key(key);
|
|
9356
|
+
return normalized.length > 0 && DOCUMENT2_KEY_PATTERN.test(normalized);
|
|
9357
|
+
}
|
|
9347
9358
|
function isDuplicateDocument2Key(key, namespace) {
|
|
9348
9359
|
const normalized = normalizeDocument2Key(key);
|
|
9349
9360
|
if (normalized.length === 0) {
|
|
@@ -9897,6 +9908,279 @@ ${body}
|
|
|
9897
9908
|
`;
|
|
9898
9909
|
}
|
|
9899
9910
|
|
|
9911
|
+
// src/document2/validation.ts
|
|
9912
|
+
var XELATEX_UNSUPPORTED_EMOJI_PATTERN = /[\p{Emoji_Presentation}\p{Emoji_Modifier}\p{Regional_Indicator}\uFE0F\u20E3]/u;
|
|
9913
|
+
function hasXeLatexUnsupportedEmoji(value) {
|
|
9914
|
+
return XELATEX_UNSUPPORTED_EMOJI_PATTERN.test(value);
|
|
9915
|
+
}
|
|
9916
|
+
function addIssue(context, code, path, blockId, tokenId) {
|
|
9917
|
+
context.issues.push({
|
|
9918
|
+
code,
|
|
9919
|
+
path,
|
|
9920
|
+
...blockId ? { blockId } : {},
|
|
9921
|
+
...tokenId ? { tokenId } : {}
|
|
9922
|
+
});
|
|
9923
|
+
}
|
|
9924
|
+
function validateTextValue(context, value, path, blockId, tokenId) {
|
|
9925
|
+
if (hasXeLatexUnsupportedEmoji(value)) {
|
|
9926
|
+
addIssue(context, "unsupported_emoji", path, blockId, tokenId);
|
|
9927
|
+
}
|
|
9928
|
+
}
|
|
9929
|
+
function registerKey(context, key, path, kind, blockId, tokenId) {
|
|
9930
|
+
const normalized = normalizeDocument2Key(key);
|
|
9931
|
+
if (normalized.length === 0) {
|
|
9932
|
+
addIssue(context, "key_empty", path, blockId, tokenId);
|
|
9933
|
+
return;
|
|
9934
|
+
}
|
|
9935
|
+
if (!isValidDocument2Key(normalized)) {
|
|
9936
|
+
addIssue(context, "key_invalid", path, blockId, tokenId);
|
|
9937
|
+
return;
|
|
9938
|
+
}
|
|
9939
|
+
context.keyOwners.push({
|
|
9940
|
+
key: normalized,
|
|
9941
|
+
path,
|
|
9942
|
+
kind,
|
|
9943
|
+
...blockId ? { blockId } : {},
|
|
9944
|
+
...tokenId ? { tokenId } : {}
|
|
9945
|
+
});
|
|
9946
|
+
if (kind !== "reference" && !context.labelKinds.has(normalized)) {
|
|
9947
|
+
context.labelKinds.set(normalized, kind);
|
|
9948
|
+
}
|
|
9949
|
+
}
|
|
9950
|
+
function validateToken(context, token, path, blockId) {
|
|
9951
|
+
if (token.kind === "text") {
|
|
9952
|
+
validateTextValue(context, token.text, `${path}.text`, blockId, token.id);
|
|
9953
|
+
return;
|
|
9954
|
+
}
|
|
9955
|
+
if (token.kind === "cite") {
|
|
9956
|
+
if (token.keys.length === 0) {
|
|
9957
|
+
addIssue(context, "empty_citation", `${path}.keys`, blockId, token.id);
|
|
9958
|
+
}
|
|
9959
|
+
context.pendingCitations.push({ token, path, blockId });
|
|
9960
|
+
return;
|
|
9961
|
+
}
|
|
9962
|
+
if (token.kind === "ref") {
|
|
9963
|
+
if (token.keys.length === 0) {
|
|
9964
|
+
addIssue(context, "empty_reference", `${path}.keys`, blockId, token.id);
|
|
9965
|
+
}
|
|
9966
|
+
context.pendingReferences.push({ token, path, blockId });
|
|
9967
|
+
return;
|
|
9968
|
+
}
|
|
9969
|
+
validateTextValue(context, token.source, `${path}.source`, blockId, token.id);
|
|
9970
|
+
if (!token.labelEnabled) {
|
|
9971
|
+
return;
|
|
9972
|
+
}
|
|
9973
|
+
if (!token.display) {
|
|
9974
|
+
addIssue(context, "invalid_equation_label", `${path}.label`, blockId, token.id);
|
|
9975
|
+
return;
|
|
9976
|
+
}
|
|
9977
|
+
registerKey(context, token.label ?? "", `${path}.label`, "eq", blockId, token.id);
|
|
9978
|
+
}
|
|
9979
|
+
function validateInlineField(context, field, path, blockId) {
|
|
9980
|
+
field.tokens.forEach((token, index) => {
|
|
9981
|
+
validateToken(context, token, `${path}.tokens[${String(index)}]`, blockId);
|
|
9982
|
+
});
|
|
9983
|
+
}
|
|
9984
|
+
function validateBlock(context, block, path) {
|
|
9985
|
+
if (block.kind === "textBlock") {
|
|
9986
|
+
validateInlineField(context, block.field, `${path}.field`, block.id);
|
|
9987
|
+
return;
|
|
9988
|
+
}
|
|
9989
|
+
if (block.kind === "list") {
|
|
9990
|
+
block.items.forEach((item, itemIndex) => {
|
|
9991
|
+
const itemPath = `${path}.items[${String(itemIndex)}]`;
|
|
9992
|
+
validateInlineField(context, item.field, `${itemPath}.field`, block.id);
|
|
9993
|
+
item.blocks.forEach((child, childIndex) => {
|
|
9994
|
+
validateBlock(context, child, `${itemPath}.blocks[${String(childIndex)}]`);
|
|
9995
|
+
});
|
|
9996
|
+
});
|
|
9997
|
+
return;
|
|
9998
|
+
}
|
|
9999
|
+
if (block.kind === "table") {
|
|
10000
|
+
if (block.columns.trim().length === 0 || block.rows.length === 0) {
|
|
10001
|
+
addIssue(context, "invalid_table", path, block.id);
|
|
10002
|
+
}
|
|
10003
|
+
const expectedColumns = block.rows[0]?.length ?? 0;
|
|
10004
|
+
if (expectedColumns === 0 || block.rows.some((row) => row.length !== expectedColumns)) {
|
|
10005
|
+
addIssue(context, "invalid_table", `${path}.rows`, block.id);
|
|
10006
|
+
}
|
|
10007
|
+
block.rows.forEach((row, rowIndex) => {
|
|
10008
|
+
row.forEach((cell, columnIndex) => {
|
|
10009
|
+
validateInlineField(
|
|
10010
|
+
context,
|
|
10011
|
+
cell,
|
|
10012
|
+
`${path}.rows[${String(rowIndex)}][${String(columnIndex)}]`,
|
|
10013
|
+
block.id
|
|
10014
|
+
);
|
|
10015
|
+
});
|
|
10016
|
+
});
|
|
10017
|
+
validateTextValue(context, block.caption, `${path}.caption`, block.id);
|
|
10018
|
+
if (block.labelEnabled) {
|
|
10019
|
+
registerKey(context, block.label, `${path}.label`, "tab", block.id);
|
|
10020
|
+
}
|
|
10021
|
+
return;
|
|
10022
|
+
}
|
|
10023
|
+
if (block.kind === "image") {
|
|
10024
|
+
const hasAssetId = typeof block.assetId === "string" && block.assetId.trim().length > 0;
|
|
10025
|
+
const hasValue = block.value.trim().length > 0;
|
|
10026
|
+
if (!hasAssetId && !hasValue) {
|
|
10027
|
+
addIssue(context, "empty_image", path, block.id);
|
|
10028
|
+
}
|
|
10029
|
+
validateTextValue(context, block.value, `${path}.value`, block.id);
|
|
10030
|
+
validateTextValue(context, block.caption, `${path}.caption`, block.id);
|
|
10031
|
+
if (block.labelEnabled) {
|
|
10032
|
+
registerKey(context, block.label, `${path}.label`, "fig", block.id);
|
|
10033
|
+
}
|
|
10034
|
+
return;
|
|
10035
|
+
}
|
|
10036
|
+
if (block.kind === "raw") {
|
|
10037
|
+
validateTextValue(context, block.value, `${path}.value`, block.id);
|
|
10038
|
+
}
|
|
10039
|
+
}
|
|
10040
|
+
function validateDuplicateKeys(context) {
|
|
10041
|
+
const grouped = /* @__PURE__ */ new Map();
|
|
10042
|
+
for (const owner of context.keyOwners) {
|
|
10043
|
+
const group = grouped.get(owner.key) ?? [];
|
|
10044
|
+
group.push(owner);
|
|
10045
|
+
grouped.set(owner.key, group);
|
|
10046
|
+
}
|
|
10047
|
+
for (const owners of grouped.values()) {
|
|
10048
|
+
if (owners.length < 2) {
|
|
10049
|
+
continue;
|
|
10050
|
+
}
|
|
10051
|
+
for (const owner of owners) {
|
|
10052
|
+
addIssue(context, "key_duplicate", owner.path, owner.blockId, owner.tokenId);
|
|
10053
|
+
}
|
|
10054
|
+
}
|
|
10055
|
+
}
|
|
10056
|
+
function validatePendingReferences(context) {
|
|
10057
|
+
for (const pending of context.pendingCitations) {
|
|
10058
|
+
if (pending.token.keys.some((key) => !isValidDocument2Key(normalizeDocument2Key(key)))) {
|
|
10059
|
+
addIssue(
|
|
10060
|
+
context,
|
|
10061
|
+
"missing_citation",
|
|
10062
|
+
`${pending.path}.keys`,
|
|
10063
|
+
pending.blockId,
|
|
10064
|
+
pending.token.id
|
|
10065
|
+
);
|
|
10066
|
+
}
|
|
10067
|
+
}
|
|
10068
|
+
for (const pending of context.pendingReferences) {
|
|
10069
|
+
for (const key of pending.token.keys) {
|
|
10070
|
+
const normalized = normalizeDocument2Key(key);
|
|
10071
|
+
if (!isValidDocument2Key(normalized)) {
|
|
10072
|
+
addIssue(
|
|
10073
|
+
context,
|
|
10074
|
+
"missing_reference",
|
|
10075
|
+
`${pending.path}.keys`,
|
|
10076
|
+
pending.blockId,
|
|
10077
|
+
pending.token.id
|
|
10078
|
+
);
|
|
10079
|
+
break;
|
|
10080
|
+
}
|
|
10081
|
+
const kind = context.labelKinds.get(normalized);
|
|
10082
|
+
if (kind && pending.token.refCommand === "eqref" !== (kind === "eq")) {
|
|
10083
|
+
addIssue(
|
|
10084
|
+
context,
|
|
10085
|
+
"reference_kind_mismatch",
|
|
10086
|
+
`${pending.path}.keys`,
|
|
10087
|
+
pending.blockId,
|
|
10088
|
+
pending.token.id
|
|
10089
|
+
);
|
|
10090
|
+
break;
|
|
10091
|
+
}
|
|
10092
|
+
}
|
|
10093
|
+
}
|
|
10094
|
+
}
|
|
10095
|
+
function isRecord(value) {
|
|
10096
|
+
return typeof value === "object" && value !== null;
|
|
10097
|
+
}
|
|
10098
|
+
function hasRuntimeDocumentShape(document2) {
|
|
10099
|
+
const value = document2;
|
|
10100
|
+
return isRecord(value) && value.nodeType === "DocumentObject";
|
|
10101
|
+
}
|
|
10102
|
+
function hasWireDocumentShape(document2) {
|
|
10103
|
+
const value = document2;
|
|
10104
|
+
if (!isRecord(value) || value.node_type !== "DocumentObject" || !Array.isArray(value.blocks)) {
|
|
10105
|
+
return false;
|
|
10106
|
+
}
|
|
10107
|
+
if (value.meta !== void 0 && !isRecord(value.meta)) {
|
|
10108
|
+
return false;
|
|
10109
|
+
}
|
|
10110
|
+
if (value.references !== void 0) {
|
|
10111
|
+
if (!Array.isArray(value.references)) {
|
|
10112
|
+
return false;
|
|
10113
|
+
}
|
|
10114
|
+
for (const reference of value.references) {
|
|
10115
|
+
if (!isRecord(reference) || typeof reference.key !== "string" || reference.key.trim().length === 0) {
|
|
10116
|
+
return false;
|
|
10117
|
+
}
|
|
10118
|
+
}
|
|
10119
|
+
}
|
|
10120
|
+
return true;
|
|
10121
|
+
}
|
|
10122
|
+
function resolveDocument(document2) {
|
|
10123
|
+
if (hasRuntimeDocumentShape(document2)) {
|
|
10124
|
+
try {
|
|
10125
|
+
toDocumentJson2(document2);
|
|
10126
|
+
return document2;
|
|
10127
|
+
} catch {
|
|
10128
|
+
return null;
|
|
10129
|
+
}
|
|
10130
|
+
}
|
|
10131
|
+
if (!hasWireDocumentShape(document2)) {
|
|
10132
|
+
return null;
|
|
10133
|
+
}
|
|
10134
|
+
try {
|
|
10135
|
+
return fromDocumentJson2(document2);
|
|
10136
|
+
} catch {
|
|
10137
|
+
return null;
|
|
10138
|
+
}
|
|
10139
|
+
}
|
|
10140
|
+
function validateDocument2(document2) {
|
|
10141
|
+
const resolved = resolveDocument(document2);
|
|
10142
|
+
if (!resolved) {
|
|
10143
|
+
return {
|
|
10144
|
+
valid: false,
|
|
10145
|
+
issues: [{ code: "malformed_document", path: "$" }]
|
|
10146
|
+
};
|
|
10147
|
+
}
|
|
10148
|
+
const context = {
|
|
10149
|
+
issues: [],
|
|
10150
|
+
keyOwners: [],
|
|
10151
|
+
labelKinds: /* @__PURE__ */ new Map(),
|
|
10152
|
+
pendingCitations: [],
|
|
10153
|
+
pendingReferences: []
|
|
10154
|
+
};
|
|
10155
|
+
validateTextValue(context, resolved.meta.title, "$.meta.title");
|
|
10156
|
+
validateTextValue(context, resolved.meta.authors, "$.meta.authors");
|
|
10157
|
+
validateTextValue(context, resolved.meta.abstract, "$.meta.abstract");
|
|
10158
|
+
resolved.references.forEach((reference, index) => {
|
|
10159
|
+
const path = `$.references[${String(index)}]`;
|
|
10160
|
+
registerKey(context, reference.key, `${path}.key`, "reference");
|
|
10161
|
+
validateTextValue(context, reference.authors, `${path}.authors`);
|
|
10162
|
+
validateTextValue(context, reference.title, `${path}.title`);
|
|
10163
|
+
validateTextValue(context, reference.year, `${path}.year`);
|
|
10164
|
+
validateTextValue(context, reference.url, `${path}.url`);
|
|
10165
|
+
validateTextValue(context, reference.venue, `${path}.venue`);
|
|
10166
|
+
});
|
|
10167
|
+
resolved.blocks.forEach((block, index) => {
|
|
10168
|
+
validateBlock(context, block, `$.blocks[${String(index)}]`);
|
|
10169
|
+
});
|
|
10170
|
+
for (const diagnostic of resolved.diagnostics) {
|
|
10171
|
+
addIssue(context, "parser_diagnostic", diagnostic.path);
|
|
10172
|
+
}
|
|
10173
|
+
validateDuplicateKeys(context);
|
|
10174
|
+
validatePendingReferences(context);
|
|
10175
|
+
return {
|
|
10176
|
+
valid: context.issues.length === 0,
|
|
10177
|
+
issues: context.issues
|
|
10178
|
+
};
|
|
10179
|
+
}
|
|
10180
|
+
function isDocument2Valid(document2) {
|
|
10181
|
+
return validateDocument2(document2).valid;
|
|
10182
|
+
}
|
|
10183
|
+
|
|
9900
10184
|
// src/document2/history.ts
|
|
9901
10185
|
var DEFAULT_DOCUMENT2_HISTORY_MAX_DEPTH = 100;
|
|
9902
10186
|
function createDocument2History(maxDepth = DEFAULT_DOCUMENT2_HISTORY_MAX_DEPTH) {
|
|
@@ -10486,10 +10770,6 @@ function document2Messages(locale) {
|
|
|
10486
10770
|
}
|
|
10487
10771
|
|
|
10488
10772
|
// src/react-document2/xelatexTextValidation.ts
|
|
10489
|
-
var XELATEX_UNSUPPORTED_EMOJI_PATTERN = /[\p{Emoji_Presentation}\p{Emoji_Modifier}\p{Regional_Indicator}\uFE0F\u20E3]/u;
|
|
10490
|
-
function hasXeLatexUnsupportedEmoji(value) {
|
|
10491
|
-
return XELATEX_UNSUPPORTED_EMOJI_PATTERN.test(value);
|
|
10492
|
-
}
|
|
10493
10773
|
function unsupportedEmojiMessage(uiLocale) {
|
|
10494
10774
|
return uiLocale === "ar" ? "\u0647\u0630\u0627 \u0627\u0644\u0631\u0645\u0632 \u0627\u0644\u062A\u0639\u0628\u064A\u0631\u064A \u063A\u064A\u0631 \u0645\u062F\u0639\u0648\u0645." : "This emoji is not supported.";
|
|
10495
10775
|
}
|
|
@@ -10730,6 +11010,9 @@ function focusArticleMetaPanel(panel) {
|
|
|
10730
11010
|
}
|
|
10731
11011
|
}
|
|
10732
11012
|
|
|
11013
|
+
// src/react-document2/ValidatedButexDocumentEditor2.tsx
|
|
11014
|
+
import { forwardRef as forwardRef3, useCallback as useCallback3, useRef as useRef9 } from "react";
|
|
11015
|
+
|
|
10733
11016
|
// src/react-document2/ButexDocumentEditor2.tsx
|
|
10734
11017
|
import { forwardRef as forwardRef2, useCallback as useCallback2, useEffect as useEffect10, useImperativeHandle as useImperativeHandle2, useMemo as useMemo2, useRef as useRef8, useState as useState12 } from "react";
|
|
10735
11018
|
|
|
@@ -12863,6 +13146,28 @@ function DocumentInsertToolbar({
|
|
|
12863
13146
|
|
|
12864
13147
|
// src/react-document2/DocumentPreview.tsx
|
|
12865
13148
|
import { Fragment as Fragment3, jsx as jsx11, jsxs as jsxs10 } from "react/jsx-runtime";
|
|
13149
|
+
var REF_KIND_NAMES = [
|
|
13150
|
+
{ names: ["\u0627\u0644\u0634\u0643\u0644", "\u0634\u0643\u0644", "Figure", "figure"], prefixes: ["\u0627\u0644\u0634\u0643\u0644 ", "Figure "] },
|
|
13151
|
+
{ names: ["\u0627\u0644\u062C\u062F\u0648\u0644", "\u062C\u062F\u0648\u0644", "Table", "table"], prefixes: ["\u0627\u0644\u062C\u062F\u0648\u0644 ", "Table "] },
|
|
13152
|
+
{ names: ["\u0627\u0644\u0645\u0639\u0627\u062F\u0644\u0629", "\u0645\u0639\u0627\u062F\u0644\u0629", "Equation", "equation"], prefixes: ["\u0627\u0644\u0645\u0639\u0627\u062F\u0644\u0629 ", "Equation "] }
|
|
13153
|
+
];
|
|
13154
|
+
function contextualRefLabel(inlines, index, label) {
|
|
13155
|
+
const previous = inlines[index - 1];
|
|
13156
|
+
if (previous?.kind !== "text") {
|
|
13157
|
+
return label;
|
|
13158
|
+
}
|
|
13159
|
+
const previousText = previous.text.trimEnd();
|
|
13160
|
+
for (const group of REF_KIND_NAMES) {
|
|
13161
|
+
if (!group.names.some((name) => previousText.endsWith(name))) {
|
|
13162
|
+
continue;
|
|
13163
|
+
}
|
|
13164
|
+
const prefix = group.prefixes.find((candidate) => label.startsWith(candidate));
|
|
13165
|
+
if (prefix) {
|
|
13166
|
+
return label.slice(prefix.length);
|
|
13167
|
+
}
|
|
13168
|
+
}
|
|
13169
|
+
return label;
|
|
13170
|
+
}
|
|
12866
13171
|
function PreviewInlines({ inlines, output }) {
|
|
12867
13172
|
return /* @__PURE__ */ jsx11(Fragment3, { children: inlines.map((inline, index) => {
|
|
12868
13173
|
if (inline.kind === "text") {
|
|
@@ -12882,7 +13187,7 @@ function PreviewInlines({ inlines, output }) {
|
|
|
12882
13187
|
return /* @__PURE__ */ jsx11("span", { className: "butex-document2-widget__preview-cite", children: inline.label }, inline.id);
|
|
12883
13188
|
}
|
|
12884
13189
|
if (inline.kind === "ref") {
|
|
12885
|
-
return /* @__PURE__ */ jsx11("span", { className: "butex-document2-widget__preview-cite butex-document2-widget__preview-ref", children: inline.label }, inline.id);
|
|
13190
|
+
return /* @__PURE__ */ jsx11("span", { className: "butex-document2-widget__preview-cite butex-document2-widget__preview-ref", children: contextualRefLabel(inlines, index, inline.label) }, inline.id);
|
|
12886
13191
|
}
|
|
12887
13192
|
return /* @__PURE__ */ jsx11(MathIsland, { id: inline.id, tex: inline.tex, display: inline.display, output }, inline.id);
|
|
12888
13193
|
}) });
|
|
@@ -19211,8 +19516,102 @@ var ButexDocumentEditor2 = forwardRef2(
|
|
|
19211
19516
|
}
|
|
19212
19517
|
);
|
|
19213
19518
|
ButexDocumentEditor2.displayName = "ButexDocumentEditor2";
|
|
19519
|
+
|
|
19520
|
+
// src/react-document2/ValidatedButexDocumentEditor2.tsx
|
|
19521
|
+
import { jsx as jsx18, jsxs as jsxs17 } from "react/jsx-runtime";
|
|
19522
|
+
function imageValidationMessage(uiLocale) {
|
|
19523
|
+
return uiLocale === "ar" ? "\u0644\u0645 \u062A\u064F\u062D\u062F\u0651\u062F \u0635\u0648\u0631\u0629 \u0644\u0647\u0630\u0647 \u0627\u0644\u0643\u062A\u0644\u0629." : "No image has been selected for this block.";
|
|
19524
|
+
}
|
|
19525
|
+
function imageHasIdentity(ctx) {
|
|
19526
|
+
return Boolean(ctx.assetId?.trim()) || ctx.value.trim().length > 0;
|
|
19527
|
+
}
|
|
19528
|
+
function isMalformedInitialDocument(initialDocument) {
|
|
19529
|
+
if (initialDocument === void 0) {
|
|
19530
|
+
return false;
|
|
19531
|
+
}
|
|
19532
|
+
return validateDocument2(initialDocument).issues.some((issue) => issue.code === "malformed_document");
|
|
19533
|
+
}
|
|
19534
|
+
var ButexDocumentEditor23 = forwardRef3(
|
|
19535
|
+
function ValidatedButexDocumentEditor2({
|
|
19536
|
+
initialDocument,
|
|
19537
|
+
uiLocale = "ar",
|
|
19538
|
+
onDocumentChange,
|
|
19539
|
+
onValidityChange,
|
|
19540
|
+
renderImageBlockEditor,
|
|
19541
|
+
...rest
|
|
19542
|
+
}, ref) {
|
|
19543
|
+
const lastValidityRef = useRef9(null);
|
|
19544
|
+
const initialDocumentRef = useRef9(initialDocument);
|
|
19545
|
+
const awaitingInitialResolutionRef = useRef9(true);
|
|
19546
|
+
const malformedInitialDocument = isMalformedInitialDocument(initialDocument);
|
|
19547
|
+
if (initialDocumentRef.current !== initialDocument) {
|
|
19548
|
+
initialDocumentRef.current = initialDocument;
|
|
19549
|
+
awaitingInitialResolutionRef.current = true;
|
|
19550
|
+
lastValidityRef.current = null;
|
|
19551
|
+
}
|
|
19552
|
+
const emitValidity = useCallback3(
|
|
19553
|
+
(isValid) => {
|
|
19554
|
+
if (lastValidityRef.current === isValid) {
|
|
19555
|
+
return;
|
|
19556
|
+
}
|
|
19557
|
+
lastValidityRef.current = isValid;
|
|
19558
|
+
onValidityChange?.(isValid);
|
|
19559
|
+
},
|
|
19560
|
+
[onValidityChange]
|
|
19561
|
+
);
|
|
19562
|
+
const handleDocumentChange = useCallback3(
|
|
19563
|
+
(document2) => {
|
|
19564
|
+
const validationTarget = initialDocument !== void 0 && (malformedInitialDocument || awaitingInitialResolutionRef.current) ? initialDocument : document2;
|
|
19565
|
+
awaitingInitialResolutionRef.current = false;
|
|
19566
|
+
emitValidity(isDocument2Valid(validationTarget));
|
|
19567
|
+
onDocumentChange?.(document2);
|
|
19568
|
+
},
|
|
19569
|
+
[emitValidity, initialDocument, malformedInitialDocument, onDocumentChange]
|
|
19570
|
+
);
|
|
19571
|
+
const handleImageBlockEditor = useCallback3(
|
|
19572
|
+
(ctx) => {
|
|
19573
|
+
const rendered = renderImageBlockEditor?.(ctx) ?? ctx.defaultUi;
|
|
19574
|
+
if (imageHasIdentity(ctx)) {
|
|
19575
|
+
return rendered;
|
|
19576
|
+
}
|
|
19577
|
+
const errorId = `butex-document2-image-validation-${ctx.blockId}`;
|
|
19578
|
+
return /* @__PURE__ */ jsxs17(
|
|
19579
|
+
"div",
|
|
19580
|
+
{
|
|
19581
|
+
role: "group",
|
|
19582
|
+
"aria-invalid": "true",
|
|
19583
|
+
"aria-describedby": errorId,
|
|
19584
|
+
style: {
|
|
19585
|
+
border: "1px solid var(--butex-document2-error)",
|
|
19586
|
+
background: "var(--butex-document2-error-bg)",
|
|
19587
|
+
borderRadius: "0.65rem",
|
|
19588
|
+
padding: "0.6rem"
|
|
19589
|
+
},
|
|
19590
|
+
children: [
|
|
19591
|
+
rendered,
|
|
19592
|
+
/* @__PURE__ */ jsx18("p", { id: errorId, className: "butex-document2-widget__field-error", children: imageValidationMessage(ctx.uiLocale) })
|
|
19593
|
+
]
|
|
19594
|
+
}
|
|
19595
|
+
);
|
|
19596
|
+
},
|
|
19597
|
+
[renderImageBlockEditor]
|
|
19598
|
+
);
|
|
19599
|
+
return /* @__PURE__ */ jsx18(
|
|
19600
|
+
ButexDocumentEditor2,
|
|
19601
|
+
{
|
|
19602
|
+
ref,
|
|
19603
|
+
...rest,
|
|
19604
|
+
initialDocument,
|
|
19605
|
+
uiLocale,
|
|
19606
|
+
onDocumentChange: handleDocumentChange,
|
|
19607
|
+
renderImageBlockEditor: handleImageBlockEditor
|
|
19608
|
+
}
|
|
19609
|
+
);
|
|
19610
|
+
}
|
|
19611
|
+
);
|
|
19612
|
+
ButexDocumentEditor23.displayName = "ButexDocumentEditor2";
|
|
19214
19613
|
export {
|
|
19215
|
-
ButexDocumentEditor2,
|
|
19614
|
+
ButexDocumentEditor23 as ButexDocumentEditor2,
|
|
19216
19615
|
DOCUMENT2_WIDGET_CSS,
|
|
19217
19616
|
DocumentInsertToolbar,
|
|
19218
19617
|
DocumentPreview,
|