mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-09-12 20:10:09 +02:00
Compare commits
2 Commits
zsviczian-
...
zsviczian-
Author | SHA1 | Date | |
---|---|---|---|
![]() |
5c8adfa1a9 | ||
![]() |
a977dd1bf5 |
@@ -3857,40 +3857,53 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
|
|
||||||
public getEditorUIOffsets = (): Offsets => {
|
public getEditorUIOffsets = (): Offsets => {
|
||||||
const toolbarBottom =
|
const toolbarBottom =
|
||||||
this.excalidrawContainerRef?.current
|
(this.excalidrawContainerRef?.current
|
||||||
?.querySelector(".App-toolbar")
|
?.querySelector(".App-toolbar")
|
||||||
?.getBoundingClientRect()?.bottom ?? 0;
|
?.getBoundingClientRect()?.bottom ?? 0) - this.state.offsetTop;
|
||||||
const sidebarRect = this.excalidrawContainerRef?.current
|
const sidebarRect = this.excalidrawContainerRef?.current
|
||||||
?.querySelector(".sidebar")
|
?.querySelector(".sidebar")
|
||||||
?.getBoundingClientRect();
|
?.getBoundingClientRect();
|
||||||
const propertiesPanelRect = this.excalidrawContainerRef?.current
|
const propertiesPanelRect = this.excalidrawContainerRef?.current
|
||||||
?.querySelector(".App-menu__left")
|
?.querySelector(".App-menu__left")
|
||||||
?.getBoundingClientRect();
|
?.getBoundingClientRect();
|
||||||
|
|
||||||
const PADDING = 16;
|
const PADDING = 16;
|
||||||
|
|
||||||
|
const adjustRectValueForOffset = (
|
||||||
|
value: number | undefined,
|
||||||
|
fallback: number,
|
||||||
|
) => (value ?? fallback + this.state.offsetLeft) - this.state.offsetLeft;
|
||||||
|
|
||||||
return getLanguage().rtl
|
return getLanguage().rtl
|
||||||
? {
|
? {
|
||||||
top: toolbarBottom + PADDING,
|
top: toolbarBottom + PADDING,
|
||||||
right:
|
right:
|
||||||
Math.max(
|
Math.max(
|
||||||
this.state.width -
|
this.state.width -
|
||||||
(propertiesPanelRect?.left ?? this.state.width),
|
adjustRectValueForOffset(
|
||||||
|
propertiesPanelRect?.left,
|
||||||
|
this.state.width,
|
||||||
|
),
|
||||||
0,
|
0,
|
||||||
) + PADDING,
|
) + PADDING,
|
||||||
bottom: PADDING,
|
bottom: PADDING,
|
||||||
left: Math.max(sidebarRect?.right ?? 0, 0) + PADDING,
|
left:
|
||||||
|
Math.max(adjustRectValueForOffset(sidebarRect?.right, 0), 0) +
|
||||||
|
PADDING,
|
||||||
}
|
}
|
||||||
: {
|
: {
|
||||||
top: toolbarBottom + PADDING,
|
top: toolbarBottom + PADDING,
|
||||||
right: Math.max(
|
right: Math.max(
|
||||||
this.state.width -
|
this.state.width -
|
||||||
(sidebarRect?.left ?? this.state.width) +
|
adjustRectValueForOffset(sidebarRect?.left, this.state.width) +
|
||||||
PADDING,
|
PADDING,
|
||||||
0,
|
0,
|
||||||
),
|
),
|
||||||
bottom: PADDING,
|
bottom: PADDING,
|
||||||
left: Math.max(propertiesPanelRect?.right ?? 0, 0) + PADDING,
|
left:
|
||||||
|
Math.max(
|
||||||
|
adjustRectValueForOffset(propertiesPanelRect?.right, 0),
|
||||||
|
0,
|
||||||
|
) + PADDING,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -190,7 +190,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
$theme-filter: "invert(93%) hue-rotate(180deg)";
|
$theme-filter: "invert(93%) hue-rotate(180deg)";
|
||||||
$right-sidebar-width: "19rem";
|
$right-sidebar-width: "302px";
|
||||||
|
|
||||||
:export {
|
:export {
|
||||||
themeFilter: unquote($theme-filter);
|
themeFilter: unquote($theme-filter);
|
||||||
|
@@ -45,6 +45,12 @@ const RE_GENERIC_EMBED =
|
|||||||
const RE_GIPHY =
|
const RE_GIPHY =
|
||||||
/giphy.com\/(?:clips|embed|gifs)\/[a-zA-Z0-9]*?-?([a-zA-Z0-9]+)(?:[^a-zA-Z0-9]|$)/;
|
/giphy.com\/(?:clips|embed|gifs)\/[a-zA-Z0-9]*?-?([a-zA-Z0-9]+)(?:[^a-zA-Z0-9]|$)/;
|
||||||
|
|
||||||
|
const RE_REDDIT =
|
||||||
|
/^(?:http(?:s)?:\/\/)?(?:www\.)?reddit\.com\/r\/([a-zA-Z0-9_]+)\/comments\/([a-zA-Z0-9_]+)\/([a-zA-Z0-9_]+)\/?(?:\?[^#\s]*)?(?:#[^\s]*)?$/;
|
||||||
|
|
||||||
|
const RE_REDDIT_EMBED =
|
||||||
|
/^<blockquote[\s\S]*?\shref=["'](https?:\/\/(?:www\.)?reddit\.com\/[^"']*)/i;
|
||||||
|
|
||||||
const ALLOWED_DOMAINS = new Set([
|
const ALLOWED_DOMAINS = new Set([
|
||||||
"youtube.com",
|
"youtube.com",
|
||||||
"youtu.be",
|
"youtu.be",
|
||||||
@@ -59,6 +65,7 @@ const ALLOWED_DOMAINS = new Set([
|
|||||||
"stackblitz.com",
|
"stackblitz.com",
|
||||||
"val.town",
|
"val.town",
|
||||||
"giphy.com",
|
"giphy.com",
|
||||||
|
"reddit.com",
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const ALLOW_SAME_ORIGIN = new Set([
|
const ALLOW_SAME_ORIGIN = new Set([
|
||||||
@@ -71,6 +78,7 @@ const ALLOW_SAME_ORIGIN = new Set([
|
|||||||
"x.com",
|
"x.com",
|
||||||
"*.simplepdf.eu",
|
"*.simplepdf.eu",
|
||||||
"stackblitz.com",
|
"stackblitz.com",
|
||||||
|
"reddit.com",
|
||||||
]);
|
]);
|
||||||
|
|
||||||
export const createSrcDoc = (body: string) => {
|
export const createSrcDoc = (body: string) => {
|
||||||
@@ -218,6 +226,24 @@ export const getEmbedLink = (
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (RE_REDDIT.test(link)) {
|
||||||
|
const [, page, postId, title] = link.match(RE_REDDIT)!;
|
||||||
|
const safeURL = sanitizeHTMLAttribute(
|
||||||
|
`https://reddit.com/r/${page}/comments/${postId}/${title}`,
|
||||||
|
);
|
||||||
|
const ret: IframeDataWithSandbox = {
|
||||||
|
type: "document",
|
||||||
|
srcdoc: (theme: string) =>
|
||||||
|
createSrcDoc(
|
||||||
|
`<blockquote class="reddit-embed-bq" data-embed-theme="${theme}"><a href="${safeURL}"></a><br></blockquote><script async="" src="https://embed.reddit.com/widgets.js" charset="UTF-8"></script>`,
|
||||||
|
),
|
||||||
|
intrinsicSize: { w: 480, h: 480 },
|
||||||
|
sandbox: { allowSameOrigin },
|
||||||
|
};
|
||||||
|
embeddedLinkCache.set(originalLink, ret);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
if (RE_GH_GIST.test(link)) {
|
if (RE_GH_GIST.test(link)) {
|
||||||
const [, user, gistId] = link.match(RE_GH_GIST)!;
|
const [, user, gistId] = link.match(RE_GH_GIST)!;
|
||||||
const safeURL = sanitizeHTMLAttribute(
|
const safeURL = sanitizeHTMLAttribute(
|
||||||
@@ -361,6 +387,11 @@ export const maybeParseEmbedSrc = (str: string): string => {
|
|||||||
return twitterMatch[1];
|
return twitterMatch[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const redditMatch = str.match(RE_REDDIT_EMBED);
|
||||||
|
if (redditMatch && redditMatch.length === 2) {
|
||||||
|
return redditMatch[1];
|
||||||
|
}
|
||||||
|
|
||||||
const gistMatch = str.match(RE_GH_GIST_EMBED);
|
const gistMatch = str.match(RE_GH_GIST_EMBED);
|
||||||
if (gistMatch && gistMatch.length === 2) {
|
if (gistMatch && gistMatch.length === 2) {
|
||||||
return gistMatch[1];
|
return gistMatch[1];
|
||||||
|
Reference in New Issue
Block a user