@superdoc/mcp 1.5.0-next.5 → 1.5.0-next.6
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/index.js +907 -749
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -31443,7 +31443,7 @@ var init_host = __esm(() => {
|
|
|
31443
31443
|
});
|
|
31444
31444
|
|
|
31445
31445
|
// ../../packages/sdk/langs/node/src/runtime/sdk-version.generated.ts
|
|
31446
|
-
var SDK_VERSION = "2.18.0-next.
|
|
31446
|
+
var SDK_VERSION = "2.18.0-next.6";
|
|
31447
31447
|
|
|
31448
31448
|
// ../../packages/sdk/langs/node/src/runtime/embedded-platform.ts
|
|
31449
31449
|
import { accessSync, chmodSync, constants, existsSync, statSync } from "node:fs";
|
|
@@ -164868,6 +164868,39 @@ function stripParagraphPropertyChange(pPrXml) {
|
|
|
164868
164868
|
const stripped = pPrXml.slice(0, open.index) + pPrXml.slice(end);
|
|
164869
164869
|
return /^<([\w.-]+):pPr\b[^>]*>\s*<\/\1:pPr>$/.test(stripped.trim()) ? "" : stripped;
|
|
164870
164870
|
}
|
|
164871
|
+
function replaceDirectParagraphStyleId(pPrXml, newStyleId) {
|
|
164872
|
+
const pPr = readValidatedXmlNodeAt(pPrXml, 0);
|
|
164873
|
+
if (!pPr || pPr.kind !== "element" || xmlLocalName(pPr.qname) !== "pPr" || pPr.selfClosing) {
|
|
164874
|
+
return pPrXml;
|
|
164875
|
+
}
|
|
164876
|
+
let cursor = pPr.openEnd;
|
|
164877
|
+
while (cursor < pPr.closeStart) {
|
|
164878
|
+
const childStart = pPrXml.indexOf("<", cursor);
|
|
164879
|
+
if (childStart < 0 || childStart >= pPr.closeStart)
|
|
164880
|
+
return pPrXml;
|
|
164881
|
+
const child = readValidatedXmlNodeAt(pPrXml, childStart);
|
|
164882
|
+
if (!child || child.end > pPr.closeStart)
|
|
164883
|
+
return pPrXml;
|
|
164884
|
+
if (child.kind === "element" && xmlLocalName(child.qname) === "pStyle") {
|
|
164885
|
+
const openTag = pPrXml.slice(childStart, child.openEnd);
|
|
164886
|
+
let valAttr;
|
|
164887
|
+
for (const attribute of scanRawXmlAttributes(openTag)) {
|
|
164888
|
+
if (attribute.name === "xmlns" || attribute.prefix === "xmlns")
|
|
164889
|
+
continue;
|
|
164890
|
+
if (attribute.localName === "val") {
|
|
164891
|
+
valAttr = attribute;
|
|
164892
|
+
break;
|
|
164893
|
+
}
|
|
164894
|
+
}
|
|
164895
|
+
if (!valAttr)
|
|
164896
|
+
return pPrXml;
|
|
164897
|
+
const rewrittenOpenTag = openTag.slice(0, valAttr.valueStart) + escapeXmlAttribute(newStyleId) + openTag.slice(valAttr.valueEnd);
|
|
164898
|
+
return pPrXml.slice(0, childStart) + rewrittenOpenTag + pPrXml.slice(child.openEnd);
|
|
164899
|
+
}
|
|
164900
|
+
cursor = child.end;
|
|
164901
|
+
}
|
|
164902
|
+
return pPrXml;
|
|
164903
|
+
}
|
|
164871
164904
|
function stripParagraphMarkRevisionMarkers(pPrXml, inheritedNamespaceBindings = {}) {
|
|
164872
164905
|
if (!pPrXml)
|
|
164873
164906
|
return pPrXml;
|
|
@@ -214889,7 +214922,7 @@ function sliceParagraphContentAt(input) {
|
|
|
214889
214922
|
const plan = planCut(map3.pieces, regionStart, input, map3.pieces);
|
|
214890
214923
|
if (plan.kind === "reject")
|
|
214891
214924
|
return { ok: false, reason: plan.reason };
|
|
214892
|
-
return assembleHalves(src, regionStart, regionEnd, plan);
|
|
214925
|
+
return { ...assembleHalves(src, regionStart, regionEnd, plan), terminal: input.offset === total };
|
|
214893
214926
|
}
|
|
214894
214927
|
function pieceStart(piece, input, rootPieces) {
|
|
214895
214928
|
const base2 = input.space === "tracked" ? piece.trackedStart : piece.visibleStart;
|
|
@@ -215869,6 +215902,566 @@ var init_paragraph_drawing_delete = __esm(() => {
|
|
|
215869
215902
|
init_tracked_paragraph_content();
|
|
215870
215903
|
});
|
|
215871
215904
|
|
|
215905
|
+
// ../../../v2/editor-core/dist/document/transactions/insertion-formatting-context.js
|
|
215906
|
+
function resolveInsertionFormattingContext(state, input) {
|
|
215907
|
+
const inheritance = input.inheritance ?? "anchor";
|
|
215908
|
+
const numberingProperties = input.numberingProperties ?? null;
|
|
215909
|
+
const paragraphXml = input.anchor ? readAnchorParagraphXml(state, input.anchor.entry) : null;
|
|
215910
|
+
if (input.anchor && paragraphXml == null && !input.styleRef) {
|
|
215911
|
+
return { ok: false, reason: "paragraph-target-not-found" };
|
|
215912
|
+
}
|
|
215913
|
+
const style = resolveInsertionStyle(state, paragraphXml, input.anchor, input.styleRef, inheritance, input.fallbackToDocumentDefaultStyle ?? false);
|
|
215914
|
+
if (!style.ok)
|
|
215915
|
+
return style;
|
|
215916
|
+
const direct = inheritance === "anchor" && paragraphXml != null ? resolveDirectInsertionFormatting(paragraphXml, input.anchor.placement, readAnchorNamespaceBindings(state, input.anchor.entry)) : {
|
|
215917
|
+
paragraphPropertiesXml: null,
|
|
215918
|
+
paragraphMarkRunPropertiesXml: null,
|
|
215919
|
+
runPropertiesXml: null,
|
|
215920
|
+
skippedReason: directFormattingSkippedReason(inheritance)
|
|
215921
|
+
};
|
|
215922
|
+
if ("reason" in direct)
|
|
215923
|
+
return direct;
|
|
215924
|
+
const paragraphPropertiesXml = composeParagraphPropertiesXml({
|
|
215925
|
+
styleId: style.styleId,
|
|
215926
|
+
numberingProperties,
|
|
215927
|
+
inheritedParagraphPropertiesXml: direct.paragraphPropertiesXml
|
|
215928
|
+
});
|
|
215929
|
+
return {
|
|
215930
|
+
ok: true,
|
|
215931
|
+
context: {
|
|
215932
|
+
styleId: style.styleId,
|
|
215933
|
+
numberingProperties,
|
|
215934
|
+
paragraphPropertiesXml,
|
|
215935
|
+
runPropertiesXml: direct.runPropertiesXml,
|
|
215936
|
+
provenance: {
|
|
215937
|
+
inheritedParagraphProperties: direct.paragraphPropertiesXml != null,
|
|
215938
|
+
inheritedParagraphMarkProperties: direct.paragraphMarkRunPropertiesXml != null,
|
|
215939
|
+
inheritedRunProperties: direct.runPropertiesXml != null,
|
|
215940
|
+
explicitStyleOverride: Boolean(input.styleRef),
|
|
215941
|
+
explicitNumberingOverride: numberingProperties != null,
|
|
215942
|
+
...direct.skippedReason ? { skippedReason: direct.skippedReason } : {}
|
|
215943
|
+
}
|
|
215944
|
+
}
|
|
215945
|
+
};
|
|
215946
|
+
}
|
|
215947
|
+
function directFormattingSkippedReason(inheritance) {
|
|
215948
|
+
if (inheritance === "style")
|
|
215949
|
+
return "direct-inheritance-disabled";
|
|
215950
|
+
if (inheritance === "none")
|
|
215951
|
+
return "inheritance-disabled";
|
|
215952
|
+
return "no-anchor";
|
|
215953
|
+
}
|
|
215954
|
+
function readAnchorParagraphXml(state, entry) {
|
|
215955
|
+
const bytes = state.packageBytes.get(entry.partUri);
|
|
215956
|
+
if (!bytes)
|
|
215957
|
+
return null;
|
|
215958
|
+
if (entry.byteEnd <= entry.byteStart)
|
|
215959
|
+
return "";
|
|
215960
|
+
return TD51.decode(bytes.subarray(entry.byteStart, entry.byteEnd));
|
|
215961
|
+
}
|
|
215962
|
+
function readAnchorNamespaceBindings(state, entry) {
|
|
215963
|
+
const mainOverlay = state.mainStorySourceOverlay;
|
|
215964
|
+
if (entry.directBodyChildOrdinal != null && mainOverlay?.partUri === entry.partUri && mainOverlay.storyId === entry.storyId) {
|
|
215965
|
+
return mainOverlay.rootNamespaceBindings;
|
|
215966
|
+
}
|
|
215967
|
+
const bytes = state.packageBytes.get(entry.partUri);
|
|
215968
|
+
return bytes ? namespaceBindingsAtPosition(bytes, entry.byteStart) : {};
|
|
215969
|
+
}
|
|
215970
|
+
function resolveInsertionStyle(state, anchorParagraphXml, anchor, explicitStyleRef, inheritance, fallbackToDocumentDefaultStyle) {
|
|
215971
|
+
if (explicitStyleRef)
|
|
215972
|
+
return { ok: true, styleId: explicitStyleRef };
|
|
215973
|
+
if (!anchor || inheritance === "none") {
|
|
215974
|
+
return {
|
|
215975
|
+
ok: true,
|
|
215976
|
+
styleId: fallbackToDocumentDefaultStyle ? resolveDefaultParagraphStyleId(state) : null
|
|
215977
|
+
};
|
|
215978
|
+
}
|
|
215979
|
+
if (anchorParagraphXml == null)
|
|
215980
|
+
return { ok: false, reason: "paragraph-target-not-found" };
|
|
215981
|
+
const paragraphStyle = readDirectParagraphStyleId(anchorParagraphXml);
|
|
215982
|
+
if (paragraphStyle.presence === "malformed") {
|
|
215983
|
+
return { ok: false, reason: "paragraph-style-ambiguous" };
|
|
215984
|
+
}
|
|
215985
|
+
const targetStyle = paragraphStyle.styleId;
|
|
215986
|
+
if (anchor.placement === "after" && targetStyle) {
|
|
215987
|
+
const next = lookupNextStyle(state, targetStyle);
|
|
215988
|
+
if (!next.ok)
|
|
215989
|
+
return next;
|
|
215990
|
+
if (next.styleId)
|
|
215991
|
+
return { ok: true, styleId: next.styleId };
|
|
215992
|
+
}
|
|
215993
|
+
if (targetStyle)
|
|
215994
|
+
return { ok: true, styleId: targetStyle };
|
|
215995
|
+
return {
|
|
215996
|
+
ok: true,
|
|
215997
|
+
styleId: fallbackToDocumentDefaultStyle ? resolveDefaultParagraphStyleId(state) : null
|
|
215998
|
+
};
|
|
215999
|
+
}
|
|
216000
|
+
function resolveDefaultParagraphStyleId(state) {
|
|
216001
|
+
const defaultStyle = resolveDefaultParagraphStyle(state);
|
|
216002
|
+
return defaultStyle.ok ? defaultStyle.styleId ?? "Normal" : "Normal";
|
|
216003
|
+
}
|
|
216004
|
+
function resolveDefaultParagraphStyle(state) {
|
|
216005
|
+
const inspection = inspectStyleDefinitionsPartUriFromState(state);
|
|
216006
|
+
if (!inspection.valid)
|
|
216007
|
+
return { ok: true, styleId: null };
|
|
216008
|
+
const bytes = inspection.partUri ? ensurePackagePartBytes(state, inspection.partUri) : null;
|
|
216009
|
+
if (!bytes)
|
|
216010
|
+
return { ok: true, styleId: null };
|
|
216011
|
+
const xml = TD51.decode(bytes);
|
|
216012
|
+
const namespaceUri = inspectStyleDefinitionsXmlDialect(xml);
|
|
216013
|
+
if (!namespaceUri)
|
|
216014
|
+
return { ok: true, styleId: null };
|
|
216015
|
+
let depth = 0;
|
|
216016
|
+
const defaults = [];
|
|
216017
|
+
let valid = true;
|
|
216018
|
+
const parsed = walkXmlElements(xml, {
|
|
216019
|
+
onOpenTag({ tag }) {
|
|
216020
|
+
depth += 1;
|
|
216021
|
+
if (depth !== 2 || tag.namespaceUri !== namespaceUri || tag.localName !== "style")
|
|
216022
|
+
return;
|
|
216023
|
+
if (readWordAttribute2(tag, namespaceUri, "type") !== "paragraph" || !["1", "true", "on"].includes(readWordAttribute2(tag, namespaceUri, "default") ?? ""))
|
|
216024
|
+
return;
|
|
216025
|
+
const id = readWordAttribute2(tag, namespaceUri, "styleId");
|
|
216026
|
+
if (!id)
|
|
216027
|
+
valid = false;
|
|
216028
|
+
else
|
|
216029
|
+
defaults.push(id);
|
|
216030
|
+
},
|
|
216031
|
+
onCloseTag() {
|
|
216032
|
+
depth -= 1;
|
|
216033
|
+
}
|
|
216034
|
+
});
|
|
216035
|
+
if (!valid || parsed.errors.length || defaults.length > 1)
|
|
216036
|
+
return { ok: true, styleId: null };
|
|
216037
|
+
return { ok: true, styleId: defaults[0] ?? null };
|
|
216038
|
+
}
|
|
216039
|
+
function lookupNextStyle(state, styleId) {
|
|
216040
|
+
const inspection = inspectStyleDefinitionsPartUriFromState(state);
|
|
216041
|
+
if (!inspection.valid)
|
|
216042
|
+
return { ok: false, reason: "paragraph-style-ambiguous" };
|
|
216043
|
+
const stylesBytes = inspection.partUri ? ensurePackagePartBytes(state, inspection.partUri) : null;
|
|
216044
|
+
if (!stylesBytes)
|
|
216045
|
+
return { ok: true, styleId: null };
|
|
216046
|
+
const xml = TD51.decode(stylesBytes);
|
|
216047
|
+
const namespaceUri = inspectStyleDefinitionsXmlDialect(xml);
|
|
216048
|
+
if (!namespaceUri)
|
|
216049
|
+
return { ok: false, reason: "paragraph-style-ambiguous" };
|
|
216050
|
+
let depth = 0;
|
|
216051
|
+
let targetStyleDepth = -1;
|
|
216052
|
+
let foundTargetStyle = false;
|
|
216053
|
+
let nextStyleId = null;
|
|
216054
|
+
const parsed = walkXmlElements(xml, {
|
|
216055
|
+
onOpenTag({ tag }) {
|
|
216056
|
+
depth += 1;
|
|
216057
|
+
if (!foundTargetStyle && depth === 2 && tag.namespaceUri === namespaceUri && tag.localName === "style" && readWordAttribute2(tag, namespaceUri, "styleId") === styleId) {
|
|
216058
|
+
foundTargetStyle = true;
|
|
216059
|
+
targetStyleDepth = depth;
|
|
216060
|
+
return;
|
|
216061
|
+
}
|
|
216062
|
+
if (targetStyleDepth >= 0 && depth === targetStyleDepth + 1 && tag.namespaceUri === namespaceUri && tag.localName === "next") {
|
|
216063
|
+
nextStyleId = readWordAttribute2(tag, namespaceUri, "val") ?? null;
|
|
216064
|
+
}
|
|
216065
|
+
},
|
|
216066
|
+
onCloseTag({ tag }) {
|
|
216067
|
+
if (depth === targetStyleDepth && tag.localName === "style")
|
|
216068
|
+
targetStyleDepth = -1;
|
|
216069
|
+
depth -= 1;
|
|
216070
|
+
}
|
|
216071
|
+
});
|
|
216072
|
+
if (parsed.errors.length > 0)
|
|
216073
|
+
return { ok: false, reason: "paragraph-style-ambiguous" };
|
|
216074
|
+
return { ok: true, styleId: nextStyleId };
|
|
216075
|
+
}
|
|
216076
|
+
function readWordAttribute2(tag, namespaceUri, localName2) {
|
|
216077
|
+
return readXmlAttribute(tag, namespaceUri, localName2)?.value;
|
|
216078
|
+
}
|
|
216079
|
+
function resolveDirectInsertionFormatting(paragraphXml, placement2, inheritedNamespaceBindings = {}) {
|
|
216080
|
+
const paragraphPropertiesXml = cloneDirectParagraphPropertiesForInsert(paragraphXml);
|
|
216081
|
+
const paragraphMarkRunPropertiesXml = cloneParagraphMarkRunPropertiesForInsert(paragraphXml);
|
|
216082
|
+
const adjacentRunProperties = cloneAdjacentRunPropertiesForInsert(paragraphXml, placement2, paragraphMarkRunPropertiesXml, inheritedNamespaceBindings);
|
|
216083
|
+
if (!adjacentRunProperties.ok)
|
|
216084
|
+
return adjacentRunProperties;
|
|
216085
|
+
const runPropertiesXml = adjacentRunProperties.runPropertiesXml;
|
|
216086
|
+
return {
|
|
216087
|
+
paragraphPropertiesXml,
|
|
216088
|
+
paragraphMarkRunPropertiesXml,
|
|
216089
|
+
runPropertiesXml,
|
|
216090
|
+
...!paragraphPropertiesXml && !runPropertiesXml ? { skippedReason: "no-direct-formatting" } : {}
|
|
216091
|
+
};
|
|
216092
|
+
}
|
|
216093
|
+
function cloneAdjacentRunPropertiesCarrierForInsertion(paragraphXml, placement2, inheritedNamespaceBindings = {}) {
|
|
216094
|
+
const paragraphWithoutNestedTextboxes = stripElements(paragraphXml, "txbxContent");
|
|
216095
|
+
const run = adjacentFormattingCarrierRun(paragraphWithoutNestedTextboxes, placement2, inheritedNamespaceBindings);
|
|
216096
|
+
if (!run.ok)
|
|
216097
|
+
return run;
|
|
216098
|
+
if (!run.run)
|
|
216099
|
+
return { ok: true, carrier: null };
|
|
216100
|
+
const carrierRun = run.run;
|
|
216101
|
+
const runPropertiesXml = readRunPropertiesXml(carrierRun.xml);
|
|
216102
|
+
if (!runPropertiesXml)
|
|
216103
|
+
return { ok: true, carrier: null };
|
|
216104
|
+
const namespaceSource = namespaceSourceForRunProperties(paragraphWithoutNestedTextboxes, carrierRun, runPropertiesXml, inheritedNamespaceBindings);
|
|
216105
|
+
if (!namespaceSource)
|
|
216106
|
+
return { ok: true, carrier: null };
|
|
216107
|
+
const { openTag: namespaceSourceOpenTag, hasParagraphRootMarkupCompatibilityAttributes, hasInheritedMarkupCompatibilityAttributes, hasUnresolvedInheritedAttributeNamespaces } = namespaceSource;
|
|
216108
|
+
const hasForeignRevisionLikeRunProperties = runPropertiesContainForeignRevisionLikeElement(runPropertiesXml, namespaceSourceOpenTag);
|
|
216109
|
+
if (hasForeignRevisionLikeRunProperties == null)
|
|
216110
|
+
return { ok: true, carrier: null };
|
|
216111
|
+
if (hasForeignRevisionLikeRunProperties) {
|
|
216112
|
+
return {
|
|
216113
|
+
ok: true,
|
|
216114
|
+
carrier: {
|
|
216115
|
+
runPropertiesXml,
|
|
216116
|
+
namespaceSourceOpenTag,
|
|
216117
|
+
hasForeignRevisionLikeRunProperties,
|
|
216118
|
+
hasNonWordMarkup: runPropertiesContainNonWordMarkup(runPropertiesXml, namespaceSourceOpenTag),
|
|
216119
|
+
hasParagraphRootMarkupCompatibilityAttributes,
|
|
216120
|
+
hasInheritedMarkupCompatibilityAttributes,
|
|
216121
|
+
hasUnresolvedInheritedAttributeNamespaces
|
|
216122
|
+
}
|
|
216123
|
+
};
|
|
216124
|
+
}
|
|
216125
|
+
const normalizedRunProperties = normalizeClonedRunProperties(runPropertiesXml);
|
|
216126
|
+
const normalizedRunPropertiesXml = normalizedRunProperties && carrierRun.insideHyperlink ? stripHyperlinkRunStyle(normalizedRunProperties, namespaceSourceOpenTag) : normalizedRunProperties;
|
|
216127
|
+
return {
|
|
216128
|
+
ok: true,
|
|
216129
|
+
carrier: normalizedRunPropertiesXml ? {
|
|
216130
|
+
runPropertiesXml: normalizedRunPropertiesXml,
|
|
216131
|
+
namespaceSourceOpenTag,
|
|
216132
|
+
hasForeignRevisionLikeRunProperties: false,
|
|
216133
|
+
hasNonWordMarkup: runPropertiesContainNonWordMarkup(normalizedRunPropertiesXml, namespaceSourceOpenTag),
|
|
216134
|
+
hasParagraphRootMarkupCompatibilityAttributes,
|
|
216135
|
+
hasInheritedMarkupCompatibilityAttributes,
|
|
216136
|
+
hasUnresolvedInheritedAttributeNamespaces
|
|
216137
|
+
} : null
|
|
216138
|
+
};
|
|
216139
|
+
}
|
|
216140
|
+
function cloneDirectParagraphPropertiesForInsert(paraXml) {
|
|
216141
|
+
const inner = paragraphInnerXml(paraXml);
|
|
216142
|
+
if (inner == null)
|
|
216143
|
+
return null;
|
|
216144
|
+
const { pPr } = splitLeadingParagraphPropertyBlock(inner);
|
|
216145
|
+
if (!pPr)
|
|
216146
|
+
return null;
|
|
216147
|
+
let direct = stripParagraphPropertyChange(pPr);
|
|
216148
|
+
if (!direct)
|
|
216149
|
+
return null;
|
|
216150
|
+
for (const localName2 of ["pStyle", "numPr", "sectPr"]) {
|
|
216151
|
+
direct = stripElements(direct, localName2);
|
|
216152
|
+
}
|
|
216153
|
+
direct = replaceParagraphMarkRunProperties(direct);
|
|
216154
|
+
return paragraphPropertiesXmlIsEmpty(direct) ? null : direct;
|
|
216155
|
+
}
|
|
216156
|
+
function replaceParagraphMarkRunProperties(pPrXml) {
|
|
216157
|
+
const markProperties = extractParagraphMarkRunProperties(pPrXml);
|
|
216158
|
+
if (markProperties == null)
|
|
216159
|
+
return stripElements(pPrXml, "rPr");
|
|
216160
|
+
const span = topLevelMarkRPrSpan(pPrXml);
|
|
216161
|
+
if (!span)
|
|
216162
|
+
return pPrXml;
|
|
216163
|
+
return pPrXml.slice(0, span.start) + markProperties + pPrXml.slice(span.end);
|
|
216164
|
+
}
|
|
216165
|
+
function topLevelMarkRPrSpan(pPrXml) {
|
|
216166
|
+
const changeOffset = pPrXml.search(/<[\w.-]+:pPrChange\b/);
|
|
216167
|
+
const limit = changeOffset >= 0 ? changeOffset : pPrXml.length;
|
|
216168
|
+
const openOffset = pPrXml.search(/<[\w.-]+:rPr\b/);
|
|
216169
|
+
if (openOffset < 0 || openOffset >= limit)
|
|
216170
|
+
return null;
|
|
216171
|
+
const span = matchLeadingElement(pPrXml.slice(openOffset), "rPr");
|
|
216172
|
+
if (!span)
|
|
216173
|
+
return null;
|
|
216174
|
+
return { start: openOffset, end: openOffset + span.length };
|
|
216175
|
+
}
|
|
216176
|
+
function cloneAdjacentRunPropertiesForInsert(paraXml, placement2, paragraphMarkRunPropertiesXml, inheritedNamespaceBindings = {}) {
|
|
216177
|
+
const carrierResult = cloneAdjacentRunPropertiesCarrierForInsertion(paraXml, placement2, inheritedNamespaceBindings);
|
|
216178
|
+
if (!carrierResult.ok)
|
|
216179
|
+
return carrierResult;
|
|
216180
|
+
const carrier = carrierResult.carrier;
|
|
216181
|
+
if (!carrier) {
|
|
216182
|
+
return {
|
|
216183
|
+
ok: true,
|
|
216184
|
+
runPropertiesXml: paragraphMarkRunPropertiesXml || null
|
|
216185
|
+
};
|
|
216186
|
+
}
|
|
216187
|
+
if (carrier.hasForeignRevisionLikeRunProperties || carrier.hasInheritedMarkupCompatibilityAttributes && carrier.hasNonWordMarkup !== false || carrier.hasUnresolvedInheritedAttributeNamespaces) {
|
|
216188
|
+
return { ok: false, reason: "unsupported-context" };
|
|
216189
|
+
}
|
|
216190
|
+
if (carrier.hasParagraphRootMarkupCompatibilityAttributes && carrier.hasNonWordMarkup !== false) {
|
|
216191
|
+
return { ok: false, reason: "unsupported-context" };
|
|
216192
|
+
}
|
|
216193
|
+
const runPropertiesXml = namespaceCloseRunPropertiesForRelocation(carrier.runPropertiesXml, carrier.namespaceSourceOpenTag, inheritedNamespaceBindings);
|
|
216194
|
+
if (!runPropertiesXml)
|
|
216195
|
+
return { ok: false, reason: "unsupported-context" };
|
|
216196
|
+
return {
|
|
216197
|
+
ok: true,
|
|
216198
|
+
runPropertiesXml
|
|
216199
|
+
};
|
|
216200
|
+
}
|
|
216201
|
+
function adjacentFormattingCarrierRun(paragraphXml, placement2, inheritedNamespaceBindings = {}) {
|
|
216202
|
+
const paragraphPrefix = /^<(?:(?<prefix>[\w.-]+):)?p\b/.exec(paragraphXml)?.groups?.prefix ?? "";
|
|
216203
|
+
const additionalNamespaces = xmlFragmentAdditionalNamespaces(paragraphXml, new Map(Object.entries(inheritedNamespaceBindings)), { w: NS_W, [paragraphPrefix]: NS_W });
|
|
216204
|
+
const parsed = collectXmlElementRanges(paragraphXml, { additionalNamespaces });
|
|
216205
|
+
if (parsed.errors.length > 0)
|
|
216206
|
+
return { ok: true, run: undefined };
|
|
216207
|
+
const carrier = adjacentFormattingCarrierPiece(parseParagraphInlineMap(paragraphXml, inheritedNamespaceBindings).pieces, placement2);
|
|
216208
|
+
if (!carrier.ok)
|
|
216209
|
+
return carrier;
|
|
216210
|
+
const carrierPiece = carrier.piece;
|
|
216211
|
+
if (!carrierPiece)
|
|
216212
|
+
return { ok: true, run: undefined };
|
|
216213
|
+
const payloadLocalName = carrierPiece.kind === "text" ? "t" : carrierPiece.control;
|
|
216214
|
+
const run = parsed.ranges.find((range) => range.start === carrierPiece.runCharStart && range.end === carrierPiece.runCharEnd && range.tag.namespaceUri === NS_W && range.tag.localName === "r");
|
|
216215
|
+
const payload = parsed.ranges.find((range) => range.start === carrierPiece.charStart && range.end === carrierPiece.charEnd && range.tag.namespaceUri === NS_W && range.tag.localName === payloadLocalName);
|
|
216216
|
+
if (!run || !payload)
|
|
216217
|
+
return { ok: true, run: undefined };
|
|
216218
|
+
const hyperlinkRanges = parsed.ranges.filter((range) => range.tag.namespaceUri === NS_W && range.tag.localName === "hyperlink");
|
|
216219
|
+
return {
|
|
216220
|
+
ok: true,
|
|
216221
|
+
run: {
|
|
216222
|
+
start: run.start,
|
|
216223
|
+
end: run.end,
|
|
216224
|
+
xml: paragraphXml.slice(run.start, run.end),
|
|
216225
|
+
insideHyperlink: hyperlinkRanges.some((hyperlink) => hyperlink.start < run.start && run.end <= hyperlink.end)
|
|
216226
|
+
}
|
|
216227
|
+
};
|
|
216228
|
+
}
|
|
216229
|
+
function adjacentFormattingCarrierPiece(pieces, placement2) {
|
|
216230
|
+
const candidates = placement2 === "before" ? pieces : [...pieces].reverse();
|
|
216231
|
+
for (const piece of candidates) {
|
|
216232
|
+
if (piece.kind === "marker")
|
|
216233
|
+
continue;
|
|
216234
|
+
if (piece.kind === "text") {
|
|
216235
|
+
if (piece.textRole === "visible")
|
|
216236
|
+
return { ok: true, piece };
|
|
216237
|
+
continue;
|
|
216238
|
+
}
|
|
216239
|
+
if (piece.kind === "control") {
|
|
216240
|
+
if (!piece.deleted)
|
|
216241
|
+
return { ok: true, piece };
|
|
216242
|
+
continue;
|
|
216243
|
+
}
|
|
216244
|
+
if (piece.kind === "tracked") {
|
|
216245
|
+
if (piece.removesVisible)
|
|
216246
|
+
continue;
|
|
216247
|
+
const nested = adjacentFormattingCarrierPiece(piece.children, placement2);
|
|
216248
|
+
if (!nested.ok || nested.piece)
|
|
216249
|
+
return nested;
|
|
216250
|
+
if (piece.visibleStart === piece.visibleEnd)
|
|
216251
|
+
continue;
|
|
216252
|
+
return { ok: true, piece: undefined };
|
|
216253
|
+
}
|
|
216254
|
+
if (piece.kind === "container") {
|
|
216255
|
+
if (piece.policy === "fail-closed")
|
|
216256
|
+
return { ok: false, reason: "unsupported-context" };
|
|
216257
|
+
if (piece.policy === "atomic") {
|
|
216258
|
+
if (piece.containerKind === "math")
|
|
216259
|
+
return { ok: true, piece: undefined };
|
|
216260
|
+
continue;
|
|
216261
|
+
}
|
|
216262
|
+
const nested = adjacentFormattingCarrierPiece(piece.children, placement2);
|
|
216263
|
+
if (!nested.ok || nested.piece)
|
|
216264
|
+
return nested;
|
|
216265
|
+
if (piece.visibleStart === piece.visibleEnd)
|
|
216266
|
+
continue;
|
|
216267
|
+
return { ok: true, piece: undefined };
|
|
216268
|
+
}
|
|
216269
|
+
if (piece.kind === "noteReference") {
|
|
216270
|
+
continue;
|
|
216271
|
+
}
|
|
216272
|
+
return { ok: true, piece: undefined };
|
|
216273
|
+
}
|
|
216274
|
+
return { ok: true, piece: undefined };
|
|
216275
|
+
}
|
|
216276
|
+
function runPropertiesContainForeignRevisionLikeElement(rPrXml, namespaceSourceOpenTag) {
|
|
216277
|
+
const runPropertiesNode = readXmlNodeAt(rPrXml, 0);
|
|
216278
|
+
if (!runPropertiesNode || runPropertiesNode.kind !== "element" || runPropertiesNode.selfClosing || xmlLocalName(runPropertiesNode.qname) !== "rPr" || runPropertiesNode.end !== rPrXml.length) {
|
|
216279
|
+
return null;
|
|
216280
|
+
}
|
|
216281
|
+
const parsedXml = namespaceSourceOpenTag + rPrXml.slice(runPropertiesNode.openEnd, runPropertiesNode.closeStart) + rPrXml.slice(runPropertiesNode.closeStart);
|
|
216282
|
+
const additionalNamespaces = xmlFragmentAdditionalNamespaces(parsedXml, new Map, { w: NS_W });
|
|
216283
|
+
const parsed = collectXmlElementRanges(parsedXml, { additionalNamespaces });
|
|
216284
|
+
if (parsed.errors.length > 0)
|
|
216285
|
+
return null;
|
|
216286
|
+
return parsed.ranges.some((range) => range.tag.localName === "rPrChange" && range.tag.namespaceUri !== NS_W);
|
|
216287
|
+
}
|
|
216288
|
+
function runPropertiesContainNonWordMarkup(rPrXml, namespaceSourceOpenTag) {
|
|
216289
|
+
const runPropertiesNode = readXmlNodeAt(rPrXml, 0);
|
|
216290
|
+
if (!runPropertiesNode || runPropertiesNode.kind !== "element" || runPropertiesNode.selfClosing || xmlLocalName(runPropertiesNode.qname) !== "rPr" || runPropertiesNode.end !== rPrXml.length) {
|
|
216291
|
+
return null;
|
|
216292
|
+
}
|
|
216293
|
+
const parsedXml = namespaceSourceOpenTag + rPrXml.slice(runPropertiesNode.openEnd, runPropertiesNode.closeStart) + rPrXml.slice(runPropertiesNode.closeStart);
|
|
216294
|
+
const additionalNamespaces = xmlFragmentAdditionalNamespaces(parsedXml, new Map, { w: NS_W });
|
|
216295
|
+
const parsed = collectXmlElementRanges(parsedXml, { additionalNamespaces });
|
|
216296
|
+
if (parsed.errors.length > 0)
|
|
216297
|
+
return null;
|
|
216298
|
+
return parsed.ranges.some((range) => range.tag.namespaceUri !== NS_W || range.tag.attributes.some((attribute) => attribute.prefix !== "xmlns" && attribute.name !== "xmlns" && attribute.namespaceUri !== "" && attribute.namespaceUri !== NS_W && attribute.namespaceUri !== NS_XML));
|
|
216299
|
+
}
|
|
216300
|
+
function stripHyperlinkRunStyle(rPrXml, namespaceSourceOpenTag) {
|
|
216301
|
+
const runPropertiesNode = readXmlNodeAt(rPrXml, 0);
|
|
216302
|
+
if (!runPropertiesNode || runPropertiesNode.kind !== "element" || runPropertiesNode.selfClosing || xmlLocalName(runPropertiesNode.qname) !== "rPr" || runPropertiesNode.end !== rPrXml.length) {
|
|
216303
|
+
return null;
|
|
216304
|
+
}
|
|
216305
|
+
const parsedXml = namespaceSourceOpenTag + rPrXml.slice(runPropertiesNode.openEnd, runPropertiesNode.closeStart) + rPrXml.slice(runPropertiesNode.closeStart);
|
|
216306
|
+
const additionalNamespaces = xmlFragmentAdditionalNamespaces(parsedXml, new Map, { w: NS_W });
|
|
216307
|
+
const parsed = collectXmlElementRanges(parsedXml, { additionalNamespaces });
|
|
216308
|
+
if (parsed.errors.length > 0)
|
|
216309
|
+
return null;
|
|
216310
|
+
const openTagDelta = namespaceSourceOpenTag.length - runPropertiesNode.openEnd;
|
|
216311
|
+
const styleSpans = parsed.ranges.filter((range) => range.tag.namespaceUri === NS_W && range.tag.localName === "rStyle" && readXmlAttribute(range.tag, NS_W, "val")?.value === "Hyperlink").map((range) => ({ start: range.start - openTagDelta, end: range.end - openTagDelta })).filter((range) => range.start >= runPropertiesNode.openEnd && range.end <= runPropertiesNode.closeStart).sort((left, right) => right.start - left.start);
|
|
216312
|
+
let stripped = rPrXml;
|
|
216313
|
+
for (const span of styleSpans)
|
|
216314
|
+
stripped = stripped.slice(0, span.start) + stripped.slice(span.end);
|
|
216315
|
+
return runPropertiesXmlIsEmpty(stripped) ? null : stripped;
|
|
216316
|
+
}
|
|
216317
|
+
function namespaceSourceForRunProperties(paragraphXml, run, runPropertiesXml, inheritedNamespaceBindings) {
|
|
216318
|
+
const runProperties = findFirstElement(run.xml, "rPr");
|
|
216319
|
+
const runPropertiesNode = readXmlNodeAt(runPropertiesXml, 0);
|
|
216320
|
+
if (!runProperties || !runPropertiesNode || runPropertiesNode.kind !== "element" || xmlLocalName(runPropertiesNode.qname) !== "rPr") {
|
|
216321
|
+
return null;
|
|
216322
|
+
}
|
|
216323
|
+
const runPropertiesOpenTag = runPropertiesXml.slice(0, runPropertiesNode.openEnd);
|
|
216324
|
+
const targetStart = run.start + runProperties.start;
|
|
216325
|
+
const inheritedScopes = [];
|
|
216326
|
+
const inheritedCompatibilityScopes = [];
|
|
216327
|
+
const unresolvedInheritedAttributeScopes = [];
|
|
216328
|
+
const compatibilityStack = [];
|
|
216329
|
+
const unresolvedAttributeStack = [];
|
|
216330
|
+
let hasParagraphRootMarkupCompatibilityAttributes = false;
|
|
216331
|
+
const additionalNamespaces = xmlFragmentAdditionalNamespaces(paragraphXml, new Map(Object.entries(inheritedNamespaceBindings)), { w: NS_W });
|
|
216332
|
+
const parsed = walkXmlElements(paragraphXml, {
|
|
216333
|
+
additionalNamespaces,
|
|
216334
|
+
onOpenTag(event) {
|
|
216335
|
+
const parentHasCompatibilityAttributes = compatibilityStack.at(-1) ?? false;
|
|
216336
|
+
const parentHasUnresolvedAttributeNamespaces = unresolvedAttributeStack.at(-1) ?? false;
|
|
216337
|
+
if (event.start === targetStart && event.tag.namespaceUri === NS_W && event.tag.localName === "rPr") {
|
|
216338
|
+
const inherited = { ...event.namespaceBindings };
|
|
216339
|
+
for (const prefix of Object.keys(event.tag.namespaceBindings))
|
|
216340
|
+
delete inherited[prefix];
|
|
216341
|
+
inheritedScopes.push(inherited);
|
|
216342
|
+
inheritedCompatibilityScopes.push(parentHasCompatibilityAttributes);
|
|
216343
|
+
unresolvedInheritedAttributeScopes.push(parentHasUnresolvedAttributeNamespaces);
|
|
216344
|
+
}
|
|
216345
|
+
const isParagraphRoot = event.start === 0 && event.tag.namespaceUri === NS_W && event.tag.localName === "p";
|
|
216346
|
+
if (isParagraphRoot) {
|
|
216347
|
+
hasParagraphRootMarkupCompatibilityAttributes = event.tag.attributes.some((attribute) => attribute.namespaceUri === NS_MC);
|
|
216348
|
+
}
|
|
216349
|
+
const hasLocalCompatibilityAttributes = !isParagraphRoot && event.tag.attributes.some((attribute) => attribute.namespaceUri === NS_MC);
|
|
216350
|
+
compatibilityStack.push(parentHasCompatibilityAttributes || hasLocalCompatibilityAttributes);
|
|
216351
|
+
const hasUnresolvedAttributeNamespaces = event.tag.attributes.some((attribute) => attribute.namespaceUri.startsWith("urn:superdoc:unresolved-namespace-prefix:"));
|
|
216352
|
+
unresolvedAttributeStack.push(parentHasUnresolvedAttributeNamespaces || hasUnresolvedAttributeNamespaces);
|
|
216353
|
+
},
|
|
216354
|
+
onCloseTag() {
|
|
216355
|
+
compatibilityStack.pop();
|
|
216356
|
+
unresolvedAttributeStack.pop();
|
|
216357
|
+
}
|
|
216358
|
+
});
|
|
216359
|
+
const inheritedBindings = inheritedScopes[0];
|
|
216360
|
+
const hasInheritedMarkupCompatibilityAttributes = inheritedCompatibilityScopes[0];
|
|
216361
|
+
const hasUnresolvedInheritedAttributeNamespaces = unresolvedInheritedAttributeScopes[0];
|
|
216362
|
+
if (parsed.errors.length > 0 || !inheritedBindings || hasInheritedMarkupCompatibilityAttributes == null || hasUnresolvedInheritedAttributeNamespaces == null) {
|
|
216363
|
+
return null;
|
|
216364
|
+
}
|
|
216365
|
+
let declarations = "";
|
|
216366
|
+
for (const [prefix, namespaceUri] of Object.entries(inheritedBindings)) {
|
|
216367
|
+
if (prefix === "xml")
|
|
216368
|
+
continue;
|
|
216369
|
+
declarations += prefix.length > 0 ? ` xmlns:${prefix}="${escapeXmlAttribute(namespaceUri)}"` : ` xmlns="${escapeXmlAttribute(namespaceUri)}"`;
|
|
216370
|
+
}
|
|
216371
|
+
return {
|
|
216372
|
+
openTag: declarations.length > 0 ? runPropertiesOpenTag.replace(/>$/, `${declarations}>`) : runPropertiesOpenTag,
|
|
216373
|
+
hasParagraphRootMarkupCompatibilityAttributes,
|
|
216374
|
+
hasInheritedMarkupCompatibilityAttributes,
|
|
216375
|
+
hasUnresolvedInheritedAttributeNamespaces
|
|
216376
|
+
};
|
|
216377
|
+
}
|
|
216378
|
+
function readRunPropertiesXml(runXml) {
|
|
216379
|
+
const inner = runInnerXml(runXml);
|
|
216380
|
+
if (inner == null)
|
|
216381
|
+
return null;
|
|
216382
|
+
const leading = /^\s*/.exec(inner)?.[0] ?? "";
|
|
216383
|
+
const rPrXml = matchLeadingElement(inner.slice(leading.length), "rPr");
|
|
216384
|
+
return rPrXml || null;
|
|
216385
|
+
}
|
|
216386
|
+
function cloneParagraphMarkRunPropertiesForInsert(paraXml) {
|
|
216387
|
+
const inner = paragraphInnerXml(paraXml);
|
|
216388
|
+
if (inner == null)
|
|
216389
|
+
return null;
|
|
216390
|
+
const { pPr } = splitLeadingParagraphPropertyBlock(inner);
|
|
216391
|
+
if (!pPr)
|
|
216392
|
+
return null;
|
|
216393
|
+
const markProperties = extractParagraphMarkRunProperties(stripParagraphPropertyChange(pPr));
|
|
216394
|
+
return markProperties && !runPropertiesXmlIsEmpty(markProperties) ? markProperties : null;
|
|
216395
|
+
}
|
|
216396
|
+
function normalizeClonedRunProperties(rPrXml) {
|
|
216397
|
+
const stripped = stripElements(rPrXml, "rPrChange");
|
|
216398
|
+
return runPropertiesXmlIsEmpty(stripped) ? null : stripped;
|
|
216399
|
+
}
|
|
216400
|
+
function paragraphInnerXml(paraXml) {
|
|
216401
|
+
const openTag = /^<[\w.-]+:p\b[^>]*>/.exec(paraXml)?.[0];
|
|
216402
|
+
const closeTag = /<\/[\w.-]+:p>\s*$/.exec(paraXml)?.[0];
|
|
216403
|
+
if (!openTag || !closeTag)
|
|
216404
|
+
return null;
|
|
216405
|
+
return paraXml.slice(openTag.length, paraXml.length - closeTag.length);
|
|
216406
|
+
}
|
|
216407
|
+
function runInnerXml(runXml) {
|
|
216408
|
+
const openTag = /^<[\w.-]+:r\b[^>]*>/.exec(runXml)?.[0];
|
|
216409
|
+
const closeTag = /<\/[\w.-]+:r>\s*$/.exec(runXml)?.[0];
|
|
216410
|
+
if (!openTag || !closeTag)
|
|
216411
|
+
return null;
|
|
216412
|
+
return runXml.slice(openTag.length, runXml.length - closeTag.length);
|
|
216413
|
+
}
|
|
216414
|
+
function composeParagraphPropertiesXml(input) {
|
|
216415
|
+
const explicit = renderParagraphProperties2(input.styleId, input.numberingProperties);
|
|
216416
|
+
const explicitChildren = paragraphPropertiesChildrenXml(explicit);
|
|
216417
|
+
const inheritedChildren = paragraphPropertiesChildrenXml(input.inheritedParagraphPropertiesXml);
|
|
216418
|
+
const children = `${explicitChildren}${inheritedChildren}`;
|
|
216419
|
+
const namespaceAttrs = paragraphPropertiesNamespaceAttrs(input.inheritedParagraphPropertiesXml);
|
|
216420
|
+
return children.trim().length > 0 ? `<w:pPr${namespaceAttrs}>${children}</w:pPr>` : null;
|
|
216421
|
+
}
|
|
216422
|
+
function paragraphPropertiesChildrenXml(pPrXml) {
|
|
216423
|
+
if (!pPrXml)
|
|
216424
|
+
return "";
|
|
216425
|
+
const trimmed = pPrXml.trim();
|
|
216426
|
+
const selfClosing = /^<[\w.-]+:pPr\b[^>]*\/>$/.exec(trimmed);
|
|
216427
|
+
if (selfClosing)
|
|
216428
|
+
return "";
|
|
216429
|
+
const open = /^<[\w.-]+:pPr\b[^>]*>/.exec(trimmed)?.[0];
|
|
216430
|
+
const close = /<\/[\w.-]+:pPr>\s*$/.exec(trimmed)?.[0];
|
|
216431
|
+
if (!open || !close)
|
|
216432
|
+
return "";
|
|
216433
|
+
return trimmed.slice(open.length, trimmed.length - close.length);
|
|
216434
|
+
}
|
|
216435
|
+
function paragraphPropertiesNamespaceAttrs(pPrXml) {
|
|
216436
|
+
if (!pPrXml)
|
|
216437
|
+
return "";
|
|
216438
|
+
const trimmed = pPrXml.trim();
|
|
216439
|
+
const openAttrs = /^<[\w.-]+:pPr\b([^>]*)\/?>/.exec(trimmed)?.[1] ?? "";
|
|
216440
|
+
return openAttrs.match(/\s+xmlns(?::[\w.-]+)?=(?:"[^"]*"|'[^']*')/g)?.join("") ?? "";
|
|
216441
|
+
}
|
|
216442
|
+
function paragraphPropertiesXmlIsEmpty(pPrXml) {
|
|
216443
|
+
const trimmed = pPrXml.trim();
|
|
216444
|
+
return /^<[\w.-]+:pPr\b[^>]*\/>$/.test(trimmed) || /^<([\w.-]+):pPr\b[^>]*>\s*<\/\1:pPr>$/.test(trimmed);
|
|
216445
|
+
}
|
|
216446
|
+
function runPropertiesXmlIsEmpty(rPrXml) {
|
|
216447
|
+
const trimmed = rPrXml.trim();
|
|
216448
|
+
return /^<[\w.-]+:rPr\b[^>]*\/>$/.test(trimmed) || /^<([\w.-]+):rPr\b[^>]*>\s*<\/\1:rPr>$/.test(trimmed);
|
|
216449
|
+
}
|
|
216450
|
+
var TD51;
|
|
216451
|
+
var init_insertion_formatting_context = __esm(() => {
|
|
216452
|
+
init_sd_document_state();
|
|
216453
|
+
init_style_definitions_part();
|
|
216454
|
+
init_style_definitions_xml();
|
|
216455
|
+
init_paragraph_inline_model();
|
|
216456
|
+
init_xml_text();
|
|
216457
|
+
init_xml_sax();
|
|
216458
|
+
init_paragraph_contribution();
|
|
216459
|
+
init_direct_paragraph_list_properties();
|
|
216460
|
+
init_paragraph_property_block();
|
|
216461
|
+
init_paragraph_para_id_attrs();
|
|
216462
|
+
TD51 = new TextDecoder;
|
|
216463
|
+
});
|
|
216464
|
+
|
|
215872
216465
|
// ../../../v2/editor-core/dist/document/transactions/field-paragraph-owner.js
|
|
215873
216466
|
function createPackedFieldParagraphOwnerResolver(input) {
|
|
215874
216467
|
if (parseXmlForError(input.xml, { namespaceAware: true }) != null) {
|
|
@@ -216250,7 +216843,7 @@ function resolveOwnerFromOpeningTag(bytes, entry) {
|
|
|
216250
216843
|
}
|
|
216251
216844
|
if (tagEnd < 0)
|
|
216252
216845
|
return { resolved: false };
|
|
216253
|
-
const tag = parseRawXmlElementTag(
|
|
216846
|
+
const tag = parseRawXmlElementTag(TD52.decode(bytes.subarray(entry.byteStart, tagEnd)));
|
|
216254
216847
|
if (!tag || tag.isClose || tag.prefix !== "w" || tag.localName !== "p")
|
|
216255
216848
|
return { resolved: false };
|
|
216256
216849
|
const paraIds = [...scanRawXmlAttributes(tag.attrs)].filter((attribute) => attribute.localName === "paraId");
|
|
@@ -216280,13 +216873,13 @@ async function parseXmlForErrorCooperatively(xml, checkpoint) {
|
|
|
216280
216873
|
}
|
|
216281
216874
|
return !parseError;
|
|
216282
216875
|
}
|
|
216283
|
-
var
|
|
216876
|
+
var TD52, XML_PARSE_CHUNK_CODE_UNITS, MAX_PARAGRAPH_OPEN_TAG_BYTES;
|
|
216284
216877
|
var init_field_paragraph_owner = __esm(() => {
|
|
216285
216878
|
init_sd_document_state();
|
|
216286
216879
|
init_paragraph_index();
|
|
216287
216880
|
init_xml_text();
|
|
216288
216881
|
init_xml_sax();
|
|
216289
|
-
|
|
216882
|
+
TD52 = new TextDecoder;
|
|
216290
216883
|
XML_PARSE_CHUNK_CODE_UNITS = 512 * 1024;
|
|
216291
216884
|
MAX_PARAGRAPH_OPEN_TAG_BYTES = 64 * 1024;
|
|
216292
216885
|
});
|
|
@@ -216382,7 +216975,7 @@ async function screenFieldCandidatesCooperatively(xml, checkpoint) {
|
|
|
216382
216975
|
return false;
|
|
216383
216976
|
}
|
|
216384
216977
|
function buildFieldCatalog(input) {
|
|
216385
|
-
const xml = input.sharedXml ??
|
|
216978
|
+
const xml = input.sharedXml ?? TD53.decode(input.bytes);
|
|
216386
216979
|
if (!hasFieldCandidates(xml))
|
|
216387
216980
|
return emptyFieldCatalog(input.storyId, input.partUri, xml.length);
|
|
216388
216981
|
return buildFieldCatalogFromXml(input, xml, buildSparseFieldUtf8OffsetIndex(xml));
|
|
@@ -216873,12 +217466,12 @@ function getOrBuildFieldCatalogForStory(state, storyId) {
|
|
|
216873
217466
|
return existing.catalog;
|
|
216874
217467
|
}
|
|
216875
217468
|
if (!hasFieldByteCandidates(bytes)) {
|
|
216876
|
-
const catalog2 = emptyFieldCatalog(storyId, partUri, () =>
|
|
217469
|
+
const catalog2 = emptyFieldCatalog(storyId, partUri, () => TD53.decode(bytes).length);
|
|
216877
217470
|
perStory.set(storyId, { catalog: catalog2, partBytes: bytes });
|
|
216878
217471
|
return catalog2;
|
|
216879
217472
|
}
|
|
216880
217473
|
const shared = peekPartWmlScanFacts(state, partUri);
|
|
216881
|
-
const xml = shared?.bytes === bytes ? shared.xml : DECODED_PART_IN_FLIGHT.get(bytes)?.xml ??
|
|
217474
|
+
const xml = shared?.bytes === bytes ? shared.xml : DECODED_PART_IN_FLIGHT.get(bytes)?.xml ?? TD53.decode(bytes);
|
|
216882
217475
|
if (!hasFieldCandidates(xml)) {
|
|
216883
217476
|
const catalog2 = emptyFieldCatalog(storyId, partUri, xml.length);
|
|
216884
217477
|
perStory.set(storyId, { catalog: catalog2, partBytes: bytes });
|
|
@@ -216958,7 +217551,7 @@ async function buildFieldCatalogForStoryCooperatively(input) {
|
|
|
216958
217551
|
if (decoded)
|
|
216959
217552
|
decoded.users += 1;
|
|
216960
217553
|
else {
|
|
216961
|
-
decoded = { xml:
|
|
217554
|
+
decoded = { xml: TD53.decode(input.bytes), users: 1 };
|
|
216962
217555
|
DECODED_PART_IN_FLIGHT.set(input.bytes, decoded);
|
|
216963
217556
|
}
|
|
216964
217557
|
let syncWinner = null;
|
|
@@ -217092,7 +217685,7 @@ function listFieldCatalogsForState(state) {
|
|
|
217092
217685
|
}
|
|
217093
217686
|
return out;
|
|
217094
217687
|
}
|
|
217095
|
-
var
|
|
217688
|
+
var TD53, UTF8_OFFSET_CHECKPOINT_STRIDE = 256, FIELD_CANDIDATE_BYTES, FIELD_CANDIDATE_SEARCHES, STATE_CACHE2, STATE_IN_FLIGHT, DECODED_PART_IN_FLIGHT;
|
|
217096
217689
|
var init_field_catalog = __esm(() => {
|
|
217097
217690
|
init_sd_document_state();
|
|
217098
217691
|
init_xml_text();
|
|
@@ -217100,7 +217693,7 @@ var init_field_catalog = __esm(() => {
|
|
|
217100
217693
|
init_wml_paragraph_spans();
|
|
217101
217694
|
init_part_wml_scan_cache();
|
|
217102
217695
|
init_field_paragraph_owner();
|
|
217103
|
-
|
|
217696
|
+
TD53 = new TextDecoder;
|
|
217104
217697
|
FIELD_CANDIDATE_BYTES = [["fldSimple", 3], ["fldChar", 3], ["instrText", 7]];
|
|
217105
217698
|
FIELD_CANDIDATE_SEARCHES = FIELD_CANDIDATE_BYTES.map(([token, anchorOffset]) => ({
|
|
217106
217699
|
token: new TextEncoder().encode(token),
|
|
@@ -217113,7 +217706,7 @@ var init_field_catalog = __esm(() => {
|
|
|
217113
217706
|
|
|
217114
217707
|
// ../../../v2/editor-core/dist/document/transactions/range-integrity.js
|
|
217115
217708
|
function isParagraphRangeMarkerGap(bytes, startByte, endByte) {
|
|
217116
|
-
const xml =
|
|
217709
|
+
const xml = TD54.decode(bytes.subarray(startByte, endByte));
|
|
217117
217710
|
if (xml.trim() === "")
|
|
217118
217711
|
return true;
|
|
217119
217712
|
const offsetAt = createMonotonicUtf8OffsetResolver(xml);
|
|
@@ -217180,7 +217773,7 @@ function validateParagraphRangeIntegrity(input) {
|
|
|
217180
217773
|
const markerWindow = selectedParagraphByteWindow(input.bytes, startEntry, endEntry);
|
|
217181
217774
|
if (markerWindow) {
|
|
217182
217775
|
recordSDTxPerf("rangeIntegrityBoundedMarkerBytes", markerWindow.byteLength);
|
|
217183
|
-
if (!PAIRED_RANGE_MARKER_TAG.test(
|
|
217776
|
+
if (!PAIRED_RANGE_MARKER_TAG.test(TD54.decode(markerWindow))) {
|
|
217184
217777
|
return { ok: true, removedBookmarkNames: [] };
|
|
217185
217778
|
}
|
|
217186
217779
|
}
|
|
@@ -217292,7 +217885,7 @@ function createVisiblePointResolver(bytes, index) {
|
|
|
217292
217885
|
return null;
|
|
217293
217886
|
let model = models.get(entry.ordinal);
|
|
217294
217887
|
if (!model) {
|
|
217295
|
-
model = parseParagraphInlineMap(
|
|
217888
|
+
model = parseParagraphInlineMap(TD54.decode(bytes.subarray(entry.byteStart, entry.byteEnd)));
|
|
217296
217889
|
models.set(entry.ordinal, model);
|
|
217297
217890
|
}
|
|
217298
217891
|
return {
|
|
@@ -217308,7 +217901,7 @@ function comparePoints(left, right) {
|
|
|
217308
217901
|
return left.ordinal - right.ordinal || left.offset - right.offset;
|
|
217309
217902
|
}
|
|
217310
217903
|
function collectPairedRangeMarkers(bytes) {
|
|
217311
|
-
const xml =
|
|
217904
|
+
const xml = TD54.decode(bytes);
|
|
217312
217905
|
const byteOffsetAt4 = createMonotonicUtf8OffsetResolver(xml);
|
|
217313
217906
|
const markers = [];
|
|
217314
217907
|
const scanned = walkXmlElements(xml, {
|
|
@@ -217371,13 +217964,13 @@ function incompleteFieldAt(catalog, byteOffset) {
|
|
|
217371
217964
|
complete: false
|
|
217372
217965
|
};
|
|
217373
217966
|
}
|
|
217374
|
-
var
|
|
217967
|
+
var TD54, PAIRED_RANGE_MARKER_FAMILIES, PAIRED_RANGE_MARKER_TAG;
|
|
217375
217968
|
var init_range_integrity = __esm(() => {
|
|
217376
217969
|
init_paragraph_inline_model();
|
|
217377
217970
|
init_paragraph_para_id_attrs();
|
|
217378
217971
|
init_xml_sax();
|
|
217379
217972
|
init_field_catalog();
|
|
217380
|
-
|
|
217973
|
+
TD54 = new TextDecoder;
|
|
217381
217974
|
PAIRED_RANGE_MARKER_FAMILIES = {
|
|
217382
217975
|
bookmark: "bookmark",
|
|
217383
217976
|
perm: "permission",
|
|
@@ -217714,566 +218307,6 @@ var init_tracked_block_move = __esm(() => {
|
|
|
217714
218307
|
init_moved_picture_identities();
|
|
217715
218308
|
});
|
|
217716
218309
|
|
|
217717
|
-
// ../../../v2/editor-core/dist/document/transactions/insertion-formatting-context.js
|
|
217718
|
-
function resolveInsertionFormattingContext(state, input) {
|
|
217719
|
-
const inheritance = input.inheritance ?? "anchor";
|
|
217720
|
-
const numberingProperties = input.numberingProperties ?? null;
|
|
217721
|
-
const paragraphXml = input.anchor ? readAnchorParagraphXml(state, input.anchor.entry) : null;
|
|
217722
|
-
if (input.anchor && paragraphXml == null && !input.styleRef) {
|
|
217723
|
-
return { ok: false, reason: "paragraph-target-not-found" };
|
|
217724
|
-
}
|
|
217725
|
-
const style = resolveInsertionStyle(state, paragraphXml, input.anchor, input.styleRef, inheritance, input.fallbackToDocumentDefaultStyle ?? false);
|
|
217726
|
-
if (!style.ok)
|
|
217727
|
-
return style;
|
|
217728
|
-
const direct = inheritance === "anchor" && paragraphXml != null ? resolveDirectInsertionFormatting(paragraphXml, input.anchor.placement, readAnchorNamespaceBindings(state, input.anchor.entry)) : {
|
|
217729
|
-
paragraphPropertiesXml: null,
|
|
217730
|
-
paragraphMarkRunPropertiesXml: null,
|
|
217731
|
-
runPropertiesXml: null,
|
|
217732
|
-
skippedReason: directFormattingSkippedReason(inheritance)
|
|
217733
|
-
};
|
|
217734
|
-
if ("reason" in direct)
|
|
217735
|
-
return direct;
|
|
217736
|
-
const paragraphPropertiesXml = composeParagraphPropertiesXml({
|
|
217737
|
-
styleId: style.styleId,
|
|
217738
|
-
numberingProperties,
|
|
217739
|
-
inheritedParagraphPropertiesXml: direct.paragraphPropertiesXml
|
|
217740
|
-
});
|
|
217741
|
-
return {
|
|
217742
|
-
ok: true,
|
|
217743
|
-
context: {
|
|
217744
|
-
styleId: style.styleId,
|
|
217745
|
-
numberingProperties,
|
|
217746
|
-
paragraphPropertiesXml,
|
|
217747
|
-
runPropertiesXml: direct.runPropertiesXml,
|
|
217748
|
-
provenance: {
|
|
217749
|
-
inheritedParagraphProperties: direct.paragraphPropertiesXml != null,
|
|
217750
|
-
inheritedParagraphMarkProperties: direct.paragraphMarkRunPropertiesXml != null,
|
|
217751
|
-
inheritedRunProperties: direct.runPropertiesXml != null,
|
|
217752
|
-
explicitStyleOverride: Boolean(input.styleRef),
|
|
217753
|
-
explicitNumberingOverride: numberingProperties != null,
|
|
217754
|
-
...direct.skippedReason ? { skippedReason: direct.skippedReason } : {}
|
|
217755
|
-
}
|
|
217756
|
-
}
|
|
217757
|
-
};
|
|
217758
|
-
}
|
|
217759
|
-
function directFormattingSkippedReason(inheritance) {
|
|
217760
|
-
if (inheritance === "style")
|
|
217761
|
-
return "direct-inheritance-disabled";
|
|
217762
|
-
if (inheritance === "none")
|
|
217763
|
-
return "inheritance-disabled";
|
|
217764
|
-
return "no-anchor";
|
|
217765
|
-
}
|
|
217766
|
-
function readAnchorParagraphXml(state, entry) {
|
|
217767
|
-
const bytes = state.packageBytes.get(entry.partUri);
|
|
217768
|
-
if (!bytes)
|
|
217769
|
-
return null;
|
|
217770
|
-
if (entry.byteEnd <= entry.byteStart)
|
|
217771
|
-
return "";
|
|
217772
|
-
return TD54.decode(bytes.subarray(entry.byteStart, entry.byteEnd));
|
|
217773
|
-
}
|
|
217774
|
-
function readAnchorNamespaceBindings(state, entry) {
|
|
217775
|
-
const mainOverlay = state.mainStorySourceOverlay;
|
|
217776
|
-
if (entry.directBodyChildOrdinal != null && mainOverlay?.partUri === entry.partUri && mainOverlay.storyId === entry.storyId) {
|
|
217777
|
-
return mainOverlay.rootNamespaceBindings;
|
|
217778
|
-
}
|
|
217779
|
-
const bytes = state.packageBytes.get(entry.partUri);
|
|
217780
|
-
return bytes ? namespaceBindingsAtPosition(bytes, entry.byteStart) : {};
|
|
217781
|
-
}
|
|
217782
|
-
function resolveInsertionStyle(state, anchorParagraphXml, anchor, explicitStyleRef, inheritance, fallbackToDocumentDefaultStyle) {
|
|
217783
|
-
if (explicitStyleRef)
|
|
217784
|
-
return { ok: true, styleId: explicitStyleRef };
|
|
217785
|
-
if (!anchor || inheritance === "none") {
|
|
217786
|
-
return {
|
|
217787
|
-
ok: true,
|
|
217788
|
-
styleId: fallbackToDocumentDefaultStyle ? resolveDefaultParagraphStyleId(state) : null
|
|
217789
|
-
};
|
|
217790
|
-
}
|
|
217791
|
-
if (anchorParagraphXml == null)
|
|
217792
|
-
return { ok: false, reason: "paragraph-target-not-found" };
|
|
217793
|
-
const paragraphStyle = readDirectParagraphStyleId(anchorParagraphXml);
|
|
217794
|
-
if (paragraphStyle.presence === "malformed") {
|
|
217795
|
-
return { ok: false, reason: "paragraph-style-ambiguous" };
|
|
217796
|
-
}
|
|
217797
|
-
const targetStyle = paragraphStyle.styleId;
|
|
217798
|
-
if (anchor.placement === "after" && targetStyle) {
|
|
217799
|
-
const next = lookupNextStyle(state, targetStyle);
|
|
217800
|
-
if (!next.ok)
|
|
217801
|
-
return next;
|
|
217802
|
-
if (next.styleId)
|
|
217803
|
-
return { ok: true, styleId: next.styleId };
|
|
217804
|
-
}
|
|
217805
|
-
if (targetStyle)
|
|
217806
|
-
return { ok: true, styleId: targetStyle };
|
|
217807
|
-
return {
|
|
217808
|
-
ok: true,
|
|
217809
|
-
styleId: fallbackToDocumentDefaultStyle ? resolveDefaultParagraphStyleId(state) : null
|
|
217810
|
-
};
|
|
217811
|
-
}
|
|
217812
|
-
function resolveDefaultParagraphStyleId(state) {
|
|
217813
|
-
const defaultStyle = resolveDefaultParagraphStyle(state);
|
|
217814
|
-
return defaultStyle.ok ? defaultStyle.styleId ?? "Normal" : "Normal";
|
|
217815
|
-
}
|
|
217816
|
-
function resolveDefaultParagraphStyle(state) {
|
|
217817
|
-
const inspection = inspectStyleDefinitionsPartUriFromState(state);
|
|
217818
|
-
if (!inspection.valid)
|
|
217819
|
-
return { ok: true, styleId: null };
|
|
217820
|
-
const bytes = inspection.partUri ? ensurePackagePartBytes(state, inspection.partUri) : null;
|
|
217821
|
-
if (!bytes)
|
|
217822
|
-
return { ok: true, styleId: null };
|
|
217823
|
-
const xml = TD54.decode(bytes);
|
|
217824
|
-
const namespaceUri = inspectStyleDefinitionsXmlDialect(xml);
|
|
217825
|
-
if (!namespaceUri)
|
|
217826
|
-
return { ok: true, styleId: null };
|
|
217827
|
-
let depth = 0;
|
|
217828
|
-
const defaults = [];
|
|
217829
|
-
let valid = true;
|
|
217830
|
-
const parsed = walkXmlElements(xml, {
|
|
217831
|
-
onOpenTag({ tag }) {
|
|
217832
|
-
depth += 1;
|
|
217833
|
-
if (depth !== 2 || tag.namespaceUri !== namespaceUri || tag.localName !== "style")
|
|
217834
|
-
return;
|
|
217835
|
-
if (readWordAttribute2(tag, namespaceUri, "type") !== "paragraph" || !["1", "true", "on"].includes(readWordAttribute2(tag, namespaceUri, "default") ?? ""))
|
|
217836
|
-
return;
|
|
217837
|
-
const id = readWordAttribute2(tag, namespaceUri, "styleId");
|
|
217838
|
-
if (!id)
|
|
217839
|
-
valid = false;
|
|
217840
|
-
else
|
|
217841
|
-
defaults.push(id);
|
|
217842
|
-
},
|
|
217843
|
-
onCloseTag() {
|
|
217844
|
-
depth -= 1;
|
|
217845
|
-
}
|
|
217846
|
-
});
|
|
217847
|
-
if (!valid || parsed.errors.length || defaults.length > 1)
|
|
217848
|
-
return { ok: true, styleId: null };
|
|
217849
|
-
return { ok: true, styleId: defaults[0] ?? null };
|
|
217850
|
-
}
|
|
217851
|
-
function lookupNextStyle(state, styleId) {
|
|
217852
|
-
const inspection = inspectStyleDefinitionsPartUriFromState(state);
|
|
217853
|
-
if (!inspection.valid)
|
|
217854
|
-
return { ok: false, reason: "paragraph-style-ambiguous" };
|
|
217855
|
-
const stylesBytes = inspection.partUri ? ensurePackagePartBytes(state, inspection.partUri) : null;
|
|
217856
|
-
if (!stylesBytes)
|
|
217857
|
-
return { ok: true, styleId: null };
|
|
217858
|
-
const xml = TD54.decode(stylesBytes);
|
|
217859
|
-
const namespaceUri = inspectStyleDefinitionsXmlDialect(xml);
|
|
217860
|
-
if (!namespaceUri)
|
|
217861
|
-
return { ok: false, reason: "paragraph-style-ambiguous" };
|
|
217862
|
-
let depth = 0;
|
|
217863
|
-
let targetStyleDepth = -1;
|
|
217864
|
-
let foundTargetStyle = false;
|
|
217865
|
-
let nextStyleId = null;
|
|
217866
|
-
const parsed = walkXmlElements(xml, {
|
|
217867
|
-
onOpenTag({ tag }) {
|
|
217868
|
-
depth += 1;
|
|
217869
|
-
if (!foundTargetStyle && depth === 2 && tag.namespaceUri === namespaceUri && tag.localName === "style" && readWordAttribute2(tag, namespaceUri, "styleId") === styleId) {
|
|
217870
|
-
foundTargetStyle = true;
|
|
217871
|
-
targetStyleDepth = depth;
|
|
217872
|
-
return;
|
|
217873
|
-
}
|
|
217874
|
-
if (targetStyleDepth >= 0 && depth === targetStyleDepth + 1 && tag.namespaceUri === namespaceUri && tag.localName === "next") {
|
|
217875
|
-
nextStyleId = readWordAttribute2(tag, namespaceUri, "val") ?? null;
|
|
217876
|
-
}
|
|
217877
|
-
},
|
|
217878
|
-
onCloseTag({ tag }) {
|
|
217879
|
-
if (depth === targetStyleDepth && tag.localName === "style")
|
|
217880
|
-
targetStyleDepth = -1;
|
|
217881
|
-
depth -= 1;
|
|
217882
|
-
}
|
|
217883
|
-
});
|
|
217884
|
-
if (parsed.errors.length > 0)
|
|
217885
|
-
return { ok: false, reason: "paragraph-style-ambiguous" };
|
|
217886
|
-
return { ok: true, styleId: nextStyleId };
|
|
217887
|
-
}
|
|
217888
|
-
function readWordAttribute2(tag, namespaceUri, localName2) {
|
|
217889
|
-
return readXmlAttribute(tag, namespaceUri, localName2)?.value;
|
|
217890
|
-
}
|
|
217891
|
-
function resolveDirectInsertionFormatting(paragraphXml, placement2, inheritedNamespaceBindings = {}) {
|
|
217892
|
-
const paragraphPropertiesXml = cloneDirectParagraphPropertiesForInsert(paragraphXml);
|
|
217893
|
-
const paragraphMarkRunPropertiesXml = cloneParagraphMarkRunPropertiesForInsert(paragraphXml);
|
|
217894
|
-
const adjacentRunProperties = cloneAdjacentRunPropertiesForInsert(paragraphXml, placement2, paragraphMarkRunPropertiesXml, inheritedNamespaceBindings);
|
|
217895
|
-
if (!adjacentRunProperties.ok)
|
|
217896
|
-
return adjacentRunProperties;
|
|
217897
|
-
const runPropertiesXml = adjacentRunProperties.runPropertiesXml;
|
|
217898
|
-
return {
|
|
217899
|
-
paragraphPropertiesXml,
|
|
217900
|
-
paragraphMarkRunPropertiesXml,
|
|
217901
|
-
runPropertiesXml,
|
|
217902
|
-
...!paragraphPropertiesXml && !runPropertiesXml ? { skippedReason: "no-direct-formatting" } : {}
|
|
217903
|
-
};
|
|
217904
|
-
}
|
|
217905
|
-
function cloneAdjacentRunPropertiesCarrierForInsertion(paragraphXml, placement2, inheritedNamespaceBindings = {}) {
|
|
217906
|
-
const paragraphWithoutNestedTextboxes = stripElements(paragraphXml, "txbxContent");
|
|
217907
|
-
const run = adjacentFormattingCarrierRun(paragraphWithoutNestedTextboxes, placement2, inheritedNamespaceBindings);
|
|
217908
|
-
if (!run.ok)
|
|
217909
|
-
return run;
|
|
217910
|
-
if (!run.run)
|
|
217911
|
-
return { ok: true, carrier: null };
|
|
217912
|
-
const carrierRun = run.run;
|
|
217913
|
-
const runPropertiesXml = readRunPropertiesXml(carrierRun.xml);
|
|
217914
|
-
if (!runPropertiesXml)
|
|
217915
|
-
return { ok: true, carrier: null };
|
|
217916
|
-
const namespaceSource = namespaceSourceForRunProperties(paragraphWithoutNestedTextboxes, carrierRun, runPropertiesXml, inheritedNamespaceBindings);
|
|
217917
|
-
if (!namespaceSource)
|
|
217918
|
-
return { ok: true, carrier: null };
|
|
217919
|
-
const { openTag: namespaceSourceOpenTag, hasParagraphRootMarkupCompatibilityAttributes, hasInheritedMarkupCompatibilityAttributes, hasUnresolvedInheritedAttributeNamespaces } = namespaceSource;
|
|
217920
|
-
const hasForeignRevisionLikeRunProperties = runPropertiesContainForeignRevisionLikeElement(runPropertiesXml, namespaceSourceOpenTag);
|
|
217921
|
-
if (hasForeignRevisionLikeRunProperties == null)
|
|
217922
|
-
return { ok: true, carrier: null };
|
|
217923
|
-
if (hasForeignRevisionLikeRunProperties) {
|
|
217924
|
-
return {
|
|
217925
|
-
ok: true,
|
|
217926
|
-
carrier: {
|
|
217927
|
-
runPropertiesXml,
|
|
217928
|
-
namespaceSourceOpenTag,
|
|
217929
|
-
hasForeignRevisionLikeRunProperties,
|
|
217930
|
-
hasNonWordMarkup: runPropertiesContainNonWordMarkup(runPropertiesXml, namespaceSourceOpenTag),
|
|
217931
|
-
hasParagraphRootMarkupCompatibilityAttributes,
|
|
217932
|
-
hasInheritedMarkupCompatibilityAttributes,
|
|
217933
|
-
hasUnresolvedInheritedAttributeNamespaces
|
|
217934
|
-
}
|
|
217935
|
-
};
|
|
217936
|
-
}
|
|
217937
|
-
const normalizedRunProperties = normalizeClonedRunProperties(runPropertiesXml);
|
|
217938
|
-
const normalizedRunPropertiesXml = normalizedRunProperties && carrierRun.insideHyperlink ? stripHyperlinkRunStyle(normalizedRunProperties, namespaceSourceOpenTag) : normalizedRunProperties;
|
|
217939
|
-
return {
|
|
217940
|
-
ok: true,
|
|
217941
|
-
carrier: normalizedRunPropertiesXml ? {
|
|
217942
|
-
runPropertiesXml: normalizedRunPropertiesXml,
|
|
217943
|
-
namespaceSourceOpenTag,
|
|
217944
|
-
hasForeignRevisionLikeRunProperties: false,
|
|
217945
|
-
hasNonWordMarkup: runPropertiesContainNonWordMarkup(normalizedRunPropertiesXml, namespaceSourceOpenTag),
|
|
217946
|
-
hasParagraphRootMarkupCompatibilityAttributes,
|
|
217947
|
-
hasInheritedMarkupCompatibilityAttributes,
|
|
217948
|
-
hasUnresolvedInheritedAttributeNamespaces
|
|
217949
|
-
} : null
|
|
217950
|
-
};
|
|
217951
|
-
}
|
|
217952
|
-
function cloneDirectParagraphPropertiesForInsert(paraXml) {
|
|
217953
|
-
const inner = paragraphInnerXml(paraXml);
|
|
217954
|
-
if (inner == null)
|
|
217955
|
-
return null;
|
|
217956
|
-
const { pPr } = splitLeadingParagraphPropertyBlock(inner);
|
|
217957
|
-
if (!pPr)
|
|
217958
|
-
return null;
|
|
217959
|
-
let direct = stripParagraphPropertyChange(pPr);
|
|
217960
|
-
if (!direct)
|
|
217961
|
-
return null;
|
|
217962
|
-
for (const localName2 of ["pStyle", "numPr", "sectPr"]) {
|
|
217963
|
-
direct = stripElements(direct, localName2);
|
|
217964
|
-
}
|
|
217965
|
-
direct = replaceParagraphMarkRunProperties(direct);
|
|
217966
|
-
return paragraphPropertiesXmlIsEmpty(direct) ? null : direct;
|
|
217967
|
-
}
|
|
217968
|
-
function replaceParagraphMarkRunProperties(pPrXml) {
|
|
217969
|
-
const markProperties = extractParagraphMarkRunProperties(pPrXml);
|
|
217970
|
-
if (markProperties == null)
|
|
217971
|
-
return stripElements(pPrXml, "rPr");
|
|
217972
|
-
const span = topLevelMarkRPrSpan(pPrXml);
|
|
217973
|
-
if (!span)
|
|
217974
|
-
return pPrXml;
|
|
217975
|
-
return pPrXml.slice(0, span.start) + markProperties + pPrXml.slice(span.end);
|
|
217976
|
-
}
|
|
217977
|
-
function topLevelMarkRPrSpan(pPrXml) {
|
|
217978
|
-
const changeOffset = pPrXml.search(/<[\w.-]+:pPrChange\b/);
|
|
217979
|
-
const limit = changeOffset >= 0 ? changeOffset : pPrXml.length;
|
|
217980
|
-
const openOffset = pPrXml.search(/<[\w.-]+:rPr\b/);
|
|
217981
|
-
if (openOffset < 0 || openOffset >= limit)
|
|
217982
|
-
return null;
|
|
217983
|
-
const span = matchLeadingElement(pPrXml.slice(openOffset), "rPr");
|
|
217984
|
-
if (!span)
|
|
217985
|
-
return null;
|
|
217986
|
-
return { start: openOffset, end: openOffset + span.length };
|
|
217987
|
-
}
|
|
217988
|
-
function cloneAdjacentRunPropertiesForInsert(paraXml, placement2, paragraphMarkRunPropertiesXml, inheritedNamespaceBindings = {}) {
|
|
217989
|
-
const carrierResult = cloneAdjacentRunPropertiesCarrierForInsertion(paraXml, placement2, inheritedNamespaceBindings);
|
|
217990
|
-
if (!carrierResult.ok)
|
|
217991
|
-
return carrierResult;
|
|
217992
|
-
const carrier = carrierResult.carrier;
|
|
217993
|
-
if (!carrier) {
|
|
217994
|
-
return {
|
|
217995
|
-
ok: true,
|
|
217996
|
-
runPropertiesXml: paragraphMarkRunPropertiesXml || null
|
|
217997
|
-
};
|
|
217998
|
-
}
|
|
217999
|
-
if (carrier.hasForeignRevisionLikeRunProperties || carrier.hasInheritedMarkupCompatibilityAttributes && carrier.hasNonWordMarkup !== false || carrier.hasUnresolvedInheritedAttributeNamespaces) {
|
|
218000
|
-
return { ok: false, reason: "unsupported-context" };
|
|
218001
|
-
}
|
|
218002
|
-
if (carrier.hasParagraphRootMarkupCompatibilityAttributes && carrier.hasNonWordMarkup !== false) {
|
|
218003
|
-
return { ok: false, reason: "unsupported-context" };
|
|
218004
|
-
}
|
|
218005
|
-
const runPropertiesXml = namespaceCloseRunPropertiesForRelocation(carrier.runPropertiesXml, carrier.namespaceSourceOpenTag, inheritedNamespaceBindings);
|
|
218006
|
-
if (!runPropertiesXml)
|
|
218007
|
-
return { ok: false, reason: "unsupported-context" };
|
|
218008
|
-
return {
|
|
218009
|
-
ok: true,
|
|
218010
|
-
runPropertiesXml
|
|
218011
|
-
};
|
|
218012
|
-
}
|
|
218013
|
-
function adjacentFormattingCarrierRun(paragraphXml, placement2, inheritedNamespaceBindings = {}) {
|
|
218014
|
-
const paragraphPrefix = /^<(?:(?<prefix>[\w.-]+):)?p\b/.exec(paragraphXml)?.groups?.prefix ?? "";
|
|
218015
|
-
const additionalNamespaces = xmlFragmentAdditionalNamespaces(paragraphXml, new Map(Object.entries(inheritedNamespaceBindings)), { w: NS_W, [paragraphPrefix]: NS_W });
|
|
218016
|
-
const parsed = collectXmlElementRanges(paragraphXml, { additionalNamespaces });
|
|
218017
|
-
if (parsed.errors.length > 0)
|
|
218018
|
-
return { ok: true, run: undefined };
|
|
218019
|
-
const carrier = adjacentFormattingCarrierPiece(parseParagraphInlineMap(paragraphXml, inheritedNamespaceBindings).pieces, placement2);
|
|
218020
|
-
if (!carrier.ok)
|
|
218021
|
-
return carrier;
|
|
218022
|
-
const carrierPiece = carrier.piece;
|
|
218023
|
-
if (!carrierPiece)
|
|
218024
|
-
return { ok: true, run: undefined };
|
|
218025
|
-
const payloadLocalName = carrierPiece.kind === "text" ? "t" : carrierPiece.control;
|
|
218026
|
-
const run = parsed.ranges.find((range) => range.start === carrierPiece.runCharStart && range.end === carrierPiece.runCharEnd && range.tag.namespaceUri === NS_W && range.tag.localName === "r");
|
|
218027
|
-
const payload = parsed.ranges.find((range) => range.start === carrierPiece.charStart && range.end === carrierPiece.charEnd && range.tag.namespaceUri === NS_W && range.tag.localName === payloadLocalName);
|
|
218028
|
-
if (!run || !payload)
|
|
218029
|
-
return { ok: true, run: undefined };
|
|
218030
|
-
const hyperlinkRanges = parsed.ranges.filter((range) => range.tag.namespaceUri === NS_W && range.tag.localName === "hyperlink");
|
|
218031
|
-
return {
|
|
218032
|
-
ok: true,
|
|
218033
|
-
run: {
|
|
218034
|
-
start: run.start,
|
|
218035
|
-
end: run.end,
|
|
218036
|
-
xml: paragraphXml.slice(run.start, run.end),
|
|
218037
|
-
insideHyperlink: hyperlinkRanges.some((hyperlink) => hyperlink.start < run.start && run.end <= hyperlink.end)
|
|
218038
|
-
}
|
|
218039
|
-
};
|
|
218040
|
-
}
|
|
218041
|
-
function adjacentFormattingCarrierPiece(pieces, placement2) {
|
|
218042
|
-
const candidates = placement2 === "before" ? pieces : [...pieces].reverse();
|
|
218043
|
-
for (const piece of candidates) {
|
|
218044
|
-
if (piece.kind === "marker")
|
|
218045
|
-
continue;
|
|
218046
|
-
if (piece.kind === "text") {
|
|
218047
|
-
if (piece.textRole === "visible")
|
|
218048
|
-
return { ok: true, piece };
|
|
218049
|
-
continue;
|
|
218050
|
-
}
|
|
218051
|
-
if (piece.kind === "control") {
|
|
218052
|
-
if (!piece.deleted)
|
|
218053
|
-
return { ok: true, piece };
|
|
218054
|
-
continue;
|
|
218055
|
-
}
|
|
218056
|
-
if (piece.kind === "tracked") {
|
|
218057
|
-
if (piece.removesVisible)
|
|
218058
|
-
continue;
|
|
218059
|
-
const nested = adjacentFormattingCarrierPiece(piece.children, placement2);
|
|
218060
|
-
if (!nested.ok || nested.piece)
|
|
218061
|
-
return nested;
|
|
218062
|
-
if (piece.visibleStart === piece.visibleEnd)
|
|
218063
|
-
continue;
|
|
218064
|
-
return { ok: true, piece: undefined };
|
|
218065
|
-
}
|
|
218066
|
-
if (piece.kind === "container") {
|
|
218067
|
-
if (piece.policy === "fail-closed")
|
|
218068
|
-
return { ok: false, reason: "unsupported-context" };
|
|
218069
|
-
if (piece.policy === "atomic") {
|
|
218070
|
-
if (piece.containerKind === "math")
|
|
218071
|
-
return { ok: true, piece: undefined };
|
|
218072
|
-
continue;
|
|
218073
|
-
}
|
|
218074
|
-
const nested = adjacentFormattingCarrierPiece(piece.children, placement2);
|
|
218075
|
-
if (!nested.ok || nested.piece)
|
|
218076
|
-
return nested;
|
|
218077
|
-
if (piece.visibleStart === piece.visibleEnd)
|
|
218078
|
-
continue;
|
|
218079
|
-
return { ok: true, piece: undefined };
|
|
218080
|
-
}
|
|
218081
|
-
if (piece.kind === "noteReference") {
|
|
218082
|
-
continue;
|
|
218083
|
-
}
|
|
218084
|
-
return { ok: true, piece: undefined };
|
|
218085
|
-
}
|
|
218086
|
-
return { ok: true, piece: undefined };
|
|
218087
|
-
}
|
|
218088
|
-
function runPropertiesContainForeignRevisionLikeElement(rPrXml, namespaceSourceOpenTag) {
|
|
218089
|
-
const runPropertiesNode = readXmlNodeAt(rPrXml, 0);
|
|
218090
|
-
if (!runPropertiesNode || runPropertiesNode.kind !== "element" || runPropertiesNode.selfClosing || xmlLocalName(runPropertiesNode.qname) !== "rPr" || runPropertiesNode.end !== rPrXml.length) {
|
|
218091
|
-
return null;
|
|
218092
|
-
}
|
|
218093
|
-
const parsedXml = namespaceSourceOpenTag + rPrXml.slice(runPropertiesNode.openEnd, runPropertiesNode.closeStart) + rPrXml.slice(runPropertiesNode.closeStart);
|
|
218094
|
-
const additionalNamespaces = xmlFragmentAdditionalNamespaces(parsedXml, new Map, { w: NS_W });
|
|
218095
|
-
const parsed = collectXmlElementRanges(parsedXml, { additionalNamespaces });
|
|
218096
|
-
if (parsed.errors.length > 0)
|
|
218097
|
-
return null;
|
|
218098
|
-
return parsed.ranges.some((range) => range.tag.localName === "rPrChange" && range.tag.namespaceUri !== NS_W);
|
|
218099
|
-
}
|
|
218100
|
-
function runPropertiesContainNonWordMarkup(rPrXml, namespaceSourceOpenTag) {
|
|
218101
|
-
const runPropertiesNode = readXmlNodeAt(rPrXml, 0);
|
|
218102
|
-
if (!runPropertiesNode || runPropertiesNode.kind !== "element" || runPropertiesNode.selfClosing || xmlLocalName(runPropertiesNode.qname) !== "rPr" || runPropertiesNode.end !== rPrXml.length) {
|
|
218103
|
-
return null;
|
|
218104
|
-
}
|
|
218105
|
-
const parsedXml = namespaceSourceOpenTag + rPrXml.slice(runPropertiesNode.openEnd, runPropertiesNode.closeStart) + rPrXml.slice(runPropertiesNode.closeStart);
|
|
218106
|
-
const additionalNamespaces = xmlFragmentAdditionalNamespaces(parsedXml, new Map, { w: NS_W });
|
|
218107
|
-
const parsed = collectXmlElementRanges(parsedXml, { additionalNamespaces });
|
|
218108
|
-
if (parsed.errors.length > 0)
|
|
218109
|
-
return null;
|
|
218110
|
-
return parsed.ranges.some((range) => range.tag.namespaceUri !== NS_W || range.tag.attributes.some((attribute) => attribute.prefix !== "xmlns" && attribute.name !== "xmlns" && attribute.namespaceUri !== "" && attribute.namespaceUri !== NS_W && attribute.namespaceUri !== NS_XML));
|
|
218111
|
-
}
|
|
218112
|
-
function stripHyperlinkRunStyle(rPrXml, namespaceSourceOpenTag) {
|
|
218113
|
-
const runPropertiesNode = readXmlNodeAt(rPrXml, 0);
|
|
218114
|
-
if (!runPropertiesNode || runPropertiesNode.kind !== "element" || runPropertiesNode.selfClosing || xmlLocalName(runPropertiesNode.qname) !== "rPr" || runPropertiesNode.end !== rPrXml.length) {
|
|
218115
|
-
return null;
|
|
218116
|
-
}
|
|
218117
|
-
const parsedXml = namespaceSourceOpenTag + rPrXml.slice(runPropertiesNode.openEnd, runPropertiesNode.closeStart) + rPrXml.slice(runPropertiesNode.closeStart);
|
|
218118
|
-
const additionalNamespaces = xmlFragmentAdditionalNamespaces(parsedXml, new Map, { w: NS_W });
|
|
218119
|
-
const parsed = collectXmlElementRanges(parsedXml, { additionalNamespaces });
|
|
218120
|
-
if (parsed.errors.length > 0)
|
|
218121
|
-
return null;
|
|
218122
|
-
const openTagDelta = namespaceSourceOpenTag.length - runPropertiesNode.openEnd;
|
|
218123
|
-
const styleSpans = parsed.ranges.filter((range) => range.tag.namespaceUri === NS_W && range.tag.localName === "rStyle" && readXmlAttribute(range.tag, NS_W, "val")?.value === "Hyperlink").map((range) => ({ start: range.start - openTagDelta, end: range.end - openTagDelta })).filter((range) => range.start >= runPropertiesNode.openEnd && range.end <= runPropertiesNode.closeStart).sort((left, right) => right.start - left.start);
|
|
218124
|
-
let stripped = rPrXml;
|
|
218125
|
-
for (const span of styleSpans)
|
|
218126
|
-
stripped = stripped.slice(0, span.start) + stripped.slice(span.end);
|
|
218127
|
-
return runPropertiesXmlIsEmpty(stripped) ? null : stripped;
|
|
218128
|
-
}
|
|
218129
|
-
function namespaceSourceForRunProperties(paragraphXml, run, runPropertiesXml, inheritedNamespaceBindings) {
|
|
218130
|
-
const runProperties = findFirstElement(run.xml, "rPr");
|
|
218131
|
-
const runPropertiesNode = readXmlNodeAt(runPropertiesXml, 0);
|
|
218132
|
-
if (!runProperties || !runPropertiesNode || runPropertiesNode.kind !== "element" || xmlLocalName(runPropertiesNode.qname) !== "rPr") {
|
|
218133
|
-
return null;
|
|
218134
|
-
}
|
|
218135
|
-
const runPropertiesOpenTag = runPropertiesXml.slice(0, runPropertiesNode.openEnd);
|
|
218136
|
-
const targetStart = run.start + runProperties.start;
|
|
218137
|
-
const inheritedScopes = [];
|
|
218138
|
-
const inheritedCompatibilityScopes = [];
|
|
218139
|
-
const unresolvedInheritedAttributeScopes = [];
|
|
218140
|
-
const compatibilityStack = [];
|
|
218141
|
-
const unresolvedAttributeStack = [];
|
|
218142
|
-
let hasParagraphRootMarkupCompatibilityAttributes = false;
|
|
218143
|
-
const additionalNamespaces = xmlFragmentAdditionalNamespaces(paragraphXml, new Map(Object.entries(inheritedNamespaceBindings)), { w: NS_W });
|
|
218144
|
-
const parsed = walkXmlElements(paragraphXml, {
|
|
218145
|
-
additionalNamespaces,
|
|
218146
|
-
onOpenTag(event) {
|
|
218147
|
-
const parentHasCompatibilityAttributes = compatibilityStack.at(-1) ?? false;
|
|
218148
|
-
const parentHasUnresolvedAttributeNamespaces = unresolvedAttributeStack.at(-1) ?? false;
|
|
218149
|
-
if (event.start === targetStart && event.tag.namespaceUri === NS_W && event.tag.localName === "rPr") {
|
|
218150
|
-
const inherited = { ...event.namespaceBindings };
|
|
218151
|
-
for (const prefix of Object.keys(event.tag.namespaceBindings))
|
|
218152
|
-
delete inherited[prefix];
|
|
218153
|
-
inheritedScopes.push(inherited);
|
|
218154
|
-
inheritedCompatibilityScopes.push(parentHasCompatibilityAttributes);
|
|
218155
|
-
unresolvedInheritedAttributeScopes.push(parentHasUnresolvedAttributeNamespaces);
|
|
218156
|
-
}
|
|
218157
|
-
const isParagraphRoot = event.start === 0 && event.tag.namespaceUri === NS_W && event.tag.localName === "p";
|
|
218158
|
-
if (isParagraphRoot) {
|
|
218159
|
-
hasParagraphRootMarkupCompatibilityAttributes = event.tag.attributes.some((attribute) => attribute.namespaceUri === NS_MC);
|
|
218160
|
-
}
|
|
218161
|
-
const hasLocalCompatibilityAttributes = !isParagraphRoot && event.tag.attributes.some((attribute) => attribute.namespaceUri === NS_MC);
|
|
218162
|
-
compatibilityStack.push(parentHasCompatibilityAttributes || hasLocalCompatibilityAttributes);
|
|
218163
|
-
const hasUnresolvedAttributeNamespaces = event.tag.attributes.some((attribute) => attribute.namespaceUri.startsWith("urn:superdoc:unresolved-namespace-prefix:"));
|
|
218164
|
-
unresolvedAttributeStack.push(parentHasUnresolvedAttributeNamespaces || hasUnresolvedAttributeNamespaces);
|
|
218165
|
-
},
|
|
218166
|
-
onCloseTag() {
|
|
218167
|
-
compatibilityStack.pop();
|
|
218168
|
-
unresolvedAttributeStack.pop();
|
|
218169
|
-
}
|
|
218170
|
-
});
|
|
218171
|
-
const inheritedBindings = inheritedScopes[0];
|
|
218172
|
-
const hasInheritedMarkupCompatibilityAttributes = inheritedCompatibilityScopes[0];
|
|
218173
|
-
const hasUnresolvedInheritedAttributeNamespaces = unresolvedInheritedAttributeScopes[0];
|
|
218174
|
-
if (parsed.errors.length > 0 || !inheritedBindings || hasInheritedMarkupCompatibilityAttributes == null || hasUnresolvedInheritedAttributeNamespaces == null) {
|
|
218175
|
-
return null;
|
|
218176
|
-
}
|
|
218177
|
-
let declarations = "";
|
|
218178
|
-
for (const [prefix, namespaceUri] of Object.entries(inheritedBindings)) {
|
|
218179
|
-
if (prefix === "xml")
|
|
218180
|
-
continue;
|
|
218181
|
-
declarations += prefix.length > 0 ? ` xmlns:${prefix}="${escapeXmlAttribute(namespaceUri)}"` : ` xmlns="${escapeXmlAttribute(namespaceUri)}"`;
|
|
218182
|
-
}
|
|
218183
|
-
return {
|
|
218184
|
-
openTag: declarations.length > 0 ? runPropertiesOpenTag.replace(/>$/, `${declarations}>`) : runPropertiesOpenTag,
|
|
218185
|
-
hasParagraphRootMarkupCompatibilityAttributes,
|
|
218186
|
-
hasInheritedMarkupCompatibilityAttributes,
|
|
218187
|
-
hasUnresolvedInheritedAttributeNamespaces
|
|
218188
|
-
};
|
|
218189
|
-
}
|
|
218190
|
-
function readRunPropertiesXml(runXml) {
|
|
218191
|
-
const inner = runInnerXml(runXml);
|
|
218192
|
-
if (inner == null)
|
|
218193
|
-
return null;
|
|
218194
|
-
const leading = /^\s*/.exec(inner)?.[0] ?? "";
|
|
218195
|
-
const rPrXml = matchLeadingElement(inner.slice(leading.length), "rPr");
|
|
218196
|
-
return rPrXml || null;
|
|
218197
|
-
}
|
|
218198
|
-
function cloneParagraphMarkRunPropertiesForInsert(paraXml) {
|
|
218199
|
-
const inner = paragraphInnerXml(paraXml);
|
|
218200
|
-
if (inner == null)
|
|
218201
|
-
return null;
|
|
218202
|
-
const { pPr } = splitLeadingParagraphPropertyBlock(inner);
|
|
218203
|
-
if (!pPr)
|
|
218204
|
-
return null;
|
|
218205
|
-
const markProperties = extractParagraphMarkRunProperties(stripParagraphPropertyChange(pPr));
|
|
218206
|
-
return markProperties && !runPropertiesXmlIsEmpty(markProperties) ? markProperties : null;
|
|
218207
|
-
}
|
|
218208
|
-
function normalizeClonedRunProperties(rPrXml) {
|
|
218209
|
-
const stripped = stripElements(rPrXml, "rPrChange");
|
|
218210
|
-
return runPropertiesXmlIsEmpty(stripped) ? null : stripped;
|
|
218211
|
-
}
|
|
218212
|
-
function paragraphInnerXml(paraXml) {
|
|
218213
|
-
const openTag = /^<[\w.-]+:p\b[^>]*>/.exec(paraXml)?.[0];
|
|
218214
|
-
const closeTag = /<\/[\w.-]+:p>\s*$/.exec(paraXml)?.[0];
|
|
218215
|
-
if (!openTag || !closeTag)
|
|
218216
|
-
return null;
|
|
218217
|
-
return paraXml.slice(openTag.length, paraXml.length - closeTag.length);
|
|
218218
|
-
}
|
|
218219
|
-
function runInnerXml(runXml) {
|
|
218220
|
-
const openTag = /^<[\w.-]+:r\b[^>]*>/.exec(runXml)?.[0];
|
|
218221
|
-
const closeTag = /<\/[\w.-]+:r>\s*$/.exec(runXml)?.[0];
|
|
218222
|
-
if (!openTag || !closeTag)
|
|
218223
|
-
return null;
|
|
218224
|
-
return runXml.slice(openTag.length, runXml.length - closeTag.length);
|
|
218225
|
-
}
|
|
218226
|
-
function composeParagraphPropertiesXml(input) {
|
|
218227
|
-
const explicit = renderParagraphProperties2(input.styleId, input.numberingProperties);
|
|
218228
|
-
const explicitChildren = paragraphPropertiesChildrenXml(explicit);
|
|
218229
|
-
const inheritedChildren = paragraphPropertiesChildrenXml(input.inheritedParagraphPropertiesXml);
|
|
218230
|
-
const children = `${explicitChildren}${inheritedChildren}`;
|
|
218231
|
-
const namespaceAttrs = paragraphPropertiesNamespaceAttrs(input.inheritedParagraphPropertiesXml);
|
|
218232
|
-
return children.trim().length > 0 ? `<w:pPr${namespaceAttrs}>${children}</w:pPr>` : null;
|
|
218233
|
-
}
|
|
218234
|
-
function paragraphPropertiesChildrenXml(pPrXml) {
|
|
218235
|
-
if (!pPrXml)
|
|
218236
|
-
return "";
|
|
218237
|
-
const trimmed = pPrXml.trim();
|
|
218238
|
-
const selfClosing = /^<[\w.-]+:pPr\b[^>]*\/>$/.exec(trimmed);
|
|
218239
|
-
if (selfClosing)
|
|
218240
|
-
return "";
|
|
218241
|
-
const open = /^<[\w.-]+:pPr\b[^>]*>/.exec(trimmed)?.[0];
|
|
218242
|
-
const close = /<\/[\w.-]+:pPr>\s*$/.exec(trimmed)?.[0];
|
|
218243
|
-
if (!open || !close)
|
|
218244
|
-
return "";
|
|
218245
|
-
return trimmed.slice(open.length, trimmed.length - close.length);
|
|
218246
|
-
}
|
|
218247
|
-
function paragraphPropertiesNamespaceAttrs(pPrXml) {
|
|
218248
|
-
if (!pPrXml)
|
|
218249
|
-
return "";
|
|
218250
|
-
const trimmed = pPrXml.trim();
|
|
218251
|
-
const openAttrs = /^<[\w.-]+:pPr\b([^>]*)\/?>/.exec(trimmed)?.[1] ?? "";
|
|
218252
|
-
return openAttrs.match(/\s+xmlns(?::[\w.-]+)?=(?:"[^"]*"|'[^']*')/g)?.join("") ?? "";
|
|
218253
|
-
}
|
|
218254
|
-
function paragraphPropertiesXmlIsEmpty(pPrXml) {
|
|
218255
|
-
const trimmed = pPrXml.trim();
|
|
218256
|
-
return /^<[\w.-]+:pPr\b[^>]*\/>$/.test(trimmed) || /^<([\w.-]+):pPr\b[^>]*>\s*<\/\1:pPr>$/.test(trimmed);
|
|
218257
|
-
}
|
|
218258
|
-
function runPropertiesXmlIsEmpty(rPrXml) {
|
|
218259
|
-
const trimmed = rPrXml.trim();
|
|
218260
|
-
return /^<[\w.-]+:rPr\b[^>]*\/>$/.test(trimmed) || /^<([\w.-]+):rPr\b[^>]*>\s*<\/\1:rPr>$/.test(trimmed);
|
|
218261
|
-
}
|
|
218262
|
-
var TD54;
|
|
218263
|
-
var init_insertion_formatting_context = __esm(() => {
|
|
218264
|
-
init_sd_document_state();
|
|
218265
|
-
init_style_definitions_part();
|
|
218266
|
-
init_style_definitions_xml();
|
|
218267
|
-
init_paragraph_inline_model();
|
|
218268
|
-
init_xml_text();
|
|
218269
|
-
init_xml_sax();
|
|
218270
|
-
init_paragraph_contribution();
|
|
218271
|
-
init_direct_paragraph_list_properties();
|
|
218272
|
-
init_paragraph_property_block();
|
|
218273
|
-
init_paragraph_para_id_attrs();
|
|
218274
|
-
TD54 = new TextDecoder;
|
|
218275
|
-
});
|
|
218276
|
-
|
|
218277
218310
|
// ../../../v2/editor-core/dist/document/transactions/compile-paragraph-ops.js
|
|
218278
218311
|
function prepareParagraphInsert(state, op) {
|
|
218279
218312
|
const site = resolveParagraphInsertSite(state, op);
|
|
@@ -219541,7 +219574,17 @@ function prepareParagraphSplit(input) {
|
|
|
219541
219574
|
});
|
|
219542
219575
|
if (!tailProperties.ok)
|
|
219543
219576
|
return tailProperties;
|
|
219544
|
-
|
|
219577
|
+
let tailPropertiesXml = tailProperties.paragraphPropertiesXml;
|
|
219578
|
+
if (slice.terminal && input.resolveTailStyleId) {
|
|
219579
|
+
const sourceStyle = readDirectParagraphStyleId(paragraphXml);
|
|
219580
|
+
if (sourceStyle.presence === "present") {
|
|
219581
|
+
const tailStyleId = input.resolveTailStyleId(sourceStyle.styleId);
|
|
219582
|
+
if (tailStyleId) {
|
|
219583
|
+
tailPropertiesXml = replaceDirectParagraphStyleId(tailPropertiesXml, tailStyleId);
|
|
219584
|
+
}
|
|
219585
|
+
}
|
|
219586
|
+
}
|
|
219587
|
+
const tailXml = tailWithId + tailPropertiesXml + slice.tail + closeTag;
|
|
219545
219588
|
const headMarkProperties = /<(?:[\w.-]+:)?(?:ins|del|moveFrom|moveTo)\b/.test(pPrXml) ? stripParagraphMarkRevisionMarkers(pPrXml, namespaceBindingsAtPosition(input.partBytes, input.paragraphByteStart, openTag)) : pPrXml;
|
|
219546
219589
|
const headProperties = stripParagraphPropertyChange(headMarkProperties);
|
|
219547
219590
|
const headXml = openTag + headProperties + slice.head + closeTag;
|
|
@@ -219633,6 +219676,17 @@ function runParagraphSplitCommit(input) {
|
|
|
219633
219676
|
const tailParaId = provisionalParaId;
|
|
219634
219677
|
const splitAllocatedWIds = [];
|
|
219635
219678
|
const metadataClones = [];
|
|
219679
|
+
const nextStyleCache = new Map;
|
|
219680
|
+
const resolveTailStyleId = (currentStyleId) => {
|
|
219681
|
+
let cached2 = nextStyleCache.get(currentStyleId);
|
|
219682
|
+
if (cached2 === undefined) {
|
|
219683
|
+
cached2 = lookupNextStyle(input.state, currentStyleId);
|
|
219684
|
+
nextStyleCache.set(currentStyleId, cached2);
|
|
219685
|
+
}
|
|
219686
|
+
if (!cached2.ok)
|
|
219687
|
+
return null;
|
|
219688
|
+
return cached2.styleId && cached2.styleId !== currentStyleId ? cached2.styleId : null;
|
|
219689
|
+
};
|
|
219636
219690
|
const primarySplit = prepareParagraphSplit({
|
|
219637
219691
|
paragraphXml: paraXml,
|
|
219638
219692
|
partBytes: bytes,
|
|
@@ -219646,7 +219700,8 @@ function runParagraphSplitCommit(input) {
|
|
|
219646
219700
|
const wId = allocateRevisionWId(input.state);
|
|
219647
219701
|
splitAllocatedWIds.push(wId);
|
|
219648
219702
|
return wId;
|
|
219649
|
-
}
|
|
219703
|
+
},
|
|
219704
|
+
resolveTailStyleId
|
|
219650
219705
|
});
|
|
219651
219706
|
if (!primarySplit.ok)
|
|
219652
219707
|
return rejected8(input.txId, primarySplit.reason);
|
|
@@ -219685,7 +219740,8 @@ function runParagraphSplitCommit(input) {
|
|
|
219685
219740
|
return 0;
|
|
219686
219741
|
}
|
|
219687
219742
|
return wId;
|
|
219688
|
-
}
|
|
219743
|
+
},
|
|
219744
|
+
resolveTailStyleId
|
|
219689
219745
|
});
|
|
219690
219746
|
if (!split.ok)
|
|
219691
219747
|
return split;
|
|
@@ -221250,6 +221306,8 @@ var init_compile_paragraph_ops = __esm(() => {
|
|
|
221250
221306
|
init_part_payload();
|
|
221251
221307
|
init_paragraph_contribution();
|
|
221252
221308
|
init_paragraph_property_block();
|
|
221309
|
+
init_direct_paragraph_list_properties();
|
|
221310
|
+
init_insertion_formatting_context();
|
|
221253
221311
|
init_paragraph_para_id_attrs();
|
|
221254
221312
|
init_paragraph_index();
|
|
221255
221313
|
init_commit_prepared_mutation();
|
|
@@ -278610,6 +278668,17 @@ function storyMatches(a, b) {
|
|
|
278610
278668
|
const bn = canonicalStory(b);
|
|
278611
278669
|
return an === bn;
|
|
278612
278670
|
}
|
|
278671
|
+
function pickStoryLocator(target, override) {
|
|
278672
|
+
if (override)
|
|
278673
|
+
return override;
|
|
278674
|
+
if (target.story)
|
|
278675
|
+
return target.story;
|
|
278676
|
+
if (target.start.kind === "text" && target.start.story)
|
|
278677
|
+
return target.start.story;
|
|
278678
|
+
if (target.end.kind === "text" && target.end.story)
|
|
278679
|
+
return target.end.story;
|
|
278680
|
+
return;
|
|
278681
|
+
}
|
|
278613
278682
|
function selectionTargetStoriesMatch(target, overrideStory) {
|
|
278614
278683
|
const suppliedStories = [
|
|
278615
278684
|
overrideStory,
|
|
@@ -279084,6 +279153,9 @@ function resolveBodySelectionTarget(context, target) {
|
|
|
279084
279153
|
const index = getSDDocumentSessionInternalParagraphIndex(context.session);
|
|
279085
279154
|
if (!index)
|
|
279086
279155
|
return { error: "PRECONDITION_FAILED", message: "paragraph index is not available." };
|
|
279156
|
+
return resolveStorySelectionTarget(context, target, index);
|
|
279157
|
+
}
|
|
279158
|
+
function resolveStorySelectionTarget(context, target, index) {
|
|
279087
279159
|
return resolveSelectionTargetToRange({
|
|
279088
279160
|
target,
|
|
279089
279161
|
index,
|
|
@@ -279093,6 +279165,24 @@ function resolveBodySelectionTarget(context, target) {
|
|
|
279093
279165
|
buildOffsetMap: buildSDDocumentSessionInternalParagraphOffsetMap
|
|
279094
279166
|
});
|
|
279095
279167
|
}
|
|
279168
|
+
function listStoryPartSources(context) {
|
|
279169
|
+
const body = context.resolveFullStoryLocator({ kind: "story", storyType: "body" });
|
|
279170
|
+
if ("error" in body)
|
|
279171
|
+
throw operationError("TARGET_NOT_FOUND", "body story is not available.");
|
|
279172
|
+
const sources = [{ partUri: body.partUri, storyId: body.storyId }];
|
|
279173
|
+
const seen = new Set([body.partUri]);
|
|
279174
|
+
for (const rel of listSDDocumentSessionInternalHeaderFooterRels(context.session)) {
|
|
279175
|
+
if (seen.has(rel.partUri))
|
|
279176
|
+
continue;
|
|
279177
|
+
const story = { kind: "story", storyType: "headerFooterPart", refId: rel.refId };
|
|
279178
|
+
const resolved = context.resolveFullStoryLocator(story);
|
|
279179
|
+
if ("error" in resolved)
|
|
279180
|
+
continue;
|
|
279181
|
+
seen.add(rel.partUri);
|
|
279182
|
+
sources.push({ partUri: rel.partUri, storyId: resolved.storyId, story });
|
|
279183
|
+
}
|
|
279184
|
+
return sources;
|
|
279185
|
+
}
|
|
279096
279186
|
function contentTypeForPart2(partUri) {
|
|
279097
279187
|
if (partUri.endsWith(".rels"))
|
|
279098
279188
|
return "application/vnd.openxmlformats-package.relationships+xml";
|
|
@@ -328322,7 +328412,112 @@ var init_tracked_structural_wrapper = __esm(() => {
|
|
|
328322
328412
|
init_common();
|
|
328323
328413
|
});
|
|
328324
328414
|
|
|
328415
|
+
// ../../../v2/document-api-v2-adapter/dist/address/story-surface.js
|
|
328416
|
+
function resolveStorySurface(session, bodyStoryId, locator) {
|
|
328417
|
+
const resolved = resolveSessionStoryLocator(session, bodyStoryId, locator);
|
|
328418
|
+
if ("error" in resolved) {
|
|
328419
|
+
return { ok: false, failure: classifyStoryLocatorFailure(resolved.error) };
|
|
328420
|
+
}
|
|
328421
|
+
return { ok: true, descriptor: toStorySurfaceDescriptor(resolved) };
|
|
328422
|
+
}
|
|
328423
|
+
function toStorySurfaceDescriptor(resolved) {
|
|
328424
|
+
const descriptor = {
|
|
328425
|
+
storyId: resolved.storyId,
|
|
328426
|
+
partUri: resolved.partUri,
|
|
328427
|
+
storyKind: resolved.storyKind,
|
|
328428
|
+
relationshipOwnerPartUri: resolved.relationshipOwnerPartUri,
|
|
328429
|
+
sourceAvailability: resolved.materialization ? "materialize-on-write" : "available"
|
|
328430
|
+
};
|
|
328431
|
+
if (resolved.storyByteRange)
|
|
328432
|
+
descriptor.storyByteRange = resolved.storyByteRange;
|
|
328433
|
+
if (resolved.refId)
|
|
328434
|
+
descriptor.refId = resolved.refId;
|
|
328435
|
+
if (resolved.noteId)
|
|
328436
|
+
descriptor.noteId = resolved.noteId;
|
|
328437
|
+
if (resolved.textboxId)
|
|
328438
|
+
descriptor.textboxId = resolved.textboxId;
|
|
328439
|
+
if (resolved.materialization)
|
|
328440
|
+
descriptor.materialization = resolved.materialization;
|
|
328441
|
+
if (resolved.slot)
|
|
328442
|
+
descriptor.slot = resolved.slot;
|
|
328443
|
+
if (resolved.resolvedFromSectionId)
|
|
328444
|
+
descriptor.resolvedFromSectionId = resolved.resolvedFromSectionId;
|
|
328445
|
+
return descriptor;
|
|
328446
|
+
}
|
|
328447
|
+
function classifyStoryLocatorFailure(error48) {
|
|
328448
|
+
return {
|
|
328449
|
+
category: storyLocatorFailureCategory(error48),
|
|
328450
|
+
reason: error48,
|
|
328451
|
+
message: storyLocatorFailureMessage(error48)
|
|
328452
|
+
};
|
|
328453
|
+
}
|
|
328454
|
+
function receiptFailureForStoryLocatorError(error48) {
|
|
328455
|
+
const failure4 = classifyStoryLocatorFailure(error48);
|
|
328456
|
+
return {
|
|
328457
|
+
code: failure4.category,
|
|
328458
|
+
message: failure4.message
|
|
328459
|
+
};
|
|
328460
|
+
}
|
|
328461
|
+
function storyLocatorFailureCategory(error48) {
|
|
328462
|
+
switch (error48) {
|
|
328463
|
+
case "not-found":
|
|
328464
|
+
case "unknown-section":
|
|
328465
|
+
case "no-sections":
|
|
328466
|
+
return "TARGET_NOT_FOUND";
|
|
328467
|
+
case "unsupported-story":
|
|
328468
|
+
case "inherited-edit-rejected":
|
|
328469
|
+
case "cross-story-write-rejected":
|
|
328470
|
+
return "CAPABILITY_UNAVAILABLE";
|
|
328471
|
+
case "no-source-for-edit":
|
|
328472
|
+
return "PRECONDITION_FAILED";
|
|
328473
|
+
default: {
|
|
328474
|
+
const _exhaustive = error48;
|
|
328475
|
+
return _exhaustive;
|
|
328476
|
+
}
|
|
328477
|
+
}
|
|
328478
|
+
}
|
|
328479
|
+
function storyLocatorFailureMessage(error48) {
|
|
328480
|
+
switch (error48) {
|
|
328481
|
+
case "not-found":
|
|
328482
|
+
return "the requested story target was not found";
|
|
328483
|
+
case "unknown-section":
|
|
328484
|
+
return "the requested section is not part of this document";
|
|
328485
|
+
case "no-sections":
|
|
328486
|
+
return "the document has no resolvable sections for this story";
|
|
328487
|
+
case "unsupported-story":
|
|
328488
|
+
return "this story family is not supported for the requested operation";
|
|
328489
|
+
case "inherited-edit-rejected":
|
|
328490
|
+
return "the header/footer slot is inherited and cannot be edited under the requested write policy";
|
|
328491
|
+
case "cross-story-write-rejected":
|
|
328492
|
+
return "the requested write would cross story boundaries";
|
|
328493
|
+
case "no-source-for-edit":
|
|
328494
|
+
return "the requested story has no source bytes available for this edit";
|
|
328495
|
+
default:
|
|
328496
|
+
return "the requested story could not be resolved";
|
|
328497
|
+
}
|
|
328498
|
+
}
|
|
328499
|
+
function rangeWithinStorySurface(descriptor, range) {
|
|
328500
|
+
const window2 = descriptor.storyByteRange;
|
|
328501
|
+
if (!window2)
|
|
328502
|
+
return null;
|
|
328503
|
+
if (range.start >= window2[0] && range.end <= window2[1] && range.start <= range.end) {
|
|
328504
|
+
return null;
|
|
328505
|
+
}
|
|
328506
|
+
return {
|
|
328507
|
+
category: "INVALID_CONTEXT",
|
|
328508
|
+
reason: null,
|
|
328509
|
+
message: `byte range [${range.start}, ${range.end}] falls outside the resolved story window ` + `[${window2[0]}, ${window2[1]}] for story ${descriptor.storyId}`
|
|
328510
|
+
};
|
|
328511
|
+
}
|
|
328512
|
+
var init_story_surface = __esm(() => {
|
|
328513
|
+
init_story_locator();
|
|
328514
|
+
});
|
|
328515
|
+
|
|
328325
328516
|
// ../../../v2/document-api-v2-adapter/dist/permission-ranges/adapter.js
|
|
328517
|
+
function isSupportedStoryKind(storyKind) {
|
|
328518
|
+
return storyKind === "main" || storyKind === "header" || storyKind === "footer";
|
|
328519
|
+
}
|
|
328520
|
+
|
|
328326
328521
|
class V2PermissionRangesAdapter {
|
|
328327
328522
|
constructor(context) {
|
|
328328
328523
|
this.context = context;
|
|
@@ -328338,10 +328533,7 @@ class V2PermissionRangesAdapter {
|
|
|
328338
328533
|
});
|
|
328339
328534
|
}
|
|
328340
328535
|
get(input) {
|
|
328341
|
-
|
|
328342
|
-
if (!range)
|
|
328343
|
-
throw operationError("TARGET_NOT_FOUND", `permission range ${input.id} not found.`);
|
|
328344
|
-
return stripInternal2(range);
|
|
328536
|
+
return stripInternal2(this.findByIdOrThrow(input.id));
|
|
328345
328537
|
}
|
|
328346
328538
|
create(input, options) {
|
|
328347
328539
|
const mutationGuard = guardDirectOnlyMutation(this.context, input, options);
|
|
@@ -328349,11 +328541,12 @@ class V2PermissionRangesAdapter {
|
|
|
328349
328541
|
return mutationGuard;
|
|
328350
328542
|
const wholeControl = resolveWholeControlPermissionTarget(this.context, input.target);
|
|
328351
328543
|
if (wholeControl) {
|
|
328352
|
-
const xml2 = this.
|
|
328353
|
-
const
|
|
328354
|
-
if (
|
|
328355
|
-
throw operationError("
|
|
328544
|
+
const xml2 = this.readPartXmlOrThrow(DOCUMENT_PART_URI5);
|
|
328545
|
+
const rawIds2 = listPermissionRangeRawIds(this.context);
|
|
328546
|
+
if (input.id !== undefined && rawIds2.has(input.id)) {
|
|
328547
|
+
throw operationError("DUPLICATE_ID", `permission range id "${input.id}" already exists.`);
|
|
328356
328548
|
}
|
|
328549
|
+
const id2 = input.id ?? allocateRangeId(rawIds2);
|
|
328357
328550
|
const rangeXml = buildPermStart(id2, input.principal) + xml2.slice(wholeControl.start, wholeControl.end) + buildPermEnd(id2);
|
|
328358
328551
|
const nextXml2 = replaceRange2(xml2, wholeControl.start, wholeControl.end, rangeXml);
|
|
328359
328552
|
if (dryRunRequested(input, options)) {
|
|
@@ -328365,14 +328558,38 @@ class V2PermissionRangesAdapter {
|
|
|
328365
328558
|
return { success: false, failure: { code: committed2.code, message: committed2.message } };
|
|
328366
328559
|
return { success: true, range: this.get({ id: id2 }) };
|
|
328367
328560
|
}
|
|
328368
|
-
const
|
|
328561
|
+
const storyLocator = pickStoryLocator(input.target, undefined);
|
|
328562
|
+
if (storyLocator && storyLocator.storyType !== "headerFooterPart" && storyLocator.storyType !== "body") {
|
|
328563
|
+
throw operationError("CAPABILITY_UNAVAILABLE", "permissionRanges.create only supports body and headerFooterPart story targets.");
|
|
328564
|
+
}
|
|
328565
|
+
const resolvedStory = this.context.resolveFullStoryLocator(storyLocator);
|
|
328566
|
+
if ("error" in resolvedStory) {
|
|
328567
|
+
const failure4 = classifyStoryLocatorFailure(resolvedStory.error);
|
|
328568
|
+
throw operationError(failure4.category, failure4.message);
|
|
328569
|
+
}
|
|
328570
|
+
if (!isSupportedStoryKind(resolvedStory.storyKind) || resolvedStory.materialization) {
|
|
328571
|
+
throw operationError("CAPABILITY_UNAVAILABLE", "permissionRanges.create only supports body and explicit header/footer story targets.");
|
|
328572
|
+
}
|
|
328573
|
+
if (resolvedStory.storyKind !== "main" && this.context.isCollaborativeSession()) {
|
|
328574
|
+
throw operationError("CAPABILITY_UNAVAILABLE", COLLABORATIVE_SECONDARY_STORY_MESSAGE);
|
|
328575
|
+
}
|
|
328576
|
+
const index2 = resolvedStory.storyKind === "main" ? getSDDocumentSessionInternalParagraphIndex(this.context.session) : getSDDocumentSessionInternalStoryParagraphIndex(this.context.session, resolvedStory.storyId);
|
|
328577
|
+
if (!index2)
|
|
328578
|
+
throw operationError("PRECONDITION_FAILED", "paragraph index is not available.");
|
|
328579
|
+
const resolved = resolveStorySelectionTarget(this.context, input.target, index2);
|
|
328369
328580
|
if ("error" in resolved)
|
|
328370
328581
|
throw operationError(resolved.error, resolved.message);
|
|
328371
328582
|
if (resolved.startBlockId !== resolved.endBlockId) {
|
|
328372
328583
|
throw operationError("INVALID_TARGET", "permissionRanges.create requires a same-paragraph text selection.");
|
|
328373
328584
|
}
|
|
328374
|
-
const
|
|
328375
|
-
|
|
328585
|
+
const rawIds = listPermissionRangeRawIds(this.context);
|
|
328586
|
+
if (input.id !== undefined && rawIds.has(input.id)) {
|
|
328587
|
+
throw operationError("DUPLICATE_ID", `permission range id "${input.id}" already exists.`);
|
|
328588
|
+
}
|
|
328589
|
+
const id = input.id ?? allocateRangeId(rawIds);
|
|
328590
|
+
const targetPartUri = resolvedStory.partUri;
|
|
328591
|
+
const story = resolvedStory.storyKind === "main" ? undefined : { kind: "story", storyType: "headerFooterPart", refId: resolvedStory.refId };
|
|
328592
|
+
const xml = this.readPartXmlOrThrow(targetPartUri);
|
|
328376
328593
|
const para = findParagraphById2(xml, resolved.startBlockId);
|
|
328377
328594
|
if (!para)
|
|
328378
328595
|
throw operationError("TARGET_NOT_FOUND", `paragraph ${resolved.startBlockId} not found.`);
|
|
@@ -328384,13 +328601,14 @@ class V2PermissionRangesAdapter {
|
|
|
328384
328601
|
principal: input.principal,
|
|
328385
328602
|
kind: "inline",
|
|
328386
328603
|
start: { blockId: resolved.startBlockId, offset: resolved.startOffset },
|
|
328387
|
-
end: { blockId: resolved.endBlockId, offset: resolved.endOffset }
|
|
328604
|
+
end: { blockId: resolved.endBlockId, offset: resolved.endOffset },
|
|
328605
|
+
...story ? { story } : {}
|
|
328388
328606
|
}
|
|
328389
328607
|
};
|
|
328390
328608
|
}
|
|
328391
328609
|
const wrapped = wrapTextRangeWithPermissionMarkers(para.xml, resolved.startOffset, resolved.endOffset, id, input.principal);
|
|
328392
328610
|
const nextXml = replaceRange2(xml, para.start, para.end, wrapped);
|
|
328393
|
-
const committed = commitWholePartUpdates(this.context, "permission-range-create", { [
|
|
328611
|
+
const committed = commitWholePartUpdates(this.context, "permission-range-create", { [targetPartUri]: encodeXml(nextXml) }, { expectedRevision: expectedRevisionFrom(input, options), storyIds: [resolvedStory.storyId] });
|
|
328394
328612
|
if (!committed.ok)
|
|
328395
328613
|
return { success: false, failure: { code: committed.code, message: committed.message } };
|
|
328396
328614
|
return { success: true, range: this.get({ id }) };
|
|
@@ -328399,15 +328617,14 @@ class V2PermissionRangesAdapter {
|
|
|
328399
328617
|
const mutationGuard = guardDirectOnlyMutation(this.context, input, options);
|
|
328400
328618
|
if (mutationGuard)
|
|
328401
328619
|
return mutationGuard;
|
|
328402
|
-
const range =
|
|
328403
|
-
|
|
328404
|
-
throw operationError("TARGET_NOT_FOUND", `permission range ${input.id} not found.`);
|
|
328620
|
+
const range = this.findByIdOrThrow(input.id);
|
|
328621
|
+
this.guardCollaborativeSecondaryStory(range);
|
|
328405
328622
|
if (dryRunRequested(input, options))
|
|
328406
328623
|
return { success: true, id: input.id };
|
|
328407
|
-
let xml = this.
|
|
328624
|
+
let xml = this.readPartXmlOrThrow(range.partUri);
|
|
328408
328625
|
xml = removeMarkerAt(xml, range.endTagStart, range.endTagEnd);
|
|
328409
328626
|
xml = removeMarkerAt(xml, range.startTagStart, range.startTagEnd);
|
|
328410
|
-
const committed = commitWholePartUpdates(this.context, "permission-range-remove", { [
|
|
328627
|
+
const committed = commitWholePartUpdates(this.context, "permission-range-remove", { [range.partUri]: encodeXml(xml) }, { expectedRevision: expectedRevisionFrom(input, options), storyIds: [range.storyId] });
|
|
328411
328628
|
if (!committed.ok)
|
|
328412
328629
|
return { success: false, failure: { code: committed.code, message: committed.message } };
|
|
328413
328630
|
return { success: true, id: input.id };
|
|
@@ -328416,37 +328633,80 @@ class V2PermissionRangesAdapter {
|
|
|
328416
328633
|
const mutationGuard = guardDirectOnlyMutation(this.context, input, options);
|
|
328417
328634
|
if (mutationGuard)
|
|
328418
328635
|
return mutationGuard;
|
|
328419
|
-
const range =
|
|
328420
|
-
|
|
328421
|
-
throw operationError("TARGET_NOT_FOUND", `permission range ${input.id} not found.`);
|
|
328636
|
+
const range = this.findByIdOrThrow(input.id);
|
|
328637
|
+
this.guardCollaborativeSecondaryStory(range);
|
|
328422
328638
|
if (dryRunRequested(input, options))
|
|
328423
328639
|
return { success: true, range: stripInternal2(range) };
|
|
328424
|
-
const xml = this.
|
|
328640
|
+
const xml = this.readPartXmlOrThrow(range.partUri);
|
|
328425
328641
|
const marker = xml.slice(range.startTagStart, range.startTagEnd);
|
|
328426
328642
|
const nextMarker = buildPermStart(input.id, input.principal);
|
|
328427
328643
|
const nextXml = xml.replace(marker, nextMarker);
|
|
328428
|
-
const committed = commitWholePartUpdates(this.context, "permission-range-update", { [
|
|
328644
|
+
const committed = commitWholePartUpdates(this.context, "permission-range-update", { [range.partUri]: encodeXml(nextXml) }, { expectedRevision: expectedRevisionFrom(input, options), storyIds: [range.storyId] });
|
|
328429
328645
|
if (!committed.ok)
|
|
328430
328646
|
return { success: false, failure: { code: committed.code, message: committed.message } };
|
|
328431
328647
|
return { success: true, range: this.get({ id: input.id }) };
|
|
328432
328648
|
}
|
|
328433
|
-
|
|
328434
|
-
const
|
|
328649
|
+
findByIdOrThrow(id) {
|
|
328650
|
+
const matches = listPermissionRanges(this.context).filter((entry) => entry.id === id);
|
|
328651
|
+
if (matches.length === 0)
|
|
328652
|
+
throw operationError("TARGET_NOT_FOUND", `permission range ${id} not found.`);
|
|
328653
|
+
if (matches.length > 1) {
|
|
328654
|
+
throw operationError("AMBIGUOUS_MATCH", `permission range id "${id}" exists in more than one part.`);
|
|
328655
|
+
}
|
|
328656
|
+
const [match] = matches;
|
|
328657
|
+
if (match.malformed) {
|
|
328658
|
+
throw operationError("AMBIGUOUS_MATCH", `permission range id "${id}" has duplicated markers within its part and cannot be resolved unambiguously.`);
|
|
328659
|
+
}
|
|
328660
|
+
return match;
|
|
328661
|
+
}
|
|
328662
|
+
readPartXmlOrThrow(partUri) {
|
|
328663
|
+
const xml = readPartXml(this.context, partUri);
|
|
328435
328664
|
if (!xml)
|
|
328436
|
-
throw operationError("PRECONDITION_FAILED",
|
|
328665
|
+
throw operationError("PRECONDITION_FAILED", `${partUri} bytes are unavailable.`);
|
|
328437
328666
|
return xml;
|
|
328438
328667
|
}
|
|
328668
|
+
guardCollaborativeSecondaryStory(range) {
|
|
328669
|
+
if (range.story && this.context.isCollaborativeSession()) {
|
|
328670
|
+
throw operationError("CAPABILITY_UNAVAILABLE", COLLABORATIVE_SECONDARY_STORY_MESSAGE);
|
|
328671
|
+
}
|
|
328672
|
+
}
|
|
328439
328673
|
}
|
|
328440
328674
|
function listPermissionRanges(context) {
|
|
328441
|
-
const
|
|
328442
|
-
|
|
328443
|
-
|
|
328675
|
+
const out = [];
|
|
328676
|
+
for (const source of listStoryPartSources(context)) {
|
|
328677
|
+
const xml = readPartXml(context, source.partUri);
|
|
328678
|
+
if (!xml)
|
|
328679
|
+
continue;
|
|
328680
|
+
out.push(...parsePermissionRangesFromXml(xml, source));
|
|
328681
|
+
}
|
|
328682
|
+
return out.sort((a, b) => a.partUri === b.partUri ? a.startTagStart - b.startTagStart : a.partUri.localeCompare(b.partUri));
|
|
328683
|
+
}
|
|
328684
|
+
function listPermissionRangeRawIds(context) {
|
|
328685
|
+
const ids = new Set;
|
|
328686
|
+
const markerRe = /<w:perm(?:Start|End)\b[^>]*\/>/g;
|
|
328687
|
+
for (const source of listStoryPartSources(context)) {
|
|
328688
|
+
const xml = readPartXml(context, source.partUri);
|
|
328689
|
+
if (!xml)
|
|
328690
|
+
continue;
|
|
328691
|
+
for (let match = markerRe.exec(xml);match; match = markerRe.exec(xml)) {
|
|
328692
|
+
const id = attrValue(match[0], "id");
|
|
328693
|
+
if (id)
|
|
328694
|
+
ids.add(id);
|
|
328695
|
+
}
|
|
328696
|
+
}
|
|
328697
|
+
return ids;
|
|
328698
|
+
}
|
|
328699
|
+
function parsePermissionRangesFromXml(xml, source) {
|
|
328444
328700
|
const starts = new Map;
|
|
328701
|
+
const duplicateStartIds = new Set;
|
|
328445
328702
|
const startRe = /<w:permStart\b[^>]*\/>/g;
|
|
328446
328703
|
for (let match = startRe.exec(xml);match; match = startRe.exec(xml)) {
|
|
328447
328704
|
const id = attrValue(match[0], "id");
|
|
328448
|
-
if (id)
|
|
328449
|
-
|
|
328705
|
+
if (!id)
|
|
328706
|
+
continue;
|
|
328707
|
+
if (starts.has(id))
|
|
328708
|
+
duplicateStartIds.add(id);
|
|
328709
|
+
starts.set(id, { start: match.index, end: startRe.lastIndex, tag: match[0] });
|
|
328450
328710
|
}
|
|
328451
328711
|
const out = [];
|
|
328452
328712
|
const endRe = /<w:permEnd\b[^>]*\/>/g;
|
|
@@ -328458,21 +328718,23 @@ function listPermissionRanges(context) {
|
|
|
328458
328718
|
if (!start)
|
|
328459
328719
|
continue;
|
|
328460
328720
|
const positions = positionsForMarkerEnvelope(xml, start.start, match.index);
|
|
328461
|
-
const startPos = positions.start;
|
|
328462
|
-
const endPos = positions.end;
|
|
328463
328721
|
out.push({
|
|
328464
328722
|
id,
|
|
328465
328723
|
principal: principalFromPermStart(start.tag),
|
|
328466
|
-
kind:
|
|
328467
|
-
start:
|
|
328468
|
-
end:
|
|
328724
|
+
kind: positions.start.blockId === positions.end.blockId ? "inline" : "block",
|
|
328725
|
+
start: positions.start,
|
|
328726
|
+
end: positions.end,
|
|
328727
|
+
partUri: source.partUri,
|
|
328728
|
+
storyId: source.storyId,
|
|
328729
|
+
malformed: duplicateStartIds.has(id),
|
|
328730
|
+
...source.story ? { story: source.story } : {},
|
|
328469
328731
|
startTagStart: start.start,
|
|
328470
328732
|
startTagEnd: start.end,
|
|
328471
328733
|
endTagStart: match.index,
|
|
328472
328734
|
endTagEnd: endRe.lastIndex
|
|
328473
328735
|
});
|
|
328474
328736
|
}
|
|
328475
|
-
return out
|
|
328737
|
+
return out;
|
|
328476
328738
|
}
|
|
328477
328739
|
function findContentControlXmlRange(xml, id) {
|
|
328478
328740
|
const parsed = collectXmlElementRanges(xml);
|
|
@@ -328520,7 +328782,8 @@ function stripInternal2(range) {
|
|
|
328520
328782
|
principal: range.principal,
|
|
328521
328783
|
kind: range.kind,
|
|
328522
328784
|
start: range.start,
|
|
328523
|
-
end: range.end
|
|
328785
|
+
end: range.end,
|
|
328786
|
+
...range.story ? { story: range.story } : {}
|
|
328524
328787
|
};
|
|
328525
328788
|
}
|
|
328526
328789
|
function principalFromPermStart(tag) {
|
|
@@ -328540,9 +328803,9 @@ function buildPermEnd(id) {
|
|
|
328540
328803
|
}
|
|
328541
328804
|
function wrapTextRangeWithPermissionMarkers(paragraphXml, start, end, id, principal) {
|
|
328542
328805
|
return replaceTextRangeInParagraph(paragraphXml, start, end, (selected) => [
|
|
328543
|
-
|
|
328806
|
+
buildPermStart(id, principal),
|
|
328544
328807
|
`<w:r><w:t>${xmlEscapeText(selected)}</w:t></w:r>`,
|
|
328545
|
-
|
|
328808
|
+
buildPermEnd(id)
|
|
328546
328809
|
].join(""));
|
|
328547
328810
|
}
|
|
328548
328811
|
function positionForXmlIndex(documentXml, index2) {
|
|
@@ -328598,10 +328861,13 @@ function replaceTextRangeInParagraph(paragraphXml, start, end, replacement) {
|
|
|
328598
328861
|
}
|
|
328599
328862
|
function removeMarkerAt(xml, start, end) {
|
|
328600
328863
|
const runStart = findEnclosingRunStart(xml, start);
|
|
328601
|
-
|
|
328602
|
-
|
|
328603
|
-
const
|
|
328604
|
-
|
|
328864
|
+
if (runStart >= 0) {
|
|
328865
|
+
const { runOpenTag, runProperties } = readRunOpenTagAndProperties(xml, runStart);
|
|
328866
|
+
const runContentStart = runStart + runOpenTag.length + runProperties.length;
|
|
328867
|
+
const runEnd = xml.indexOf("</w:r>", end);
|
|
328868
|
+
const beforeMarker = xml.slice(runContentStart, start);
|
|
328869
|
+
const afterMarker = runEnd >= end ? xml.slice(end, runEnd) : null;
|
|
328870
|
+
if (afterMarker !== null && /^\s*$/.test(beforeMarker) && /^\s*$/.test(afterMarker)) {
|
|
328605
328871
|
return replaceRange2(xml, runStart, runEnd + "</w:r>".length, "");
|
|
328606
328872
|
}
|
|
328607
328873
|
}
|
|
@@ -328617,14 +328883,19 @@ function extractText2(xml) {
|
|
|
328617
328883
|
out += decodeXmlEntities(match[1]);
|
|
328618
328884
|
return out;
|
|
328619
328885
|
}
|
|
328620
|
-
function allocateRangeId(
|
|
328621
|
-
|
|
328886
|
+
function allocateRangeId(existingIds) {
|
|
328887
|
+
let max2 = 1000;
|
|
328888
|
+
for (const id of existingIds)
|
|
328889
|
+
max2 = Math.max(max2, Number(id) || 0);
|
|
328622
328890
|
return String(max2 + 1 + Math.floor(Math.random() * 1000));
|
|
328623
328891
|
}
|
|
328892
|
+
var COLLABORATIVE_SECONDARY_STORY_MESSAGE = "permission ranges in header/footer stories are not supported in collaborative sessions.";
|
|
328624
328893
|
var init_adapter6 = __esm(() => {
|
|
328625
328894
|
init_src3();
|
|
328626
328895
|
init_sd_document_session_internal();
|
|
328627
328896
|
init_visible_text();
|
|
328897
|
+
init_selection_target();
|
|
328898
|
+
init_story_surface();
|
|
328628
328899
|
init_shared();
|
|
328629
328900
|
init_xml();
|
|
328630
328901
|
});
|
|
@@ -328813,9 +329084,9 @@ var init_adapter7 = __esm(() => {
|
|
|
328813
329084
|
function documentProtectionAllowsXmlRange(context, partUri, start, end) {
|
|
328814
329085
|
if (!new V2ProtectionAdapter(context).get().editingRestriction.runtimeEnforced)
|
|
328815
329086
|
return true;
|
|
328816
|
-
if (
|
|
329087
|
+
if (start < 0 || end < start)
|
|
328817
329088
|
return false;
|
|
328818
|
-
return listPermissionRanges(context).some((range) => range.principal.kind === "everyone" && range.startTagEnd <= start && end <= range.endTagStart);
|
|
329089
|
+
return listPermissionRanges(context).some((range) => range.partUri === partUri && !range.malformed && range.principal.kind === "everyone" && range.startTagEnd <= start && end <= range.endTagStart);
|
|
328819
329090
|
}
|
|
328820
329091
|
function requireDocumentProtectionXmlRange(context, partUri, start, end) {
|
|
328821
329092
|
if (!documentProtectionAllowsXmlRange(context, partUri, start, end)) {
|
|
@@ -328840,7 +329111,6 @@ var DOCUMENT_PROTECTION_MESSAGE = "document protection permits edits only within
|
|
|
328840
329111
|
var init_mutation_guard = __esm(() => {
|
|
328841
329112
|
init_shared();
|
|
328842
329113
|
init_adapter6();
|
|
328843
|
-
init_xml();
|
|
328844
329114
|
init_adapter7();
|
|
328845
329115
|
});
|
|
328846
329116
|
|
|
@@ -329577,107 +329847,6 @@ var init_v2_search_ref = __esm(() => {
|
|
|
329577
329847
|
init_textbox_story();
|
|
329578
329848
|
});
|
|
329579
329849
|
|
|
329580
|
-
// ../../../v2/document-api-v2-adapter/dist/address/story-surface.js
|
|
329581
|
-
function resolveStorySurface(session, bodyStoryId, locator) {
|
|
329582
|
-
const resolved = resolveSessionStoryLocator(session, bodyStoryId, locator);
|
|
329583
|
-
if ("error" in resolved) {
|
|
329584
|
-
return { ok: false, failure: classifyStoryLocatorFailure(resolved.error) };
|
|
329585
|
-
}
|
|
329586
|
-
return { ok: true, descriptor: toStorySurfaceDescriptor(resolved) };
|
|
329587
|
-
}
|
|
329588
|
-
function toStorySurfaceDescriptor(resolved) {
|
|
329589
|
-
const descriptor = {
|
|
329590
|
-
storyId: resolved.storyId,
|
|
329591
|
-
partUri: resolved.partUri,
|
|
329592
|
-
storyKind: resolved.storyKind,
|
|
329593
|
-
relationshipOwnerPartUri: resolved.relationshipOwnerPartUri,
|
|
329594
|
-
sourceAvailability: resolved.materialization ? "materialize-on-write" : "available"
|
|
329595
|
-
};
|
|
329596
|
-
if (resolved.storyByteRange)
|
|
329597
|
-
descriptor.storyByteRange = resolved.storyByteRange;
|
|
329598
|
-
if (resolved.refId)
|
|
329599
|
-
descriptor.refId = resolved.refId;
|
|
329600
|
-
if (resolved.noteId)
|
|
329601
|
-
descriptor.noteId = resolved.noteId;
|
|
329602
|
-
if (resolved.textboxId)
|
|
329603
|
-
descriptor.textboxId = resolved.textboxId;
|
|
329604
|
-
if (resolved.materialization)
|
|
329605
|
-
descriptor.materialization = resolved.materialization;
|
|
329606
|
-
if (resolved.slot)
|
|
329607
|
-
descriptor.slot = resolved.slot;
|
|
329608
|
-
if (resolved.resolvedFromSectionId)
|
|
329609
|
-
descriptor.resolvedFromSectionId = resolved.resolvedFromSectionId;
|
|
329610
|
-
return descriptor;
|
|
329611
|
-
}
|
|
329612
|
-
function classifyStoryLocatorFailure(error48) {
|
|
329613
|
-
return {
|
|
329614
|
-
category: storyLocatorFailureCategory(error48),
|
|
329615
|
-
reason: error48,
|
|
329616
|
-
message: storyLocatorFailureMessage(error48)
|
|
329617
|
-
};
|
|
329618
|
-
}
|
|
329619
|
-
function receiptFailureForStoryLocatorError(error48) {
|
|
329620
|
-
const failure5 = classifyStoryLocatorFailure(error48);
|
|
329621
|
-
return {
|
|
329622
|
-
code: failure5.category,
|
|
329623
|
-
message: failure5.message
|
|
329624
|
-
};
|
|
329625
|
-
}
|
|
329626
|
-
function storyLocatorFailureCategory(error48) {
|
|
329627
|
-
switch (error48) {
|
|
329628
|
-
case "not-found":
|
|
329629
|
-
case "unknown-section":
|
|
329630
|
-
case "no-sections":
|
|
329631
|
-
return "TARGET_NOT_FOUND";
|
|
329632
|
-
case "unsupported-story":
|
|
329633
|
-
case "inherited-edit-rejected":
|
|
329634
|
-
case "cross-story-write-rejected":
|
|
329635
|
-
return "CAPABILITY_UNAVAILABLE";
|
|
329636
|
-
case "no-source-for-edit":
|
|
329637
|
-
return "PRECONDITION_FAILED";
|
|
329638
|
-
default: {
|
|
329639
|
-
const _exhaustive = error48;
|
|
329640
|
-
return _exhaustive;
|
|
329641
|
-
}
|
|
329642
|
-
}
|
|
329643
|
-
}
|
|
329644
|
-
function storyLocatorFailureMessage(error48) {
|
|
329645
|
-
switch (error48) {
|
|
329646
|
-
case "not-found":
|
|
329647
|
-
return "the requested story target was not found";
|
|
329648
|
-
case "unknown-section":
|
|
329649
|
-
return "the requested section is not part of this document";
|
|
329650
|
-
case "no-sections":
|
|
329651
|
-
return "the document has no resolvable sections for this story";
|
|
329652
|
-
case "unsupported-story":
|
|
329653
|
-
return "this story family is not supported for the requested operation";
|
|
329654
|
-
case "inherited-edit-rejected":
|
|
329655
|
-
return "the header/footer slot is inherited and cannot be edited under the requested write policy";
|
|
329656
|
-
case "cross-story-write-rejected":
|
|
329657
|
-
return "the requested write would cross story boundaries";
|
|
329658
|
-
case "no-source-for-edit":
|
|
329659
|
-
return "the requested story has no source bytes available for this edit";
|
|
329660
|
-
default:
|
|
329661
|
-
return "the requested story could not be resolved";
|
|
329662
|
-
}
|
|
329663
|
-
}
|
|
329664
|
-
function rangeWithinStorySurface(descriptor, range) {
|
|
329665
|
-
const window2 = descriptor.storyByteRange;
|
|
329666
|
-
if (!window2)
|
|
329667
|
-
return null;
|
|
329668
|
-
if (range.start >= window2[0] && range.end <= window2[1] && range.start <= range.end) {
|
|
329669
|
-
return null;
|
|
329670
|
-
}
|
|
329671
|
-
return {
|
|
329672
|
-
category: "INVALID_CONTEXT",
|
|
329673
|
-
reason: null,
|
|
329674
|
-
message: `byte range [${range.start}, ${range.end}] falls outside the resolved story window ` + `[${window2[0]}, ${window2[1]}] for story ${descriptor.storyId}`
|
|
329675
|
-
};
|
|
329676
|
-
}
|
|
329677
|
-
var init_story_surface = __esm(() => {
|
|
329678
|
-
init_story_locator();
|
|
329679
|
-
});
|
|
329680
|
-
|
|
329681
329850
|
// ../../../v2/document-api-v2-adapter/dist/address/raw-block-ref.js
|
|
329682
329851
|
function resolveRawBlockRefTarget(context, ref5, scope) {
|
|
329683
329852
|
if (scope) {
|
|
@@ -331265,14 +331434,14 @@ var init_effective_inline_uniformity = __esm(() => {
|
|
|
331265
331434
|
});
|
|
331266
331435
|
|
|
331267
331436
|
// ../../../v2/document-api-v2-adapter/dist/selection-mutation/adapter.js
|
|
331268
|
-
function selectionIsAllowedByDocumentProtection(context, target, index2) {
|
|
331437
|
+
function selectionIsAllowedByDocumentProtection(context, target, index2, storyId) {
|
|
331269
331438
|
const protection = new V2ProtectionAdapter(context).get().editingRestriction;
|
|
331270
331439
|
if (!protection.runtimeEnforced)
|
|
331271
331440
|
return true;
|
|
331272
331441
|
const { start, end } = target;
|
|
331273
331442
|
if (start.kind !== "text" || end.kind !== "text")
|
|
331274
331443
|
return false;
|
|
331275
|
-
return listPermissionRanges(context).some((range) => range.principal.kind === "everyone" && textPointIsWithinPermissionRange(start, range, index2) && textPointIsWithinPermissionRange(end, range, index2));
|
|
331444
|
+
return listPermissionRanges(context).some((range) => range.storyId === storyId && !range.malformed && range.principal.kind === "everyone" && textPointIsWithinPermissionRange(start, range, index2) && textPointIsWithinPermissionRange(end, range, index2));
|
|
331276
331445
|
}
|
|
331277
331446
|
function textPointIsWithinPermissionRange(point3, range, index2) {
|
|
331278
331447
|
const pointEntry = index2.byParaId(point3.blockId);
|
|
@@ -331296,7 +331465,7 @@ function resolvedTextRangeIsAllowedByDocumentProtection(context, range) {
|
|
|
331296
331465
|
kind: "selection",
|
|
331297
331466
|
start: { kind: "text", blockId: range.startBlockId, offset: range.startOffset },
|
|
331298
331467
|
end: { kind: "text", blockId: range.endBlockId, offset: range.endOffset }
|
|
331299
|
-
}, index2);
|
|
331468
|
+
}, index2, range.storyId);
|
|
331300
331469
|
}
|
|
331301
331470
|
|
|
331302
331471
|
class V2SelectionMutationAdapter {
|
|
@@ -331588,7 +331757,7 @@ class V2SelectionMutationAdapter {
|
|
|
331588
331757
|
return failureWithoutResolution("PRECONDITION_FAILED", "paragraph index is not available.");
|
|
331589
331758
|
}
|
|
331590
331759
|
const storyResolveMs = nowMs6() - storyResolveStartedAt;
|
|
331591
|
-
if (!selectionIsAllowedByDocumentProtection(this.context, target, index2)) {
|
|
331760
|
+
if (!selectionIsAllowedByDocumentProtection(this.context, target, index2, story.storyId)) {
|
|
331592
331761
|
return failureWithoutResolution("PERMISSION_DENIED", PERMISSION_DENIED_DOC_PROTECTION);
|
|
331593
331762
|
}
|
|
331594
331763
|
if ((options?.changeMode ?? "direct") === "tracked" && story.storyKind === "main") {
|
|
@@ -332318,7 +332487,7 @@ class V2SelectionMutationAdapter {
|
|
|
332318
332487
|
resolved: outcome.resolved
|
|
332319
332488
|
});
|
|
332320
332489
|
const index2 = isMainStoryId(outcome.resolved.storyId) ? getSDDocumentSessionInternalParagraphIndex(this.context.session) : getSDDocumentSessionInternalStoryParagraphIndex(this.context.session, outcome.resolved.storyId);
|
|
332321
|
-
if (index2 && !selectionIsAllowedByDocumentProtection(this.context, outcome.selectionTarget, index2)) {
|
|
332490
|
+
if (index2 && !selectionIsAllowedByDocumentProtection(this.context, outcome.selectionTarget, index2, outcome.resolved.storyId)) {
|
|
332322
332491
|
return {
|
|
332323
332492
|
success: false,
|
|
332324
332493
|
failure: {
|
|
@@ -332353,7 +332522,7 @@ class V2SelectionMutationAdapter {
|
|
|
332353
332522
|
if (!index2) {
|
|
332354
332523
|
return failureWithoutResolution("PRECONDITION_FAILED", "paragraph index is not available.");
|
|
332355
332524
|
}
|
|
332356
|
-
if (!selectionIsAllowedByDocumentProtection(this.context, destination, index2)) {
|
|
332525
|
+
if (!selectionIsAllowedByDocumentProtection(this.context, destination, index2, story.storyId)) {
|
|
332357
332526
|
return failureWithoutResolution("PERMISSION_DENIED", PERMISSION_DENIED_DOC_PROTECTION);
|
|
332358
332527
|
}
|
|
332359
332528
|
const offsetSpace = selectionOffsetSpace(options);
|
|
@@ -332498,7 +332667,7 @@ class V2SelectionMutationAdapter {
|
|
|
332498
332667
|
if (!index2) {
|
|
332499
332668
|
return failureWithoutResolution("PRECONDITION_FAILED", "paragraph index is not available.");
|
|
332500
332669
|
}
|
|
332501
|
-
if (!selectionIsAllowedByDocumentProtection(this.context, target, index2)) {
|
|
332670
|
+
if (!selectionIsAllowedByDocumentProtection(this.context, target, index2, story.storyId)) {
|
|
332502
332671
|
return failureWithoutResolution("PERMISSION_DENIED", PERMISSION_DENIED_DOC_PROTECTION);
|
|
332503
332672
|
}
|
|
332504
332673
|
const offsetSpace = selectionOffsetSpace(options);
|
|
@@ -332925,7 +333094,7 @@ class V2SelectionMutationAdapter {
|
|
|
332925
333094
|
if (!index2 || index2.entries.length === 0) {
|
|
332926
333095
|
return failureWithoutResolution("PRECONDITION_FAILED", "paragraph index is not available.");
|
|
332927
333096
|
}
|
|
332928
|
-
if (!selectionIsAllowedByDocumentProtection(this.context, target, index2)) {
|
|
333097
|
+
if (!selectionIsAllowedByDocumentProtection(this.context, target, index2, story.storyId)) {
|
|
332929
333098
|
return failureWithoutResolution("PERMISSION_DENIED", "document protection permits edits only within an everyone permission range.");
|
|
332930
333099
|
}
|
|
332931
333100
|
const startEntry = index2.byParaId(target.start.blockId);
|
|
@@ -333272,17 +333441,6 @@ function buildInsertedTextEffect(input) {
|
|
|
333272
333441
|
insertedText: [{ kind: "insertedText", target, selectionTarget, text: input.text }]
|
|
333273
333442
|
};
|
|
333274
333443
|
}
|
|
333275
|
-
function pickStoryLocator(target, override) {
|
|
333276
|
-
if (override)
|
|
333277
|
-
return override;
|
|
333278
|
-
if (target.story)
|
|
333279
|
-
return target.story;
|
|
333280
|
-
if (target.start.kind === "text" && target.start.story)
|
|
333281
|
-
return target.start.story;
|
|
333282
|
-
if (target.end.kind === "text" && target.end.story)
|
|
333283
|
-
return target.end.story;
|
|
333284
|
-
return;
|
|
333285
|
-
}
|
|
333286
333444
|
function selectionOffsetSpace(options) {
|
|
333287
333445
|
const offsetSpace = options?.offsetSpace;
|
|
333288
333446
|
return offsetSpace === "selection" || offsetSpace === "kernel" ? offsetSpace : undefined;
|