@harbour-enterprises/superdoc 0.18.1-next.2 → 0.19.0-next.1
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/chunks/{PdfViewer-DPqO7muc.cjs → PdfViewer-C2T9YTtR.cjs} +1 -1
- package/dist/chunks/{PdfViewer-BM7Ea3yr.es.js → PdfViewer-DXueyp6G.es.js} +1 -1
- package/dist/chunks/{index-CyUWXfUG.es.js → index-DYPEIENP.es.js} +2 -2
- package/dist/chunks/{index-CPLP-MPz.cjs → index-Do3Yz9zO.cjs} +2 -2
- package/dist/chunks/{super-editor.es-CzgdqA6a.es.js → super-editor.es-BY32iqnX.es.js} +300 -1
- package/dist/chunks/{super-editor.es-BSOX4l_Z.cjs → super-editor.es-ehqZe3p-.cjs} +300 -1
- package/dist/core/SuperDoc.d.ts.map +1 -1
- package/dist/super-editor/ai-writer.es.js +1 -1
- package/dist/super-editor/chunks/{editor-BZitQIK-.js → editor-DJIu60o8.js} +300 -1
- package/dist/super-editor/chunks/{toolbar-D1SFDkxX.js → toolbar-DYCZq9kV.js} +1 -1
- package/dist/super-editor/editor.es.js +1 -1
- package/dist/super-editor/src/core/super-validator/validators/xml/index.d.ts +2 -0
- package/dist/super-editor/src/core/super-validator/validators/xml/relationships/relationships-validator.d.ts +31 -0
- package/dist/super-editor/super-editor.es.js +3 -3
- package/dist/super-editor/toolbar.es.js +2 -2
- package/dist/super-editor.cjs +1 -1
- package/dist/super-editor.es.js +1 -1
- package/dist/superdoc.cjs +2 -2
- package/dist/superdoc.es.js +2 -2
- package/dist/superdoc.umd.js +300 -1
- package/dist/superdoc.umd.js.map +1 -1
- package/package.json +1 -1
package/dist/superdoc.umd.js
CHANGED
|
@@ -54901,8 +54901,307 @@ Please report this to https://github.com/markedjs/marked.`, e) {
|
|
|
54901
54901
|
}
|
|
54902
54902
|
node2.elements = next;
|
|
54903
54903
|
}
|
|
54904
|
+
function createRelationshipsValidator({ editor, logger }) {
|
|
54905
|
+
return () => {
|
|
54906
|
+
const results = [];
|
|
54907
|
+
let modified = false;
|
|
54908
|
+
const convertedXml = editor?.converter?.convertedXml;
|
|
54909
|
+
if (!convertedXml || typeof convertedXml !== "object") {
|
|
54910
|
+
return { results, modified };
|
|
54911
|
+
}
|
|
54912
|
+
const { relsKey, wasNormalized } = findAndNormalizeRelationshipsFile(convertedXml, results);
|
|
54913
|
+
if (!relsKey) {
|
|
54914
|
+
return { results, modified };
|
|
54915
|
+
}
|
|
54916
|
+
if (wasNormalized) modified = true;
|
|
54917
|
+
const { root: root2, wasFixed } = validateRelationshipsRoot(convertedXml[relsKey], relsKey, results);
|
|
54918
|
+
if (!root2) {
|
|
54919
|
+
return { results, modified };
|
|
54920
|
+
}
|
|
54921
|
+
if (wasFixed) modified = true;
|
|
54922
|
+
const wasCleaned = cleanupRootChildren(root2);
|
|
54923
|
+
if (wasCleaned) modified = true;
|
|
54924
|
+
const { filteredIds, binMediaTargets, wasProcessed } = processRelationships(root2, convertedXml, results);
|
|
54925
|
+
if (wasProcessed) modified = true;
|
|
54926
|
+
const wasDocumentFixed = fixMissingDocumentRefs(convertedXml, filteredIds, results, logger);
|
|
54927
|
+
if (wasDocumentFixed) modified = true;
|
|
54928
|
+
const contentTypesKey = "[Content_Types].xml";
|
|
54929
|
+
const contentTypesXml = convertedXml[contentTypesKey];
|
|
54930
|
+
if (binMediaTargets.size > 0 || contentTypesXml) {
|
|
54931
|
+
const wasContentTypesUpdated = updateContentTypes(convertedXml, binMediaTargets, results);
|
|
54932
|
+
if (wasContentTypesUpdated) modified = true;
|
|
54933
|
+
} else {
|
|
54934
|
+
results.push("[Content_Types].xml not found or not parseable. Skipped content types patch.");
|
|
54935
|
+
}
|
|
54936
|
+
return { results, modified };
|
|
54937
|
+
};
|
|
54938
|
+
}
|
|
54939
|
+
function findAndNormalizeRelationshipsFile(convertedXml, results) {
|
|
54940
|
+
const candidateKeys = [
|
|
54941
|
+
"word/_rels/document.xml.rels",
|
|
54942
|
+
"word/document.xml.rels",
|
|
54943
|
+
"_rels/document.xml.rels",
|
|
54944
|
+
"document.xml.rels"
|
|
54945
|
+
];
|
|
54946
|
+
const relsKey = candidateKeys.find((k) => convertedXml?.[k]?.elements);
|
|
54947
|
+
if (!relsKey) return { relsKey: null, wasNormalized: false };
|
|
54948
|
+
const canonicalKey = "word/_rels/document.xml.rels";
|
|
54949
|
+
if (relsKey !== canonicalKey) {
|
|
54950
|
+
convertedXml[canonicalKey] = convertedXml[relsKey];
|
|
54951
|
+
delete convertedXml[relsKey];
|
|
54952
|
+
results.push(`Normalized relationships location to ${canonicalKey} (was ${relsKey})`);
|
|
54953
|
+
return { relsKey: canonicalKey, wasNormalized: true };
|
|
54954
|
+
}
|
|
54955
|
+
return { relsKey, wasNormalized: false };
|
|
54956
|
+
}
|
|
54957
|
+
function validateRelationshipsRoot(relsTree, relsKey, results) {
|
|
54958
|
+
const root2 = relsTree?.elements?.[0];
|
|
54959
|
+
if (!root2 || root2.type !== "element") {
|
|
54960
|
+
results.push(`${relsKey} is not a valid xml`);
|
|
54961
|
+
return { root: null, wasFixed: false };
|
|
54962
|
+
}
|
|
54963
|
+
const RELS_NS = "http://schemas.openxmlformats.org/package/2006/relationships";
|
|
54964
|
+
let wasFixed = false;
|
|
54965
|
+
if (root2.name !== "Relationships") {
|
|
54966
|
+
root2.name = "Relationships";
|
|
54967
|
+
results.push(`Fixed relationships root element name to "Relationships"`);
|
|
54968
|
+
wasFixed = true;
|
|
54969
|
+
}
|
|
54970
|
+
root2.attributes = root2.attributes || {};
|
|
54971
|
+
if (root2.attributes.xmlns !== RELS_NS) {
|
|
54972
|
+
root2.attributes.xmlns = RELS_NS;
|
|
54973
|
+
results.push(`Set relationships xmlns to ${RELS_NS}`);
|
|
54974
|
+
wasFixed = true;
|
|
54975
|
+
}
|
|
54976
|
+
return { root: root2, wasFixed };
|
|
54977
|
+
}
|
|
54978
|
+
function cleanupRootChildren(root2, results) {
|
|
54979
|
+
const validChildren = root2.elements?.filter((child) => child?.type === "element" && child.name === "Relationship") || [];
|
|
54980
|
+
if (root2.elements?.length !== validChildren.length) {
|
|
54981
|
+
root2.elements = validChildren;
|
|
54982
|
+
return true;
|
|
54983
|
+
}
|
|
54984
|
+
return false;
|
|
54985
|
+
}
|
|
54986
|
+
function processRelationships(root2, convertedXml, results) {
|
|
54987
|
+
const binMediaTargets = /* @__PURE__ */ new Set();
|
|
54988
|
+
const filteredIds = /* @__PURE__ */ new Set();
|
|
54989
|
+
let wasProcessed = false;
|
|
54990
|
+
const ridNum = (id) => {
|
|
54991
|
+
const m2 = /^rId(\d+)$/.exec(String(id || ""));
|
|
54992
|
+
return m2 ? parseInt(m2[1], 10) : null;
|
|
54993
|
+
};
|
|
54994
|
+
const isType2 = (type2, tail) => typeof type2 === "string" && new RegExp(`/relationships/${tail}$`, "i").test(type2);
|
|
54995
|
+
const isHyperlinkType = (type2) => isType2(type2, "hyperlink");
|
|
54996
|
+
const isImageType = (type2) => isType2(type2, "image");
|
|
54997
|
+
const looksExternal = (target) => /^https?:\/\//i.test(target || "") || /^mailto:/i.test(target || "");
|
|
54998
|
+
const usedIds = /* @__PURE__ */ new Set();
|
|
54999
|
+
let maxRid = 0;
|
|
55000
|
+
for (const el of root2.elements) {
|
|
55001
|
+
el.attributes = el.attributes || {};
|
|
55002
|
+
const id = el.attributes.Id;
|
|
55003
|
+
const n = ridNum(id);
|
|
55004
|
+
if (Number.isInteger(n)) maxRid = Math.max(maxRid, n);
|
|
55005
|
+
if (typeof id === "string" && id) {
|
|
55006
|
+
usedIds.add(id);
|
|
55007
|
+
}
|
|
55008
|
+
}
|
|
55009
|
+
let ridCounter = maxRid;
|
|
55010
|
+
const allocateId = (preferred) => {
|
|
55011
|
+
let newId;
|
|
55012
|
+
do {
|
|
55013
|
+
ridCounter += 1;
|
|
55014
|
+
newId = `rId${ridCounter}`;
|
|
55015
|
+
} while (usedIds.has(newId));
|
|
55016
|
+
usedIds.add(newId);
|
|
55017
|
+
return newId;
|
|
55018
|
+
};
|
|
55019
|
+
const seenIds = /* @__PURE__ */ new Set();
|
|
55020
|
+
const filtered = [];
|
|
55021
|
+
function extractStringAttr(attrs, key) {
|
|
55022
|
+
return typeof attrs[key] === "string" ? attrs[key].trim() : "";
|
|
55023
|
+
}
|
|
55024
|
+
for (const rel of root2.elements) {
|
|
55025
|
+
rel.attributes = rel.attributes || {};
|
|
55026
|
+
const attrs = rel.attributes;
|
|
55027
|
+
let id = extractStringAttr(attrs, "Id");
|
|
55028
|
+
const type2 = extractStringAttr(attrs, "Type");
|
|
55029
|
+
let target = extractStringAttr(attrs, "Target");
|
|
55030
|
+
let targetMode = extractStringAttr(attrs, "TargetMode");
|
|
55031
|
+
if (!target) {
|
|
55032
|
+
results.push(`Removed relationship "${id}" without Target`);
|
|
55033
|
+
wasProcessed = true;
|
|
55034
|
+
continue;
|
|
55035
|
+
}
|
|
55036
|
+
if (isHyperlinkType(type2) && looksExternal(target) && targetMode.toLowerCase() !== "external") {
|
|
55037
|
+
attrs.TargetMode = "External";
|
|
55038
|
+
targetMode = "External";
|
|
55039
|
+
results.push(`Set TargetMode="External" for hyperlink ${id}`);
|
|
55040
|
+
wasProcessed = true;
|
|
55041
|
+
}
|
|
55042
|
+
if (isImageType(type2)) {
|
|
55043
|
+
const relPath = `word/${target.replace(/^\.?\//, "")}`;
|
|
55044
|
+
if (/^media\/.+\.bin$/i.test(target) && relPath in convertedXml) {
|
|
55045
|
+
binMediaTargets.add(`/${relPath}`);
|
|
55046
|
+
}
|
|
55047
|
+
}
|
|
55048
|
+
if (targetMode.toLowerCase() !== "external" && !looksExternal(target)) {
|
|
55049
|
+
const likelyPath = `word/${target.replace(/^\.?\//, "")}`;
|
|
55050
|
+
if (!(likelyPath in convertedXml)) {
|
|
55051
|
+
if (!isImageType(type2)) {
|
|
55052
|
+
results.push(`Removed relationship ${id} with missing target: ${target}`);
|
|
55053
|
+
wasProcessed = true;
|
|
55054
|
+
continue;
|
|
55055
|
+
} else {
|
|
55056
|
+
results.push(`Warning: image relationship ${id} target not found: ${target}.`);
|
|
55057
|
+
}
|
|
55058
|
+
}
|
|
55059
|
+
}
|
|
55060
|
+
if (!id) {
|
|
55061
|
+
const newId = allocateId();
|
|
55062
|
+
attrs.Id = newId;
|
|
55063
|
+
results.push(`Assigned missing Id "${newId}"`);
|
|
55064
|
+
wasProcessed = true;
|
|
55065
|
+
id = newId;
|
|
55066
|
+
}
|
|
55067
|
+
if (seenIds.has(id)) {
|
|
55068
|
+
results.push(`Removed duplicate relationship with ID "${id}"`);
|
|
55069
|
+
wasProcessed = true;
|
|
55070
|
+
continue;
|
|
55071
|
+
}
|
|
55072
|
+
seenIds.add(id);
|
|
55073
|
+
filtered.push(rel);
|
|
55074
|
+
}
|
|
55075
|
+
if (root2.elements.length !== filtered.length) {
|
|
55076
|
+
root2.elements = filtered;
|
|
55077
|
+
wasProcessed = true;
|
|
55078
|
+
} else {
|
|
55079
|
+
const contentChanged = root2.elements.some((el, i2) => el !== filtered[i2]);
|
|
55080
|
+
if (contentChanged) {
|
|
55081
|
+
root2.elements = filtered;
|
|
55082
|
+
wasProcessed = true;
|
|
55083
|
+
}
|
|
55084
|
+
}
|
|
55085
|
+
for (const rel of root2.elements) {
|
|
55086
|
+
const id = rel.attributes?.Id;
|
|
55087
|
+
if (typeof id === "string" && id) {
|
|
55088
|
+
filteredIds.add(id);
|
|
55089
|
+
}
|
|
55090
|
+
}
|
|
55091
|
+
return { filteredIds, binMediaTargets, wasProcessed };
|
|
55092
|
+
}
|
|
55093
|
+
function fixMissingDocumentRefs(convertedXml, filteredIds, results, logger) {
|
|
55094
|
+
const documentPath = "word/document.xml";
|
|
55095
|
+
const document2 = convertedXml[documentPath];
|
|
55096
|
+
if (document2?.elements?.length) {
|
|
55097
|
+
const documentRoot = document2.elements[0];
|
|
55098
|
+
if (documentRoot?.type === "element") {
|
|
55099
|
+
const missingRefs = [];
|
|
55100
|
+
processDocumentForMissingRefs(documentRoot, filteredIds, missingRefs);
|
|
55101
|
+
if (missingRefs.length) {
|
|
55102
|
+
results.push(`Fixed ${missingRefs.length} missing relationship references`);
|
|
55103
|
+
logger?.debug?.(`Fixed ${missingRefs.length} missing relationship references in document`);
|
|
55104
|
+
return true;
|
|
55105
|
+
}
|
|
55106
|
+
}
|
|
55107
|
+
}
|
|
55108
|
+
return false;
|
|
55109
|
+
}
|
|
55110
|
+
function updateContentTypes(convertedXml, binMediaTargets, results) {
|
|
55111
|
+
const contentTypesKey = "[Content_Types].xml";
|
|
55112
|
+
const contentTypesXml = convertedXml[contentTypesKey];
|
|
55113
|
+
if (typeof contentTypesXml === "string") {
|
|
55114
|
+
return updateContentTypesString(contentTypesXml, binMediaTargets, results, convertedXml, contentTypesKey);
|
|
55115
|
+
} else if (contentTypesXml?.elements?.length) {
|
|
55116
|
+
return updateContentTypesElements(contentTypesXml, binMediaTargets, results);
|
|
55117
|
+
} else {
|
|
55118
|
+
return false;
|
|
55119
|
+
}
|
|
55120
|
+
}
|
|
55121
|
+
function updateContentTypesString(contentTypesXml, binMediaTargets, results, convertedXml, contentTypesKey) {
|
|
55122
|
+
const CONTENT_TYPES_NS = '<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">';
|
|
55123
|
+
const ensureDefault = (xmlString, ext, contentType) => {
|
|
55124
|
+
const defRe = new RegExp(`<Default\\s+Extension="${ext}"\\b`, "i");
|
|
55125
|
+
if (defRe.test(xmlString)) return xmlString;
|
|
55126
|
+
return xmlString.replace(
|
|
55127
|
+
CONTENT_TYPES_NS,
|
|
55128
|
+
`${CONTENT_TYPES_NS}<Default Extension="${ext}" ContentType="${contentType}"/>`
|
|
55129
|
+
);
|
|
55130
|
+
};
|
|
55131
|
+
const ensureOverride = (xmlString, partName, contentType) => {
|
|
55132
|
+
const esc = partName.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
55133
|
+
const ovRe = new RegExp(`<Override\\s+PartName="${esc}"\\b`, "i");
|
|
55134
|
+
if (ovRe.test(xmlString)) return xmlString;
|
|
55135
|
+
return xmlString.replace(
|
|
55136
|
+
CONTENT_TYPES_NS,
|
|
55137
|
+
`${CONTENT_TYPES_NS}<Override PartName="${partName}" ContentType="${contentType}" />`
|
|
55138
|
+
);
|
|
55139
|
+
};
|
|
55140
|
+
let updated = contentTypesXml;
|
|
55141
|
+
updated = ensureDefault(updated, "rels", "application/vnd.openxmlformats-package.relationships+xml");
|
|
55142
|
+
updated = ensureDefault(updated, "xml", "application/xml");
|
|
55143
|
+
for (const partName of binMediaTargets) {
|
|
55144
|
+
updated = ensureOverride(updated, partName, "image/png");
|
|
55145
|
+
results.push(`Added Content Types Override for "${partName}" as image/png`);
|
|
55146
|
+
}
|
|
55147
|
+
if (updated !== contentTypesXml) {
|
|
55148
|
+
convertedXml[contentTypesKey] = updated;
|
|
55149
|
+
return true;
|
|
55150
|
+
}
|
|
55151
|
+
return false;
|
|
55152
|
+
}
|
|
55153
|
+
function updateContentTypesElements(contentTypesXml, binMediaTargets, results) {
|
|
55154
|
+
const typesRoot = contentTypesXml.elements.find((el) => el.name === "Types") || contentTypesXml.elements[0];
|
|
55155
|
+
typesRoot.elements = typesRoot.elements || [];
|
|
55156
|
+
const hasDefault = (ext) => typesRoot.elements.some((el) => el.name === "Default" && el.attributes?.Extension === ext);
|
|
55157
|
+
const addDefault = (ext, ct) => {
|
|
55158
|
+
typesRoot.elements.unshift({
|
|
55159
|
+
type: "element",
|
|
55160
|
+
name: "Default",
|
|
55161
|
+
attributes: { Extension: ext, ContentType: ct }
|
|
55162
|
+
});
|
|
55163
|
+
};
|
|
55164
|
+
const hasOverride = (part) => typesRoot.elements.some((el) => el.name === "Override" && el.attributes?.PartName === part);
|
|
55165
|
+
const addOverride = (part, ct) => {
|
|
55166
|
+
typesRoot.elements.unshift({
|
|
55167
|
+
type: "element",
|
|
55168
|
+
name: "Override",
|
|
55169
|
+
attributes: { PartName: part, ContentType: ct }
|
|
55170
|
+
});
|
|
55171
|
+
};
|
|
55172
|
+
let wasUpdated = false;
|
|
55173
|
+
if (!hasDefault("rels")) {
|
|
55174
|
+
addDefault("rels", "application/vnd.openxmlformats-package.relationships+xml");
|
|
55175
|
+
wasUpdated = true;
|
|
55176
|
+
}
|
|
55177
|
+
if (!hasDefault("xml")) {
|
|
55178
|
+
addDefault("xml", "application/xml");
|
|
55179
|
+
wasUpdated = true;
|
|
55180
|
+
}
|
|
55181
|
+
for (const partName of binMediaTargets) {
|
|
55182
|
+
if (!hasOverride(partName)) {
|
|
55183
|
+
addOverride(partName, "image/png");
|
|
55184
|
+
results.push(`Added Content Types Override for "${partName}" as image/png`);
|
|
55185
|
+
wasUpdated = true;
|
|
55186
|
+
}
|
|
55187
|
+
}
|
|
55188
|
+
return wasUpdated;
|
|
55189
|
+
}
|
|
55190
|
+
function processDocumentForMissingRefs(node2, usedIds, fixed) {
|
|
55191
|
+
if (!node2?.elements?.length) return;
|
|
55192
|
+
for (const element of node2.elements) {
|
|
55193
|
+
if (element?.type !== "element") continue;
|
|
55194
|
+
const rIdValue = element.attributes?.["r:id"];
|
|
55195
|
+
if (typeof rIdValue === "string" && !usedIds.has(rIdValue)) {
|
|
55196
|
+
delete element.attributes["r:id"];
|
|
55197
|
+
fixed.push(`Removed invalid r:id="${rIdValue}"`);
|
|
55198
|
+
}
|
|
55199
|
+
processDocumentForMissingRefs(element, usedIds, fixed);
|
|
55200
|
+
}
|
|
55201
|
+
}
|
|
54904
55202
|
const XmlValidators = {
|
|
54905
|
-
numberingValidator: createNumberingValidator
|
|
55203
|
+
numberingValidator: createNumberingValidator,
|
|
55204
|
+
relationshipsValidator: createRelationshipsValidator
|
|
54906
55205
|
};
|
|
54907
55206
|
class SuperValidator {
|
|
54908
55207
|
/**
|