Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

fix: always access editor instance via editor.current

thecodrr21c16b8f73ca
diff --git a/packages/editor/dist/toolbar/popups/embedpopup.js b/packages/editor/dist/toolbar/popups/embedpopup.js
index 256776f7e..e4756d8bf 100644
--- a/packages/editor/dist/toolbar/popups/embedpopup.js
+++ b/packages/editor/dist/toolbar/popups/embedpopup.js
@@ -30,6 +30,7 @@ import { Flex, Text } from "rebass";
import { useCallback, useEffect, useState } from "react";
import { Popup } from "../components/popup";
import { Input, Textarea } from "@rebass/forms";
+import { convertUrlToEmbedUrl } from "@social-embed/lib";
import { InlineInput } from "../../components/inline-input";
import { Tabs, Tab } from "../../components/tabs";
export function EmbedPopup(props) {
@@ -62,7 +63,38 @@ export function EmbedPopup(props) {
useEffect(function () {
onSourceChanged && onSourceChanged(src);
}, [onSourceChanged, src]);
- return (_jsx(Popup, __assign({ title: title, onClose: function () { return onClose(); }, action: { title: title, onClick: function () { return onClose(); } } }, { children: _jsxs(Flex, __assign({ sx: { flexDirection: "column", width: ["auto", 300] } }, { children: [error && (_jsxs(Text, __assign({ variant: "error", sx: {
+ return (_jsx(Popup, __assign({ title: title, onClose: function () { return onClose(); }, action: {
+ title: title,
+ onClick: function () {
+ setError(null);
+ var _src = src;
+ var _width = width;
+ var _height = height;
+ if (embedSource === "code") {
+ var document_1 = new DOMParser().parseFromString(src, "text/html");
+ if (document_1.getElementsByTagName("iframe").length <= 0)
+ return setError("Embed code must include an iframe.");
+ var srcValue = getAttribute(document_1, "src");
+ if (!srcValue)
+ return setError("Embed code must include an iframe with an src attribute.");
+ _src = srcValue;
+ var widthValue = getAttribute(document_1, "width");
+ if (widthValue && !isNaN(parseInt(widthValue)))
+ _width = parseInt(widthValue);
+ var heightValue = getAttribute(document_1, "height");
+ if (heightValue && !isNaN(parseInt(heightValue)))
+ _height = parseInt(heightValue);
+ }
+ var convertedUrl = convertUrlToEmbedUrl(_src);
+ if (!!convertedUrl)
+ _src = convertedUrl;
+ onClose({
+ height: _height,
+ width: _width,
+ src: _src,
+ });
+ },
+ } }, { children: _jsxs(Flex, __assign({ sx: { flexDirection: "column", width: ["auto", 300] } }, { children: [error && (_jsxs(Text, __assign({ variant: "error", sx: {
bg: "errorBg",
color: "error",
p: 1,
diff --git a/packages/editor/dist/toolbar/tools/embed.js b/packages/editor/dist/toolbar/tools/embed.js
index d12c9ab41..903da19d9 100644
--- a/packages/editor/dist/toolbar/tools/embed.js
+++ b/packages/editor/dist/toolbar/tools/embed.js
@@ -75,5 +75,5 @@ export function EmbedProperties(props) {
location: "below",
yOffset: 10,
isTargetAbsolute: true,
- } }, { children: _jsx(EmbedPopup, { title: "Embed properties", onClose: function () { return setIsOpen(false); }, embed: embed, onSourceChanged: function (src) { return editor.commands.setEmbedSource(src); }, onSizeChanged: function (size) { return editor.commands.setEmbedSize(size); } }) }))] }));
+ } }, { children: _jsx(EmbedPopup, { title: "Embed properties", onClose: function () { return setIsOpen(false); }, embed: embed, onSourceChanged: function (src) { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.commands.setEmbedSource(src); }, onSizeChanged: function (size) { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.commands.setEmbedSize(size); } }) }))] }));
}
diff --git a/packages/editor/dist/toolbar/tools/link.js b/packages/editor/dist/toolbar/tools/link.js
index d4c51b841..b20b6126e 100644
--- a/packages/editor/dist/toolbar/tools/link.js
+++ b/packages/editor/dist/toolbar/tools/link.js
@@ -105,10 +105,10 @@ export function EditLink(props) {
export function RemoveLink(props) {
var editor = props.editor, selectedNode = props.selectedNode;
return (_jsx(ToolButton, __assign({}, props, { toggled: false, onClick: function () {
- var _a;
+ var _a, _b;
if (selectedNode)
- editor.commands.setTextSelection(selectedNode.from);
- (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().unsetLink().run();
+ (_a = editor.current) === null || _a === void 0 ? void 0 : _a.commands.setTextSelection(selectedNode.from);
+ (_b = editor.current) === null || _b === void 0 ? void 0 : _b.chain().focus().unsetLink().run();
} })));
}
export function OpenLink(props) {
diff --git a/packages/editor/src/toolbar/popups/embed-popup.tsx b/packages/editor/src/toolbar/popups/embed-popup.tsx
index a0a92251c..7fe425a39 100644
--- a/packages/editor/src/toolbar/popups/embed-popup.tsx
+++ b/packages/editor/src/toolbar/popups/embed-popup.tsx
@@ -64,7 +64,43 @@ export function EmbedPopup(props: EmbedPopupProps) {
<Popup
title={title}
onClose={() => onClose()}
- action={{ title, onClick: () => onClose() }}
+ action={{
+ title,
+ onClick: () => {
+ setError(null);
+ let _src = src;
+ let _width = width;
+ let _height = height;
+ if (embedSource === "code") {
+ const document = new DOMParser().parseFromString(src, "text/html");
+ if (document.getElementsByTagName("iframe").length <= 0)
+ return setError("Embed code must include an iframe.");
+
+ const srcValue = getAttribute(document, "src");
+ if (!srcValue)
+ return setError(
+ "Embed code must include an iframe with an src attribute."
+ );
+
+ _src = srcValue;
+
+ const widthValue = getAttribute(document, "width");
+ if (widthValue && !isNaN(parseInt(widthValue)))
+ _width = parseInt(widthValue);
+
+ const heightValue = getAttribute(document, "height");
+ if (heightValue && !isNaN(parseInt(heightValue)))
+ _height = parseInt(heightValue);
+ }
+ const convertedUrl = convertUrlToEmbedUrl(_src);
+ if (!!convertedUrl) _src = convertedUrl;
+ onClose({
+ height: _height,
+ width: _width,
+ src: _src,
+ });
+ },
+ }}
>
<Flex sx={{ flexDirection: "column", width: ["auto", 300] }}>
{error && (
@@ -131,56 +167,6 @@ export function EmbedPopup(props: EmbedPopupProps) {
/>
</Tab>
</Tabs>
-
- {/* <Button
- variant={"primary"}
- sx={{
- alignSelf: ["stretch", "end", "end"],
- my: 1,
- mr: 1,
- ml: [1, 0],
- py: 2,
- }}
- onClick={() => {
- setError(null);
- let _src = src;
- let _width = width;
- let _height = height;
- if (embedSource === "code") {
- const document = new DOMParser().parseFromString(
- src,
- "text/html"
- );
- if (document.getElementsByTagName("iframe").length <= 0)
- return setError("Embed code must include an iframe.");
-
- const srcValue = getAttribute(document, "src");
- if (!srcValue)
- return setError(
- "Embed code must include an iframe with an src attribute."
- );
-
- _src = srcValue;
-
- const widthValue = getAttribute(document, "width");
- if (widthValue && !isNaN(parseInt(widthValue)))
- _width = parseInt(widthValue);
-
- const heightValue = getAttribute(document, "height");
- if (heightValue && !isNaN(parseInt(heightValue)))
- _height = parseInt(heightValue);
- }
- const convertedUrl = convertUrlToEmbedUrl(_src);
- if (!!convertedUrl) _src = convertedUrl;
- onClose({
- height: _height,
- width: _width,
- src: _src,
- });
- }}
- >
- {title}
- </Button> */}
</Flex>
</Popup>
);
diff --git a/packages/editor/src/toolbar/tools/embed.tsx b/packages/editor/src/toolbar/tools/embed.tsx
index 762a4b4d7..7512f5925 100644
--- a/packages/editor/src/toolbar/tools/embed.tsx
+++ b/packages/editor/src/toolbar/tools/embed.tsx
@@ -113,8 +113,10 @@ export function EmbedProperties(props: ToolProps) {
title="Embed properties"
onClose={() => setIsOpen(false)}
embed={embed}
- onSourceChanged={(src) => editor.commands.setEmbedSource(src)}
- onSizeChanged={(size) => editor.commands.setEmbedSize(size)}
+ onSourceChanged={(src) =>
+ editor.current?.commands.setEmbedSource(src)
+ }
+ onSizeChanged={(size) => editor.current?.commands.setEmbedSize(size)}
/>
</ResponsivePresenter>
</>
diff --git a/packages/editor/src/toolbar/tools/link.tsx b/packages/editor/src/toolbar/tools/link.tsx
index a5c53c8e7..7abff9e7c 100644
--- a/packages/editor/src/toolbar/tools/link.tsx
+++ b/packages/editor/src/toolbar/tools/link.tsx
@@ -111,7 +111,8 @@ export function RemoveLink(props: ToolProps) {
{...props}
toggled={false}
onClick={() => {
- if (selectedNode) editor.commands.setTextSelection(selectedNode.from);
+ if (selectedNode)
+ editor.current?.commands.setTextSelection(selectedNode.from);
editor.current?.chain().focus().unsetLink().run();
}}
/>