Phase 16E Fix - Office.js ContentControlCollection.items PropertyNotLoaded Error
This commit is contained in:
parent
f26cd48173
commit
35eef02322
@ -1295,8 +1295,17 @@
|
||||
return Number.isInteger(id) && id > 0 ? id : null;
|
||||
};
|
||||
|
||||
const safeContentControlItems = (paragraph) => {
|
||||
try {
|
||||
return Array.isArray(paragraph?.contentControls?.items) ? paragraph.contentControls.items : [];
|
||||
} catch (error) {
|
||||
console.warn("Word paragraph content controls were not available.", error);
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
||||
const paragraphAnchorId = (paragraph, prefix) => {
|
||||
const controls = Array.isArray(paragraph?.contentControls?.items) ? paragraph.contentControls.items : [];
|
||||
const controls = safeContentControlItems(paragraph);
|
||||
for (const control of controls) {
|
||||
const id = anchorIdFromTag(control.tag, prefix);
|
||||
if (id) {
|
||||
@ -1453,8 +1462,8 @@
|
||||
styleBuiltIn: paragraph?.styleBuiltIn || "",
|
||||
style: paragraph?.style || "",
|
||||
wordCount: countWords(text),
|
||||
chapterAnchorId: paragraphAnchorId(paragraph, "PD-CHAPTER"),
|
||||
sceneAnchorId: paragraphAnchorId(paragraph, "PD-SCENE")
|
||||
chapterAnchorId: null,
|
||||
sceneAnchorId: null
|
||||
};
|
||||
};
|
||||
|
||||
@ -2039,12 +2048,16 @@
|
||||
selectionParagraphs.load("text,styleBuiltIn,style");
|
||||
await context.sync();
|
||||
|
||||
for (const paragraph of bodyParagraphs.items) {
|
||||
if (isBuiltInHeading(paragraph, 1) || isBuiltInHeading(paragraph, 2)) {
|
||||
paragraph.contentControls.load("items/tag,title");
|
||||
try {
|
||||
for (const paragraph of bodyParagraphs.items) {
|
||||
if (isBuiltInHeading(paragraph, 1) || isBuiltInHeading(paragraph, 2)) {
|
||||
paragraph.contentControls.load("items/tag,title");
|
||||
}
|
||||
}
|
||||
await context.sync();
|
||||
} catch (error) {
|
||||
console.warn("Unable to load Word heading content controls. Continuing without PlotDirector anchors.", error);
|
||||
}
|
||||
await context.sync();
|
||||
|
||||
const structure = buildDocumentStructure(bodyParagraphs.items, selectionParagraphs.items);
|
||||
structure.bodyParagraphs = bodyParagraphs.items;
|
||||
@ -2059,13 +2072,6 @@
|
||||
selectionParagraphs.load("text,styleBuiltIn,style");
|
||||
await context.sync();
|
||||
|
||||
for (const paragraph of bodyParagraphs.items) {
|
||||
if (isBuiltInHeading(paragraph, 1)) {
|
||||
paragraph.contentControls.load("items/tag,title");
|
||||
}
|
||||
}
|
||||
await context.sync();
|
||||
|
||||
const cache = buildRuntimeDocumentStructure(bodyParagraphs.items, usesExplicitScenes);
|
||||
const selectedIndex = findSelectedParagraphIndex(cache, selectionParagraphs.items);
|
||||
documentStructureCache = cache;
|
||||
@ -2946,7 +2952,7 @@
|
||||
};
|
||||
|
||||
const findAnchorControl = (paragraph, prefix) => {
|
||||
const controls = Array.isArray(paragraph?.contentControls?.items) ? paragraph.contentControls.items : [];
|
||||
const controls = safeContentControlItems(paragraph);
|
||||
return controls.find((control) => anchorIdFromTag(control.tag, prefix)) || null;
|
||||
};
|
||||
|
||||
|
||||
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user