Add desmos graph embed type (#3608)

I added a new embed type, for desmos graphing calculator
(https://www.desmos.com/calculator) that uses their supported embed URL.
I added an icon, the new embed shape, and created tests for it.


https://github.com/tldraw/tldraw/assets/111339712/acc1a6b0-2551-4f25-8f85-20e6f829930e


### Change Type

<!--  Please select a 'Scope' label ️ -->

- [ ] `sdk` — Changes the tldraw SDK
- [x] `dotcom` — Changes the tldraw.com web app
- [ ] `docs` — Changes to the documentation, examples, or templates.
- [ ] `vs code` — Changes to the vscode plugin
- [ ] `internal` — Does not affect user-facing stuff

<!--  Please select a 'Type' label ️ -->

- [ ] `bugfix` — Bug fix
- [x] `feature` — New feature
- [ ] `improvement` — Improving existing features
- [ ] `chore` — Updating dependencies, other boring stuff
- [ ] `galaxy brain` — Architectural changes
- [x] `tests` — Changes to any test code
- [ ] `tools` — Changes to infrastructure, CI, internal scripts,
debugging tools, etc.
- [ ] `dunno` — I don't know


### Test Plan

1. Add links for desmos graphing calculator (e.g.
https://www.desmos.com/calculator/4wa2im6u31) by either pasting or using
the insert embed menu.

### Release Notes

- (feature) add desmos embed

---------

Co-authored-by: Steve Ruiz <steveruizok@gmail.com>
This commit is contained in:
fakerr 2024-04-27 22:30:58 +10:00 committed by GitHub
parent 7442456d85
commit 8c0e3c7f93
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 206 additions and 611 deletions

View file

@ -404,6 +404,15 @@ export const EMBED_DEFINITIONS: readonly [{
readonly toEmbedUrl: (url: string) => string | undefined;
readonly type: "observable";
readonly width: 720;
}, {
readonly doesResize: true;
readonly fromEmbedUrl: (url: string) => string | undefined;
readonly height: 450;
readonly hostnames: readonly ["desmos.com"];
readonly title: "Desmos";
readonly toEmbedUrl: (url: string) => string | undefined;
readonly type: "desmos";
readonly width: 700;
}];
// @public (undocumented)

View file

@ -524,6 +524,40 @@ export const EMBED_DEFINITIONS = [
return
},
},
{
type: 'desmos',
title: 'Desmos',
hostnames: ['desmos.com'],
width: 700,
height: 450,
doesResize: true,
toEmbedUrl: (url) => {
const urlObj = safeParseUrl(url)
if (
urlObj &&
urlObj.hostname === 'www.desmos.com' &&
urlObj.pathname.match(/^\/calculator\/([^/]+)\/?$/) &&
urlObj.search === '' &&
urlObj.hash === ''
) {
return `${url}?embed`
}
return
},
fromEmbedUrl: (url) => {
const urlObj = safeParseUrl(url)
if (
urlObj &&
urlObj.hostname === 'www.desmos.com' &&
urlObj.pathname.match(/^\/calculator\/([^/]+)\/?$/) &&
urlObj.search === '?embed' &&
urlObj.hash === ''
) {
return url.replace('?embed', '')
}
return
},
},
] as const satisfies readonly EmbedDefinition[]
/**