Skip to content

Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.

fix(doc): support copy plain text and without html (#750)

Ran Luo9837a8983348
diff --git a/examples/docs/public/favicon.svg b/examples/docs/public/favicon.svg
new file mode 100644
index 0000000000..37084e0ff3
--- /dev/null
+++ b/examples/docs/public/favicon.svg
@@ -0,0 +1,13 @@
+<svg width="17" height="17" viewBox="0 0 17 17" fill="none" xmlns="http://www.w3.org/2000/svg">
+<path d="M0.720703 2.21973C0.720703 1.11516 1.61613 0.219727 2.7207 0.219727H14.7207C15.8253 0.219727 16.7207 1.11516 16.7207 2.21973V14.2197C16.7207 15.3243 15.8253 16.2197 14.7207 16.2197H2.7207C1.61613 16.2197 0.720703 15.3243 0.720703 14.2197V2.21973Z" fill="white"/>
+<path d="M3.05945 11.7462C3.02958 11.7293 3.00188 11.7073 2.97813 11.68C2.34633 10.9647 2.24522 9.93316 2.72627 9.11354L6.11665 3.33661C6.20481 3.18657 6.39982 3.13512 6.55237 3.22184C6.70493 3.30855 6.7571 3.50032 6.6693 3.65072L3.27892 9.42764C2.93388 10.0156 3.00656 10.7553 3.4599 11.2684C3.5754 11.3993 3.56137 11.5976 3.42824 11.7113C3.32282 11.8016 3.17386 11.8113 3.05945 11.7462ZM2.37151 8.67062L5.84753 2.74762C5.96914 2.54038 6.12997 2.36444 6.32534 2.22483C6.42032 2.15683 6.44155 2.02622 6.37247 1.93268C6.30339 1.83913 6.17026 1.81862 6.07528 1.88626C5.83133 2.06041 5.63057 2.27988 5.47909 2.53822L2.00308 8.46122C1.94443 8.56125 1.97933 8.68933 2.08079 8.7469C2.18226 8.80447 2.3125 8.77029 2.37151 8.67026V8.67062ZM7.54218 11.2741L8.79823 9.13368C8.94503 8.88362 8.85796 8.5634 8.60358 8.41912C8.3492 8.27449 8.02395 8.36048 7.87715 8.61054L6.62109 10.751C6.38614 11.1511 5.86408 11.2889 5.4575 11.0579C5.05057 10.8269 4.91061 10.3131 5.14556 9.91301L7.91061 5.20181C8.05741 4.95175 7.97034 4.63153 7.71596 4.48725C7.46158 4.34261 7.13632 4.4286 6.98953 4.67866L4.22447 9.38986C3.69629 10.2897 4.01075 11.4443 4.92572 11.9639C5.84033 12.4834 7.01435 12.174 7.54218 11.2741ZM14.0132 4.72831C13.88 4.84201 13.866 5.04026 13.9815 5.17122C14.4348 5.6843 14.5075 6.42404 14.1625 7.01195L10.7721 12.7889C10.6839 12.9389 10.7361 13.131 10.889 13.2178C11.0416 13.3045 11.2366 13.253 11.3247 13.103L14.7151 7.32606C15.1962 6.50608 15.0951 5.47489 14.4633 4.75961C14.4395 4.73263 14.4118 4.71068 14.3819 4.69341C14.2672 4.62829 14.1186 4.63836 14.0132 4.72831ZM15.0699 7.76897L11.5939 13.692C11.4723 13.8992 11.3114 14.0752 11.1161 14.2148C11.0211 14.2828 10.9998 14.4134 11.0689 14.5069C11.138 14.6005 11.2711 14.621 11.3661 14.5533C11.6101 14.3792 11.8108 14.1597 11.9623 13.9014L15.4383 7.97837C15.497 7.87835 15.4621 7.75026 15.3606 7.69269C15.2588 7.63476 15.1289 7.6693 15.0699 7.76933V7.76897ZM9.89922 5.16547L8.64316 7.30591C8.49636 7.55597 8.58343 7.87619 8.83781 8.02047C9.09219 8.16511 9.41745 8.07912 9.56424 7.82906L10.8203 5.68861C11.0552 5.28852 11.5773 5.15072 11.9839 5.38171C12.3908 5.6127 12.5308 6.12649 12.2958 6.52658L9.53078 11.2378C9.38398 11.4878 9.47106 11.8081 9.72543 11.9523C9.97981 12.097 10.3051 12.011 10.4519 11.7609L13.2169 7.04973C13.7451 6.14988 13.4306 4.99528 12.5157 4.47573C11.6011 3.95618 10.427 4.26561 9.89922 5.16547Z" fill="url(#paint0_linear_167_3)"/>
+<defs>
+<linearGradient id="paint0_linear_167_3" x1="3.94409" y1="5.15948" x2="13.6248" y2="11.3617" gradientUnits="userSpaceOnUse">
+<stop stop-color="#0B00D0"/>
+<stop offset="0.49" stop-color="#0492ED"/>
+<stop offset="0.65" stop-color="#029DCE"/>
+<stop offset="0.88" stop-color="#00ABA6"/>
+<stop offset="1" stop-color="#00B197"/>
+</linearGradient>
+</defs>
+</svg>
diff --git a/examples/docs/public/index.html b/examples/docs/public/index.html
index d05c4c6bdb..c3e04ca6e4 100644
--- a/examples/docs/public/index.html
+++ b/examples/docs/public/index.html
@@ -5,6 +5,7 @@
<meta content="width=device-width, initial-scale=1" name="viewport" />
<title>UniverDoc</title>
+ <link rel="icon" type="image/x-icon" href="/favicon.svg">
<link rel="stylesheet" href="./main.css" />
<style>
html,
diff --git a/examples/docs/src/main.ts b/examples/docs/src/main.ts
index 25714168af..be16ab03f6 100644
--- a/examples/docs/src/main.ts
+++ b/examples/docs/src/main.ts
@@ -64,6 +64,7 @@ univer.createUniverDoc(DEFAULT_DOCUMENT_DATA_CN);
// use for console test
declare global {
+ // eslint-disable-next-line @typescript-eslint/naming-convention
interface Window {
univer?: Univer;
}
diff --git a/packages/docs/src/services/clipboard/clipboard.service.ts b/packages/docs/src/services/clipboard/clipboard.service.ts
index 2dc78246de..3a347e9f79 100644
--- a/packages/docs/src/services/clipboard/clipboard.service.ts
+++ b/packages/docs/src/services/clipboard/clipboard.service.ts
@@ -60,32 +60,46 @@ export class DocClipboardService extends Disposable implements IDocClipboardServ
async queryClipboardData(): Promise<IDocumentBody> {
const clipboardItems = await this._clipboardInterfaceService.read();
-
if (clipboardItems.length === 0) {
return Promise.reject();
}
- const clipboardItem = clipboardItems[0];
- const text = await clipboardItem.getType(PLAIN_TEXT_CLIPBOARD_MIME_TYPE).then((blob) => blob && blob.text());
- const html = await clipboardItem.getType(HTML_CLIPBOARD_MIME_TYPE).then((blob) => blob && blob.text());
-
- if (!html) {
- // TODO: @JOCS, Parsing paragraphs and sections
- return {
- dataStream: text,
- };
- }
- const copyId = extractId(html);
+ try {
+ // TODO: support paste image.
+ let html = '';
+ let text = '';
+
+ for (const clipboardItem of clipboardItems) {
+ for (const type of clipboardItem.types) {
+ if (type === PLAIN_TEXT_CLIPBOARD_MIME_TYPE) {
+ text = await clipboardItem.getType(type).then((blob) => blob && blob.text());
+ } else if (type === HTML_CLIPBOARD_MIME_TYPE) {
+ html = await clipboardItem.getType(type).then((blob) => blob && blob.text());
+ }
+ }
+ }
+
+ if (!html) {
+ // TODO: @JOCS, Parsing paragraphs and sections
+ return {
+ dataStream: text,
+ };
+ }
+
+ const copyId = extractId(html);
- if (copyId) {
- const copyCache = copyContentCache.get(copyId);
+ if (copyId) {
+ const copyCache = copyContentCache.get(copyId);
- if (copyCache) {
- return copyCache;
+ if (copyCache) {
+ return copyCache;
+ }
}
- }
- return this._htmlToUDM.convert(html);
+ return this._htmlToUDM.convert(html);
+ } catch (e) {
+ return Promise.reject(e);
+ }
}
async setClipboardData(documentBodyList: IDocumentBody[]): Promise<void> {