@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
|
@@ -506,7 +506,7 @@ type ImageBlockEditorRenderContext = {
|
|
|
506
506
|
defaultUi: ReactNode;
|
|
507
507
|
};
|
|
508
508
|
|
|
509
|
-
type ButexDocumentEditor2Props = {
|
|
509
|
+
type ButexDocumentEditor2Props$1 = {
|
|
510
510
|
initialDocument?: Document2Json | Document2Node;
|
|
511
511
|
/** Seed article metadata when JSON/node omits fields (JSON wins when present). */
|
|
512
512
|
documentMeta?: Document2MetaProp;
|
|
@@ -555,7 +555,15 @@ type ButexDocumentEditor2Ref = {
|
|
|
555
555
|
};
|
|
556
556
|
|
|
557
557
|
declare function resolveInitialDocument2(initialDocument: Document2Json | Document2Node | undefined, uiLocale?: ButexUiLocale, documentMeta?: Document2MetaProp): Document2InitialState;
|
|
558
|
-
|
|
558
|
+
|
|
559
|
+
type ButexDocumentEditor2Props = ButexDocumentEditor2Props$1 & {
|
|
560
|
+
/** Reports whether the current draft is safe for LaTeX compilation. */
|
|
561
|
+
onValidityChange?: (isValid: boolean) => void;
|
|
562
|
+
};
|
|
563
|
+
declare const ButexDocumentEditor2: react.ForwardRefExoticComponent<ButexDocumentEditor2Props$1 & {
|
|
564
|
+
/** Reports whether the current draft is safe for LaTeX compilation. */
|
|
565
|
+
onValidityChange?: (isValid: boolean) => void;
|
|
566
|
+
} & react.RefAttributes<ButexDocumentEditor2Ref>>;
|
|
559
567
|
|
|
560
568
|
type DocumentInsertToolbarProps = {
|
|
561
569
|
canUndo: boolean;
|
|
@@ -506,7 +506,7 @@ type ImageBlockEditorRenderContext = {
|
|
|
506
506
|
defaultUi: ReactNode;
|
|
507
507
|
};
|
|
508
508
|
|
|
509
|
-
type ButexDocumentEditor2Props = {
|
|
509
|
+
type ButexDocumentEditor2Props$1 = {
|
|
510
510
|
initialDocument?: Document2Json | Document2Node;
|
|
511
511
|
/** Seed article metadata when JSON/node omits fields (JSON wins when present). */
|
|
512
512
|
documentMeta?: Document2MetaProp;
|
|
@@ -555,7 +555,15 @@ type ButexDocumentEditor2Ref = {
|
|
|
555
555
|
};
|
|
556
556
|
|
|
557
557
|
declare function resolveInitialDocument2(initialDocument: Document2Json | Document2Node | undefined, uiLocale?: ButexUiLocale, documentMeta?: Document2MetaProp): Document2InitialState;
|
|
558
|
-
|
|
558
|
+
|
|
559
|
+
type ButexDocumentEditor2Props = ButexDocumentEditor2Props$1 & {
|
|
560
|
+
/** Reports whether the current draft is safe for LaTeX compilation. */
|
|
561
|
+
onValidityChange?: (isValid: boolean) => void;
|
|
562
|
+
};
|
|
563
|
+
declare const ButexDocumentEditor2: react.ForwardRefExoticComponent<ButexDocumentEditor2Props$1 & {
|
|
564
|
+
/** Reports whether the current draft is safe for LaTeX compilation. */
|
|
565
|
+
onValidityChange?: (isValid: boolean) => void;
|
|
566
|
+
} & react.RefAttributes<ButexDocumentEditor2Ref>>;
|
|
559
567
|
|
|
560
568
|
type DocumentInsertToolbarProps = {
|
|
561
569
|
canUndo: boolean;
|
package/dist/react-document2.js
CHANGED
|
@@ -20,7 +20,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/react-document2-entry.ts
|
|
21
21
|
var react_document2_entry_exports = {};
|
|
22
22
|
__export(react_document2_entry_exports, {
|
|
23
|
-
ButexDocumentEditor2: () =>
|
|
23
|
+
ButexDocumentEditor2: () => ButexDocumentEditor23,
|
|
24
24
|
DOCUMENT2_WIDGET_CSS: () => DOCUMENT2_WIDGET_CSS,
|
|
25
25
|
DocumentInsertToolbar: () => DocumentInsertToolbar,
|
|
26
26
|
DocumentPreview: () => DocumentPreview,
|
|
@@ -955,14 +955,22 @@ function labelNumberMap(document2) {
|
|
|
955
955
|
}
|
|
956
956
|
return map;
|
|
957
957
|
}
|
|
958
|
+
function labelKindWord(kind, uiLocale) {
|
|
959
|
+
if (kind === "fig") {
|
|
960
|
+
return uiLocale === "ar" ? "\u0627\u0644\u0634\u0643\u0644" : "Figure";
|
|
961
|
+
}
|
|
962
|
+
if (kind === "tab") {
|
|
963
|
+
return uiLocale === "ar" ? "\u0627\u0644\u062C\u062F\u0648\u0644" : "Table";
|
|
964
|
+
}
|
|
965
|
+
return uiLocale === "ar" ? "\u0627\u0644\u0645\u0639\u0627\u062F\u0644\u0629" : "Equation";
|
|
966
|
+
}
|
|
958
967
|
function formatFloatCaptionTitle(kind, number, options = {}) {
|
|
959
968
|
const locale = options.uiLocale ?? "ar";
|
|
960
|
-
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";
|
|
961
969
|
const digits = formatBibliographyNumber(number, {
|
|
962
970
|
documentDirection: options.documentDirection ?? (locale === "ar" ? "rtl" : "ltr"),
|
|
963
971
|
digitForm: options.digitForm ?? (locale === "ar" ? "arabicIndic" : "western")
|
|
964
972
|
});
|
|
965
|
-
return `${
|
|
973
|
+
return `${labelKindWord(kind, locale)} ${digits}`;
|
|
966
974
|
}
|
|
967
975
|
function formatFloatCaptionPreview(title, caption, uiLocale = "ar") {
|
|
968
976
|
const trimmed = caption?.trim() ?? "";
|
|
@@ -975,19 +983,18 @@ function formatFloatCaptionPreview(title, caption, uiLocale = "ar") {
|
|
|
975
983
|
function formatRefLabel(keys, document2, refCommand, options = {}) {
|
|
976
984
|
const documentDirection = options.documentDirection ?? "rtl";
|
|
977
985
|
const digitForm = options.digitForm ?? (documentDirection === "rtl" ? "arabicIndic" : "western");
|
|
986
|
+
const uiLocale = documentDirection === "rtl" ? "ar" : "en";
|
|
978
987
|
const map = labelNumberMap(document2);
|
|
979
988
|
const parts = keys.map((key) => {
|
|
980
989
|
const hit = map.get(key);
|
|
981
990
|
if (!hit) {
|
|
982
|
-
return "?";
|
|
991
|
+
return refCommand === "eqref" ? "(?)" : "?";
|
|
983
992
|
}
|
|
984
|
-
|
|
993
|
+
const digits = formatDigits(String(hit.number), digitForm);
|
|
994
|
+
const numberLabel = refCommand === "eqref" ? `(${digits})` : digits;
|
|
995
|
+
return `${labelKindWord(hit.kind, uiLocale)} ${numberLabel}`;
|
|
985
996
|
});
|
|
986
|
-
|
|
987
|
-
if (refCommand === "eqref") {
|
|
988
|
-
return `(${body})`;
|
|
989
|
-
}
|
|
990
|
-
return body;
|
|
997
|
+
return parts.join(documentDirection === "rtl" ? "\u060C" : ", ");
|
|
991
998
|
}
|
|
992
999
|
function stripDisplayMathDelimiters(source) {
|
|
993
1000
|
const trimmed = source.trim();
|
|
@@ -9379,6 +9386,10 @@ var DOCUMENT2_KEY_PATTERN = /^[\p{L}\p{M}\p{Nd}:._-]+$/u;
|
|
|
9379
9386
|
function normalizeDocument2Key(key) {
|
|
9380
9387
|
return key.normalize("NFC").trim();
|
|
9381
9388
|
}
|
|
9389
|
+
function isValidDocument2Key(key) {
|
|
9390
|
+
const normalized = normalizeDocument2Key(key);
|
|
9391
|
+
return normalized.length > 0 && DOCUMENT2_KEY_PATTERN.test(normalized);
|
|
9392
|
+
}
|
|
9382
9393
|
function isDuplicateDocument2Key(key, namespace) {
|
|
9383
9394
|
const normalized = normalizeDocument2Key(key);
|
|
9384
9395
|
if (normalized.length === 0) {
|
|
@@ -9932,6 +9943,279 @@ ${body}
|
|
|
9932
9943
|
`;
|
|
9933
9944
|
}
|
|
9934
9945
|
|
|
9946
|
+
// src/document2/validation.ts
|
|
9947
|
+
var XELATEX_UNSUPPORTED_EMOJI_PATTERN = /[\p{Emoji_Presentation}\p{Emoji_Modifier}\p{Regional_Indicator}\uFE0F\u20E3]/u;
|
|
9948
|
+
function hasXeLatexUnsupportedEmoji(value) {
|
|
9949
|
+
return XELATEX_UNSUPPORTED_EMOJI_PATTERN.test(value);
|
|
9950
|
+
}
|
|
9951
|
+
function addIssue(context, code, path, blockId, tokenId) {
|
|
9952
|
+
context.issues.push({
|
|
9953
|
+
code,
|
|
9954
|
+
path,
|
|
9955
|
+
...blockId ? { blockId } : {},
|
|
9956
|
+
...tokenId ? { tokenId } : {}
|
|
9957
|
+
});
|
|
9958
|
+
}
|
|
9959
|
+
function validateTextValue(context, value, path, blockId, tokenId) {
|
|
9960
|
+
if (hasXeLatexUnsupportedEmoji(value)) {
|
|
9961
|
+
addIssue(context, "unsupported_emoji", path, blockId, tokenId);
|
|
9962
|
+
}
|
|
9963
|
+
}
|
|
9964
|
+
function registerKey(context, key, path, kind, blockId, tokenId) {
|
|
9965
|
+
const normalized = normalizeDocument2Key(key);
|
|
9966
|
+
if (normalized.length === 0) {
|
|
9967
|
+
addIssue(context, "key_empty", path, blockId, tokenId);
|
|
9968
|
+
return;
|
|
9969
|
+
}
|
|
9970
|
+
if (!isValidDocument2Key(normalized)) {
|
|
9971
|
+
addIssue(context, "key_invalid", path, blockId, tokenId);
|
|
9972
|
+
return;
|
|
9973
|
+
}
|
|
9974
|
+
context.keyOwners.push({
|
|
9975
|
+
key: normalized,
|
|
9976
|
+
path,
|
|
9977
|
+
kind,
|
|
9978
|
+
...blockId ? { blockId } : {},
|
|
9979
|
+
...tokenId ? { tokenId } : {}
|
|
9980
|
+
});
|
|
9981
|
+
if (kind !== "reference" && !context.labelKinds.has(normalized)) {
|
|
9982
|
+
context.labelKinds.set(normalized, kind);
|
|
9983
|
+
}
|
|
9984
|
+
}
|
|
9985
|
+
function validateToken(context, token, path, blockId) {
|
|
9986
|
+
if (token.kind === "text") {
|
|
9987
|
+
validateTextValue(context, token.text, `${path}.text`, blockId, token.id);
|
|
9988
|
+
return;
|
|
9989
|
+
}
|
|
9990
|
+
if (token.kind === "cite") {
|
|
9991
|
+
if (token.keys.length === 0) {
|
|
9992
|
+
addIssue(context, "empty_citation", `${path}.keys`, blockId, token.id);
|
|
9993
|
+
}
|
|
9994
|
+
context.pendingCitations.push({ token, path, blockId });
|
|
9995
|
+
return;
|
|
9996
|
+
}
|
|
9997
|
+
if (token.kind === "ref") {
|
|
9998
|
+
if (token.keys.length === 0) {
|
|
9999
|
+
addIssue(context, "empty_reference", `${path}.keys`, blockId, token.id);
|
|
10000
|
+
}
|
|
10001
|
+
context.pendingReferences.push({ token, path, blockId });
|
|
10002
|
+
return;
|
|
10003
|
+
}
|
|
10004
|
+
validateTextValue(context, token.source, `${path}.source`, blockId, token.id);
|
|
10005
|
+
if (!token.labelEnabled) {
|
|
10006
|
+
return;
|
|
10007
|
+
}
|
|
10008
|
+
if (!token.display) {
|
|
10009
|
+
addIssue(context, "invalid_equation_label", `${path}.label`, blockId, token.id);
|
|
10010
|
+
return;
|
|
10011
|
+
}
|
|
10012
|
+
registerKey(context, token.label ?? "", `${path}.label`, "eq", blockId, token.id);
|
|
10013
|
+
}
|
|
10014
|
+
function validateInlineField(context, field, path, blockId) {
|
|
10015
|
+
field.tokens.forEach((token, index) => {
|
|
10016
|
+
validateToken(context, token, `${path}.tokens[${String(index)}]`, blockId);
|
|
10017
|
+
});
|
|
10018
|
+
}
|
|
10019
|
+
function validateBlock(context, block, path) {
|
|
10020
|
+
if (block.kind === "textBlock") {
|
|
10021
|
+
validateInlineField(context, block.field, `${path}.field`, block.id);
|
|
10022
|
+
return;
|
|
10023
|
+
}
|
|
10024
|
+
if (block.kind === "list") {
|
|
10025
|
+
block.items.forEach((item, itemIndex) => {
|
|
10026
|
+
const itemPath = `${path}.items[${String(itemIndex)}]`;
|
|
10027
|
+
validateInlineField(context, item.field, `${itemPath}.field`, block.id);
|
|
10028
|
+
item.blocks.forEach((child, childIndex) => {
|
|
10029
|
+
validateBlock(context, child, `${itemPath}.blocks[${String(childIndex)}]`);
|
|
10030
|
+
});
|
|
10031
|
+
});
|
|
10032
|
+
return;
|
|
10033
|
+
}
|
|
10034
|
+
if (block.kind === "table") {
|
|
10035
|
+
if (block.columns.trim().length === 0 || block.rows.length === 0) {
|
|
10036
|
+
addIssue(context, "invalid_table", path, block.id);
|
|
10037
|
+
}
|
|
10038
|
+
const expectedColumns = block.rows[0]?.length ?? 0;
|
|
10039
|
+
if (expectedColumns === 0 || block.rows.some((row) => row.length !== expectedColumns)) {
|
|
10040
|
+
addIssue(context, "invalid_table", `${path}.rows`, block.id);
|
|
10041
|
+
}
|
|
10042
|
+
block.rows.forEach((row, rowIndex) => {
|
|
10043
|
+
row.forEach((cell, columnIndex) => {
|
|
10044
|
+
validateInlineField(
|
|
10045
|
+
context,
|
|
10046
|
+
cell,
|
|
10047
|
+
`${path}.rows[${String(rowIndex)}][${String(columnIndex)}]`,
|
|
10048
|
+
block.id
|
|
10049
|
+
);
|
|
10050
|
+
});
|
|
10051
|
+
});
|
|
10052
|
+
validateTextValue(context, block.caption, `${path}.caption`, block.id);
|
|
10053
|
+
if (block.labelEnabled) {
|
|
10054
|
+
registerKey(context, block.label, `${path}.label`, "tab", block.id);
|
|
10055
|
+
}
|
|
10056
|
+
return;
|
|
10057
|
+
}
|
|
10058
|
+
if (block.kind === "image") {
|
|
10059
|
+
const hasAssetId = typeof block.assetId === "string" && block.assetId.trim().length > 0;
|
|
10060
|
+
const hasValue = block.value.trim().length > 0;
|
|
10061
|
+
if (!hasAssetId && !hasValue) {
|
|
10062
|
+
addIssue(context, "empty_image", path, block.id);
|
|
10063
|
+
}
|
|
10064
|
+
validateTextValue(context, block.value, `${path}.value`, block.id);
|
|
10065
|
+
validateTextValue(context, block.caption, `${path}.caption`, block.id);
|
|
10066
|
+
if (block.labelEnabled) {
|
|
10067
|
+
registerKey(context, block.label, `${path}.label`, "fig", block.id);
|
|
10068
|
+
}
|
|
10069
|
+
return;
|
|
10070
|
+
}
|
|
10071
|
+
if (block.kind === "raw") {
|
|
10072
|
+
validateTextValue(context, block.value, `${path}.value`, block.id);
|
|
10073
|
+
}
|
|
10074
|
+
}
|
|
10075
|
+
function validateDuplicateKeys(context) {
|
|
10076
|
+
const grouped = /* @__PURE__ */ new Map();
|
|
10077
|
+
for (const owner of context.keyOwners) {
|
|
10078
|
+
const group = grouped.get(owner.key) ?? [];
|
|
10079
|
+
group.push(owner);
|
|
10080
|
+
grouped.set(owner.key, group);
|
|
10081
|
+
}
|
|
10082
|
+
for (const owners of grouped.values()) {
|
|
10083
|
+
if (owners.length < 2) {
|
|
10084
|
+
continue;
|
|
10085
|
+
}
|
|
10086
|
+
for (const owner of owners) {
|
|
10087
|
+
addIssue(context, "key_duplicate", owner.path, owner.blockId, owner.tokenId);
|
|
10088
|
+
}
|
|
10089
|
+
}
|
|
10090
|
+
}
|
|
10091
|
+
function validatePendingReferences(context) {
|
|
10092
|
+
for (const pending of context.pendingCitations) {
|
|
10093
|
+
if (pending.token.keys.some((key) => !isValidDocument2Key(normalizeDocument2Key(key)))) {
|
|
10094
|
+
addIssue(
|
|
10095
|
+
context,
|
|
10096
|
+
"missing_citation",
|
|
10097
|
+
`${pending.path}.keys`,
|
|
10098
|
+
pending.blockId,
|
|
10099
|
+
pending.token.id
|
|
10100
|
+
);
|
|
10101
|
+
}
|
|
10102
|
+
}
|
|
10103
|
+
for (const pending of context.pendingReferences) {
|
|
10104
|
+
for (const key of pending.token.keys) {
|
|
10105
|
+
const normalized = normalizeDocument2Key(key);
|
|
10106
|
+
if (!isValidDocument2Key(normalized)) {
|
|
10107
|
+
addIssue(
|
|
10108
|
+
context,
|
|
10109
|
+
"missing_reference",
|
|
10110
|
+
`${pending.path}.keys`,
|
|
10111
|
+
pending.blockId,
|
|
10112
|
+
pending.token.id
|
|
10113
|
+
);
|
|
10114
|
+
break;
|
|
10115
|
+
}
|
|
10116
|
+
const kind = context.labelKinds.get(normalized);
|
|
10117
|
+
if (kind && pending.token.refCommand === "eqref" !== (kind === "eq")) {
|
|
10118
|
+
addIssue(
|
|
10119
|
+
context,
|
|
10120
|
+
"reference_kind_mismatch",
|
|
10121
|
+
`${pending.path}.keys`,
|
|
10122
|
+
pending.blockId,
|
|
10123
|
+
pending.token.id
|
|
10124
|
+
);
|
|
10125
|
+
break;
|
|
10126
|
+
}
|
|
10127
|
+
}
|
|
10128
|
+
}
|
|
10129
|
+
}
|
|
10130
|
+
function isRecord(value) {
|
|
10131
|
+
return typeof value === "object" && value !== null;
|
|
10132
|
+
}
|
|
10133
|
+
function hasRuntimeDocumentShape(document2) {
|
|
10134
|
+
const value = document2;
|
|
10135
|
+
return isRecord(value) && value.nodeType === "DocumentObject";
|
|
10136
|
+
}
|
|
10137
|
+
function hasWireDocumentShape(document2) {
|
|
10138
|
+
const value = document2;
|
|
10139
|
+
if (!isRecord(value) || value.node_type !== "DocumentObject" || !Array.isArray(value.blocks)) {
|
|
10140
|
+
return false;
|
|
10141
|
+
}
|
|
10142
|
+
if (value.meta !== void 0 && !isRecord(value.meta)) {
|
|
10143
|
+
return false;
|
|
10144
|
+
}
|
|
10145
|
+
if (value.references !== void 0) {
|
|
10146
|
+
if (!Array.isArray(value.references)) {
|
|
10147
|
+
return false;
|
|
10148
|
+
}
|
|
10149
|
+
for (const reference of value.references) {
|
|
10150
|
+
if (!isRecord(reference) || typeof reference.key !== "string" || reference.key.trim().length === 0) {
|
|
10151
|
+
return false;
|
|
10152
|
+
}
|
|
10153
|
+
}
|
|
10154
|
+
}
|
|
10155
|
+
return true;
|
|
10156
|
+
}
|
|
10157
|
+
function resolveDocument(document2) {
|
|
10158
|
+
if (hasRuntimeDocumentShape(document2)) {
|
|
10159
|
+
try {
|
|
10160
|
+
toDocumentJson2(document2);
|
|
10161
|
+
return document2;
|
|
10162
|
+
} catch {
|
|
10163
|
+
return null;
|
|
10164
|
+
}
|
|
10165
|
+
}
|
|
10166
|
+
if (!hasWireDocumentShape(document2)) {
|
|
10167
|
+
return null;
|
|
10168
|
+
}
|
|
10169
|
+
try {
|
|
10170
|
+
return fromDocumentJson2(document2);
|
|
10171
|
+
} catch {
|
|
10172
|
+
return null;
|
|
10173
|
+
}
|
|
10174
|
+
}
|
|
10175
|
+
function validateDocument2(document2) {
|
|
10176
|
+
const resolved = resolveDocument(document2);
|
|
10177
|
+
if (!resolved) {
|
|
10178
|
+
return {
|
|
10179
|
+
valid: false,
|
|
10180
|
+
issues: [{ code: "malformed_document", path: "$" }]
|
|
10181
|
+
};
|
|
10182
|
+
}
|
|
10183
|
+
const context = {
|
|
10184
|
+
issues: [],
|
|
10185
|
+
keyOwners: [],
|
|
10186
|
+
labelKinds: /* @__PURE__ */ new Map(),
|
|
10187
|
+
pendingCitations: [],
|
|
10188
|
+
pendingReferences: []
|
|
10189
|
+
};
|
|
10190
|
+
validateTextValue(context, resolved.meta.title, "$.meta.title");
|
|
10191
|
+
validateTextValue(context, resolved.meta.authors, "$.meta.authors");
|
|
10192
|
+
validateTextValue(context, resolved.meta.abstract, "$.meta.abstract");
|
|
10193
|
+
resolved.references.forEach((reference, index) => {
|
|
10194
|
+
const path = `$.references[${String(index)}]`;
|
|
10195
|
+
registerKey(context, reference.key, `${path}.key`, "reference");
|
|
10196
|
+
validateTextValue(context, reference.authors, `${path}.authors`);
|
|
10197
|
+
validateTextValue(context, reference.title, `${path}.title`);
|
|
10198
|
+
validateTextValue(context, reference.year, `${path}.year`);
|
|
10199
|
+
validateTextValue(context, reference.url, `${path}.url`);
|
|
10200
|
+
validateTextValue(context, reference.venue, `${path}.venue`);
|
|
10201
|
+
});
|
|
10202
|
+
resolved.blocks.forEach((block, index) => {
|
|
10203
|
+
validateBlock(context, block, `$.blocks[${String(index)}]`);
|
|
10204
|
+
});
|
|
10205
|
+
for (const diagnostic of resolved.diagnostics) {
|
|
10206
|
+
addIssue(context, "parser_diagnostic", diagnostic.path);
|
|
10207
|
+
}
|
|
10208
|
+
validateDuplicateKeys(context);
|
|
10209
|
+
validatePendingReferences(context);
|
|
10210
|
+
return {
|
|
10211
|
+
valid: context.issues.length === 0,
|
|
10212
|
+
issues: context.issues
|
|
10213
|
+
};
|
|
10214
|
+
}
|
|
10215
|
+
function isDocument2Valid(document2) {
|
|
10216
|
+
return validateDocument2(document2).valid;
|
|
10217
|
+
}
|
|
10218
|
+
|
|
9935
10219
|
// src/document2/history.ts
|
|
9936
10220
|
var DEFAULT_DOCUMENT2_HISTORY_MAX_DEPTH = 100;
|
|
9937
10221
|
function createDocument2History(maxDepth = DEFAULT_DOCUMENT2_HISTORY_MAX_DEPTH) {
|
|
@@ -10521,10 +10805,6 @@ function document2Messages(locale) {
|
|
|
10521
10805
|
}
|
|
10522
10806
|
|
|
10523
10807
|
// src/react-document2/xelatexTextValidation.ts
|
|
10524
|
-
var XELATEX_UNSUPPORTED_EMOJI_PATTERN = /[\p{Emoji_Presentation}\p{Emoji_Modifier}\p{Regional_Indicator}\uFE0F\u20E3]/u;
|
|
10525
|
-
function hasXeLatexUnsupportedEmoji(value) {
|
|
10526
|
-
return XELATEX_UNSUPPORTED_EMOJI_PATTERN.test(value);
|
|
10527
|
-
}
|
|
10528
10808
|
function unsupportedEmojiMessage(uiLocale) {
|
|
10529
10809
|
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.";
|
|
10530
10810
|
}
|
|
@@ -10765,6 +11045,9 @@ function focusArticleMetaPanel(panel) {
|
|
|
10765
11045
|
}
|
|
10766
11046
|
}
|
|
10767
11047
|
|
|
11048
|
+
// src/react-document2/ValidatedButexDocumentEditor2.tsx
|
|
11049
|
+
var import_react14 = require("react");
|
|
11050
|
+
|
|
10768
11051
|
// src/react-document2/ButexDocumentEditor2.tsx
|
|
10769
11052
|
var import_react13 = require("react");
|
|
10770
11053
|
|
|
@@ -12898,6 +13181,28 @@ function DocumentInsertToolbar({
|
|
|
12898
13181
|
|
|
12899
13182
|
// src/react-document2/DocumentPreview.tsx
|
|
12900
13183
|
var import_jsx_runtime11 = require("react/jsx-runtime");
|
|
13184
|
+
var REF_KIND_NAMES = [
|
|
13185
|
+
{ names: ["\u0627\u0644\u0634\u0643\u0644", "\u0634\u0643\u0644", "Figure", "figure"], prefixes: ["\u0627\u0644\u0634\u0643\u0644 ", "Figure "] },
|
|
13186
|
+
{ names: ["\u0627\u0644\u062C\u062F\u0648\u0644", "\u062C\u062F\u0648\u0644", "Table", "table"], prefixes: ["\u0627\u0644\u062C\u062F\u0648\u0644 ", "Table "] },
|
|
13187
|
+
{ 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 "] }
|
|
13188
|
+
];
|
|
13189
|
+
function contextualRefLabel(inlines, index, label) {
|
|
13190
|
+
const previous = inlines[index - 1];
|
|
13191
|
+
if (previous?.kind !== "text") {
|
|
13192
|
+
return label;
|
|
13193
|
+
}
|
|
13194
|
+
const previousText = previous.text.trimEnd();
|
|
13195
|
+
for (const group of REF_KIND_NAMES) {
|
|
13196
|
+
if (!group.names.some((name) => previousText.endsWith(name))) {
|
|
13197
|
+
continue;
|
|
13198
|
+
}
|
|
13199
|
+
const prefix = group.prefixes.find((candidate) => label.startsWith(candidate));
|
|
13200
|
+
if (prefix) {
|
|
13201
|
+
return label.slice(prefix.length);
|
|
13202
|
+
}
|
|
13203
|
+
}
|
|
13204
|
+
return label;
|
|
13205
|
+
}
|
|
12901
13206
|
function PreviewInlines({ inlines, output }) {
|
|
12902
13207
|
return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_jsx_runtime11.Fragment, { children: inlines.map((inline, index) => {
|
|
12903
13208
|
if (inline.kind === "text") {
|
|
@@ -12917,7 +13222,7 @@ function PreviewInlines({ inlines, output }) {
|
|
|
12917
13222
|
return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("span", { className: "butex-document2-widget__preview-cite", children: inline.label }, inline.id);
|
|
12918
13223
|
}
|
|
12919
13224
|
if (inline.kind === "ref") {
|
|
12920
|
-
return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("span", { className: "butex-document2-widget__preview-cite butex-document2-widget__preview-ref", children: inline.label }, inline.id);
|
|
13225
|
+
return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("span", { className: "butex-document2-widget__preview-cite butex-document2-widget__preview-ref", children: contextualRefLabel(inlines, index, inline.label) }, inline.id);
|
|
12921
13226
|
}
|
|
12922
13227
|
return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(MathIsland, { id: inline.id, tex: inline.tex, display: inline.display, output }, inline.id);
|
|
12923
13228
|
}) });
|
|
@@ -19239,6 +19544,100 @@ var ButexDocumentEditor2 = (0, import_react13.forwardRef)(
|
|
|
19239
19544
|
}
|
|
19240
19545
|
);
|
|
19241
19546
|
ButexDocumentEditor2.displayName = "ButexDocumentEditor2";
|
|
19547
|
+
|
|
19548
|
+
// src/react-document2/ValidatedButexDocumentEditor2.tsx
|
|
19549
|
+
var import_jsx_runtime18 = require("react/jsx-runtime");
|
|
19550
|
+
function imageValidationMessage(uiLocale) {
|
|
19551
|
+
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.";
|
|
19552
|
+
}
|
|
19553
|
+
function imageHasIdentity(ctx) {
|
|
19554
|
+
return Boolean(ctx.assetId?.trim()) || ctx.value.trim().length > 0;
|
|
19555
|
+
}
|
|
19556
|
+
function isMalformedInitialDocument(initialDocument) {
|
|
19557
|
+
if (initialDocument === void 0) {
|
|
19558
|
+
return false;
|
|
19559
|
+
}
|
|
19560
|
+
return validateDocument2(initialDocument).issues.some((issue) => issue.code === "malformed_document");
|
|
19561
|
+
}
|
|
19562
|
+
var ButexDocumentEditor23 = (0, import_react14.forwardRef)(
|
|
19563
|
+
function ValidatedButexDocumentEditor2({
|
|
19564
|
+
initialDocument,
|
|
19565
|
+
uiLocale = "ar",
|
|
19566
|
+
onDocumentChange,
|
|
19567
|
+
onValidityChange,
|
|
19568
|
+
renderImageBlockEditor,
|
|
19569
|
+
...rest
|
|
19570
|
+
}, ref) {
|
|
19571
|
+
const lastValidityRef = (0, import_react14.useRef)(null);
|
|
19572
|
+
const initialDocumentRef = (0, import_react14.useRef)(initialDocument);
|
|
19573
|
+
const awaitingInitialResolutionRef = (0, import_react14.useRef)(true);
|
|
19574
|
+
const malformedInitialDocument = isMalformedInitialDocument(initialDocument);
|
|
19575
|
+
if (initialDocumentRef.current !== initialDocument) {
|
|
19576
|
+
initialDocumentRef.current = initialDocument;
|
|
19577
|
+
awaitingInitialResolutionRef.current = true;
|
|
19578
|
+
lastValidityRef.current = null;
|
|
19579
|
+
}
|
|
19580
|
+
const emitValidity = (0, import_react14.useCallback)(
|
|
19581
|
+
(isValid) => {
|
|
19582
|
+
if (lastValidityRef.current === isValid) {
|
|
19583
|
+
return;
|
|
19584
|
+
}
|
|
19585
|
+
lastValidityRef.current = isValid;
|
|
19586
|
+
onValidityChange?.(isValid);
|
|
19587
|
+
},
|
|
19588
|
+
[onValidityChange]
|
|
19589
|
+
);
|
|
19590
|
+
const handleDocumentChange = (0, import_react14.useCallback)(
|
|
19591
|
+
(document2) => {
|
|
19592
|
+
const validationTarget = initialDocument !== void 0 && (malformedInitialDocument || awaitingInitialResolutionRef.current) ? initialDocument : document2;
|
|
19593
|
+
awaitingInitialResolutionRef.current = false;
|
|
19594
|
+
emitValidity(isDocument2Valid(validationTarget));
|
|
19595
|
+
onDocumentChange?.(document2);
|
|
19596
|
+
},
|
|
19597
|
+
[emitValidity, initialDocument, malformedInitialDocument, onDocumentChange]
|
|
19598
|
+
);
|
|
19599
|
+
const handleImageBlockEditor = (0, import_react14.useCallback)(
|
|
19600
|
+
(ctx) => {
|
|
19601
|
+
const rendered = renderImageBlockEditor?.(ctx) ?? ctx.defaultUi;
|
|
19602
|
+
if (imageHasIdentity(ctx)) {
|
|
19603
|
+
return rendered;
|
|
19604
|
+
}
|
|
19605
|
+
const errorId = `butex-document2-image-validation-${ctx.blockId}`;
|
|
19606
|
+
return /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)(
|
|
19607
|
+
"div",
|
|
19608
|
+
{
|
|
19609
|
+
role: "group",
|
|
19610
|
+
"aria-invalid": "true",
|
|
19611
|
+
"aria-describedby": errorId,
|
|
19612
|
+
style: {
|
|
19613
|
+
border: "1px solid var(--butex-document2-error)",
|
|
19614
|
+
background: "var(--butex-document2-error-bg)",
|
|
19615
|
+
borderRadius: "0.65rem",
|
|
19616
|
+
padding: "0.6rem"
|
|
19617
|
+
},
|
|
19618
|
+
children: [
|
|
19619
|
+
rendered,
|
|
19620
|
+
/* @__PURE__ */ (0, import_jsx_runtime18.jsx)("p", { id: errorId, className: "butex-document2-widget__field-error", children: imageValidationMessage(ctx.uiLocale) })
|
|
19621
|
+
]
|
|
19622
|
+
}
|
|
19623
|
+
);
|
|
19624
|
+
},
|
|
19625
|
+
[renderImageBlockEditor]
|
|
19626
|
+
);
|
|
19627
|
+
return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
|
|
19628
|
+
ButexDocumentEditor2,
|
|
19629
|
+
{
|
|
19630
|
+
ref,
|
|
19631
|
+
...rest,
|
|
19632
|
+
initialDocument,
|
|
19633
|
+
uiLocale,
|
|
19634
|
+
onDocumentChange: handleDocumentChange,
|
|
19635
|
+
renderImageBlockEditor: handleImageBlockEditor
|
|
19636
|
+
}
|
|
19637
|
+
);
|
|
19638
|
+
}
|
|
19639
|
+
);
|
|
19640
|
+
ButexDocumentEditor23.displayName = "ButexDocumentEditor2";
|
|
19242
19641
|
// Annotate the CommonJS export names for ESM import in node:
|
|
19243
19642
|
0 && (module.exports = {
|
|
19244
19643
|
ButexDocumentEditor2,
|