UNPKG

@mikezimm/fps-core-v7

Version:

Library of reusable core interfaces, types and constants migrated from fps-library-v2

68 lines 3.42 kB
import { getFpsPageAsSpecialAPI } from "../../../../restAPIs/lists/items/getFpsPageAsSpecialAPI"; /** * Replaces getDocWikiD * * import { getDocWikiAPI } from "@mikezimm/fps-core-v7/lib/components/molecules/ModernPages/functions/getDocWikiAPI"; * * This takes a current page item, goes and fetches the extra content for the DocWiki (Single Modern Page) * It uses getFpsPageAsXmlAPI above to do the fetching. * This function just handles the post-processing and callback * * @param item * @param source * @param canvasOptions * @param showCanvasContent1 * @param callBack https://github.com/fps-solutions/HubCon/issues/120 * @returns */ export async function getDocWikiAPI(item, source, canvasOptions, showCanvasContent1, callBack) { var _a; const itemId = item.ID || `${item.ID}` === '0' ? item.ID : item.Id || `${item.Id}` === '0' ? item.Id : ''; if (!itemId) { console.log('Error getting item wiki'); const errResult = { fetchError: 'getDocWiki item is null!', CanvasContent1: 'CanvasContent1: getDocWiki item is null!', }; // 2024-12-31: Casted showCanvasContent1 as any because it does not look like it is really used and not important in getModernContent callBack(errResult, showCanvasContent1); return errResult; } else { const result = await getFpsPageAsSpecialAPI(source, source.isModern === false ? false : true, itemId, 'FieldValuesAsHtml', true, true); if (result.status === 'Success') { const fetchedItem = result.item; //Added this to fit images into the current width or else the image is full size if (fetchedItem.CanvasContent1) { fetchedItem.CanvasContent1Str = fetchedItem.CanvasContent1.replace(/<img\s*/ig, `<img ${(_a = canvasOptions.imageOptions) === null || _a === void 0 ? void 0 : _a.style} `); } fetchedItem.BannerImageUrl = item.BannerImageUrl; fetchedItem.fetchError = ''; console.log('Fetched modern page'); fetchedItem.originalContent = {}; // Set type of thisKey as 'originalContent' to resolve typing error without casting entire object as any Object.keys(item).map((thisKey) => { if (thisKey === 'originalContent') { console.log('getModernContent.ts ~ 57'); } else if (fetchedItem[thisKey] && fetchedItem[thisKey] !== item[thisKey]) { fetchedItem.originalContent[thisKey] = item[thisKey]; } else { fetchedItem[thisKey] = item[thisKey]; } }); result.item = fetchedItem; // https://github.com/fps-solutions/HubCon/issues/120 - MUST pass back showCanvasContent1 first, then optional result callBack(fetchedItem, showCanvasContent1, result); } else { item.fetchError = 'Error getting item wiki'; console.log('Error getting item wiki'); // https://github.com/fps-solutions/HubCon/issues/120 - MUST pass back showCanvasContent1 first, then optional result callBack(item, showCanvasContent1, result); } return result; } } //# sourceMappingURL=getDocWikiAPI.js.map