From f54bc71dc76f69301158af857d7bc1a05bd904d9 Mon Sep 17 00:00:00 2001 From: ncqwer <1732031236@qq.com> Date: Mon, 1 Apr 2024 15:25:12 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=8E=B0=E5=9C=A8=E7=B2=98=E8=B4=B4bas?= =?UTF-8?q?e64=E6=A0=BC=E5=BC=8F=E7=9A=84=E5=9B=BE=E7=89=87=E7=9A=84?= =?UTF-8?q?=E6=97=B6=E5=80=99=E4=BC=9A=E5=85=88=E6=8A=8Abase64=E7=9A=84?= =?UTF-8?q?=E5=9B=BE=E7=89=87=E5=85=88=E4=B8=8A=E4=BC=A0=E5=88=B0=E6=8C=87?= =?UTF-8?q?=E5=AE=9A=E6=9C=8D=E5=8A=A1=E5=99=A8=E5=90=8E=E5=9C=A8=E6=89=A7?= =?UTF-8?q?=E8=A1=8C=E7=B2=98=E8=B4=B4=E6=8C=87=E4=BB=A4=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cw/cw_text_power_library/CHANGELOG.md | 8 + .../cw-wang-editor/docs/examples.md | 182 +++-- .../components/cw-wang-editor/index.vue | 634 ++++++++++-------- .../components/cw-wang-editor/processHTML.js | 27 + packages/cw/cw_text_power_library/manifest | 6 +- .../cw/cw_text_power_library/package.json | 4 +- 6 files changed, 502 insertions(+), 359 deletions(-) create mode 100644 packages/cw/cw_text_power_library/CHANGELOG.md create mode 100644 packages/cw/cw_text_power_library/components/cw-wang-editor/processHTML.js diff --git a/packages/cw/cw_text_power_library/CHANGELOG.md b/packages/cw/cw_text_power_library/CHANGELOG.md new file mode 100644 index 00000000..f1a6322b --- /dev/null +++ b/packages/cw/cw_text_power_library/CHANGELOG.md @@ -0,0 +1,8 @@ +## 1.1.6 + +Associated Task: [#278603](https://projectmanage.netease-official.lcap.163yun.com/dashboard/TaskDetail?id=2786032954278656) + +### ✨Features + +- [60094da](https://github.com/vusion/cloud-ui-materials/commit/60094dad3f3ad4538558d691aa9331ef4a636b63) Thanks [ncqwer](https://github.com/ncqwer) ! - 现在粘贴base64格式的图片的时候会先把base64的图片先上传到指定服务器后在执行粘贴指令。 + diff --git a/packages/cw/cw_text_power_library/components/cw-wang-editor/docs/examples.md b/packages/cw/cw_text_power_library/components/cw-wang-editor/docs/examples.md index 07f396b3..c73a99ec 100644 --- a/packages/cw/cw_text_power_library/components/cw-wang-editor/docs/examples.md +++ b/packages/cw/cw_text_power_library/components/cw-wang-editor/docs/examples.md @@ -2,29 +2,77 @@ ```vue ``` @@ -33,9 +81,8 @@ export default { ```html + value="

hello

``` ### 只读模式 @@ -44,27 +91,26 @@ export default { ```vue ``` @@ -73,42 +119,40 @@ export default { ```vue ``` diff --git a/packages/cw/cw_text_power_library/components/cw-wang-editor/index.vue b/packages/cw/cw_text_power_library/components/cw-wang-editor/index.vue index fa9a4c20..0327ac98 100644 --- a/packages/cw/cw_text_power_library/components/cw-wang-editor/index.vue +++ b/packages/cw/cw_text_power_library/components/cw-wang-editor/index.vue @@ -1,328 +1,392 @@ diff --git a/packages/cw/cw_text_power_library/components/cw-wang-editor/processHTML.js b/packages/cw/cw_text_power_library/components/cw-wang-editor/processHTML.js new file mode 100644 index 00000000..dea88306 --- /dev/null +++ b/packages/cw/cw_text_power_library/components/cw-wang-editor/processHTML.js @@ -0,0 +1,27 @@ +export const traverseNode = (node, fn) => { + fn(node); + return Array.from(node.childNodes).forEach((n) => traverseNode(n, fn)); +}; + +export const processHTML = async (html, upload) => { + const domBody = new DOMParser().parseFromString(html, 'text/html').body; + const needUploadImgs = []; + traverseNode(domBody, (node) => { + if (node instanceof HTMLImageElement) { + const src = node.getAttribute('src'); + if (src.startsWith('data:image')) { + needUploadImgs.push({ + node, + src, + }); + } + } + }); + await Promise.all( + needUploadImgs.map(async ({ node, src }) => { + const realSrc = await upload(src); + node.setAttribute('src', realSrc); + }) + ); + return domBody; +}; diff --git a/packages/cw/cw_text_power_library/manifest b/packages/cw/cw_text_power_library/manifest index 9c159541..f65f642e 100644 --- a/packages/cw/cw_text_power_library/manifest +++ b/packages/cw/cw_text_power_library/manifest @@ -1,6 +1,6 @@ Plugin-Version: 1.0.0 Library-Type: Frontend Metadata-File: usage.json -packages/extension/cw_text_power_library@1.1.4/dist-theme/demo.html: dist-theme/demo.html -packages/extension/cw_text_power_library@1.1.4/dist-theme/index.js: dist-theme/index.js -packages/extension/cw_text_power_library@1.1.4/dist-theme/index.js.map: dist-theme/index.js.map +packages/extension/cw_text_power_library@1.1.6/dist-theme/demo.html: dist-theme/demo.html +packages/extension/cw_text_power_library@1.1.6/dist-theme/index.js: dist-theme/index.js +packages/extension/cw_text_power_library@1.1.6/dist-theme/index.js.map: dist-theme/index.js.map \ No newline at end of file diff --git a/packages/cw/cw_text_power_library/package.json b/packages/cw/cw_text_power_library/package.json index 819fcbdf..c52d7964 100644 --- a/packages/cw/cw_text_power_library/package.json +++ b/packages/cw/cw_text_power_library/package.json @@ -2,7 +2,7 @@ "name": "cw_text_power_library", "title": "文本功能依赖库", "description": "", - "version": "1.1.4", + "version": "1.1.6", "main": "./index.js", "author": "", "repository": "", @@ -56,4 +56,4 @@ "template": { "inited": true } -} +} \ No newline at end of file