fix: Embeds not converted in collaborative editor

This commit is contained in:
Tom Moor committed 2021-08-30 18:17:09 -07:00
1 parent 26835cb7c4
commit 2e721f90ea
69 files changed
+68 -31

No files matched your search

+1 -1
View File
@@ -5,11 +5,11 @@ import { useTranslation } from "react-i18next";
import { withRouter, type RouterHistory } from "react-router-dom";
import { Extension } from "rich-markdown-editor";
import styled, { withTheme } from "styled-components";
import embeds from "shared/embeds";
import { light } from "shared/theme";
import UiStore from "stores/UiStore";
import ErrorBoundary from "components/ErrorBoundary";
import Tooltip from "components/Tooltip";
import embeds from "../embeds";
import useMediaQuery from "hooks/useMediaQuery";
import useToasts from "hooks/useToasts";
import { type Theme } from "types";
+1 -1
View File
@@ -2,8 +2,8 @@
import { observer } from "mobx-react";
import * as React from "react";
import { Helmet } from "react-helmet";
import { cdnPath } from "../../shared/utils/urls";
import useStores from "hooks/useStores";
import { cdnPath } from "utils/urls";
type Props = {|
title: string,
-9
View File
@@ -1,6 +1,5 @@
// @flow
import { parseDomain } from "../../shared/utils/domains";
import env from "env";
export function isInternalUrl(href: string) {
if (href[0] === "/") return true;
@@ -21,14 +20,6 @@ export function isInternalUrl(href: string) {
return false;
}
export function cdnPath(path: string): string {
return `${env.CDN_URL}${path}`;
}
export function imagePath(path: string): string {
return cdnPath(`/images/${path}`);
}
export function decodeURIComponentSafe(text: string) {
return text
? decodeURIComponent(text.replace(/%(?![0-9][0-9a-fA-F]+)/g, "%25"))
+1 -1
View File
@@ -150,7 +150,7 @@
"react-window": "^1.8.6",
"reakit": "^1.3.8",
"regenerator-runtime": "^0.13.7",
"rich-markdown-editor": "^11.17.3",
"rich-markdown-editor": "^11.17.4-0",
"semver": "^7.3.2",
"sequelize": "^6.3.4",
"sequelize-cli": "^6.2.0",
+2 -4
View File
@@ -1,11 +1,10 @@
// @flow
import debug from "debug";
import { debounce } from "lodash";
import { parser } from "rich-markdown-editor";
import { prosemirrorToYDoc } from "y-prosemirror";
import * as Y from "yjs";
import documentUpdater from "../commands/documentUpdater";
import { Document, User } from "../models";
import markdownToYDoc from "./utils/markdownToYDoc";
const log = debug("server");
const DELAY = 3000;
@@ -39,8 +38,7 @@ export default class Persistence {
}
log(`Document ${documentId} is not in state, creating state from markdown`);
const node = parser.parse(document.text);
return prosemirrorToYDoc(node, fieldName);
return markdownToYDoc(document.text, fieldName);
}
onChange = debounce(
@@ -0,0 +1,42 @@
// @flow
import { Node, Fragment } from "prosemirror-model";
import { parser, schema } from "rich-markdown-editor";
import { prosemirrorToYDoc } from "y-prosemirror";
import * as Y from "yjs";
import embeds from "../../../shared/embeds";
export default function markdownToYDoc(
markdown: string,
fieldName?: string = "default"
): Y.Doc {
let node = parser.parse(markdown);
// in rich-markdown-editor embeds were created at runtime by converting links
// into embeds where they match. Because we're converting to a CRDT structure
// on the server we need to mimic this behavior.
function urlsToEmbeds(node: Node): Node {
if (node.type.name === "paragraph") {
for (const textNode of node.content.content) {
for (const embed of embeds) {
if (embed.matcher(textNode.text)) {
return schema.nodes.embed.createAndFill({
href: textNode.text,
});
}
}
}
}
if (node.content) {
const contentAsArray =
node.content instanceof Fragment ? node.content.content : node.content;
node.content = Fragment.fromArray(contentAsArray.map(urlsToEmbeds));
}
return node;
}
node = urlsToEmbeds(node);
return prosemirrorToYDoc(node, fieldName);
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -1,7 +1,7 @@
// @flow
import * as React from "react";
import Image from "components/Image";
import Frame from "./components/Frame";
import Image from "./components/Image";
const URL_REGEX = new RegExp("^https://viewer.diagrams.net/.*(title=\\w+)?");
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -1,7 +1,7 @@
// @flow
import * as React from "react";
import Image from "components/Image";
import Frame from "./components/Frame";
import Image from "./components/Image";
const URL_REGEX = new RegExp(
"^https?://datastudio.google.com/(embed|u/0)/reporting/(.*)/page/(.*)(/edit)?$"
File renamed without changes.
@@ -1,7 +1,7 @@
// @flow
import * as React from "react";
import Image from "components/Image";
import Frame from "./components/Frame";
import Image from "./components/Image";
const URL_REGEX = new RegExp("^https?://docs.google.com/document/(.*)$");
File renamed without changes.
@@ -1,7 +1,7 @@
// @flow
import * as React from "react";
import Image from "components/Image";
import Frame from "./components/Frame";
import Image from "./components/Image";
const URL_REGEX = new RegExp(
"^https://docs.google.com/drawings/d/(.*)/(edit|preview)(.*)$"
File renamed without changes.
@@ -1,7 +1,7 @@
// @flow
import * as React from "react";
import Image from "components/Image";
import Frame from "./components/Frame";
import Image from "./components/Image";
const URL_REGEX = new RegExp(
"^https?://drive.google.com/file/d/(.*)/(preview|view).?usp=sharing(.*)"
File renamed without changes.
@@ -1,7 +1,7 @@
// @flow
import * as React from "react";
import Image from "components/Image";
import Frame from "./components/Frame";
import Image from "./components/Image";
const URL_REGEX = new RegExp("^https?://docs.google.com/spreadsheets/d/(.*)$");
File renamed without changes.
@@ -1,7 +1,7 @@
// @flow
import * as React from "react";
import Image from "components/Image";
import Frame from "./components/Frame";
import Image from "./components/Image";
const URL_REGEX = new RegExp("^https?://docs.google.com/presentation/d/(.*)$");
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -4,7 +4,6 @@ import { observer } from "mobx-react";
import { OpenIcon } from "outline-icons";
import * as React from "react";
import styled from "styled-components";
import Flex from "components/Flex";
// This wrapper allows us to pass non-standard HTML attributes through to the DOM element
// https://www.styled-components.com/docs/basics#passed-props
@@ -130,7 +129,8 @@ const Title = styled.span`
padding-left: 4px;
`;
const Bar = styled(Flex)`
const Bar = styled.div`
display: flex;
border-top: 1px solid ${(props) => props.theme.embedBorder};
background: ${(props) => props.theme.secondaryBackground};
color: ${(props) => props.theme.textSecondary};
@@ -1,6 +1,6 @@
// @flow
import * as React from "react";
import { cdnPath } from "utils/urls";
import { cdnPath } from "../../utils/urls";
type Props = {|
alt: string,
@@ -1,7 +1,6 @@
// @flow
import * as React from "react";
import styled from "styled-components";
import Image from "components/Image";
import Abstract from "./Abstract";
import Airtable from "./Airtable";
import Cawemo from "./Cawemo";
@@ -32,6 +31,7 @@ import Trello from "./Trello";
import Typeform from "./Typeform";
import Vimeo from "./Vimeo";
import YouTube from "./YouTube";
import Image from "./components/Image";
function matcher(Component) {
return (url: string) => {
+6
View File
@@ -0,0 +1,6 @@
// @flow
const env = typeof window !== "undefined" ? window.env : process.env;
export function cdnPath(path: string): string {
return `${env.CDN_URL}${path}`;
}
+4 -4
View File
@@ -12295,10 +12295,10 @@ retry-as-promised@^3.2.0:
dependencies:
any-promise "^1.3.0"
rich-markdown-editor@^11.17.3:
version "11.17.3"
resolved "https://registry.yarnpkg.com/rich-markdown-editor/-/rich-markdown-editor-11.17.3.tgz#be6831f77eebaa55b250677490d68229fff98a2f"
integrity sha512-8ISpruzocSVrkoiSgCwrKoB/YGb8/Ue/f04CfBJw6SMGUXB2rSSZVoRtHaH5QKS1dtsg8BJguu1llBkny3jkGw==
rich-markdown-editor@^11.17.4-0:
version "11.17.4-0"
resolved "https://registry.yarnpkg.com/rich-markdown-editor/-/rich-markdown-editor-11.17.4-0.tgz#81530e4416a3fc7bf76fed9a0f1f98260dffed81"
integrity sha512-s3SVatk6KVz8FTk7vDlSiJewA9gCq/vjBDhP1RsZiiYfaPDDEgxJf0XM1U01g0czEjTXkowrPp5GEbepSHdKsg==
dependencies:
copy-to-clipboard "^3.0.8"
lodash "^4.17.11"