From b5453790cab7e6d0348d621ba490d83d4d853cbb Mon Sep 17 00:00:00 2001 From: sunhao Date: Tue, 31 Dec 2024 18:21:27 +0800 Subject: [PATCH] * [ui] add method to import file to doc editor. --- lib/zin/wg/docapp/js/v1.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/zin/wg/docapp/js/v1.js b/lib/zin/wg/docapp/js/v1.js index 3f8f9da94e..f05656b178 100644 --- a/lib/zin/wg/docapp/js/v1.js +++ b/lib/zin/wg/docapp/js/v1.js @@ -578,6 +578,19 @@ function renameDocFile(file, doc) }); } +/* Import markdown or json file to editor. */ +function importFileToEditor(type) +{ + const accept = type === 'markdown' ? '.md' : '.json'; + return zui.selectFile(accept).then(file => { + if(!file) return; + zui.readFile(file).then(content => { + if(typeof content !== 'string' || !content.length) return; + return getDocApp().importDoc(content, type, file.name.split('.').shift()); + }); + }); +} + /** * 定义文档各个试图和 UI 元素的上的操作方法。 * Define the operation methods on the views and UI elements of the doc.