diff --git a/lib/zin/wg/docapp/js/v1.js b/lib/zin/wg/docapp/js/v1.js index 67e8e0604b..f39dfc2e5d 100644 --- a/lib/zin/wg/docapp/js/v1.js +++ b/lib/zin/wg/docapp/js/v1.js @@ -2325,6 +2325,39 @@ function initOfficePreview(options) }); } +/** + * 处理导入的文档快照。 + * Handle the imported doc snapshot. + */ +function handleImportDocSnapshot(snapshot) +{ + const forEachBlock = (blocks, callback) => + { + blocks.forEach(block => + { + callback(block); + if(block.children) forEachBlock(block.children, callback); + }); + }; + const requestType = config.requestType.toUpperCase(); + const fixUrl = (url, method, paramList) => + { + const link = $.parseLink(url, 'auto'); + if(link.requestType.toUpperCase() === requestType || method.toLowerCase() !== link.methodName.toLowerCase()) return url; + return $.createLink('doc', method, paramList.map((p, i) => [p, link.vars[i][1]])); + }; + /* Fix custom block with fetcher in difference request type. */ + forEachBlock(snapshot.blocks.children, block => + { + if(block.flavour !== 'affine:embed-zui-custom') return; + const content = block.props.content; + if(!content || typeof content !== 'object') return; + if(content.fetcher) content.fetcher = fixUrl(content.fetcher, 'zentaoList', ['type', 'blockID']); + if(content.exportUrl) content.exportUrl = fixUrl(content.exportUrl, 'ajaxExportZentaoList', ['blockID']); + }); + return snapshot; +} + /** * 设置文档应用组件选项。 * Set the doc app options. @@ -2340,6 +2373,7 @@ window.setDocAppOptions = function(_, options) return $.extend( { + editorProps : {onImportSnapshot: handleImportDocSnapshot}, defaultState : {listType: '', libReleaseMap: {}}, commands : commands, customRenders : customRenders,