Compare commits

..

2 Commits

Author SHA1 Message Date
Aakansha Doshi
555bf6338f fix test 2022-11-09 22:55:27 +05:30
Daniel J. Geiger
0bef3945f6 Fix #5855. 2022-11-09 07:54:49 -06:00
11 changed files with 59 additions and 163 deletions

View File

@@ -4755,9 +4755,9 @@ loader-runner@^4.2.0:
integrity sha512-3R/1M+yS3j5ou80Me59j7F9IMs4PXs3VqRrm0TU3AbKPxlmpoY1TNscJV/oGJXo8qCatFGTfDbY6W6ipGOYXfg== integrity sha512-3R/1M+yS3j5ou80Me59j7F9IMs4PXs3VqRrm0TU3AbKPxlmpoY1TNscJV/oGJXo8qCatFGTfDbY6W6ipGOYXfg==
loader-utils@^2.0.0: loader-utils@^2.0.0:
version "2.0.3" version "2.0.2"
resolved "https://registry.yarnpkg.com/loader-utils/-/loader-utils-2.0.3.tgz#d4b15b8504c63d1fc3f2ade52d41bc8459d6ede1" resolved "https://registry.yarnpkg.com/loader-utils/-/loader-utils-2.0.2.tgz#d6e3b4fb81870721ae4e0868ab11dd638368c129"
integrity sha512-THWqIsn8QRnvLl0shHYVBN9syumU8pYWEHPTmkiVGd+7K5eFNVSY6AJhRvgGF70gg1Dz+l/k8WicvFCxdEs60A== integrity sha512-TM57VeHptv569d/GKh6TAYdzKblwDNiumOdkFnejjD0XwTH87K90w3O7AiJRqdQoXygvi1VQTJTLGhJl7WqA7A==
dependencies: dependencies:
big.js "^5.2.2" big.js "^5.2.2"
emojis-list "^3.0.0" emojis-list "^3.0.0"

View File

@@ -1,27 +0,0 @@
import { parseClipboard } from "./clipboard";
describe("Test parseClipboard", () => {
it("should parse valid json correctly", async () => {
let text = "123";
let clipboardData = await parseClipboard({
//@ts-ignore
clipboardData: {
getData: () => text,
},
});
expect(clipboardData.text).toBe(text);
text = "[123]";
clipboardData = await parseClipboard({
//@ts-ignore
clipboardData: {
getData: () => text,
},
});
expect(clipboardData.text).toBe(text);
});
});

View File

@@ -156,13 +156,15 @@ export const parseClipboard = async (
files: systemClipboardData.files, files: systemClipboardData.files,
}; };
} }
} catch (e) {} return appClipboardData;
// system clipboard doesn't contain excalidraw elements → return plaintext } catch {
// unless we set a flag to prefer in-app clipboard because browser didn't // system clipboard doesn't contain excalidraw elements → return plaintext
// support storing to system clipboard on copy // unless we set a flag to prefer in-app clipboard because browser didn't
return PREFER_APP_CLIPBOARD && appClipboardData.elements // support storing to system clipboard on copy
? appClipboardData return PREFER_APP_CLIPBOARD && appClipboardData.elements
: { text: systemClipboard }; ? appClipboardData
: { text: systemClipboard };
}
}; };
export const copyBlobToClipboardAsPng = async (blob: Blob | Promise<Blob>) => { export const copyBlobToClipboardAsPng = async (blob: Blob | Promise<Blob>) => {

View File

@@ -411,8 +411,7 @@ const LayerUI = ({
onClick={onCollabButtonClick} onClick={onCollabButtonClick}
/> />
)} )}
{!appState.viewModeEnabled && {renderTopRightUI?.(device.isMobile, appState)}
renderTopRightUI?.(device.isMobile, appState)}
{!appState.viewModeEnabled && ( {!appState.viewModeEnabled && (
<LibraryButton appState={appState} setAppState={setAppState} /> <LibraryButton appState={appState} setAppState={setAppState} />
)} )}

View File

@@ -111,9 +111,8 @@ export const MobileMenu = ({
/> />
</Stack.Row> </Stack.Row>
</Island> </Island>
{renderTopRightUI && renderTopRightUI(true, appState)}
<div className="mobile-misc-tools-container"> <div className="mobile-misc-tools-container">
{!appState.viewModeEnabled &&
renderTopRightUI?.(true, appState)}
<PenModeButton <PenModeButton
checked={appState.penMode} checked={appState.penMode}
onChange={onPenModeToggle} onChange={onPenModeToggle}

View File

@@ -1470,11 +1470,11 @@ export const TextAlignRightIcon = createIcon(
export const TextAlignTopIcon = React.memo(({ theme }: { theme: Theme }) => export const TextAlignTopIcon = React.memo(({ theme }: { theme: Theme }) =>
createIcon( createIcon(
<g <g
strokeWidth="1.5" stroke-width="1.5"
stroke="currentColor" stroke="currentColor"
fill="none" fill="none"
strokeLinecap="round" stroke-linecap="round"
strokeLinejoin="round" stroke-linejoin="round"
> >
<path stroke="none" d="M0 0h24v24H0z" fill="none" /> <path stroke="none" d="M0 0h24v24H0z" fill="none" />
<line x1="4" y1="4" x2="20" y2="4" /> <line x1="4" y1="4" x2="20" y2="4" />
@@ -1488,11 +1488,11 @@ export const TextAlignTopIcon = React.memo(({ theme }: { theme: Theme }) =>
export const TextAlignBottomIcon = React.memo(({ theme }: { theme: Theme }) => export const TextAlignBottomIcon = React.memo(({ theme }: { theme: Theme }) =>
createIcon( createIcon(
<g <g
strokeWidth="2" stroke-width="2"
stroke="currentColor" stroke="currentColor"
fill="none" fill="none"
strokeLinecap="round" stroke-linecap="round"
strokeLinejoin="round" stroke-linejoin="round"
> >
<path stroke="none" d="M0 0h24v24H0z" fill="none" /> <path stroke="none" d="M0 0h24v24H0z" fill="none" />
<line x1="4" y1="20" x2="20" y2="20" /> <line x1="4" y1="20" x2="20" y2="20" />
@@ -1506,11 +1506,11 @@ export const TextAlignBottomIcon = React.memo(({ theme }: { theme: Theme }) =>
export const TextAlignMiddleIcon = React.memo(({ theme }: { theme: Theme }) => export const TextAlignMiddleIcon = React.memo(({ theme }: { theme: Theme }) =>
createIcon( createIcon(
<g <g
strokeWidth="1.5" stroke-width="1.5"
stroke="currentColor" stroke="currentColor"
fill="none" fill="none"
strokeLinecap="round" stroke-linecap="round"
strokeLinejoin="round" stroke-linejoin="round"
> >
<path stroke="none" d="M0 0h24v24H0z" fill="none" /> <path stroke="none" d="M0 0h24v24H0z" fill="none" />
<line x1="4" y1="12" x2="9" y2="12" /> <line x1="4" y1="12" x2="9" y2="12" />

View File

@@ -439,7 +439,7 @@ describe("textWysiwyg", () => {
it("should paste text correctly", async () => { it("should paste text correctly", async () => {
Keyboard.keyPress(KEYS.ENTER); Keyboard.keyPress(KEYS.ENTER);
await new Promise((r) => setTimeout(r, 0)); await new Promise((r) => setTimeout(r, 0));
let text = "A quick brown fox jumps over the lazy dog."; const text = "A quick brown fox jumps over the lazy dog.";
//@ts-ignore //@ts-ignore
textarea.onpaste({ textarea.onpaste({
@@ -453,23 +453,6 @@ describe("textWysiwyg", () => {
await new Promise((cb) => setTimeout(cb, 0)); await new Promise((cb) => setTimeout(cb, 0));
textarea.blur(); textarea.blur();
expect(textElement.text).toBe(text); expect(textElement.text).toBe(text);
Keyboard.keyPress(KEYS.ENTER);
await new Promise((r) => setTimeout(r, 0));
text = "Hello this text should get merged with the existing one";
//@ts-ignore
textarea.onpaste({
preventDefault: () => {},
//@ts-ignore
clipboardData: {
getData: () => text,
},
});
await new Promise((cb) => setTimeout(cb, 0));
textarea.blur();
expect(textElement.text).toMatchInlineSnapshot(
`"A quick brown fox jumps over the lazy dog.Hello this text should get merged with the existing one"`,
);
}); });
}); });
@@ -922,11 +905,9 @@ describe("textWysiwyg", () => {
) as HTMLTextAreaElement; ) as HTMLTextAreaElement;
await new Promise((r) => setTimeout(r, 0)); await new Promise((r) => setTimeout(r, 0));
const font = "20px Cascadia, width: Segoe UI Emoji" as FontString; const font = "20px Cascadia, width: Segoe UI Emoji" as FontString;
let text =
"Wikipedia is hosted by the Wikimedia Foundation, a non-profit organization that also hosts a range of other projects.";
let wrappedText = textElementUtils.wrapText( const wrappedText = textElementUtils.wrapText(
text, "Wikipedia is hosted by the Wikimedia Foundation, a non-profit organization that also hosts a range of other projects.",
font, font,
getMaxContainerWidth(rectangle), getMaxContainerWidth(rectangle),
); );
@@ -945,7 +926,8 @@ describe("textWysiwyg", () => {
preventDefault: () => {}, preventDefault: () => {},
//@ts-ignore //@ts-ignore
clipboardData: { clipboardData: {
getData: () => text, getData: () =>
"Wikipedia is hosted by the Wikimedia Foundation, a non-profit organization that also hosts a range of other projects.",
}, },
}); });
@@ -953,8 +935,9 @@ describe("textWysiwyg", () => {
editor.blur(); editor.blur();
expect(rectangle.width).toBe(100); expect(rectangle.width).toBe(100);
expect(rectangle.height).toBe(210); expect(rectangle.height).toBe(210);
expect((h.elements[1] as ExcalidrawTextElement).text) const textElement = h.elements[1] as ExcalidrawTextElement;
.toMatchInlineSnapshot(` expect(textElement.text).toMatchInlineSnapshot(
`
"Wikipedi "Wikipedi
a is a is
hosted hosted
@@ -974,64 +957,7 @@ describe("textWysiwyg", () => {
other other
projects projects
." ."
`); `,
expect(
(h.elements[1] as ExcalidrawTextElement).originalText,
).toMatchInlineSnapshot(
`"Wikipedia is hosted by the Wikimedia Foundation, a non-profit organization that also hosts a range of other projects."`,
);
text = "Hello this text should get merged with the existing one";
wrappedText = textElementUtils.wrapText(
text,
font,
getMaxContainerWidth(rectangle),
);
//@ts-ignore
editor.onpaste({
preventDefault: () => {},
//@ts-ignore
clipboardData: {
getData: () => text,
},
});
await new Promise((cb) => setTimeout(cb, 0));
editor.blur();
expect((h.elements[1] as ExcalidrawTextElement).text)
.toMatchInlineSnapshot(`
"Wikipedi
a is
hosted
by the
Wikimedi
a
Foundati
on, a
non-prof
it
organiza
tion
that
also
hosts a
range of
other
projects
.Hello
this
text
should
get
merged
with the
existing
one"
`);
expect(
(h.elements[1] as ExcalidrawTextElement).originalText,
).toMatchInlineSnapshot(
`"Wikipedia is hosted by the Wikimedia Foundation, a non-profit organization that also hosts a range of other projects.Hello this text should get merged with the existing one"`,
); );
}); });
}); });

View File

@@ -284,17 +284,6 @@ export const textWysiwyg = ({
return; return;
} }
const data = normalizeText(clipboardData.text); const data = normalizeText(clipboardData.text);
if (!data) {
return;
}
const text = editable.value;
const start = Math.min(editable.selectionStart, editable.selectionEnd);
const end = Math.max(editable.selectionStart, editable.selectionEnd);
const newText = `${text.substring(0, start)}${data}${text.substring(
end,
)}`;
const container = getContainerElement(element); const container = getContainerElement(element);
const font = getFontString({ const font = getFontString({
@@ -302,12 +291,20 @@ export const textWysiwyg = ({
fontFamily: app.state.currentItemFontFamily, fontFamily: app.state.currentItemFontFamily,
}); });
const wrappedText = container if (data) {
? wrapText(newText, font, getMaxContainerWidth(container)) const text = editable.value;
: newText; const start = Math.min(editable.selectionStart, editable.selectionEnd);
const dimensions = measureText(wrappedText, font); const end = Math.max(editable.selectionStart, editable.selectionEnd);
editable.style.height = `${dimensions.height}px`; const newText = `${text.substring(0, start)}${data}${text.substring(
onChange(newText); end,
)}`;
const wrappedText = container
? wrapText(newText, font, getMaxContainerWidth(container!))
: newText;
const dimensions = measureText(wrappedText, font);
editable.style.height = `${dimensions.height}px`;
onChange(newText);
}
}; };
editable.oninput = () => { editable.oninput = () => {
const updatedTextElement = Scene.getScene(element)?.getElement( const updatedTextElement = Scene.getScene(element)?.getElement(

View File

@@ -1873,7 +1873,7 @@ compression@^1.7.4:
concat-map@0.0.1: concat-map@0.0.1:
version "0.0.1" version "0.0.1"
resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b" resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b"
integrity sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg== integrity sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=
connect-history-api-fallback@^2.0.0: connect-history-api-fallback@^2.0.0:
version "2.0.0" version "2.0.0"
@@ -2697,9 +2697,9 @@ loader-runner@^4.2.0:
integrity sha512-92+huvxMvYlMzMt0iIOukcwYBFpkYJdpl2xsZ7LrlayO7E8SOv+JJUEK17B/dJIHAOLMfh2dZZ/Y18WgmGtYNw== integrity sha512-92+huvxMvYlMzMt0iIOukcwYBFpkYJdpl2xsZ7LrlayO7E8SOv+JJUEK17B/dJIHAOLMfh2dZZ/Y18WgmGtYNw==
loader-utils@^2.0.0: loader-utils@^2.0.0:
version "2.0.3" version "2.0.2"
resolved "https://registry.yarnpkg.com/loader-utils/-/loader-utils-2.0.3.tgz#d4b15b8504c63d1fc3f2ade52d41bc8459d6ede1" resolved "https://registry.yarnpkg.com/loader-utils/-/loader-utils-2.0.2.tgz#d6e3b4fb81870721ae4e0868ab11dd638368c129"
integrity sha512-THWqIsn8QRnvLl0shHYVBN9syumU8pYWEHPTmkiVGd+7K5eFNVSY6AJhRvgGF70gg1Dz+l/k8WicvFCxdEs60A== integrity sha512-TM57VeHptv569d/GKh6TAYdzKblwDNiumOdkFnejjD0XwTH87K90w3O7AiJRqdQoXygvi1VQTJTLGhJl7WqA7A==
dependencies: dependencies:
big.js "^5.2.2" big.js "^5.2.2"
emojis-list "^3.0.0" emojis-list "^3.0.0"
@@ -2823,9 +2823,9 @@ minimalistic-assert@^1.0.0:
integrity sha512-UtJcAD4yEaGtjPezWuO9wC4nwUnVH/8/Im3yEHQP4b67cXlD/Qr9hdITCU1xDbSEXg2XKNaP8jsReV7vQd00/A== integrity sha512-UtJcAD4yEaGtjPezWuO9wC4nwUnVH/8/Im3yEHQP4b67cXlD/Qr9hdITCU1xDbSEXg2XKNaP8jsReV7vQd00/A==
minimatch@^3.0.4: minimatch@^3.0.4:
version "3.1.2" version "3.0.4"
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.1.2.tgz#19cd194bfd3e428f049a70817c038d89ab4be35b" resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.4.tgz#5166e286457f03306064be5497e8dbb0c3d32083"
integrity sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw== integrity sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==
dependencies: dependencies:
brace-expansion "^1.1.7" brace-expansion "^1.1.7"

View File

@@ -1915,9 +1915,9 @@ loader-runner@^4.2.0:
integrity sha512-92+huvxMvYlMzMt0iIOukcwYBFpkYJdpl2xsZ7LrlayO7E8SOv+JJUEK17B/dJIHAOLMfh2dZZ/Y18WgmGtYNw== integrity sha512-92+huvxMvYlMzMt0iIOukcwYBFpkYJdpl2xsZ7LrlayO7E8SOv+JJUEK17B/dJIHAOLMfh2dZZ/Y18WgmGtYNw==
loader-utils@^2.0.0: loader-utils@^2.0.0:
version "2.0.4" version "2.0.0"
resolved "https://registry.yarnpkg.com/loader-utils/-/loader-utils-2.0.4.tgz#8b5cb38b5c34a9a018ee1fc0e6a066d1dfcc528c" resolved "https://registry.yarnpkg.com/loader-utils/-/loader-utils-2.0.0.tgz#e4cace5b816d425a166b5f097e10cd12b36064b0"
integrity sha512-xXqpXoINfFhgua9xiqD8fPFHgkoq1mmmpE92WlDbm9rNRd/EbRb+Gqf908T2DMfuHjjJlksiK2RbHVOdD/MqSw== integrity sha512-rP4F0h2RaWSvPEkD7BLDFQnvSf+nK+wr3ESUjNTyAGobqrijmW92zc+SO6d4p4B1wh7+B/Jg1mkQe5NYUEHtHQ==
dependencies: dependencies:
big.js "^5.2.2" big.js "^5.2.2"
emojis-list "^3.0.0" emojis-list "^3.0.0"

View File

@@ -11263,9 +11263,9 @@ socket.io-client@2.3.1:
to-array "0.1.4" to-array "0.1.4"
socket.io-parser@~3.3.0: socket.io-parser@~3.3.0:
version "3.3.3" version "3.3.2"
resolved "https://registry.yarnpkg.com/socket.io-parser/-/socket.io-parser-3.3.3.tgz#3a8b84823eba87f3f7624e64a8aaab6d6318a72f" resolved "https://registry.yarnpkg.com/socket.io-parser/-/socket.io-parser-3.3.2.tgz#ef872009d0adcf704f2fbe830191a14752ad50b6"
integrity sha512-qOg87q1PMWWTeO01768Yh9ogn7chB9zkKtQnya41Y355S0UmpXgpcrFwAgjYJxu9BdKug5r5e9YtVSeWhKBUZg== integrity sha512-FJvDBuOALxdCI9qwRrO/Rfp9yfndRtc1jSgVgV8FDraihmSP/MLGD5PEuJrNfjALvcQ+vMDM/33AWOYP/JSjDg==
dependencies: dependencies:
component-emitter "~1.3.0" component-emitter "~1.3.0"
debug "~3.1.0" debug "~3.1.0"