From 374d3fc1171dece1d0dad3ee0286db7271e48a39 Mon Sep 17 00:00:00 2001 From: Dmitry Mozolevsky Date: Wed, 12 Jun 2024 20:37:57 -0700 Subject: [PATCH 01/15] feat: Annotated Text component --- .../content/CoreAnnotatedText.vue | 339 ++++++++++++++++++ 1 file changed, 339 insertions(+) create mode 100644 src/ui/src/core_components/content/CoreAnnotatedText.vue diff --git a/src/ui/src/core_components/content/CoreAnnotatedText.vue b/src/ui/src/core_components/content/CoreAnnotatedText.vue new file mode 100644 index 000000000..c1481ee06 --- /dev/null +++ b/src/ui/src/core_components/content/CoreAnnotatedText.vue @@ -0,0 +1,339 @@ + + + + + + From 2d4ae72958e139fbe6e1f3ada41a47076a34fc4e Mon Sep 17 00:00:00 2001 From: Dmitry Mozolevsky Date: Sun, 7 Jul 2024 19:36:13 -0700 Subject: [PATCH 02/15] fix: got rid of name shortener for the annotated text component --- .../content/CoreAnnotatedText.vue | 21 +------------------ 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/src/ui/src/core_components/content/CoreAnnotatedText.vue b/src/ui/src/core_components/content/CoreAnnotatedText.vue index c1481ee06..9e97d265e 100644 --- a/src/ui/src/core_components/content/CoreAnnotatedText.vue +++ b/src/ui/src/core_components/content/CoreAnnotatedText.vue @@ -11,7 +11,7 @@ > {{ content[0] }} {{ - getShortName(content[1]) + {{ content[1] }} }} @@ -258,25 +258,6 @@ function copyToClipboard({ return false; } -const defaultShortNameDictionary = { - verb: "Verb", - adjective: "Adj", - noun: "Noun", - pronoun: "Pronoun", -}; - -function getShortName(name: string) { - if (!name) { - return ""; - } - - const lowerCaseName = name.toLowerCase(); - if (defaultShortNameDictionary[lowerCaseName]) { - return `${defaultShortNameDictionary[lowerCaseName]}`; - } - - return name[0].toUpperCase() + name.slice(1); -} diff --git a/src/ui/src/core_components/content/CoreAnnotatedText.vue b/src/ui/src/core_components/content/CoreAnnotatedText.vue index ea7061c6e..f042c93ef 100644 --- a/src/ui/src/core_components/content/CoreAnnotatedText.vue +++ b/src/ui/src/core_components/content/CoreAnnotatedText.vue @@ -16,20 +16,10 @@ @@ -179,85 +169,23 @@ function generateColor(s: string) { return generateColorCss(baseColor, colorData); } -function copyText(arr: string[]) { - const text = arr.reduce((acc, val) => { +function textToString(text: string[]) { + return text.reduce((acc, val) => { if (typeof val === "string") { return acc + val; } return acc + val[0]; }, ""); - - copyToClipboard({ text }); } -function copyJSON(arr: string[]) { +function stringifyData(arr: string[]) { try { - copyToClipboard({ text: JSON.stringify(arr) }); + return JSON.stringify(arr); } catch (e) { - copyToClipboard({ text: arr.join("") }); - } -} - -function setClipboardData( - source: T & { clipboardData: DataTransfer | null | undefined }, - { text, html }: { text?: string; html?: string }, -): void { - if (text) { - source.clipboardData?.setData("text/plain", text); - source.clipboardData?.setData("Text", text); // IE mimetype - } - - if (html) { - source.clipboardData?.setData("text/html", html); - } -} - -function copyToClipboard({ - text = "", - html = "", -}: { - text?: string; - html?: string; -}): boolean { - if ( - (window as any)?.clipboardData && - (window as any)?.clipboardData.setData - ) { - // Internet Explorer-specific code path to prevent textarea being shown while dialog is visible. - setClipboardData(window, { text, html }); - - return true; - } else if ( - document.queryCommandSupported && - document.queryCommandSupported("copy") - ) { - const copyListener = (event: ClipboardEvent) => { - event.preventDefault(); - setClipboardData(event, { text, html }); - }; - - document.addEventListener("copy", copyListener, false); - - const textarea = document.createElement("textarea"); - textarea.textContent = text || html; - textarea.style.position = "fixed"; - document.body.appendChild(textarea); - textarea.select(); - - try { - return document.execCommand("copy"); // Security exception may be thrown by some browsers. - } catch (ex) { - return false; - } finally { - document.body.removeChild(textarea); - document.removeEventListener("copy", copyListener, false); - } + return arr.join(""); } - - return false; } -