Skip to content

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

editor: add rtl support in embed

Abdullah Atta0ae24d12d805
diff --git a/packages/editor/src/extensions/embed/component.tsx b/packages/editor/src/extensions/embed/component.tsx
index daf674add..7757bcc21 100644
--- a/packages/editor/src/extensions/embed/component.tsx
+++ b/packages/editor/src/extensions/embed/component.tsx
@@ -34,115 +34,114 @@ export function EmbedComponent(
const { editor, updateAttributes, selected, node } = props;
const [isLoading, setIsLoading] = useState(true);
const embedRef = useRef<HTMLIFrameElement>(null);
- const { src, width, height, align } = node.attrs;
+ const { src, width, height, textDirection } = node.attrs;
+
+ let align = node.attrs.align;
+ if (!align) align = textDirection ? "right" : "left";
return (
- <>
- <Box
- sx={{
- display: "flex",
- flexDirection: "column",
- justifyContent:
- align === "center" ? "center" : align === "left" ? "start" : "end",
- position: "relative"
+ <Flex
+ sx={{
+ justifyContent:
+ align === "center" ? "center" : align === "left" ? "start" : "end",
+ position: "relative"
+ }}
+ >
+ <Resizer
+ handleColor="primary"
+ editor={editor}
+ selected={selected}
+ width={width}
+ height={height}
+ onResize={(width, height) => {
+ updateAttributes(
+ {
+ width,
+ height
+ },
+ { addToHistory: true, preventUpdate: false }
+ );
}}
>
- <Resizer
- handleColor="primary"
- editor={editor}
- selected={selected}
- width={width}
- height={height}
- onResize={(width, height) => {
- updateAttributes(
- {
- width,
- height
- },
- { addToHistory: true, preventUpdate: false }
- );
+ <Box
+ sx={{
+ width: "100%",
+ display: editor.isEditable ? "flex" : "none",
+ position: "absolute",
+ top: -24,
+ justifyContent: "end",
+ p: "small",
+ bg: editor.isEditable ? "bgSecondary" : "transparent",
+ borderTopLeftRadius: "default",
+ borderTopRightRadius: "default",
+ borderColor: selected ? "border" : "bgSecondary",
+ cursor: "pointer",
+ ":hover": {
+ borderColor: "border"
+ }
}}
>
- <Box
- sx={{
- width: "100%",
- display: editor.isEditable ? "flex" : "none",
- position: "absolute",
- top: -24,
- justifyContent: "end",
- p: "small",
- bg: editor.isEditable ? "bgSecondary" : "transparent",
- borderTopLeftRadius: "default",
- borderTopRightRadius: "default",
- borderColor: selected ? "border" : "bgSecondary",
- cursor: "pointer",
- ":hover": {
- borderColor: "border"
- }
- }}
- >
- <Icon path={Icons.dragHandle} size={"big"} />
- <DesktopOnly>
- {selected && (
- <Flex sx={{ position: "relative", justifyContent: "end" }}>
- <Flex
+ <Icon path={Icons.dragHandle} size={"big"} />
+ <DesktopOnly>
+ {selected && (
+ <Flex sx={{ position: "relative", justifyContent: "end" }}>
+ <Flex
+ sx={{
+ position: "absolute",
+ top: -10,
+ mb: 2,
+ alignItems: "end"
+ }}
+ >
+ <ToolbarGroup
+ editor={editor}
+ tools={[
+ "embedAlignLeft",
+ "embedAlignCenter",
+ "embedAlignRight",
+ "embedProperties"
+ ]}
sx={{
- position: "absolute",
- top: -10,
- mb: 2,
- alignItems: "end"
+ boxShadow: "menu",
+ borderRadius: "default",
+ bg: "background"
}}
- >
- <ToolbarGroup
- editor={editor}
- tools={[
- "embedAlignLeft",
- "embedAlignCenter",
- "embedAlignRight",
- "embedProperties"
- ]}
- sx={{
- boxShadow: "menu",
- borderRadius: "default",
- bg: "background"
- }}
- />
- </Flex>
+ />
</Flex>
- )}
- </DesktopOnly>
- </Box>
- <Embed
- ref={embedRef}
- src={src}
- width={"100%"}
- height={"100%"}
+ </Flex>
+ )}
+ </DesktopOnly>
+ </Box>
+ <Embed
+ ref={embedRef}
+ src={src}
+ width={"100%"}
+ height={"100%"}
+ sx={{
+ bg: "bgSecondary",
+ border: selected
+ ? "2px solid var(--primary)"
+ : "2px solid transparent",
+ borderRadius: "default"
+ }}
+ onLoad={() => setIsLoading(false)}
+ {...props}
+ />
+ {isLoading && (
+ <Flex
sx={{
- bg: "bgSecondary",
- border: selected
- ? "2px solid var(--primary)"
- : "2px solid transparent",
- borderRadius: "default"
+ position: "absolute",
+ bottom: 0,
+ width: "100%",
+ height: "calc(100% - 20px)",
+ alignItems: "center",
+ justifyContent: "center"
}}
- onLoad={() => setIsLoading(false)}
- {...props}
- />
- {isLoading && (
- <Flex
- sx={{
- position: "absolute",
- bottom: 0,
- width: "100%",
- height: "calc(100% - 20px)",
- alignItems: "center",
- justifyContent: "center"
- }}
- >
- <Icon path={Icons.loading} rotate size={32} color="disabled" />
- </Flex>
- )}
- </Resizer>
- </Box>
- </>
+ >
+ <Icon path={Icons.loading} rotate size={32} color="disabled" />
+ </Flex>
+ )}
+ </Resizer>
+ </Flex>
);
}
diff --git a/packages/editor/src/extensions/embed/embed.ts b/packages/editor/src/extensions/embed/embed.ts
index 8c28ae0bc..ee061e965 100644
--- a/packages/editor/src/extensions/embed/embed.ts
+++ b/packages/editor/src/extensions/embed/embed.ts
@@ -19,6 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
import { Node, mergeAttributes } from "@tiptap/core";
import { createSelectionBasedNodeView } from "../react";
+import { TextDirections } from "../text-direction";
import { EmbedComponent } from "./component";
export interface EmbedOptions {
@@ -31,6 +32,7 @@ export type EmbedAttributes = Partial<EmbedSizeOptions> & {
export type EmbedAlignmentOptions = {
align?: "center" | "left" | "right";
+ textDirection?: TextDirections;
};
export type Embed = Required<EmbedAttributes> & EmbedAlignmentOptions;
@@ -78,7 +80,7 @@ export const EmbedNode = Node.create<EmbedOptions>({
},
width: { default: null },
height: { default: null },
- align: { default: "left" }
+ align: { default: undefined }
};
},