@drghaliasri/butex 6.1.5 → 7.0.2
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 +43 -12
- package/dist/document.js +21 -4
- package/dist/document.js.map +1 -1
- package/dist/document.mjs +21 -4
- package/dist/document.mjs.map +1 -1
- package/dist/document2-cli.js +551 -5
- package/dist/document2-cli.js.map +1 -1
- package/dist/document2.d.mts +62 -2
- package/dist/document2.d.ts +62 -2
- package/dist/document2.js +476 -51
- package/dist/document2.js.map +1 -1
- package/dist/document2.mjs +476 -51
- package/dist/document2.mjs.map +1 -1
- package/dist/index.global.js +104 -6
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +104 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +104 -6
- package/dist/index.mjs.map +1 -1
- package/dist/react-document.js +2066 -599
- package/dist/react-document.js.map +1 -1
- package/dist/react-document.mjs +2064 -596
- package/dist/react-document.mjs.map +1 -1
- package/dist/react-document2.d.mts +12 -5
- package/dist/react-document2.d.ts +12 -5
- package/dist/react-document2.js +3704 -1172
- package/dist/react-document2.js.map +1 -1
- package/dist/react-document2.mjs +3692 -1159
- package/dist/react-document2.mjs.map +1 -1
- package/dist/react.d.mts +9 -2
- package/dist/react.d.ts +9 -2
- package/dist/react.js +1954 -507
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +1955 -507
- package/dist/react.mjs.map +1 -1
- package/package.json +1 -1
package/dist/document2.mjs
CHANGED
|
@@ -3738,14 +3738,20 @@ var BUTEX_EDITOR_CSS = `
|
|
|
3738
3738
|
${BUTEX_FONT_FACE_CSS}
|
|
3739
3739
|
|
|
3740
3740
|
.surface {
|
|
3741
|
+
background: var(--butex-surface-bg, linear-gradient(180deg, #ffffff 0%, #fafbfc 100%));
|
|
3741
3742
|
border: 1px solid var(--butex-border, #e2e8f0);
|
|
3742
3743
|
border-radius: 12px;
|
|
3743
|
-
min-height: 100px;
|
|
3744
|
-
padding: 8px 10px;
|
|
3745
|
-
background: var(--butex-surface-bg, linear-gradient(180deg, #ffffff 0%, #fafbfc 100%));
|
|
3746
3744
|
color: var(--butex-surface-fg, #0f172a);
|
|
3747
|
-
outline: none;
|
|
3748
3745
|
cursor: text;
|
|
3746
|
+
max-width: 100%;
|
|
3747
|
+
min-height: 100px;
|
|
3748
|
+
min-width: 0;
|
|
3749
|
+
outline: none;
|
|
3750
|
+
overflow-x: auto;
|
|
3751
|
+
overflow-y: hidden;
|
|
3752
|
+
overscroll-behavior-inline: contain;
|
|
3753
|
+
padding: 8px 10px;
|
|
3754
|
+
touch-action: pan-x pan-y;
|
|
3749
3755
|
transition: box-shadow 0.15s ease, border-color 0.15s ease;
|
|
3750
3756
|
}
|
|
3751
3757
|
|
|
@@ -3810,6 +3816,17 @@ ${CHARACTER_FONT_CSS}
|
|
|
3810
3816
|
50% { opacity: 0; }
|
|
3811
3817
|
}
|
|
3812
3818
|
|
|
3819
|
+
@media (prefers-reduced-motion: reduce) {
|
|
3820
|
+
.surface {
|
|
3821
|
+
scroll-behavior: auto;
|
|
3822
|
+
transition: none;
|
|
3823
|
+
}
|
|
3824
|
+
|
|
3825
|
+
.caret {
|
|
3826
|
+
animation: none;
|
|
3827
|
+
}
|
|
3828
|
+
}
|
|
3829
|
+
|
|
3813
3830
|
.node {
|
|
3814
3831
|
display: inline-flex;
|
|
3815
3832
|
align-items: stretch;
|
|
@@ -5425,6 +5442,12 @@ function requireBoolean(value, field) {
|
|
|
5425
5442
|
}
|
|
5426
5443
|
return value;
|
|
5427
5444
|
}
|
|
5445
|
+
function optionalBoolean(value, field) {
|
|
5446
|
+
if (!(field in value)) {
|
|
5447
|
+
return void 0;
|
|
5448
|
+
}
|
|
5449
|
+
return requireBoolean(value[field], field);
|
|
5450
|
+
}
|
|
5428
5451
|
function requireIndex(value, field) {
|
|
5429
5452
|
if (typeof value !== "number" || !Number.isInteger(value) || value < 0) {
|
|
5430
5453
|
throw new Document2CommandError("invalid_command", `${field} must be a non-negative integer`);
|
|
@@ -5655,6 +5678,301 @@ function compactTextTokens2(tokens, emptyTokenId = document2Id("text")) {
|
|
|
5655
5678
|
return compacted.length > 0 ? compacted : [{ id: emptyTokenId, kind: "text", text: "" }];
|
|
5656
5679
|
}
|
|
5657
5680
|
|
|
5681
|
+
// src/document2/keys.ts
|
|
5682
|
+
var DOCUMENT2_KEY_PATTERN = /^[\p{L}\p{M}\p{Nd}:._-]+$/u;
|
|
5683
|
+
function normalizeDocument2Key(key) {
|
|
5684
|
+
return key.normalize("NFC").trim();
|
|
5685
|
+
}
|
|
5686
|
+
function isValidDocument2Key(key) {
|
|
5687
|
+
const normalized = normalizeDocument2Key(key);
|
|
5688
|
+
return normalized.length > 0 && DOCUMENT2_KEY_PATTERN.test(normalized);
|
|
5689
|
+
}
|
|
5690
|
+
function isDuplicateDocument2Key(key, namespace) {
|
|
5691
|
+
const normalized = normalizeDocument2Key(key);
|
|
5692
|
+
if (normalized.length === 0) {
|
|
5693
|
+
return false;
|
|
5694
|
+
}
|
|
5695
|
+
for (const reference of namespace.references ?? []) {
|
|
5696
|
+
if (namespace.excludeReferenceId && reference.id === namespace.excludeReferenceId) {
|
|
5697
|
+
continue;
|
|
5698
|
+
}
|
|
5699
|
+
if (normalizeDocument2Key(reference.key) === normalized) {
|
|
5700
|
+
return true;
|
|
5701
|
+
}
|
|
5702
|
+
}
|
|
5703
|
+
for (const label of namespace.labels ?? []) {
|
|
5704
|
+
if (namespace.excludeOwnerId && label.ownerId === namespace.excludeOwnerId) {
|
|
5705
|
+
continue;
|
|
5706
|
+
}
|
|
5707
|
+
if (normalizeDocument2Key(label.key) === normalized) {
|
|
5708
|
+
return true;
|
|
5709
|
+
}
|
|
5710
|
+
}
|
|
5711
|
+
return false;
|
|
5712
|
+
}
|
|
5713
|
+
function document2KeyError(key, namespace = {}) {
|
|
5714
|
+
const normalized = normalizeDocument2Key(key);
|
|
5715
|
+
if (normalized.length === 0) {
|
|
5716
|
+
return "empty";
|
|
5717
|
+
}
|
|
5718
|
+
if (!DOCUMENT2_KEY_PATTERN.test(normalized)) {
|
|
5719
|
+
return "invalid";
|
|
5720
|
+
}
|
|
5721
|
+
if (isDuplicateDocument2Key(normalized, namespace)) {
|
|
5722
|
+
return "duplicate";
|
|
5723
|
+
}
|
|
5724
|
+
return null;
|
|
5725
|
+
}
|
|
5726
|
+
|
|
5727
|
+
// src/document2/articleJsonCommands.ts
|
|
5728
|
+
var REFERENCE_TEXT_FIELDS = ["authors", "title", "year", "venue", "url"];
|
|
5729
|
+
function hasOwn(value, field) {
|
|
5730
|
+
return Object.prototype.hasOwnProperty.call(value, field);
|
|
5731
|
+
}
|
|
5732
|
+
function parseDatePatch(value) {
|
|
5733
|
+
if (!isObject3(value)) {
|
|
5734
|
+
throw new Document2CommandError("invalid_command", "date must be an object");
|
|
5735
|
+
}
|
|
5736
|
+
const patch = {};
|
|
5737
|
+
if (hasOwn(value, "day")) {
|
|
5738
|
+
if (typeof value.day !== "number" || !Number.isInteger(value.day) || value.day < 1 || value.day > 30) {
|
|
5739
|
+
throw new Document2CommandError("invalid_command", "date.day must be an integer from 1 to 30");
|
|
5740
|
+
}
|
|
5741
|
+
patch.day = value.day;
|
|
5742
|
+
}
|
|
5743
|
+
if (hasOwn(value, "month")) {
|
|
5744
|
+
if (typeof value.month !== "string" || !HIJRI_MONTH_IDS.includes(value.month)) {
|
|
5745
|
+
throw new Document2CommandError("invalid_command", "date.month must be a supported Hijri month");
|
|
5746
|
+
}
|
|
5747
|
+
patch.month = value.month;
|
|
5748
|
+
}
|
|
5749
|
+
if (hasOwn(value, "year")) {
|
|
5750
|
+
if (typeof value.year !== "number" || !Number.isInteger(value.year) || value.year < HIJRI_YEAR_MIN || value.year > HIJRI_YEAR_MAX) {
|
|
5751
|
+
throw new Document2CommandError(
|
|
5752
|
+
"invalid_command",
|
|
5753
|
+
`date.year must be an integer from ${String(HIJRI_YEAR_MIN)} to ${String(HIJRI_YEAR_MAX)}`
|
|
5754
|
+
);
|
|
5755
|
+
}
|
|
5756
|
+
patch.year = value.year;
|
|
5757
|
+
}
|
|
5758
|
+
if (Object.keys(patch).length === 0) {
|
|
5759
|
+
throw new Document2CommandError("invalid_command", "date requires at least one field");
|
|
5760
|
+
}
|
|
5761
|
+
return patch;
|
|
5762
|
+
}
|
|
5763
|
+
function parseReferenceSeparator(value) {
|
|
5764
|
+
if (!hasOwn(value, "field_separator")) {
|
|
5765
|
+
return void 0;
|
|
5766
|
+
}
|
|
5767
|
+
if (value.field_separator !== "," && value.field_separator !== "\u060C") {
|
|
5768
|
+
throw new Document2CommandError("invalid_command", "field_separator must be , or \u060C");
|
|
5769
|
+
}
|
|
5770
|
+
return value.field_separator;
|
|
5771
|
+
}
|
|
5772
|
+
function parseReferenceAnchor(value) {
|
|
5773
|
+
if (!isObject3(value)) {
|
|
5774
|
+
throw new Document2CommandError("invalid_anchor", "anchor must be an object");
|
|
5775
|
+
}
|
|
5776
|
+
const before = typeof value.before_reference_key === "string" ? normalizeDocument2Key(value.before_reference_key) : "";
|
|
5777
|
+
const after = typeof value.after_reference_key === "string" ? normalizeDocument2Key(value.after_reference_key) : "";
|
|
5778
|
+
const choices = Number(before.length > 0) + Number(after.length > 0) + Number(value.end === true);
|
|
5779
|
+
if (choices !== 1) {
|
|
5780
|
+
throw new Document2CommandError("invalid_anchor", "anchor requires exactly one reference position");
|
|
5781
|
+
}
|
|
5782
|
+
if (before) {
|
|
5783
|
+
return { before_reference_key: before };
|
|
5784
|
+
}
|
|
5785
|
+
if (after) {
|
|
5786
|
+
return { after_reference_key: after };
|
|
5787
|
+
}
|
|
5788
|
+
return { end: true };
|
|
5789
|
+
}
|
|
5790
|
+
function parseUpdateDocumentMeta(value) {
|
|
5791
|
+
const title = optionalString(value, "title");
|
|
5792
|
+
const authors = optionalString(value, "authors");
|
|
5793
|
+
const abstract = optionalString(value, "abstract");
|
|
5794
|
+
const date = hasOwn(value, "date") ? parseDatePatch(value.date) : void 0;
|
|
5795
|
+
if (title === void 0 && authors === void 0 && abstract === void 0 && date === void 0) {
|
|
5796
|
+
throw new Document2CommandError("invalid_command", "update_document_meta requires at least one field");
|
|
5797
|
+
}
|
|
5798
|
+
return {
|
|
5799
|
+
op: "update_document_meta",
|
|
5800
|
+
...title !== void 0 ? { title } : {},
|
|
5801
|
+
...authors !== void 0 ? { authors } : {},
|
|
5802
|
+
...abstract !== void 0 ? { abstract } : {},
|
|
5803
|
+
...date !== void 0 ? { date } : {}
|
|
5804
|
+
};
|
|
5805
|
+
}
|
|
5806
|
+
function referenceFields(value) {
|
|
5807
|
+
const fields = {};
|
|
5808
|
+
for (const field of REFERENCE_TEXT_FIELDS) {
|
|
5809
|
+
const parsed = optionalString(value, field);
|
|
5810
|
+
if (parsed !== void 0) {
|
|
5811
|
+
fields[field] = parsed;
|
|
5812
|
+
}
|
|
5813
|
+
}
|
|
5814
|
+
const separator = parseReferenceSeparator(value);
|
|
5815
|
+
if (separator !== void 0) {
|
|
5816
|
+
fields.field_separator = separator;
|
|
5817
|
+
}
|
|
5818
|
+
return fields;
|
|
5819
|
+
}
|
|
5820
|
+
function parseInsertReference(value) {
|
|
5821
|
+
const key = requireString2(value.key, "key", false);
|
|
5822
|
+
return {
|
|
5823
|
+
op: "insert_reference",
|
|
5824
|
+
key,
|
|
5825
|
+
...referenceFields(value),
|
|
5826
|
+
anchor: parseReferenceAnchor(value.anchor)
|
|
5827
|
+
};
|
|
5828
|
+
}
|
|
5829
|
+
function parseUpdateReference(value) {
|
|
5830
|
+
const nextKey = optionalString(value, "key");
|
|
5831
|
+
const fields = referenceFields(value);
|
|
5832
|
+
if (nextKey === void 0 && Object.keys(fields).length === 0) {
|
|
5833
|
+
throw new Document2CommandError("invalid_command", "update_reference requires at least one field");
|
|
5834
|
+
}
|
|
5835
|
+
return {
|
|
5836
|
+
op: "update_reference",
|
|
5837
|
+
reference_key: requireString2(value.reference_key, "reference_key", false),
|
|
5838
|
+
...nextKey !== void 0 ? { key: nextKey } : {},
|
|
5839
|
+
...fields
|
|
5840
|
+
};
|
|
5841
|
+
}
|
|
5842
|
+
function parseArticleCommand(value) {
|
|
5843
|
+
if (value.op === "update_document_meta") {
|
|
5844
|
+
return parseUpdateDocumentMeta(value);
|
|
5845
|
+
}
|
|
5846
|
+
if (value.op === "insert_reference") {
|
|
5847
|
+
return parseInsertReference(value);
|
|
5848
|
+
}
|
|
5849
|
+
if (value.op === "update_reference") {
|
|
5850
|
+
return parseUpdateReference(value);
|
|
5851
|
+
}
|
|
5852
|
+
if (value.op === "remove_reference") {
|
|
5853
|
+
return {
|
|
5854
|
+
op: value.op,
|
|
5855
|
+
reference_key: requireString2(value.reference_key, "reference_key", false)
|
|
5856
|
+
};
|
|
5857
|
+
}
|
|
5858
|
+
if (value.op === "move_reference") {
|
|
5859
|
+
return {
|
|
5860
|
+
op: value.op,
|
|
5861
|
+
reference_key: requireString2(value.reference_key, "reference_key", false),
|
|
5862
|
+
anchor: parseReferenceAnchor(value.anchor)
|
|
5863
|
+
};
|
|
5864
|
+
}
|
|
5865
|
+
throw new Document2CommandError("invalid_command", "Unsupported article command");
|
|
5866
|
+
}
|
|
5867
|
+
function referenceIndexes(document2, key) {
|
|
5868
|
+
const normalized = normalizeDocument2Key(key);
|
|
5869
|
+
const indexes = [];
|
|
5870
|
+
document2.references.forEach((reference, index) => {
|
|
5871
|
+
if (normalizeDocument2Key(reference.key) === normalized) {
|
|
5872
|
+
indexes.push(index);
|
|
5873
|
+
}
|
|
5874
|
+
});
|
|
5875
|
+
return indexes;
|
|
5876
|
+
}
|
|
5877
|
+
function referenceTargetIndex(document2, key) {
|
|
5878
|
+
const indexes = referenceIndexes(document2, key);
|
|
5879
|
+
if (indexes.length === 0) {
|
|
5880
|
+
throw new Document2CommandError("reference_not_found", "Document reference was not found");
|
|
5881
|
+
}
|
|
5882
|
+
if (indexes.length > 1) {
|
|
5883
|
+
throw new Document2CommandError("duplicate_key", "Reference key is ambiguous");
|
|
5884
|
+
}
|
|
5885
|
+
return indexes[0];
|
|
5886
|
+
}
|
|
5887
|
+
function validateReferenceKey(document2, key, excludeReferenceId) {
|
|
5888
|
+
const normalized = normalizeDocument2Key(key);
|
|
5889
|
+
const error = document2KeyError(normalized, {
|
|
5890
|
+
references: document2.references,
|
|
5891
|
+
labels: collectDocument2Labels(document2),
|
|
5892
|
+
...excludeReferenceId ? { excludeReferenceId } : {}
|
|
5893
|
+
});
|
|
5894
|
+
if (error === "duplicate") {
|
|
5895
|
+
throw new Document2CommandError("duplicate_key", "Reference key is already in use");
|
|
5896
|
+
}
|
|
5897
|
+
if (error !== null) {
|
|
5898
|
+
throw new Document2CommandError("invalid_key", "Reference key is invalid");
|
|
5899
|
+
}
|
|
5900
|
+
return normalized;
|
|
5901
|
+
}
|
|
5902
|
+
function referenceInsertionIndex(document2, anchor) {
|
|
5903
|
+
if ("end" in anchor) {
|
|
5904
|
+
return document2.references.length;
|
|
5905
|
+
}
|
|
5906
|
+
const key = "before_reference_key" in anchor ? anchor.before_reference_key : anchor.after_reference_key;
|
|
5907
|
+
const indexes = referenceIndexes(document2, key);
|
|
5908
|
+
if (indexes.length === 0) {
|
|
5909
|
+
throw new Document2CommandError("anchor_not_found", "Anchor reference was not found");
|
|
5910
|
+
}
|
|
5911
|
+
if (indexes.length > 1) {
|
|
5912
|
+
throw new Document2CommandError("duplicate_key", "Anchor reference key is ambiguous");
|
|
5913
|
+
}
|
|
5914
|
+
return "before_reference_key" in anchor ? indexes[0] : indexes[0] + 1;
|
|
5915
|
+
}
|
|
5916
|
+
function applyReferenceFields(reference, command) {
|
|
5917
|
+
for (const field of REFERENCE_TEXT_FIELDS) {
|
|
5918
|
+
const next = command[field];
|
|
5919
|
+
if (next !== void 0) {
|
|
5920
|
+
reference[field] = next;
|
|
5921
|
+
}
|
|
5922
|
+
}
|
|
5923
|
+
if (command.field_separator !== void 0) {
|
|
5924
|
+
reference.fieldSeparator = command.field_separator;
|
|
5925
|
+
}
|
|
5926
|
+
}
|
|
5927
|
+
function applyArticleCommand(document2, command) {
|
|
5928
|
+
if (command.op === "update_document_meta") {
|
|
5929
|
+
document2.meta = {
|
|
5930
|
+
title: command.title ?? document2.meta.title,
|
|
5931
|
+
authors: command.authors ?? document2.meta.authors,
|
|
5932
|
+
abstract: command.abstract ?? document2.meta.abstract,
|
|
5933
|
+
date: command.date ? normalizeDocument2HijriDate({ ...document2.meta.date, ...command.date }) : { ...document2.meta.date }
|
|
5934
|
+
};
|
|
5935
|
+
return;
|
|
5936
|
+
}
|
|
5937
|
+
if (command.op === "insert_reference") {
|
|
5938
|
+
const key = validateReferenceKey(document2, command.key);
|
|
5939
|
+
const reference2 = referenceFromJson({
|
|
5940
|
+
key,
|
|
5941
|
+
authors: command.authors,
|
|
5942
|
+
title: command.title,
|
|
5943
|
+
year: command.year,
|
|
5944
|
+
venue: command.venue,
|
|
5945
|
+
url: command.url,
|
|
5946
|
+
field_separator: command.field_separator
|
|
5947
|
+
});
|
|
5948
|
+
document2.references.splice(referenceInsertionIndex(document2, command.anchor), 0, reference2);
|
|
5949
|
+
return;
|
|
5950
|
+
}
|
|
5951
|
+
const targetIndex = referenceTargetIndex(document2, command.reference_key);
|
|
5952
|
+
const target = document2.references[targetIndex];
|
|
5953
|
+
if (command.op === "update_reference") {
|
|
5954
|
+
if (command.key !== void 0) {
|
|
5955
|
+
target.key = validateReferenceKey(document2, command.key, target.id);
|
|
5956
|
+
}
|
|
5957
|
+
applyReferenceFields(target, command);
|
|
5958
|
+
return;
|
|
5959
|
+
}
|
|
5960
|
+
if (command.op === "remove_reference") {
|
|
5961
|
+
document2.references.splice(targetIndex, 1);
|
|
5962
|
+
return;
|
|
5963
|
+
}
|
|
5964
|
+
const targetKey = normalizeDocument2Key(target.key);
|
|
5965
|
+
const anchorKey = "before_reference_key" in command.anchor ? command.anchor.before_reference_key : "after_reference_key" in command.anchor ? command.anchor.after_reference_key : null;
|
|
5966
|
+
if (anchorKey !== null && normalizeDocument2Key(anchorKey) === targetKey) {
|
|
5967
|
+
throw new Document2CommandError("invalid_anchor", "A reference cannot be moved relative to itself");
|
|
5968
|
+
}
|
|
5969
|
+
if (anchorKey !== null) {
|
|
5970
|
+
referenceInsertionIndex(document2, command.anchor);
|
|
5971
|
+
}
|
|
5972
|
+
const [reference] = document2.references.splice(targetIndex, 1);
|
|
5973
|
+
document2.references.splice(referenceInsertionIndex(document2, command.anchor), 0, reference);
|
|
5974
|
+
}
|
|
5975
|
+
|
|
5658
5976
|
// src/document2/inlineJsonCommands.ts
|
|
5659
5977
|
function parseInlineAnchor(value) {
|
|
5660
5978
|
if (!isObject3(value)) {
|
|
@@ -6329,6 +6647,9 @@ function isListCommand(command) {
|
|
|
6329
6647
|
function isTableCommand(command) {
|
|
6330
6648
|
return command.op === "insert_table" || command.op === "replace_table_cell" || command.op === "insert_table_row" || command.op === "remove_table_row" || command.op === "move_table_row" || command.op === "insert_table_column" || command.op === "remove_table_column" || command.op === "move_table_column";
|
|
6331
6649
|
}
|
|
6650
|
+
function isArticleCommand(command) {
|
|
6651
|
+
return command.op === "update_document_meta" || command.op === "insert_reference" || command.op === "update_reference" || command.op === "remove_reference" || command.op === "move_reference";
|
|
6652
|
+
}
|
|
6332
6653
|
function parseTextBlockKind(value) {
|
|
6333
6654
|
if (value === "section" || value === "subsection" || value === "subsubsection" || value === "paragraph") {
|
|
6334
6655
|
return value;
|
|
@@ -6356,6 +6677,62 @@ function parseBasicCommand(value) {
|
|
|
6356
6677
|
if (value.op === "remove_block") {
|
|
6357
6678
|
return { op: value.op, block_id: requireString2(value.block_id, "block_id", false).trim() };
|
|
6358
6679
|
}
|
|
6680
|
+
if (value.op === "move_block") {
|
|
6681
|
+
return {
|
|
6682
|
+
op: value.op,
|
|
6683
|
+
block_id: requireString2(value.block_id, "block_id", false).trim(),
|
|
6684
|
+
anchor: parseBlockAnchor(value.anchor)
|
|
6685
|
+
};
|
|
6686
|
+
}
|
|
6687
|
+
if (value.op === "insert_bibliography") {
|
|
6688
|
+
const metadata = parseMetadata(value.metadata);
|
|
6689
|
+
return {
|
|
6690
|
+
op: value.op,
|
|
6691
|
+
anchor: parseBlockAnchor(value.anchor),
|
|
6692
|
+
...metadata ? { metadata } : {}
|
|
6693
|
+
};
|
|
6694
|
+
}
|
|
6695
|
+
if (value.op === "update_figure") {
|
|
6696
|
+
const hasAssetId = Object.prototype.hasOwnProperty.call(value, "asset_id");
|
|
6697
|
+
const hasValue = Object.prototype.hasOwnProperty.call(value, "value");
|
|
6698
|
+
if (!hasAssetId && !hasValue) {
|
|
6699
|
+
throw new Document2CommandError("invalid_command", "update_figure requires asset_id or value");
|
|
6700
|
+
}
|
|
6701
|
+
let assetId;
|
|
6702
|
+
if (hasAssetId) {
|
|
6703
|
+
if (value.asset_id === null) {
|
|
6704
|
+
assetId = null;
|
|
6705
|
+
} else {
|
|
6706
|
+
assetId = requireString2(value.asset_id, "asset_id", false).trim();
|
|
6707
|
+
}
|
|
6708
|
+
}
|
|
6709
|
+
const figureValue = hasValue ? requireString2(value.value, "value") : void 0;
|
|
6710
|
+
return {
|
|
6711
|
+
op: value.op,
|
|
6712
|
+
block_id: requireString2(value.block_id, "block_id", false).trim(),
|
|
6713
|
+
...hasAssetId ? { asset_id: assetId } : {},
|
|
6714
|
+
...hasValue ? { value: figureValue } : {}
|
|
6715
|
+
};
|
|
6716
|
+
}
|
|
6717
|
+
if (value.op === "update_float_meta") {
|
|
6718
|
+
const centered = optionalBoolean(value, "centered");
|
|
6719
|
+
const captionEnabled = optionalBoolean(value, "caption_enabled");
|
|
6720
|
+
const caption = optionalString(value, "caption");
|
|
6721
|
+
const labelEnabled = optionalBoolean(value, "label_enabled");
|
|
6722
|
+
const label = optionalString(value, "label");
|
|
6723
|
+
if (centered === void 0 && captionEnabled === void 0 && caption === void 0 && labelEnabled === void 0 && label === void 0) {
|
|
6724
|
+
throw new Document2CommandError("invalid_command", "update_float_meta requires at least one field");
|
|
6725
|
+
}
|
|
6726
|
+
return {
|
|
6727
|
+
op: value.op,
|
|
6728
|
+
block_id: requireString2(value.block_id, "block_id", false).trim(),
|
|
6729
|
+
...centered !== void 0 ? { centered } : {},
|
|
6730
|
+
...captionEnabled !== void 0 ? { caption_enabled: captionEnabled } : {},
|
|
6731
|
+
...caption !== void 0 ? { caption } : {},
|
|
6732
|
+
...labelEnabled !== void 0 ? { label_enabled: labelEnabled } : {},
|
|
6733
|
+
...label !== void 0 ? { label } : {}
|
|
6734
|
+
};
|
|
6735
|
+
}
|
|
6359
6736
|
if (value.op === "insert_figure") {
|
|
6360
6737
|
const figureValue = optionalString(value, "value");
|
|
6361
6738
|
const caption = optionalString(value, "caption");
|
|
@@ -6386,7 +6763,10 @@ function parseCommand2(value) {
|
|
|
6386
6763
|
if (value.op === "insert_table" || value.op === "replace_table_cell" || value.op === "insert_table_row" || value.op === "remove_table_row" || value.op === "move_table_row" || value.op === "insert_table_column" || value.op === "remove_table_column" || value.op === "move_table_column") {
|
|
6387
6764
|
return parseTableCommand(value);
|
|
6388
6765
|
}
|
|
6389
|
-
if (value.op === "
|
|
6766
|
+
if (value.op === "update_document_meta" || value.op === "insert_reference" || value.op === "update_reference" || value.op === "remove_reference" || value.op === "move_reference") {
|
|
6767
|
+
return parseArticleCommand(value);
|
|
6768
|
+
}
|
|
6769
|
+
if (value.op === "insert_text_block" || value.op === "replace_text_block" || value.op === "remove_block" || value.op === "move_block" || value.op === "insert_figure" || value.op === "update_figure" || value.op === "update_float_meta" || value.op === "insert_bibliography") {
|
|
6390
6770
|
return parseBasicCommand(value);
|
|
6391
6771
|
}
|
|
6392
6772
|
throw new Document2CommandError("invalid_command", "Unsupported document command");
|
|
@@ -6439,6 +6819,94 @@ function applyBasicCommand(document2, command) {
|
|
|
6439
6819
|
document2.blocks.splice(index, 1);
|
|
6440
6820
|
return;
|
|
6441
6821
|
}
|
|
6822
|
+
if (command.op === "move_block") {
|
|
6823
|
+
const index = document2.blocks.findIndex((block3) => block3.id === command.block_id);
|
|
6824
|
+
if (index < 0) {
|
|
6825
|
+
throw new Document2CommandError("block_not_found", "Document block was not found");
|
|
6826
|
+
}
|
|
6827
|
+
const anchorId = "before_block_id" in command.anchor ? command.anchor.before_block_id : "after_block_id" in command.anchor ? command.anchor.after_block_id : null;
|
|
6828
|
+
if (anchorId === command.block_id) {
|
|
6829
|
+
throw new Document2CommandError("invalid_anchor", "A block cannot be moved relative to itself");
|
|
6830
|
+
}
|
|
6831
|
+
if (anchorId !== null) {
|
|
6832
|
+
blockInsertionIndex(document2, command.anchor);
|
|
6833
|
+
}
|
|
6834
|
+
const [block2] = document2.blocks.splice(index, 1);
|
|
6835
|
+
document2.blocks.splice(blockInsertionIndex(document2, command.anchor), 0, block2);
|
|
6836
|
+
return;
|
|
6837
|
+
}
|
|
6838
|
+
if (command.op === "insert_bibliography") {
|
|
6839
|
+
let hasBibliography2 = function(blocks) {
|
|
6840
|
+
return blocks.some((block3) => block3.kind === "bibliography" || block3.kind === "list" && block3.items.some((item) => hasBibliography2(item.blocks)));
|
|
6841
|
+
};
|
|
6842
|
+
var hasBibliography = hasBibliography2;
|
|
6843
|
+
if (hasBibliography2(document2.blocks)) {
|
|
6844
|
+
throw new Document2CommandError("bibliography_exists", "Document already contains a bibliography block");
|
|
6845
|
+
}
|
|
6846
|
+
const block2 = {
|
|
6847
|
+
id: newBlockId(document2),
|
|
6848
|
+
kind: "bibliography",
|
|
6849
|
+
command: "\\begin{thebibliography}",
|
|
6850
|
+
closing: "\\end{thebibliography}",
|
|
6851
|
+
...command.metadata ? { metadata: { ...command.metadata } } : {}
|
|
6852
|
+
};
|
|
6853
|
+
document2.blocks.splice(blockInsertionIndex(document2, command.anchor), 0, block2);
|
|
6854
|
+
return;
|
|
6855
|
+
}
|
|
6856
|
+
if (command.op === "update_figure") {
|
|
6857
|
+
const block2 = findBlock(document2.blocks, command.block_id);
|
|
6858
|
+
if (!block2) {
|
|
6859
|
+
throw new Document2CommandError("block_not_found", "Document block was not found");
|
|
6860
|
+
}
|
|
6861
|
+
if (block2.kind !== "image") {
|
|
6862
|
+
throw new Document2CommandError("block_kind_mismatch", "Target block is not a figure");
|
|
6863
|
+
}
|
|
6864
|
+
if ("asset_id" in command) {
|
|
6865
|
+
if (command.asset_id === null) {
|
|
6866
|
+
delete block2.assetId;
|
|
6867
|
+
} else {
|
|
6868
|
+
block2.assetId = command.asset_id;
|
|
6869
|
+
}
|
|
6870
|
+
}
|
|
6871
|
+
if (command.value !== void 0) {
|
|
6872
|
+
block2.value = command.value;
|
|
6873
|
+
}
|
|
6874
|
+
return;
|
|
6875
|
+
}
|
|
6876
|
+
if (command.op === "update_float_meta") {
|
|
6877
|
+
const block2 = findBlock(document2.blocks, command.block_id);
|
|
6878
|
+
if (!block2) {
|
|
6879
|
+
throw new Document2CommandError("block_not_found", "Document block was not found");
|
|
6880
|
+
}
|
|
6881
|
+
if (block2.kind !== "image" && block2.kind !== "table") {
|
|
6882
|
+
throw new Document2CommandError("block_kind_mismatch", "Target block is not a figure or table");
|
|
6883
|
+
}
|
|
6884
|
+
let label = command.label;
|
|
6885
|
+
if (label !== void 0) {
|
|
6886
|
+
label = label.trim().length > 0 ? normalizeDocument2Key(label) : "";
|
|
6887
|
+
}
|
|
6888
|
+
if (label !== void 0 && label.length > 0) {
|
|
6889
|
+
const keyError = document2KeyError(label, {
|
|
6890
|
+
references: document2.references,
|
|
6891
|
+
labels: collectDocument2Labels(document2),
|
|
6892
|
+
excludeOwnerId: block2.id
|
|
6893
|
+
});
|
|
6894
|
+
if (keyError === "duplicate") {
|
|
6895
|
+
throw new Document2CommandError("duplicate_key", "Float label is already in use");
|
|
6896
|
+
}
|
|
6897
|
+
if (keyError !== null) {
|
|
6898
|
+
throw new Document2CommandError("invalid_key", "Float label is invalid");
|
|
6899
|
+
}
|
|
6900
|
+
}
|
|
6901
|
+
applyFloatMetaPatch(block2, {
|
|
6902
|
+
...command.centered !== void 0 ? { centered: command.centered } : {},
|
|
6903
|
+
...command.caption_enabled !== void 0 ? { captionEnabled: command.caption_enabled } : {},
|
|
6904
|
+
...command.caption !== void 0 ? { caption: command.caption } : {},
|
|
6905
|
+
...command.label_enabled !== void 0 ? { labelEnabled: command.label_enabled } : {},
|
|
6906
|
+
...label !== void 0 ? { label } : {}
|
|
6907
|
+
});
|
|
6908
|
+
return;
|
|
6909
|
+
}
|
|
6442
6910
|
const block = {
|
|
6443
6911
|
id: newBlockId(document2),
|
|
6444
6912
|
kind: "image",
|
|
@@ -6462,6 +6930,8 @@ function applyDocument2Command(json, commandInput) {
|
|
|
6462
6930
|
applyListCommand(document2, command);
|
|
6463
6931
|
} else if (isTableCommand(command)) {
|
|
6464
6932
|
applyTableCommand(document2, command);
|
|
6933
|
+
} else if (isArticleCommand(command)) {
|
|
6934
|
+
applyArticleCommand(document2, command);
|
|
6465
6935
|
} else {
|
|
6466
6936
|
applyBasicCommand(document2, command);
|
|
6467
6937
|
}
|
|
@@ -6542,52 +7012,6 @@ function document2Outline(json) {
|
|
|
6542
7012
|
});
|
|
6543
7013
|
}
|
|
6544
7014
|
|
|
6545
|
-
// src/document2/keys.ts
|
|
6546
|
-
var DOCUMENT2_KEY_PATTERN = /^[\p{L}\p{M}\p{Nd}:._-]+$/u;
|
|
6547
|
-
function normalizeDocument2Key(key) {
|
|
6548
|
-
return key.normalize("NFC").trim();
|
|
6549
|
-
}
|
|
6550
|
-
function isValidDocument2Key(key) {
|
|
6551
|
-
const normalized = normalizeDocument2Key(key);
|
|
6552
|
-
return normalized.length > 0 && DOCUMENT2_KEY_PATTERN.test(normalized);
|
|
6553
|
-
}
|
|
6554
|
-
function isDuplicateDocument2Key(key, namespace) {
|
|
6555
|
-
const normalized = normalizeDocument2Key(key);
|
|
6556
|
-
if (normalized.length === 0) {
|
|
6557
|
-
return false;
|
|
6558
|
-
}
|
|
6559
|
-
for (const reference of namespace.references ?? []) {
|
|
6560
|
-
if (namespace.excludeReferenceId && reference.id === namespace.excludeReferenceId) {
|
|
6561
|
-
continue;
|
|
6562
|
-
}
|
|
6563
|
-
if (normalizeDocument2Key(reference.key) === normalized) {
|
|
6564
|
-
return true;
|
|
6565
|
-
}
|
|
6566
|
-
}
|
|
6567
|
-
for (const label of namespace.labels ?? []) {
|
|
6568
|
-
if (namespace.excludeOwnerId && label.ownerId === namespace.excludeOwnerId) {
|
|
6569
|
-
continue;
|
|
6570
|
-
}
|
|
6571
|
-
if (normalizeDocument2Key(label.key) === normalized) {
|
|
6572
|
-
return true;
|
|
6573
|
-
}
|
|
6574
|
-
}
|
|
6575
|
-
return false;
|
|
6576
|
-
}
|
|
6577
|
-
function document2KeyError(key, namespace = {}) {
|
|
6578
|
-
const normalized = normalizeDocument2Key(key);
|
|
6579
|
-
if (normalized.length === 0) {
|
|
6580
|
-
return "empty";
|
|
6581
|
-
}
|
|
6582
|
-
if (!DOCUMENT2_KEY_PATTERN.test(normalized)) {
|
|
6583
|
-
return "invalid";
|
|
6584
|
-
}
|
|
6585
|
-
if (isDuplicateDocument2Key(normalized, namespace)) {
|
|
6586
|
-
return "duplicate";
|
|
6587
|
-
}
|
|
6588
|
-
return null;
|
|
6589
|
-
}
|
|
6590
|
-
|
|
6591
7015
|
// src/document2/arabicPreamble.ts
|
|
6592
7016
|
function fontOptions(digitsMapping, includeScript = true) {
|
|
6593
7017
|
const parts = [];
|
|
@@ -7595,6 +8019,7 @@ function blockPreview(block, islands, output, equationSide, document2, previewOp
|
|
|
7595
8019
|
src: block.value,
|
|
7596
8020
|
...block.assetId !== void 0 ? { assetId: block.assetId } : {},
|
|
7597
8021
|
options: block.options,
|
|
8022
|
+
centered: block.centered,
|
|
7598
8023
|
...block.captionEnabled && block.caption.trim().length > 0 ? { caption: block.caption.trim() } : {},
|
|
7599
8024
|
...label.length > 0 ? { label, numberLabel: floatNumberLabel(document2, label, previewOptions) } : {},
|
|
7600
8025
|
...block.metadata ? { metadata: { ...block.metadata } } : {}
|